X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Futils.c;h=2c6fd784570ed187ed54f424cd743716d06443a4;hp=3e8b466e47ff074689f422457fb16c561a53389b;hb=1365950c01a87e8ede70da4d3937d379e3050d13;hpb=7d65f1b896f60a25bb975d775ab195794741a65a diff --git a/src/utils.c b/src/utils.c index 3e8b466e..2c6fd784 100644 --- a/src/utils.c +++ b/src/utils.c @@ -84,21 +84,9 @@ extern int errno; static void memfatal (const char *what) { - /* HACK: expose save_log_p from log.c, so we can turn it off in - order to prevent saving the log. Saving the log is dangerous - because logprintf() and logputs() can call malloc(), so this - could infloop. When logging is turned off, infloop can no longer - happen. - - #### This is no longer really necessary because the new routines - in log.c cons only if the line exceeds eighty characters. But - this can come at the end of a line, so it's OK to be careful. - - On a more serious note, it would be good to have a - log_forced_shutdown() routine that exposes this cleanly. */ - extern int save_log_p; - - save_log_p = 0; + /* Make sure we don't try to store part of the log line, and thus + call malloc. */ + log_set_save_context (0); logprintf (LOG_ALWAYS, _("%s: %s: Not enough memory.\n"), exec_name, what); exit (1); } @@ -464,12 +452,17 @@ fork_to_background (void) else if (pid != 0) { /* parent, no error */ - printf (_("Continuing in background.\n")); + printf (_("Continuing in background, pid %d.\n"), (int)pid); if (changedp) printf (_("Output will be written to `%s'.\n"), opt.lfilename); - exit (0); + exit (0); /* #### should we use _exit()? */ } - /* child: keep running */ + + /* child: give up the privileges and keep running. */ + setsid (); + freopen ("/dev/null", "r", stdin); + freopen ("/dev/null", "w", stdout); + freopen ("/dev/null", "w", stderr); } #endif /* not WINDOWS */