Blame SOURCES/cups-dbus-notifier.patch

87cf9a
diff -up cups-1.6.3/notifier/dbus.c.dbus-notifier cups-1.6.3/notifier/dbus.c
87cf9a
--- cups-1.6.3/notifier/dbus.c.dbus-notifier	2013-11-19 12:23:56.860249407 +0000
87cf9a
+++ cups-1.6.3/notifier/dbus.c	2013-11-19 12:24:46.919476920 +0000
87cf9a
@@ -4,7 +4,7 @@
87cf9a
  *   D-Bus notifier for CUPS.
87cf9a
  *
87cf9a
  *   Copyright 2008-2011 by Apple Inc.
87cf9a
- *   Copyright (C) 2011 Red Hat, Inc.
87cf9a
+ *   Copyright (C) 2011, 2013 Red Hat, Inc.
87cf9a
  *   Copyright (C) 2007 Tim Waugh <twaugh@redhat.com>
87cf9a
  *   Copyright 1997-2005 by Easy Software Products.
87cf9a
  *
87cf9a
@@ -157,9 +157,16 @@ enum
87cf9a
 
87cf9a
 
87cf9a
 /*
87cf9a
+ * Global variables...
87cf9a
+ */
87cf9a
+
87cf9a
+static char		lock_filename[1024];	/* Lock filename */
87cf9a
+
87cf9a
+/*
87cf9a
  * Local functions...
87cf9a
  */
87cf9a
 
87cf9a
+static void		release_lock(void);
87cf9a
 static int		acquire_lock(int *fd, char *lockfile, size_t locksize);
87cf9a
 static const char	*validate_utf8(const char *str);
87cf9a
 
87cf9a
@@ -251,8 +258,6 @@ main(int  argc,				/* I - Number of comm
87cf9a
   DBusMessage		*message;	/* Message to send */
87cf9a
   DBusMessageIter	iter;		/* Iterator for message data */
87cf9a
   int			lock_fd = -1;	/* Lock file descriptor */
87cf9a
-  char			lock_filename[1024];
87cf9a
-					/* Lock filename */
87cf9a
 
87cf9a
 
87cf9a
  /*
87cf9a
@@ -651,7 +656,7 @@ main(int  argc,				/* I - Number of comm
87cf9a
   if (lock_fd >= 0)
87cf9a
   {
87cf9a
     close(lock_fd);
87cf9a
-    unlink(lock_filename);
87cf9a
+    release_lock();
87cf9a
   }
87cf9a
 
87cf9a
   return (0);
87cf9a
@@ -659,6 +664,27 @@ main(int  argc,				/* I - Number of comm
87cf9a
 
87cf9a
 
87cf9a
 /*
87cf9a
+ * 'release_lock()' - Release the singleton lock.
87cf9a
+ */
87cf9a
+
87cf9a
+static void
87cf9a
+release_lock(void)
87cf9a
+{
87cf9a
+  unlink(lock_filename);
87cf9a
+}
87cf9a
+
87cf9a
+
87cf9a
+/*
87cf9a
+ * 'handle_sigterm()' - Handle SIGTERM signal.
87cf9a
+ */
87cf9a
+static void
87cf9a
+handle_sigterm(int signum)
87cf9a
+{
87cf9a
+  release_lock();
87cf9a
+  _exit (0);
87cf9a
+}
87cf9a
+
87cf9a
+/*
87cf9a
  * 'acquire_lock()' - Acquire a lock so we only have a single notifier running.
87cf9a
  */
87cf9a
 
87cf9a
@@ -667,7 +692,8 @@ acquire_lock(int    *fd,		/* O - Lock fi
87cf9a
              char   *lockfile,		/* I - Lock filename buffer */
87cf9a
 	     size_t locksize)		/* I - Size of filename buffer */
87cf9a
 {
87cf9a
-  const char	*tmpdir;		/* Temporary directory */
87cf9a
+  const char		*tmpdir;	/* Temporary directory */
87cf9a
+  struct sigaction	action;		/* POSIX sigaction data */
87cf9a
 
87cf9a
 
87cf9a
  /*
87cf9a
@@ -685,8 +711,16 @@ acquire_lock(int    *fd,		/* O - Lock fi
87cf9a
 
87cf9a
   if ((*fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
87cf9a
     return (-1);
87cf9a
-  else
87cf9a
-    return (0);
87cf9a
+
87cf9a
+ /*
87cf9a
+  * Set a SIGTERM handler to make sure we release the lock if the
87cf9a
+  * scheduler decides to stop us.
87cf9a
+  */
87cf9a
+  memset(&action, 0, sizeof(action));
87cf9a
+  action.sa_handler = handle_sigterm;
87cf9a
+  sigaction(SIGTERM, &action, NULL);
87cf9a
+
87cf9a
+  return (0);
87cf9a
 }
87cf9a
 #else /* !HAVE_DBUS */
87cf9a
 int