X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=test%2Ffakesmtp.c;h=fbfe044233a2cb5b345bd0971b81617194cb78ec;hb=39a6bb2ad6c87e55d25115eb7d8e9a4043fec2e1;hp=05be6deadeccab81be8737832c052ff0aa9ff916;hpb=2ffe7ca30b85d542d02f74c39785319bcb6ad005;p=mmh diff --git a/test/fakesmtp.c b/test/fakesmtp.c index 05be6de..fbfe044 100644 --- a/test/fakesmtp.c +++ b/test/fakesmtp.c @@ -34,6 +34,7 @@ main(int argc, char *argv[]) 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; @@ -119,6 +120,32 @@ main(int argc, char *argv[]) } /* + * 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. */ @@ -202,6 +229,8 @@ main(int argc, char *argv[]) */ if (strcmp(line, "QUIT") == 0) { + fclose(f); + f = NULL; putsmtp(conn, "221 Later alligator!"); close(conn); break; @@ -213,7 +242,8 @@ main(int argc, char *argv[]) } } - fclose(f); + if (f) + fclose(f); exit(0); }