2 * Sherlock Library -- Running of Commands
4 * (c) 2004 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
19 exec_command_v(byte *cmd, va_list args)
24 while (arg = va_arg(cargs, byte *))
26 char **argv = alloca(sizeof(byte *) * cnt);
30 while (arg = va_arg(cargs, byte *))
35 echo_command_v(echo, sizeof(echo), cmd, args);
36 log(L_ERROR, "Cannot execute %s: %m", echo);
41 run_command_v(byte *cmd, va_list args)
46 log(L_ERROR, "fork() failed: %m");
50 exec_command_v(cmd, args);
54 byte msg[EXIT_STATUS_MSG_SIZE];
55 p = waitpid(p, &stat, 0);
57 die("waitpid() failed: %m");
58 if (format_exit_status(msg, stat))
61 echo_command_v(echo, sizeof(echo), cmd, args);
62 log(L_ERROR, "`%s' failed: %s", echo, msg);
70 echo_command_v(byte *buf, int size, byte *cmd, va_list args)
72 byte *limit = buf + size - 4;
79 if (p != buf && p < limit)
83 memcpy(p, arg, limit-p);
90 while (arg = va_arg(cargs, byte *));
95 run_command(byte *cmd, ...)
99 int e = run_command_v(cmd, args);
105 exec_command(byte *cmd, ...)
109 exec_command_v(cmd, args);
113 echo_command(byte *buf, int len, byte *cmd, ...)
117 echo_command_v(buf, len, cmd, args);
126 echo_command(msg, sizeof(msg), "/bin/echo", "datel", "strakapoud", NULL);
127 log(L_INFO, "Running <%s>", msg);
128 run_command("/bin/echo", "datel", "strakapoud", NULL);