Blame SOURCES/cups-dbus-notifier.patch

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