aboutsummaryrefslogtreecommitdiff
path: root/src/pidfile.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-02-24 00:49:40 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-02-24 00:57:16 +0200
commit4213ec5ef9695aa504938c0e764ba9a4f08921b2 (patch)
tree88ac2b2eb01337f0924d687df38b2a163bc94e11 /src/pidfile.c
parent337a06f32fb530e0e0884fef2f5f630cca9911a1 (diff)
downloadwydawca-4213ec5ef9695aa504938c0e764ba9a4f08921b2.tar.gz
wydawca-4213ec5ef9695aa504938c0e764ba9a4f08921b2.tar.bz2
Initial implementation of daemon mode.
* gconf/gconf-gram.y (string_to_sockaddr_: Take struct gconf_sockaddr as the first argument. * gconf/gconf.h (struct gconf_sockaddr): New data type. * src/job.c, src/net.c, src/pidfile.c: New files. * src/Makefile.am (wydawca_SOURCES): Add job.c, net.c, pidfile.c * src/cmdline.opt: New options: --cron (change semantics), --force, --foreground, --single-process, --spool * src/wydawca.c: New daemon mode. * src/config.c: New statements: spool.alias, daemon, foreground, single-process, wakeup-interval, pidfile, listen * src/directive.c, src/diskio.c, src/gpg.c, src/mail.c, src/null.c, src/process.c, src/triplet.c, src/verify.c, src/vtab.c, src/wydawca.h: use static struct spool wherever feasible. * src/triplet.c: New meta-variable "spool" * tests/etc/wydawca.rcin: Update. * tests/upload-dry.at: Update.
Diffstat (limited to 'src/pidfile.c')
-rw-r--r--src/pidfile.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/pidfile.c b/src/pidfile.c
new file mode 100644
index 0000000..484cabd
--- /dev/null
+++ b/src/pidfile.c
@@ -0,0 +1,90 @@
+/* wydawca - automatic release submission daemon
+ Copyright (C) 2007, 2009 Sergey Poznyakoff
+
+ Wydawca is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ Wydawca is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with wydawca. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "wydawca.h"
+
+char *pidfile = LOCALSTATEDIR "/run/wydawca.pid";
+int force_startup;
+
+
+void
+remove_pidfile (void)
+{
+ unlink (pidfile);
+}
+
+void
+check_pidfile ()
+{
+ FILE *fp = fopen (pidfile, "r+");
+
+ if (fp)
+ {
+ unsigned long pid;
+ if (fscanf (fp, "%ul\n", &pid) != 1)
+ {
+ logmsg (LOG_ERR, _("malformed pidfile %s"), pidfile);
+ if (!force_startup)
+ exit (1);
+ }
+ else
+ {
+ if (kill (pid, 0))
+ {
+ if (errno != ESRCH)
+ {
+ logmsg (LOG_ERR,
+ _("cannot verify if PID %lu is running: %s"),
+ pid, strerror (errno));
+ if (!force_startup)
+ exit (1);
+ }
+ }
+ else if (!force_startup)
+ {
+ logmsg (LOG_ERR,
+ _("another wydawca instance may be running (PID %lu)"),
+ pid);
+ exit (1);
+ }
+ }
+ logmsg (LOG_NOTICE, _("replacing pidfile %s (PID %lu)"),
+ pidfile, pid);
+ fseek (fp, 0, SEEK_SET);
+ }
+ else if (errno != ENOENT)
+ {
+ logmsg (LOG_ERR, _("cannot open pidfile %s: %s"), pidfile,
+ strerror (errno));
+ exit (1);
+ }
+ else
+ {
+ fp = fopen (pidfile, "w");
+ if (!fp)
+ {
+ logmsg (LOG_ERR,
+ _("cannot open pidfile %s for writing: %s"),
+ pidfile, strerror (errno));
+ exit (1);
+ }
+ }
+ fprintf (fp, "%lu\n", getpid ());
+ fclose (fp);
+ atexit (remove_pidfile);
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.