mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
New cmdline options to control debug and progress/status
Modeled after systemd.show_status, currently without the 'auto' setting. - finit.debug[=bool] - finit.show_status[=bool] - finit.status_style[=old,classic,new,modern] Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+45
-3
@@ -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;
|
||||
|
||||
+5
-5
@@ -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.
|
||||
*/
|
||||
|
||||
+11
-9
@@ -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
|
||||
|
||||
+11
-1
@@ -34,6 +34,14 @@
|
||||
#include <lite/lite.h>
|
||||
#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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user