[Pkg-cups-devel] r13 - in cupsys/trunk/debian: . patches

Kenshi Muto kmuto at debian.org
Mon Aug 15 15:19:16 UTC 2005


Hi,

At Mon, 15 Aug 2005 15:05:40 +0000,
Kenshi Muto wrote:
>    cupsys/trunk/debian/patches/47_pid.dpatch   (contents, props changed)
> Log:
> add forked PID file patch.

This patch is to try to solve restart problem, with Samba or some
others.

Current init script is taken from Ubuntu. cupsd is launched by
start-stop-daemon with -F option. It works for creating PID file, but
unfortunately it won't wait till daemon is truly ready. So, Samba goes
to fail sometimes or some environment. Without -F option, result PID
of cupsd is incorrect information because cupsd launches fork and
original process exits soon.

This patch creates PID file in fork process.

BUG:
I couldn't find where should I locate remove_pid() call. Current place
maybe be incorrect because unlink() doesn't work.

> +--- ./scheduler/main.c	2005-08-15 15:00:06.000000000 +0000
> ++++ /tmp/dpep-work.prfwXg/cupsys-1.1.23/scheduler/main.c	2005-08-15 15:01:18.277965098 +0000
> +@@ -67,7 +67,8 @@
> + static void	sigterm_handler(int sig);
> + static long	select_timeout(int fds);
> + static void	usage(void);
> +-
> ++int write_pid(void);
> ++int remove_pid(void);
> + 
> + /*
> +  * Local globals...
> +@@ -423,6 +424,11 @@
> +     setuid(User);
> +   }
> + 
> ++  if (write_pid() == 0) {
> ++    LogMessage(L_ERROR, "Unable to write pid file");
> ++    return (1);
> ++  }
> ++
> +  /*
> +   * Start any pending print jobs...
> +   */
> +@@ -786,9 +792,39 @@
> +   free(input);
> +   free(output);
> + 
> ++  remove_pid();
> ++
> +   return (!stop_scheduler);
> + }
> + 
> ++/* 'write_pid()' - Write PID file.
> ++   'remove_pid()' - Delete PID file.
> ++*/
> ++int
> ++write_pid()
> ++{
> ++  FILE *f;
> ++  int fd;
> ++  int pid;
> ++  if (((fd = open("/var/run/cups/cupsd.pid", O_RDWR|O_CREAT, 0644)) == -1)
> ++      || ((f = fdopen(fd, "r+")) == NULL) ) {
> ++    return 0;
> ++  }
> ++  pid = getpid();
> ++  if (!fprintf(f, "%d\n", pid)) {
> ++    close(fd);
> ++    return 0;
> ++  }
> ++  fflush(f);
> ++  close(fd);
> ++
> ++  return pid;
> ++}
> ++
> ++int remove_pid() {
> ++  return unlink("/var/run/cups/cupsd.pid");
> ++}
> ++
> + 
> + /*
> +  * 'cupsdClosePipe()' - Close a pipe as necessary.
-- 
Kenshi Muto
kmuto at debian.org



More information about the Pkg-cups-devel mailing list