+static int readpid(void)
+{
+ int fd;
+ int pid = -1;
+ char buf[9] = { 0 };
+
+ if ((fd = open(PID_PATH, O_RDONLY)) > -1)
+ {
+ if (read(fd, buf, sizeof(buf)))
+ {
+ buf[8] = 0;
+ pid = atoi(buf);
+ }
+
+ close(fd);
+ }
+
+ return pid;
+}
+
+static int writepid(void)
+{
+ int fd;
+ int wlen;
+ char buf[9] = { 0 };
+
+ if ((fd = open(PID_PATH, O_WRONLY | O_CREAT | O_TRUNC, 0600)) > -1)
+ {
+ wlen = snprintf(buf, sizeof(buf), "%i", getpid());
+ write(fd, buf, wlen);
+ close(fd);
+
+ return 0;
+ }
+
+ return -1;
+}
+
+static int timeout = TIMEOUT;
+static int countdown = -1;
+
+static void reset_countdown(int sig)
+{
+ countdown = timeout;
+
+}
+