Fix logging in background mode

* ../src/main.c: Re-init logfile if changed for background mode
* ../src/utils.c: fork_to_background() returns whether logfile changed
* ../src/utils.h: Set return type bool for fork_to_background()

Fixes: #53020
Reported-by: Noël Köthe
This commit is contained in:
Tim Rühsen 2018-02-07 22:33:06 +01:00
parent bb7fa977a1
commit c722973212
3 changed files with 10 additions and 3 deletions

View File

@ -1880,7 +1880,12 @@ for details.\n\n"));
sock_init();
#else
if (opt.background)
fork_to_background ();
{
bool logfile_changed = fork_to_background ();
if (logfile_changed)
log_init (opt.lfilename, append_to_log);
}
#endif
/* Initialize progress. Have to do this after the options are

View File

@ -469,7 +469,7 @@ fork_to_background (void)
#else /* def __VMS */
#if !defined(WINDOWS) && !defined(MSDOS)
void
bool
fork_to_background (void)
{
pid_t pid;
@ -514,6 +514,8 @@ fork_to_background (void)
DEBUGP (("Failed to redirect stdout to /dev/null.\n"));
if (freopen ("/dev/null", "w", stderr) == NULL)
DEBUGP (("Failed to redirect stderr to /dev/null.\n"));
return logfile_changed;
}
#endif /* !WINDOWS && !MSDOS */

View File

@ -71,7 +71,7 @@ char *xstrdup_lower (const char *);
char *strdupdelim (const char *, const char *);
char **sepstring (const char *);
bool subdir_p (const char *, const char *);
void fork_to_background (void);
bool fork_to_background (void);
char *aprintf (const char *, ...) GCC_FORMAT_ATTR (1, 2);
char *concat_strings (const char *, ...);