diff -Nru collectd-2.1.0-orig/src/collectd.c collectd-2.1.0/src/collectd.c --- collectd-2.1.0-orig/src/collectd.c 2005-09-15 22:35:14.000000000 +0200 +++ collectd-2.1.0/src/collectd.c 2005-09-24 10:34:13.000000000 +0200 @@ -16,6 +16,9 @@ kstat_ctl_t *kc; #endif /* HAVE_LIBKSTAT */ +#define PID_PATH "/var/run/collectd.pid" + + void sigIntHandler (int signal) { loop++; @@ -166,6 +169,27 @@ exit (0); } +static int create_pidfile (void) +{ + FILE *fh = fopen (PID_PATH, "w"); + + if (!fh) + { + syslog (LOG_ERR, "fopen (pidfile): %s", strerror (errno)); + return 1; + } + + fprintf(fh, "%d\n", getpid()); + fclose(fh); + + return 0; +} + +static int remove_pidfile (void) +{ + return unlink (PID_PATH); +} + int main (int argc, char **argv) { int sleepingtime; @@ -253,6 +277,9 @@ } #endif + if (create_pidfile ()) + exit (2); + /* child */ while (loop == 0) { @@ -304,6 +331,8 @@ /* close syslog */ closelog (); + + remove_pidfile(); return (0); }