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