2 * UCW 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)
25 while (arg = va_arg(cargs, byte *))
28 char **argv = alloca(sizeof(byte *) * cnt);
32 while (arg = va_arg(cargs, byte *))
38 echo_command_v(echo, sizeof(echo), cmd, args);
39 log(L_ERROR, "Cannot execute %s: %m", echo);
44 run_command_v(byte *cmd, va_list args)
49 log(L_ERROR, "fork() failed: %m");
53 exec_command_v(cmd, args);
57 byte msg[EXIT_STATUS_MSG_SIZE];
58 p = waitpid(p, &stat, 0);
60 die("waitpid() failed: %m");
61 if (format_exit_status(msg, stat))
64 echo_command_v(echo, sizeof(echo), cmd, args);
65 log(L_ERROR, "`%s' failed: %s", echo, msg);
73 echo_command_v(byte *buf, int size, byte *cmd, va_list args)
75 byte *limit = buf + size - 4;
81 if (p != buf && p < limit)
85 memcpy(p, arg, limit-p);
92 while (arg = va_arg(args, byte *));
97 run_command(byte *cmd, ...)
101 int e = run_command_v(cmd, args);
107 exec_command(byte *cmd, ...)
111 exec_command_v(cmd, args);
115 echo_command(byte *buf, int len, byte *cmd, ...)
119 echo_command_v(buf, len, cmd, args);
128 echo_command(msg, sizeof(msg), "/bin/echo", "datel", "strakapoud", NULL);
129 log(L_INFO, "Running <%s>", msg);
130 run_command("/bin/echo", "datel", "strakapoud", NULL);