+ return 1;
+ }
+
+ if (background) {
+ int pid = fork ();
+ if (pid > 0) {
+ printf ("smtp_dummy_pid='%d'\n", pid);
+ fflush (stdout);
+ close (sock);
+ return 0;
+ }
+ if (pid < 0) {
+ fprintf (stderr, "Error: fork() failed: %s\n",
+ strerror (errno));
+ close (sock);
+ return 1;
+ }
+ /* Reached if pid == 0 (the child process). */
+ /* Close stdout so that the one interested in pid value will
+ * also get EOF. */
+ close (STDOUT_FILENO);
+ /* dup2() will re-reserve fd of stdout (1) (opportunistically),
+ * in case fd of stderr (2) is open. If that was not open we
+ * don't care fd of stdout (1) either. */
+ dup2 (STDERR_FILENO, STDOUT_FILENO);
+
+ /* This process is now out of reach of shell's job control.
+ * To resolve the rare but possible condition where this
+ * "daemon" is started but never connected this process will
+ * (only) have 30 seconds to exist. */
+ alarm (30);
+ }
+
+ peer_addr_len = sizeof (peer_addr);
+ peer = accept (sock, (struct sockaddr *) &peer_addr, &peer_addr_len);
+ if (peer == -1) {
+ fprintf (stderr, "Error: accept() failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+
+ peer_file = fdopen (peer, "w+");
+ if (peer_file == NULL) {
+ fprintf (stderr, "Error: fdopen() failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+
+ do_smtp_to_file (peer_file, output);
+
+ fclose (output);
+ fclose (peer_file);
+ close (sock);