Re: Fwd: [CTTE #727708] Default init system for Debian

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Wed, 12 Feb 2014 11:16:24 +1300

On 2014-02-12 11:07, Henrik Nordström wrote:
> ons 2014-02-12 klockan 10:47 +1300 skrev Amos Jeffries:
>
>> Exactly. More deep changes needed.
>
> Well, systemd (and most other service monitors) do manage services that
> background themselves as well, just not optimally. So it's more changes
> desired, not strictly needed.
>
> But seriously, it's a very small change to Squid. All systemd and the
> like needs is that Squid stops all the backgrounding, setsid etc done
> in
> watch_child(). The rest is business as usual, including watching
> childs.
>
> I.e. all or most of the following:
>
> openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS,
> LOG_LOCAL4);
>
> if ((pid = fork()) < 0)
> syslog(LOG_ALERT, "fork failed: %s", xstrerror());
> else if (pid > 0)
> exit(0);
>
> if (setsid() < 0)
> syslog(LOG_ALERT, "setsid failed: %s", xstrerror());
>
> closelog();
>
> #ifdef TIOCNOTTY
>
> if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
> ioctl(i, TIOCNOTTY, NULL);
> close(i);
> }
>
> #endif
>
> /*
> * RBCOLLINS - if cygwin stackdumps when squid is run without
> * -N, check the cygwin1.dll version, it needs to be AT LEAST
> * 1.1.3. execvp had a bit overflow error in a loop..
> */
> /* Connect stdio to /dev/null in daemon mode */
> nullfd = open(_PATH_DEVNULL, O_RDWR | O_TEXT);
>
> if (nullfd < 0)
> fatalf(_PATH_DEVNULL " %s\n", xstrerror());
>
> dup2(nullfd, 0);
>
> if (Debug::log_stderr < 0) {
> dup2(nullfd, 1);
> dup2(nullfd, 2);
> }
>
> Note: Looking at this code I notice that the nullfd is leaked,
> consuming
> one more filedescriptor than needed. There should be a
>
> close(nullfd);
>
> somewhere around here..
>
> for now probably best by using yet another command line option. The
> opt_no_daemon flag (-N) is far too overloaded and used at a bit too
> many
> places today and trying to sort that out is likely to give some more
> gray hairs.

What about -M with a parameter to indicate style of process management?

Are you up for making the patch?

Amos
Received on Tue Feb 11 2014 - 22:16:34 MST

This archive was generated by hypermail 2.2.0 : Thu Feb 13 2014 - 12:00:12 MST