diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/cmdline/popt_common.c | 22 | ||||
-rw-r--r-- | source4/lib/debug.c | 22 | ||||
-rw-r--r-- | source4/lib/registry/tools/regdiff.c | 10 | ||||
-rw-r--r-- | source4/lib/registry/tools/regpatch.c | 10 | ||||
-rw-r--r-- | source4/lib/registry/tools/regshell.c | 11 | ||||
-rw-r--r-- | source4/lib/registry/tools/regtree.c | 10 |
6 files changed, 43 insertions, 42 deletions
diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c index 94b72c520d..fec85281ef 100644 --- a/source4/lib/cmdline/popt_common.c +++ b/source4/lib/cmdline/popt_common.c @@ -38,7 +38,7 @@ * -i,--scope */ -enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL}; +enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL, OPT_DEBUG_STDERR}; struct cli_credentials *cmdline_credentials = NULL; @@ -49,6 +49,14 @@ static void popt_common_callback(poptContext con, { const char *pname; + if (reason == POPT_CALLBACK_REASON_POST) { + /* Hook any 'every Samba program must do this, after + * the smb.conf is setup' functions here */ + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); + return; + } + /* Find out basename of current program */ pname = strrchr_m(poptGetInvocationName(con),'/'); @@ -58,9 +66,7 @@ static void popt_common_callback(poptContext con, pname++; if (reason == POPT_CALLBACK_REASON_PRE) { - char *logfile = talloc_asprintf(NULL, "%s/log.%s", dyn_LOGFILEBASE, pname); - lp_set_cmdline("log file", logfile); - talloc_free(logfile); + setup_logging(pname, DEBUG_STDOUT); return; } @@ -69,6 +75,10 @@ static void popt_common_callback(poptContext con, lp_set_cmdline("log level", arg); break; + case OPT_DEBUG_STDERR: + setup_logging(pname, DEBUG_STDERR); + break; + case 'V': printf( "Version %s\n", SAMBA_VERSION_STRING ); exit(0); @@ -128,6 +138,7 @@ static void popt_common_callback(poptContext con, case OPT_LEAK_REPORT_FULL: talloc_enable_leak_report_full(); break; + } } @@ -143,8 +154,9 @@ struct poptOption popt_common_connection[] = { }; struct poptOption popt_common_samba[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, + { "debug-stderr", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_STDERR, "Send debug output to STDERR", NULL }, { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" }, { "option", 0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" }, { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" }, diff --git a/source4/lib/debug.c b/source4/lib/debug.c index ab012a98aa..a775c46854 100644 --- a/source4/lib/debug.c +++ b/source4/lib/debug.c @@ -74,8 +74,6 @@ void reopen_logs(void) char *fname = NULL; int old_fd = state.fd; - state.fd = 0; - switch (state.logtype) { case DEBUG_STDOUT: state.fd = 1; @@ -89,12 +87,20 @@ void reopen_logs(void) if ((*logfile) == '/') { fname = strdup(logfile); } else { - asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, logfile); + asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, state.prog_name); } if (fname) { - state.fd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0644); + int newfd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0600); + if (newfd == -1) { + DEBUG(1, ("Failed to open new logfile: %s\n", fname)); + } else { + state.fd = newfd; + } free(fname); + } else { + DEBUG(1, ("Failed to find name for file-based logfile!\n")); } + break; } @@ -109,8 +115,12 @@ void reopen_logs(void) */ void setup_logging(const char *prog_name, enum debug_logtype new_logtype) { - state.logtype = new_logtype; - state.prog_name = prog_name; + if (state.logtype < new_logtype) { + state.logtype = new_logtype; + } + if (prog_name) { + state.prog_name = prog_name; + } reopen_logs(); } diff --git a/source4/lib/registry/tools/regdiff.c b/source4/lib/registry/tools/regdiff.c index 4260a56142..f86c0ae383 100644 --- a/source4/lib/registry/tools/regdiff.c +++ b/source4/lib/registry/tools/regdiff.c @@ -121,21 +121,18 @@ static void writediff(struct registry_key *oldkey, struct registry_key *newkey, WERROR error, error2; struct poptOption long_options[] = { POPT_AUTOHELP - POPT_COMMON_CREDENTIALS {"output", 'o', POPT_ARG_STRING, &outputfile, 'o', "output file to use", NULL }, {"null", 'n', POPT_ARG_NONE, &from_null, 'n', "Diff from NULL", NULL }, {"remote", 'R', POPT_ARG_STRING, NULL, 0, "Connect to remote server" , NULL }, {"local", 'L', POPT_ARG_NONE, NULL, 0, "Open local registry", NULL }, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + POPT_COMMON_VERSION POPT_TABLEEND }; regdiff_init_subsystems; - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } - - pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { @@ -157,7 +154,6 @@ static void writediff(struct registry_key *oldkey, struct registry_key *newkey, return 1; } } - setup_logging(argv[0], DEBUG_STDOUT); poptFreeContext(pc); diff --git a/source4/lib/registry/tools/regpatch.c b/source4/lib/registry/tools/regpatch.c index 5c9851b71b..02ef4d4655 100644 --- a/source4/lib/registry/tools/regpatch.c +++ b/source4/lib/registry/tools/regpatch.c @@ -749,25 +749,19 @@ static int nt_apply_reg_command_file(struct registry_context *r, const char *cmd WERROR error; struct poptOption long_options[] = { POPT_AUTOHELP - POPT_COMMON_CREDENTIALS {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL}, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS POPT_TABLEEND }; regpatch_init_subsystems; - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } - - pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } - setup_logging(argv[0], DEBUG_STDOUT); - if (remote) { error = reg_open_remote (&h, cmdline_credentials, remote); } else { diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c index 03cb09c443..0c53f737b8 100644 --- a/source4/lib/registry/tools/regshell.c +++ b/source4/lib/registry/tools/regshell.c @@ -374,26 +374,21 @@ static char **reg_completion(const char *text, int start, int end) struct registry_context *h = NULL; struct poptOption long_options[] = { POPT_AUTOHELP - POPT_COMMON_CREDENTIALS {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL}, {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL}, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + POPT_COMMON_VERSION POPT_TABLEEND }; regshell_init_subsystems; - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } - - pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } - setup_logging("regtree", DEBUG_STDOUT); - if (remote) { error = reg_open_remote (&h, cmdline_credentials, remote); } else if (backend) { diff --git a/source4/lib/registry/tools/regtree.c b/source4/lib/registry/tools/regtree.c index 2cf5f6ab96..f18467b523 100644 --- a/source4/lib/registry/tools/regtree.c +++ b/source4/lib/registry/tools/regtree.c @@ -82,28 +82,22 @@ static void print_tree(int l, struct registry_key *p, int fullpath, int novals) int fullpath = 0, no_values = 0; struct poptOption long_options[] = { POPT_AUTOHELP - POPT_COMMON_CREDENTIALS {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL}, {"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL}, {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL }, {"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL}, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS POPT_TABLEEND }; regtree_init_subsystems; - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } - - pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } - setup_logging("regtree", DEBUG_STDOUT); - if (remote) { error = reg_open_remote(&h, cmdline_credentials, remote); } else if (backend) { |