struct addrinfo hints, *res;
int rc, l, conn, on, datamode;
FILE *f, *pid;
+ pid_t child;
fd_set readfd;
struct stat st;
struct timeval tv;
}
/*
+ * Now we fork() and print out the process ID of our child
+ * for scripts to use. Once we do that, then exit.
+ */
+
+ child = fork();
+
+ switch (child) {
+ case -1:
+ fprintf(stderr, "Unable to fork child: %s\n", strerror(errno));
+ exit(1);
+ break;
+ case 0:
+ /*
+ * Close stdin & stdout, otherwise people can
+ * think we're still doing stuff. For now leave stderr
+ * open.
+ */
+ fclose(stdin);
+ fclose(stdout);
+ break;
+ default:
+ printf("%ld\n", (long) child);
+ exit(0);
+ }
+
+ /*
* Now that our socket & files are set up, wait 30 seconds for
* a connection. If there isn't one, then exit.
*/
*/
if (strcmp(line, "QUIT") == 0) {
+ fclose(f);
+ f = NULL;
putsmtp(conn, "221 Later alligator!");
close(conn);
break;
}
}
- fclose(f);
+ if (f)
+ fclose(f);
exit(0);
}