]> diplodocus.org Git - nmh/blobdiff - test/fakesmtp.c
In InitMultiPart(), always set bogus_mp_content if boundaries
[nmh] / test / fakesmtp.c
index 05be6deadeccab81be8737832c052ff0aa9ff916..7121c30211df5cd1c980a6f75b3fe8fd9ab19b07 100644 (file)
@@ -13,6 +13,7 @@
 #include <netdb.h>
 #include <errno.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <errno.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <sys/types.h>
 #include <sys/select.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/select.h>
 #include <sys/stat.h>
@@ -34,6 +35,7 @@ main(int argc, char *argv[])
        struct addrinfo hints, *res;
        int rc, l, conn, on, datamode;
        FILE *f, *pid;
        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;
        fd_set readfd;
        struct stat st;
        struct timeval tv;
@@ -118,6 +120,32 @@ main(int argc, char *argv[])
                exit(1);
        }
 
                exit(1);
        }
 
+       /*
+        * 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.
        /*
         * Now that our socket & files are set up, wait 30 seconds for
         * a connection.  If there isn't one, then exit.
@@ -202,6 +230,8 @@ main(int argc, char *argv[])
                 */
 
                if (strcmp(line, "QUIT") == 0) {
                 */
 
                if (strcmp(line, "QUIT") == 0) {
+                       fclose(f);
+                       f = NULL;
                        putsmtp(conn, "221 Later alligator!");
                        close(conn);
                        break;
                        putsmtp(conn, "221 Later alligator!");
                        close(conn);
                        break;
@@ -213,7 +243,8 @@ main(int argc, char *argv[])
                }
        }
 
                }
        }
 
-       fclose(f);
+       if (f)
+               fclose(f);
 
        exit(0);
 }
 
        exit(0);
 }