+ /*
+ * If there is a pid file already around, kill the previously running
+ * fakesmtp process. Hopefully this will reduce the race conditions
+ * that crop up when running the test suite.
+ */
+
+ if (stat(PIDFILE, &st) == 0) {
+ long oldpid;
+
+ if (!(pid = fopen(PIDFILE, "r"))) {
+ fprintf(stderr, "Cannot open " PIDFILE
+ " (%s), continuing ...\n", strerror(errno));
+ } else {
+ rc = fscanf(pid, "%ld", &oldpid);
+ fclose(pid);
+
+ if (rc != 1) {
+ fprintf(stderr, "Unable to parse pid in "
+ PIDFILE ", continuing ...\n");
+ } else {
+ kill((pid_t) oldpid, SIGTERM);
+ }
+ }
+
+ unlink(PIDFILE);
+ }
+