Blame SOURCES/cups-dbus-notifier.patch

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