diff --git a/src/initctl.c b/src/initctl.c index 4785eeed..5cefbf44 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -51,6 +51,7 @@ struct cmd { int icreate = 0; int iforce = 0; int ionce = 0; +int debug = 0; int heading = 1; int verbose = 0; int plain = 0; @@ -951,6 +952,7 @@ int main(int argc, char *argv[]) struct option long_options[] = { { "batch", 0, NULL, 'b' }, { "create", 0, NULL, 'c' }, + { "debug", 0, NULL, 'd' }, { "force", 0, NULL, 'f' }, { "help", 0, NULL, 'h' }, { "once", 0, NULL, '1' }, @@ -1012,7 +1014,7 @@ int main(int argc, char *argv[]) if (transform(progname(argv[0]))) return reboot_main(argc, argv); - while ((c = getopt_long(argc, argv, "1bcfh?pqtv", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "1bcdfh?pqtv", long_options, NULL)) != EOF) { switch(c) { case '1': ionce = 1; @@ -1026,6 +1028,10 @@ int main(int argc, char *argv[]) icreate = 1; break; + case 'd': + debug = 1; + break; + case 'f': iforce = 1; break; diff --git a/src/serv.c b/src/serv.c index e3873434..7b5e6fe5 100644 --- a/src/serv.c +++ b/src/serv.c @@ -257,7 +257,8 @@ int do_disable(char *arg, int check) if (chdir(FINIT_RCSD)) err(1, "failed cd %s", FINIT_RCSD); - (void)chdir("enabled"); /* System *may* have enabled/ dir. */ + if (chdir("enabled")) /* System *may* have enabled/ dir. */ + dbg("Failed changing to %s/enabled/: %s", FINIT_RCSD, strerror(errno)); if (check && stat(arg, &st)) errx(1, "%s not (an) enabled (service).", arg); diff --git a/src/util.c b/src/util.c index c9cd928c..79a5a59b 100644 --- a/src/util.c +++ b/src/util.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #ifdef HAVE_TERMIOS_H # include diff --git a/src/util.h b/src/util.h index 0302e18d..0a44b726 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,7 @@ #ifdef HAVE_TERMIOS_H #include #include +#include #include #include #endif @@ -37,6 +38,7 @@ #define RB_SW_SUSPEND 0xd000fce2 #endif +extern int debug; /* defined in finit or initctl */ extern int ttrows; extern int ttcols; extern char *prognm; @@ -72,6 +74,18 @@ int ttcooked (void); #define ttcooked() 0 #endif +static inline void dbg(char *fmt, ...) +{ + va_list ap; + + if (!debug) + return; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + static inline char *strterm(char *str, size_t len) { str[len - 1] = 0;