1
Description: Avoid stale lockfile in dbus notifier
2
Bug-Redhat: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=1026949
3
Author: Tim Waugh <twaugh@redhat.com>
4
Last-Updated: 2014-01-02
9
* D-Bus notifier for CUPS.
11
* Copyright 2008-2012 by Apple Inc.
12
- * Copyright (C) 2011 Red Hat, Inc.
13
+ * Copyright (C) 2011, 2013 Red Hat, Inc.
14
* Copyright (C) 2007 Tim Waugh <twaugh@redhat.com>
15
* Copyright 1997-2005 by Easy Software Products.
21
+ * Global variables...
24
+static char lock_filename[1024]; /* Lock filename */
30
+static void release_lock(void);
31
static int acquire_lock(int *fd, char *lockfile, size_t locksize);
32
static const char *validate_utf8(const char *str);
35
DBusMessage *message; /* Message to send */
36
DBusMessageIter iter; /* Iterator for message data */
37
int lock_fd = -1; /* Lock file descriptor */
38
- char lock_filename[1024];
47
- unlink(lock_filename);
56
+ * 'release_lock()' - Release the singleton lock.
62
+ unlink(lock_filename);
67
+ * 'handle_sigterm()' - Handle SIGTERM signal.
70
+handle_sigterm(int signum)
77
* 'acquire_lock()' - Acquire a lock so we only have a single notifier running.
81
char *lockfile, /* I - Lock filename buffer */
82
size_t locksize) /* I - Size of filename buffer */
84
- const char *tmpdir; /* Temporary directory */
85
+ const char *tmpdir; /* Temporary directory */
86
+ struct sigaction action; /* POSIX sigaction data */
92
if ((*fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
98
+ * Set a SIGTERM handler to make sure we release the lock if the
99
+ * scheduler decides to stop us.
101
+ memset(&action, 0, sizeof(action));
102
+ action.sa_handler = handle_sigterm;
103
+ sigaction(SIGTERM, &action, NULL);
107
#else /* !HAVE_DBUS */