summaryrefslogtreecommitdiff
path: root/execute.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-26 07:02:51 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-26 07:02:51 +0100
commit44d8db9e5aa86165c97289f6c78a7e42bac78362 (patch)
treedc17149a1d8286eea1fb40b101ca2706a5427dc0 /execute.c
parent75787bb7136e064ee623aaee00ec76a7f024c91a (diff)
various cleanups
Diffstat (limited to 'execute.c')
-rw-r--r--execute.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/execute.c b/execute.c
index 8cd4f60cdd..bcaa4e959d 100644
--- a/execute.c
+++ b/execute.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <string.h>
#include "execute.h"
#include "strv.h"
@@ -235,7 +236,7 @@ void exec_command_free_list(ExecCommand *c) {
LIST_REMOVE(ExecCommand, command, c, i);
free(i->path);
- free(i->argv);
+ strv_free(i->argv);
free(i);
}
}
@@ -276,3 +277,69 @@ void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status) {
s->status = status;
s->timestamp = now(CLOCK_REALTIME);
}
+
+char *exec_command_line(ExecCommand *c) {
+ size_t k;
+ char *n, *p, **a;
+ bool first = true;
+
+ assert(c);
+ assert(c->argv);
+
+ k = 0;
+ STRV_FOREACH(a, c->argv)
+ k += strlen(*a)+3;
+
+ if (!(n = new(char, k)))
+ return NULL;
+
+ p = n;
+ STRV_FOREACH(a, c->argv) {
+
+ if (!first)
+ *(p++) = ' ';
+ else
+ first = false;
+
+ if (strpbrk(*a, WHITESPACE)) {
+ *(p++) = '\'';
+ p = stpcpy(p, *a);
+ *(p++) = '\'';
+ } else
+ p = stpcpy(p, *a);
+
+ }
+
+ /* FIXME: this doesn't really handle arguments that have
+ * spaces and ticks in them */
+
+ return n;
+}
+
+void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix) {
+ char *cmd;
+
+ assert(c);
+ assert(f);
+
+ if (!prefix)
+ prefix = "";
+
+ cmd = exec_command_line(c);
+
+ fprintf(f,
+ "%sCommand Line: %s\n",
+ prefix, cmd ? cmd : strerror(ENOMEM));
+
+ free(cmd);
+}
+
+void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix) {
+ assert(f);
+
+ if (!prefix)
+ prefix = "";
+
+ LIST_FOREACH(command, c, c)
+ exec_command_dump(c, f, prefix);
+}