mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
log.c: New log_is_debug() function, hide access to debug variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+3
-3
@@ -171,7 +171,7 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
|
||||
/* Redirect output from cmd to a tempfile */
|
||||
fp = tempfile();
|
||||
if (fp && !debug) {
|
||||
if (fp && !log_is_debug()) {
|
||||
oldout = dup(STDOUT_FILENO);
|
||||
olderr = dup(STDERR_FILENO);
|
||||
dup2(fileno(fp), STDOUT_FILENO);
|
||||
@@ -182,7 +182,7 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
status = run(cmd);
|
||||
|
||||
/* Restore stderr/stdout */
|
||||
if (fp && !debug) {
|
||||
if (fp && !log_is_debug()) {
|
||||
if (oldout >= 0) {
|
||||
dup2(oldout, STDOUT_FILENO);
|
||||
close(oldout);
|
||||
@@ -197,7 +197,7 @@ int run_interactive(char *cmd, char *fmt, ...)
|
||||
print_result(status);
|
||||
|
||||
/* Dump any results of cmd on stderr after we've printed [ OK ] or [FAIL] */
|
||||
if (fp && !debug) {
|
||||
if (fp && !log_is_debug()) {
|
||||
size_t len, written;
|
||||
|
||||
rewind(fp);
|
||||
|
||||
+5
-5
@@ -47,7 +47,6 @@
|
||||
#include "utmp-api.h"
|
||||
#include "watchdog.h"
|
||||
|
||||
int debug = 0;
|
||||
int quiet = QUIET_MODE; /* Delayed disable of silent mode. */
|
||||
int silent = SILENT_MODE; /* Completely silent, including boot */
|
||||
int wdogpid = 0; /* No watchdog by default */
|
||||
@@ -112,8 +111,8 @@ static int fsck(int pass)
|
||||
return 1;
|
||||
}
|
||||
|
||||
save = debug;
|
||||
debug = 0;
|
||||
if ((save = log_is_debug()))
|
||||
log_debug();
|
||||
|
||||
while ((fs = getfsent())) {
|
||||
char cmd[80];
|
||||
@@ -139,7 +138,8 @@ static int fsck(int pass)
|
||||
run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
|
||||
}
|
||||
|
||||
debug = save;
|
||||
if (save)
|
||||
log_debug();
|
||||
endfsent();
|
||||
|
||||
return 0;
|
||||
@@ -311,7 +311,7 @@ int main(int argc, char* argv[])
|
||||
*/
|
||||
if (fexist("/sbin/mdev")) {
|
||||
/* Embedded Linux systems usually have BusyBox mdev */
|
||||
if (debug)
|
||||
if (log_is_debug())
|
||||
touch("/dev/mdev.log");
|
||||
devfsd = "/sbin/mdev -s";
|
||||
} else {
|
||||
|
||||
@@ -89,7 +89,6 @@ struct init_request {
|
||||
char data[368];
|
||||
};
|
||||
|
||||
extern int debug;
|
||||
extern int quiet;
|
||||
extern int silent;
|
||||
extern int wdogpid;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "finit.h"
|
||||
#include "log.h"
|
||||
|
||||
static int debug = 0;
|
||||
static int loglevel = LOG_NOTICE;
|
||||
|
||||
void log_init(int qit, int dbg)
|
||||
@@ -63,6 +64,11 @@ void log_debug(void)
|
||||
logit(LOG_NOTICE, "Debug mode %s", debug ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
int log_is_debug(void)
|
||||
{
|
||||
return debug;
|
||||
}
|
||||
|
||||
static void early_logit(int prio, const char *fmt, va_list ap)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
@@ -44,6 +44,8 @@ void log_init (int qit, int dbg);
|
||||
void log_exit (void);
|
||||
|
||||
void log_debug (void);
|
||||
int log_is_debug (void);
|
||||
|
||||
void logit (int prio, const char *fmt, ...);
|
||||
|
||||
#endif /* FINIT_LOG_H_ */
|
||||
|
||||
+2
-2
@@ -255,7 +255,7 @@ static int service_start(svc_t *svc)
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
close(fd);
|
||||
} else if (debug) {
|
||||
} else if (log_is_debug()) {
|
||||
int fd;
|
||||
|
||||
fd = open(CONSOLE, O_WRONLY | O_APPEND);
|
||||
@@ -286,7 +286,7 @@ static int service_start(svc_t *svc)
|
||||
waitpid(pid, NULL, 0);
|
||||
|
||||
exit(status);
|
||||
} else if (debug) {
|
||||
} else if (log_is_debug()) {
|
||||
char buf[CMD_SIZE] = "";
|
||||
|
||||
for (i = 0; i < (MAX_NUM_SVC_ARGS - 1) && svc->args[i][0] != 0; i++) {
|
||||
|
||||
Reference in New Issue
Block a user