+static int check_existing_pidfile(const char *pidfile)
+{
+ struct stat sb;
+ char buf[16];
+ pid_t pid;
+ FILE *f;
+
+ if (stat(pidfile, &sb))
+ return 0;
+
+ f = fopen(pidfile, "r");
+ if (!f)
+ return 0;
+
+ if (fread(buf, sb.st_size, 1, f) < 0) {
+ fclose(f);
+ return 1;
+ }
+ fclose(f);
+
+ pid = atoi(buf);
+ if (kill(pid, SIGCONT) < 0)
+ return 0;
+
+ return 1;
+}
+
+static int write_pid(pid_t pid, const char *pidfile)