summaryrefslogtreecommitdiffstats
path: root/ui/ncurses
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2012-03-08 20:48:21 -0800
committerGeoff Levand <geoff@infradead.org>2012-03-08 20:51:37 -0800
commit604a1ccf072f9f33326fb6dc919c1b6233d40866 (patch)
tree88297738af995f9ea8df78e134d0a2dac111d157 /ui/ncurses
parentae0ba68f475ae5b057aad6538765bc8702134b9a (diff)
downloadtalos-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/ncurses')
-rw-r--r--ui/ncurses/generic-main.c20
-rw-r--r--ui/ncurses/nc-cui.c23
-rw-r--r--ui/ncurses/nc-cui.h2
3 files changed, 35 insertions, 10 deletions
diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c
index 2d342c3..6b8f5ba 100644
--- a/ui/ncurses/generic-main.c
+++ b/ui/ncurses/generic-main.c
@@ -45,7 +45,8 @@ static void print_usage(void)
{
print_version();
printf(
-"Usage: petitboot-nc [-h, --help] [-l, --log log-file] [-V, --version]\n");
+"Usage: petitboot-nc [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n"
+" [-V, --version]\n");
}
/**
@@ -59,6 +60,7 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no};
*/
struct opts {
+ enum opt_value start_daemon;
enum opt_value show_help;
const char *log_file;
enum opt_value show_version;
@@ -71,12 +73,13 @@ struct opts {
static int opts_parse(struct opts *opts, int argc, char *argv[])
{
static const struct option long_options[] = {
- {"help", no_argument, NULL, 'h'},
- {"log", required_argument, NULL, 'l'},
- {"version", no_argument, NULL, 'V'},
- { NULL, 0, NULL, 0},
+ {"start-daemon", no_argument, NULL, 'd'},
+ {"help", no_argument, NULL, 'h'},
+ {"log", required_argument, NULL, 'l'},
+ {"version", no_argument, NULL, 'V'},
+ { NULL, 0, NULL, 0},
};
- static const char short_options[] = "hl:V";
+ static const char short_options[] = "dhl:V";
static const struct opts default_values = {
.log_file = "/var/log/petitboot/petitboot-nc.log",
};
@@ -91,6 +94,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
break;
switch (c) {
+ case 'd':
+ opts->start_daemon = opt_yes;
+ break;
case 'h':
opts->show_help = opt_yes;
break;
@@ -269,7 +275,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- pb.cui = cui_init(&pb, pb_kexec_cb, NULL);
+ pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon);
if (!pb.cui)
return EXIT_FAILURE;
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index aed5ff7..09e7a57 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -111,7 +111,7 @@ int cui_run_cmd(struct pmenu_item *item)
def_prog_mode();
- result = pb_run_cmd(cmd_argv);
+ result = pb_run_cmd(cmd_argv, 1);
reset_prog_mode();
redrawwin(cui->current->main_ncw);
@@ -534,7 +534,7 @@ static struct discover_client_ops cui_client_ops = {
struct cui *cui_init(void* platform_info,
int (*on_kexec)(struct cui *, struct cui_opt_data *),
- int (*js_map)(const struct js_event *e))
+ int (*js_map)(const struct js_event *e), int start_deamon)
{
struct cui *cui;
struct discover_client *client;
@@ -555,6 +555,7 @@ struct cui *cui_init(void* platform_info,
/* Loop here for scripts that just started the server. */
+start_deamon:
for (i = 10; i; i--) {
client = discover_client_init(&cui_client_ops, cui);
if (client)
@@ -563,6 +564,24 @@ struct cui *cui_init(void* platform_info,
sleep(1);
}
+ if (!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 (!client) {
pb_log("%s: discover_client_init failed.\n", __func__);
fprintf(stderr, "%s: error: discover_client_init failed.\n",
diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h
index 94fef6b..a4ac2e8 100644
--- a/ui/ncurses/nc-cui.h
+++ b/ui/ncurses/nc-cui.h
@@ -62,7 +62,7 @@ struct cui {
struct cui *cui_init(void* platform_info,
int (*on_kexec)(struct cui *, struct cui_opt_data *),
- int (*js_map)(const struct js_event *e));
+ 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_ked_run(struct pmenu_item *item);
OpenPOWER on IntegriCloud