From 604a1ccf072f9f33326fb6dc919c1b6233d40866 Mon Sep 17 00:00:00 2001 From: Geoff Levand Date: Thu, 8 Mar 2012 20:48:21 -0800 Subject: Add --start-daemon option to ui programs Add the option --start-daemon to automatically start pb-discover if it is not already started. For use when running as a stand-alone app. Signed-off-by: Geoff Levand --- ui/common/loader.c | 10 +++++----- ui/common/ui-system.c | 30 +++++++++++++++++++++++++++--- ui/common/ui-system.h | 1 + 3 files changed, 33 insertions(+), 8 deletions(-) (limited to 'ui/common') diff --git a/ui/common/loader.c b/ui/common/loader.c index 5c69533..009871d 100644 --- a/ui/common/loader.c +++ b/ui/common/loader.c @@ -94,7 +94,7 @@ static char *pb_load_nfs(void *ctx, struct pb_url *url) *p++ = local; /* 7 */ *p++ = NULL; /* 8 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); talloc_free(opts); @@ -138,7 +138,7 @@ static char *pb_load_sftp(void *ctx, struct pb_url __attribute__((unused)) *url) *p++ = local; /* 4 */ *p++ = NULL; /* 5 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); if (result) goto fail; @@ -183,7 +183,7 @@ static char *pb_load_tftp(void *ctx, struct pb_url *url) *p++ = url->port; /* 8 */ *p++ = NULL; /* 9 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); if (!result) return local; @@ -203,7 +203,7 @@ static char *pb_load_tftp(void *ctx, struct pb_url *url) *p++ = local; /* 9 */ *p++ = NULL; /* 10 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); if (!result) return local; @@ -248,7 +248,7 @@ static char *pb_load_wget(void *ctx, struct pb_url *url, enum wget_flags flags) *p++ = "--no-check-certificate"; /* 6 */ *p++ = NULL; /* 7 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); if (result) goto fail; diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c index 0140f0e..8604848 100644 --- a/ui/common/ui-system.c +++ b/ui/common/ui-system.c @@ -32,6 +32,30 @@ #include "loader.h" #include "ui-system.h" +/** + * pb_start_daemon - start the pb-discover daemon. + */ + +int pb_start_daemon(void) +{ + int result; + const char *argv[2]; + char *name = talloc_asprintf(NULL, "%s/sbin/pb-discover", + pb_system_apps.prefix); + + argv[0] = name; + argv[1] = NULL; + + result = pb_run_cmd(argv, 0); + + talloc_free(name); + + if (result) + pb_log("%s: failed: (%d)\n", __func__, result); + + return result; +} + /** * kexec_load - kexec load helper. * @l_image: The local image file for kexec to execute. @@ -67,7 +91,7 @@ static int kexec_load(const char *l_image, const char *l_initrd, *p++ = l_image; /* 5 */ *p++ = NULL; /* 6 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); if (result) pb_log("%s: failed: (%d)\n", __func__, result); @@ -98,7 +122,7 @@ static int kexec_reboot(void) *p++ = "now"; /* 3 */ *p++ = NULL; /* 4 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); /* On error, force a kexec with the -e option */ @@ -108,7 +132,7 @@ static int kexec_reboot(void) *p++ = "-e"; /* 2 */ *p++ = NULL; /* 3 */ - result = pb_run_cmd(argv); + result = pb_run_cmd(argv, 1); } if (result) diff --git a/ui/common/ui-system.h b/ui/common/ui-system.h index ca5edb4..87ab891 100644 --- a/ui/common/ui-system.h +++ b/ui/common/ui-system.h @@ -32,6 +32,7 @@ struct pb_kexec_data { }; int pb_run_kexec(const struct pb_kexec_data *kd); +int pb_start_daemon(void); unsigned int pb_elf_hash(const char *str); unsigned int pb_cat_hash(const char *a, const char *b); -- cgit v1.2.1