mirror of
https://github.com/samba-team/samba.git
synced 2025-03-25 14:50:24 +03:00
lib:cmdline: We need to always set a log file
We need to always set a log file name based on the process name. This defines e.g. the log file for smbd. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
parent
4596211e31
commit
e8780be8a4
@ -282,6 +282,35 @@ poptContext samba_popt_get_context(const char * name,
|
||||
|
||||
static bool log_to_file;
|
||||
|
||||
static bool set_logfile(TALLOC_CTX *mem_ctx,
|
||||
struct loadparm_context *lp_ctx,
|
||||
const char *log_basename,
|
||||
const char *process_name)
|
||||
{
|
||||
bool ok;
|
||||
char *new_logfile = talloc_asprintf(mem_ctx,
|
||||
"%s/log.%s",
|
||||
log_basename,
|
||||
process_name);
|
||||
if (new_logfile == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = lpcfg_set_cmdline(lp_ctx,
|
||||
"log file",
|
||||
new_logfile);
|
||||
if (!ok) {
|
||||
fprintf(stderr,
|
||||
"Failed to set log to %s\n",
|
||||
new_logfile);
|
||||
TALLOC_FREE(new_logfile);
|
||||
return false;
|
||||
}
|
||||
TALLOC_FREE(new_logfile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void popt_samba_callback(poptContext popt_ctx,
|
||||
enum poptCallbackReason reason,
|
||||
const struct poptOption *opt,
|
||||
@ -292,12 +321,27 @@ static void popt_samba_callback(poptContext popt_ctx,
|
||||
const char *pname = NULL;
|
||||
bool ok;
|
||||
|
||||
/* Find out basename of current program */
|
||||
pname = strrchr_m(poptGetInvocationName(popt_ctx), '/');
|
||||
if (pname == NULL) {
|
||||
pname = poptGetInvocationName(popt_ctx);
|
||||
} else {
|
||||
pname++;
|
||||
}
|
||||
|
||||
if (reason == POPT_CALLBACK_REASON_PRE) {
|
||||
if (lp_ctx == NULL) {
|
||||
fprintf(stderr,
|
||||
"Command line parsing not initialized!\n");
|
||||
exit(1);
|
||||
}
|
||||
ok = set_logfile(mem_ctx, lp_ctx, get_dyn_LOGFILEBASE(), pname);
|
||||
if (!ok) {
|
||||
fprintf(stderr,
|
||||
"Failed to set log file for %s\n",
|
||||
pname);
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -329,14 +373,6 @@ static void popt_samba_callback(poptContext popt_ctx,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Find out basename of current program */
|
||||
pname = strrchr_m(poptGetInvocationName(popt_ctx), '/');
|
||||
if (pname == NULL) {
|
||||
pname = poptGetInvocationName(popt_ctx);
|
||||
} else {
|
||||
pname++;
|
||||
}
|
||||
|
||||
switch(opt->val) {
|
||||
case OPT_LEAK_REPORT:
|
||||
talloc_enable_leak_report();
|
||||
@ -374,31 +410,16 @@ static void popt_samba_callback(poptContext popt_ctx,
|
||||
break;
|
||||
case 'l':
|
||||
if (arg != NULL) {
|
||||
char *new_logfile = talloc_asprintf(mem_ctx,
|
||||
"%s/log.%s",
|
||||
arg,
|
||||
pname);
|
||||
if (new_logfile == NULL) {
|
||||
fprintf(stderr,
|
||||
"Failed to allocate memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ok = lpcfg_set_cmdline(lp_ctx,
|
||||
"log file",
|
||||
new_logfile);
|
||||
ok = set_logfile(mem_ctx, lp_ctx, arg, pname);
|
||||
if (!ok) {
|
||||
fprintf(stderr,
|
||||
"Failed to set log file: %s\n",
|
||||
new_logfile);
|
||||
TALLOC_FREE(new_logfile);
|
||||
"Failed to set log file for %s\n",
|
||||
arg);
|
||||
exit(1);
|
||||
}
|
||||
log_to_file = true;
|
||||
|
||||
set_dyn_LOGFILEBASE(arg);
|
||||
|
||||
TALLOC_FREE(new_logfile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user