chiark / gitweb /
execute: introduce exec_command_set() for easy setting for command lines
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 15:46:41 +0000 (17:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 16:00:34 +0000 (18:00 +0200)
execute.c
execute.h

index 46a9832..6cf6615 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -1061,6 +1061,34 @@ void exec_command_append_list(ExecCommand **l, ExecCommand *e) {
               *l = e;
 }
 
+int exec_command_set(ExecCommand *c, const char *path, ...) {
+        va_list ap;
+        char **l, *p;
+
+        assert(c);
+        assert(path);
+
+        va_start(ap, path);
+        l = strv_new_ap(path, ap);
+        va_end(ap);
+
+        if (!l)
+                return -ENOMEM;
+
+        if (!(p = strdup(path))) {
+                strv_free(l);
+                return -ENOMEM;
+        }
+
+        free(c->path);
+        c->path = p;
+
+        strv_free(c->argv);
+        c->argv = l;
+
+        return 0;
+}
+
 static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = {
         [EXEC_OUTPUT_CONSOLE] = "console",
         [EXEC_OUTPUT_NULL] = "null",
index 8275d63..1894817 100644 (file)
--- a/execute.h
+++ b/execute.h
@@ -169,6 +169,7 @@ char *exec_command_line(ExecCommand *c);
 void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
 void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
 void exec_command_append_list(ExecCommand **l, ExecCommand *e);
+int exec_command_set(ExecCommand *c, const char *path, ...);
 
 void exec_context_init(ExecContext *c);
 void exec_context_done(ExecContext *c);