diff --git a/src/conf.c b/src/conf.c index 5d3039a6..f9857a72 100644 --- a/src/conf.c +++ b/src/conf.c @@ -75,11 +75,53 @@ static void hide_args(int argc, char *argv[]) } } +int get_bool(char *ptr, int default_value) +{ + if (string_compare(ptr, "true") || string_compare(ptr, "on") || string_compare(ptr, "1")) + return 1; + if (string_compare(ptr, "false") || string_compare(ptr, "off") || string_compare(ptr, "0")) + return 0; + + return default_value; +} + +/* + * finit.debug = [on,off] + * finit.show_status = [on,off] + */ +static void parse_finit_opts(char *opt) +{ + char *ptr; + + ptr = strchr(opt, '='); + if (ptr) + *ptr++ = 0; + + if (string_compare(opt, "debug")) { + debug = get_bool(ptr, 1); + return; + } + + if (string_compare(opt, "status_style")) { + if (string_compare(ptr, "old") || string_compare(ptr, "classic")) + show_progress(PROGRESS_CLASSIC); + else + show_progress(PROGRESS_MODERN); + return; + } + + if (string_compare(opt, "show_status")) { + show_progress(get_bool(ptr, 1) ? PROGRESS_DEFAULT : PROGRESS_SILENT); + return; + } +} + static void parse_arg(char *arg) { - /* Catches finit_debug, --debug, and debug */ - if (strstr(arg, "debug")) - debug = 1; + if (!strncmp(arg, "finit.", 6)) { + parse_finit_opts(&arg[6]); + return; + } if (string_compare(arg, "rescue") || string_compare(arg, "recover")) rescue = 1; diff --git a/src/finit.c b/src/finit.c index 5ab7be28..bf4085f6 100644 --- a/src/finit.c +++ b/src/finit.c @@ -307,11 +307,8 @@ static void finalize(void) plugin_run_hooks(HOOK_SYSTEM_UP); service_step_all(SVC_TYPE_ANY); - /* Enable silent mode before starting TTYs */ - if (!debug) { - _d("Going silent ..."); - show_progress(0); - } + /* Disable progress output at normal runtime */ + enable_progress(0); /* Delayed start of TTYs at bootstrap */ _d("Launching all getty services ..."); @@ -410,6 +407,9 @@ int main(int argc, char *argv[]) if (!rescue && !debug) screen_init(); + /* Allow progress, if enabled */ + enable_progress(1); + /* * In case of emergency. */ diff --git a/src/helpers.c b/src/helpers.c index 89e639bf..8318f344 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -39,13 +39,7 @@ #include "util.h" #include "utmp-api.h" -typedef enum { - PROGRESS_SILENT, - PROGRESS_CLASSIC, - PROGRESS_MODERN, -} pstyle_t; - -#define PROGRESS_DEFAULT PROGRESS_MODERN +static pstyle_t progress_onoff = PROGRESS_DEFAULT; static pstyle_t progress_style = PROGRESS_DEFAULT; #ifndef HOSTNAME_PATH @@ -189,14 +183,22 @@ char *strip_line(char *line) return line; } -void show_progress(int onoff) +void enable_progress(int onoff) { + if (debug) + return; + if (onoff) - progress_style = PROGRESS_DEFAULT; + progress_style = progress_onoff; else progress_style = PROGRESS_SILENT; } +void show_progress(pstyle_t style) +{ + progress_onoff = style; +} + /* * Return screen length of string, not counting escape chars, and * accounting for unicode characters as only one screen byte wide diff --git a/src/helpers.h b/src/helpers.h index a3f32a79..e4fc1595 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -34,6 +34,14 @@ #include #include "log.h" +#define PROGRESS_DEFAULT PROGRESS_MODERN + +typedef enum { + PROGRESS_SILENT, + PROGRESS_CLASSIC, + PROGRESS_MODERN, +} pstyle_t; + #ifndef HAVE_GETFSENT struct fstab { char *fs_spec; /* block device name */ @@ -55,7 +63,9 @@ void console_init (void); ssize_t cprintf (const char *fmt, ...); char *strip_line (char *line); -void show_progress (int onoff); + +void enable_progress (int onoff); +void show_progress (pstyle_t style); int getty (char *tty, speed_t speed, char *term, char *user); int sh (char *tty); diff --git a/src/log.c b/src/log.c index d2a56451..ca251c58 100644 --- a/src/log.c +++ b/src/log.c @@ -55,7 +55,7 @@ void log_exit(void) else screen_init(); - show_progress(1); + enable_progress(1); } void log_open(void) @@ -85,6 +85,7 @@ void log_debug(void) screen_init(); } log_open(); + enable_progress(1); logit(LOG_NOTICE, "Debug mode %s", debug ? "enabled" : "disabled"); }