lib/process: Add dry_run argument to process_init
authorJeremy Kerr <jk@ozlabs.org>
Tue, 20 Aug 2013 02:14:22 +0000 (10:14 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 20 Aug 2013 02:14:44 +0000 (10:14 +0800)
Implement dry-run behaviour on the discover server by passing a bool to
process_init. UIs don't need to support dry runs.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/pb-discover.c
lib/process/process.c
lib/process/process.h
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/twin/pbt-client.c

index 61da5097035ff6aedf12f6ba2c3b6692a790c170..6d62e14db2b931e20afdeb55f82cebb0a8b9e31b 100644 (file)
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
        if (!server)
                return EXIT_FAILURE;
 
-       procset = process_init(server, waitset);
+       procset = process_init(server, waitset, opts.dry_run == opt_yes);
        if (!procset)
                return EXIT_FAILURE;
 
index e1a158b0799519e391aa310228a3c8670cad7e47..6fac6492eeedd2524c71de8d4ee620a73cc3b47b 100644 (file)
@@ -29,6 +29,7 @@ struct procset {
        struct list             async_list;
        int                     sigchld_pipe[2];
        struct waiter           *sigchld_waiter;
+       bool                    dry_run;
 };
 
 /* Internal data type for process handling
@@ -245,13 +246,14 @@ static int process_fini(void *p)
        return 0;
 }
 
-struct procset *process_init(void *ctx, struct waitset *set)
+struct procset *process_init(void *ctx, struct waitset *set, bool dry_run)
 {
        struct sigaction sa;
        int rc;
 
        procset = talloc(ctx, struct procset);
        procset->waitset = set;
+       procset->dry_run = dry_run;
        list_init(&procset->async_list);
 
        rc = pipe(procset->sigchld_pipe);
@@ -330,6 +332,8 @@ static int process_run_common(struct process_info *procinfo)
 
        if (pid == 0) {
                process_setup_stdout_child(procinfo);
+               if (procset->dry_run)
+                       exit(EXIT_SUCCESS);
                execvp(process->path, (char * const *)process->argv);
                exit(EXIT_FAILURE);
        }
index 9e2a2d1b013c31c6eeb8af153ddbb54071bbe04d..caeda92131327d862492ade1b65acbaa56348e9c 100644 (file)
@@ -47,7 +47,7 @@ struct process {
  * process_create. The pointer returned can be talloc_free()-ed, or can be
  * automatically freed through destruction of the ctx talloc tree.
  */
-struct procset *process_init(void *ctx, struct waitset *set);
+struct procset *process_init(void *ctx, struct waitset *set, bool dry_run);
 
 struct process *process_create(void *ctx);
 
index b09f0309bb001fda9671737496278e723e259834..4f7b121b21ec760be378de3b4ccf78cf94ec11e6 100644 (file)
@@ -508,7 +508,7 @@ struct cui *cui_init(void* platform_info,
        cui->platform_info = platform_info;
        cui->waitset = waitset_create(cui);
 
-       process_init(cui, cui->waitset);
+       process_init(cui, cui->waitset, false);
 
        setlocale(LC_ALL, "");
 
index a5ac5d5f427e7aee92ffbd86d8fa72de44f4c5a3..4c13ddfd115f0723d39a4723a92c79768f1a4e4f 100644 (file)
@@ -62,7 +62,8 @@ struct cui {
 };
 
 struct cui *cui_init(void* platform_info,
-       int (*js_map)(const struct js_event *e), int start_deamon);
+               int (*js_map)(const struct js_event *e),
+               int start_deamon);
 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
 int cui_boot_editor_run(struct pmenu_item *item);
index 20ce31a4589390748e435ad4d21150a9c7100d00..dba61108fea6df7e137527aa0ee6229f900e5855 100644 (file)
@@ -270,7 +270,7 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
 
        pbt_client->waitset = waitset_create(pbt_client);
 
-       process_init(pbt_client, pbt_client->waitset);
+       process_init(pbt_client, pbt_client->waitset, false);
 
        pbt_client->sig = "pbt_client";
        pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset,