diff options
author | Geoff Levand <geoff@infradead.org> | 2012-03-08 20:48:21 -0800 |
---|---|---|
committer | Geoff Levand <geoff@infradead.org> | 2012-03-08 20:51:37 -0800 |
commit | 604a1ccf072f9f33326fb6dc919c1b6233d40866 (patch) | |
tree | 88297738af995f9ea8df78e134d0a2dac111d157 /ui/twin | |
parent | ae0ba68f475ae5b057aad6538765bc8702134b9a (diff) | |
download | talos-petitboot-604a1ccf072f9f33326fb6dc919c1b6233d40866.tar.gz talos-petitboot-604a1ccf072f9f33326fb6dc919c1b6233d40866.zip |
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 <geoff@infradead.org>
Diffstat (limited to 'ui/twin')
-rw-r--r-- | ui/twin/main-generic.c | 3 | ||||
-rw-r--r-- | ui/twin/pbt-client.c | 24 | ||||
-rw-r--r-- | ui/twin/pbt-client.h | 3 | ||||
-rw-r--r-- | ui/twin/pbt-main.c | 10 | ||||
-rw-r--r-- | ui/twin/pbt-main.h | 1 |
5 files changed, 33 insertions, 8 deletions
diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index 5020fa2..53c32dd 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -327,7 +327,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - client = pbt_client_init(opts.backend, 900, 300, kexec_cb); + client = pbt_client_init(opts.backend, 900, 300, kexec_cb, + opts.start_daemon); if (!client) { ui_result = EXIT_FAILURE; diff --git a/ui/twin/pbt-client.c b/ui/twin/pbt-client.c index a2c3e93..711248a 100644 --- a/ui/twin/pbt-client.c +++ b/ui/twin/pbt-client.c @@ -264,7 +264,8 @@ static void pbt_client_destructor(struct pbt_client *client) struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width, unsigned int height, - int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *)) + int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *), + int start_deamon) { struct pbt_client *pbt_client; unsigned int i; @@ -289,17 +290,34 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int w /* Loop here for scripts that just started the server. */ if (1) { +start_deamon: for (i = 10; i; i--) { pbt_client->discover_client = discover_client_init(&pbt_client_ops, pbt_client); - if (pbt_client->discover_client) break; - pb_log("%s: waiting for server %d\n", __func__, i); sleep(1); } + if (!pbt_client->discover_client && start_deamon) { + int result; + + start_deamon = 0; + + result = pb_start_daemon(); + + if (!result) + goto start_deamon; + + pb_log("%s: discover_client_init failed.\n", __func__); + fprintf(stderr, "%s: error: discover_client_init failed.\n", + __func__); + fprintf(stderr, "could not start pb-discover, the petitboot " + "daemon.\n"); + goto fail_client_init; + } + if (!pbt_client->discover_client) { pb_log("%s: discover_client_init failed.\n", __func__); fprintf(stderr, "%s: error: discover_client_init failed.\n", diff --git a/ui/twin/pbt-client.h b/ui/twin/pbt-client.h index 731bf03..119bc94 100644 --- a/ui/twin/pbt-client.h +++ b/ui/twin/pbt-client.h @@ -52,7 +52,8 @@ struct pbt_client { struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width, unsigned int height, - int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *)); + int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *), + int start_deamon); void pbt_client_destroy(struct pbt_client *client); void pbt_client_resize(struct pbt_client *client); diff --git a/ui/twin/pbt-main.c b/ui/twin/pbt-main.c index 51ff5f2..a8c1ea5 100644 --- a/ui/twin/pbt-main.c +++ b/ui/twin/pbt-main.c @@ -34,8 +34,8 @@ void pbt_print_usage(void) { pbt_print_version(); printf( -"Usage: petitboot-twin [-h, --help] [-l, --log log-file]\n" -" [-r, --reset-defaults][-t, --timeout] [-V, --version]" +"Usage: petitboot-twin [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n" +" [-r, --reset-defaults][-t, --timeout] [-V, --version]\n" " [[-f --fbdev] | [-x --x11]]\n"); } @@ -46,6 +46,7 @@ void pbt_print_usage(void) int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[]) { static const struct option long_options[] = { + {"start-daemon", no_argument, NULL, 'd'}, {"fbdev", no_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"log", required_argument, NULL, 'l'}, @@ -55,7 +56,7 @@ int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[]) {"x11", no_argument, NULL, 'x'}, { NULL, 0, NULL, 0}, }; - static const char short_options[] = "fhl:trVx"; + static const char short_options[] = "dfhl:trVx"; static const struct pbt_opts default_values = { .backend = pbt_twin_x11, .log_file = "/var/log/petitboot/petitboot-twin.log", @@ -71,6 +72,9 @@ int pbt_opts_parse(struct pbt_opts *opts, int argc, char *argv[]) break; switch (c) { + case 'd': + opts->start_daemon = pbt_opt_yes; + break; case 'f': opts->backend = pbt_twin_fbdev; break; diff --git a/ui/twin/pbt-main.h b/ui/twin/pbt-main.h index 5f0e906..47985a1 100644 --- a/ui/twin/pbt-main.h +++ b/ui/twin/pbt-main.h @@ -31,6 +31,7 @@ enum pbt_opt_value {pbt_opt_undef = 0, pbt_opt_yes, pbt_opt_no}; */ struct pbt_opts { + enum pbt_opt_value start_daemon; enum pbt_twin_backend backend; enum pbt_opt_value show_help; const char *log_file; |