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