argv[4] = "ro";
argv[5] = NULL;
- if (pb_run_cmd(argv))
+ if (pb_run_cmd(argv, 1))
argv[3] = NULL; /* try without ro */
- if (pb_run_cmd(argv))
+ if (pb_run_cmd(argv, 1))
goto out_rmdir;
setup_device_links(ctx);
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-AM_CPPFLAGS = -I$(top_srcdir)/lib $(DEFAULT_CPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/lib $(DEFAULT_CPPFLAGS) \
+ -DPREFIX='"$(prefix)"'
AM_CFLAGS = $(DEFAULT_CFLAGS)
#include "system.h"
const struct pb_system_apps pb_system_apps = {
+ .prefix = PREFIX,
.cp = "/bin/cp",
.kexec = "/sbin/kexec",
.mount = "/bin/mount",
* @cmd_argv: An argument list array for execv.
*/
-int pb_run_cmd(const char *const *cmd_argv)
+int pb_run_cmd(const char *const *cmd_argv, int wait)
{
#if defined(DEBUG)
enum {do_debug = 1};
exit(EXIT_FAILURE);
}
+ if (!wait && !waitpid(pid, &status, WNOHANG))
+ return 0;
+
if (waitpid(pid, &status, 0) == -1) {
pb_log("%s: waitpid failed: %s\n", __func__,
strerror(errno));
#define _PB_LIB_SYSTEM_H
struct pb_system_apps {
+ const char *prefix;
const char *cp;
const char *kexec;
const char *mount;
extern const struct pb_system_apps pb_system_apps;
-int pb_run_cmd(const char *const *cmd_argv);
+int pb_run_cmd(const char *const *cmd_argv, int wait);
int pb_mkdir_recursive(const char *dir);
int pb_rmdir_recursive(const char *base, const char *dir);
.Sh SYNOPSIS
.\" ========
.Nm
+.Op Fl d, -start-daemon
.Op Fl h, -help
.Op Fl l, -log Ar log-file
.Op Fl V, -version
.\" =======
.Bl -tag -width indent
.\"
+.It Fl d, -start-daemon
+Start pb-discover, the petitboot dynamic device discovery daemon, if it has
+not been started. This option is mainly useful when running petitboot as a
+stand-alone application.
+.\"
.It Fl h, -help
Print a help message.
.\"
.Sh SYNOPSIS
.\" ========
.Nm
+.Op Fl d, -start-daemon
.Op Fl h, -help
.Op Fl l, -log Ar log-file
.Op Fl V, -version
-.Op Fl V, -version
.Op Fl f, -fbdev
.Op Fl x, -x11
.\"
.\" =======
.Bl -tag -width indent
.\"
+.It Fl d, -start-daemon
+Start pb-discover, the petitboot dynamic device discovery daemon, if it has
+not been started. This option is mainly useful when running petitboot as a
+stand-alone application.
+.\"
.It Fl h, -help
Print a help message.
.\"
*p++ = local; /* 7 */
*p++ = NULL; /* 8 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
talloc_free(opts);
*p++ = local; /* 4 */
*p++ = NULL; /* 5 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
if (result)
goto fail;
*p++ = url->port; /* 8 */
*p++ = NULL; /* 9 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
if (!result)
return local;
*p++ = local; /* 9 */
*p++ = NULL; /* 10 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
if (!result)
return local;
*p++ = "--no-check-certificate"; /* 6 */
*p++ = NULL; /* 7 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
if (result)
goto fail;
#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.
*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);
*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 */
*p++ = "-e"; /* 2 */
*p++ = NULL; /* 3 */
- result = pb_run_cmd(argv);
+ result = pb_run_cmd(argv, 1);
}
if (result)
};
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);
{
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");
}
/**
*/
struct opts {
+ enum opt_value start_daemon;
enum opt_value show_help;
const char *log_file;
enum opt_value show_version;
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",
};
break;
switch (c) {
+ case 'd':
+ opts->start_daemon = opt_yes;
+ break;
case 'h':
opts->show_help = opt_yes;
break;
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;
def_prog_mode();
- result = pb_run_cmd(cmd_argv);
+ result = pb_run_cmd(cmd_argv, 1);
reset_prog_mode();
redrawwin(cui->current->main_ncw);
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;
/* 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)
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",
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);
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;
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;
/* 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",
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);
{
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");
}
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'},
{"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",
break;
switch (c) {
+ case 'd':
+ opts->start_daemon = pbt_opt_yes;
+ break;
case 'f':
opts->backend = pbt_twin_fbdev;
break;
*/
struct pbt_opts {
+ enum pbt_opt_value start_daemon;
enum pbt_twin_backend backend;
enum pbt_opt_value show_help;
const char *log_file;