* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#if defined(HAVE_CONFIG_H)
#include "config.h"
-#endif
#define _GNU_SOURCE
+
+#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <signal.h>
{
print_version();
printf(
-"Usage: petitboot-nc [-d, --start-daemon] [-h, --help] [-l, --log log-file]\n"
-" [-V, --version]\n");
+"Usage: petitboot-nc [-h, --help] [-l, --log log-file]\n"
+" [-s, --start-daemon] [-V, --version]\n");
}
/**
*/
struct opts {
- enum opt_value start_daemon;
enum opt_value show_help;
const char *log_file;
+ enum opt_value start_daemon;
enum opt_value show_version;
};
static int opts_parse(struct opts *opts, int argc, char *argv[])
{
static const struct option long_options[] = {
- {"start-daemon", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"log", required_argument, NULL, 'l'},
+ {"start-daemon", no_argument, NULL, 's'},
{"version", no_argument, NULL, 'V'},
{ NULL, 0, NULL, 0},
};
- static const char short_options[] = "dhl:V";
+ static const char short_options[] = "dhl:sV";
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;
case 'l':
opts->log_file = optarg;
break;
+ case 's':
+ opts->start_daemon = opt_yes;
+ break;
case 'V':
opts->show_version = opt_yes;
break;
struct cui *cui;
};
-static struct pb_cui *pb_from_cui(struct cui *cui)
-{
- struct pb_cui *pb;
-
- assert(cui->c_sig == pb_cui_sig);
- pb = cui->platform_info;
- assert(pb->cui->c_sig == pb_cui_sig);
- return pb;
-}
-
-/**
- * pb_kexec_cb - The kexec callback.
- */
-
-static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
-{
- struct pb_cui *pb = pb_from_cui(cui);
-
- pb_log("%s: %s\n", __func__, cod->name);
-
- assert(pb->cui->current == &pb->cui->main->scr);
-
- return pb_run_kexec(cod->kd);
-}
-
/**
* pb_mm_init - Setup the main menu instance.
*/
m->on_open = cui_on_open;
- m->scr.frame.title = talloc_strdup(m, "Petitboot");
+ m->scr.frame.title = talloc_asprintf(m,
+ "Petitboot (" PACKAGE_VERSION ")");
m->scr.frame.help = talloc_strdup(m,
"ESC=exit, Enter=accept, e=edit, o=open");
m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
DBGS("%d\n", signum);
switch (signum) {
- case SIGALRM:
- if (pb.cui)
- ui_timer_sigalrm(&pb.cui->timer);
- break;
case SIGWINCH:
if (pb.cui)
cui_resize(pb.cui);
int main(int argc, char *argv[])
{
static struct sigaction sa;
- static struct opts opts;
int result;
int cui_result;
- FILE *log;
+ struct opts opts;
result = opts_parse(&opts, argc, argv);
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ if (!log)
+ log = fopen("/dev/null", "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
return EXIT_FAILURE;
}
- pb.cui = cui_init(&pb, pb_kexec_cb, NULL, opts.start_daemon);
+ pb.cui = cui_init(&pb, NULL, opts.start_daemon);
if (!pb.cui)
return EXIT_FAILURE;
pb.mm = pb_mm_init(&pb);
- ui_timer_disable(&pb.cui->timer);
cui_result = cui_run(pb.cui, pb.mm, 0);