X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fsend.c;h=e39ab800e6a7c8569047cca2ff2a3eb61074dc90;hb=3e300b97e9a54a3157e37948f8827abbe3eecf05;hp=1529c0faa13e16cdf96f6d1fbf6b2abe83a2716b;hpb=f3cb7cde0e6f10451b6848678d95860d512224b9;p=mmh diff --git a/uip/send.c b/uip/send.c index 1529c0f..e39ab80 100644 --- a/uip/send.c +++ b/uip/send.c @@ -97,6 +97,7 @@ main(int argc, char **argv) int msgp = 0, nfiles = 0, distsw = 0, vecp = 1; int msgnum, status; int in, out; + int n; char *cp, *maildir = NULL; char buf[BUFSIZ], **ap, **argp, **arguments; char *msgs[MAXARGS], *vec[MAXARGS]; @@ -252,27 +253,17 @@ main(int argc, char **argv) if ((cp = getenv("mhdist")) && *cp && (distsw = atoi(cp)) && altmsg) { vec[vecp++] = "-dist"; - distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL)); - if (link(altmsg, distfile) == NOTOK) { - if (errno != EXDEV) { - adios(distfile, "unable to link %s to", - altmsg); - } - free(distfile); - distfile = getcpy(m_mktemp2(NULL, invo_name, - NULL, NULL)); - if ((in = open(altmsg, O_RDONLY)) == NOTOK) { - adios(altmsg, "unable to open"); - } - fstat(in, &st2); - if ((out = creat(distfile, (int)st2.st_mode & 0777)) == - NOTOK) { - adios(distfile, "unable to write"); - } - cpydata(in, out, altmsg, distfile); - close(in); - close(out); + if ((in = open(altmsg, O_RDONLY)) == NOTOK) { + adios(altmsg, "unable to open for reading"); } + fstat(in, &st2); + distfile = getcpy(m_mktemp2(NULL, invo_name, NULL, NULL)); + if ((out = creat(distfile, (int)st2.st_mode & 0777))==NOTOK) { + adios(distfile, "unable to open for writing"); + } + cpydata(in, out, altmsg, distfile); + close(in); + close(out); } else { distfile = NULL; } @@ -283,11 +274,40 @@ main(int argc, char **argv) st.st_ino = 0; } if (pushsw) { - push(); + /* push a fork into the background */ + pid_t pid; + + switch (pid = fork()) { + case -1: + /* fork error */ + advise(NULL, "unable to fork, so can't push..."); + break; + + default: + /* parent, just exit */ + done(0); + + case 0: + /* child, block a few signals and continue */ + SIGNAL(SIGHUP, SIG_IGN); + SIGNAL(SIGINT, SIG_IGN); + SIGNAL(SIGQUIT, SIG_IGN); + SIGNAL(SIGTERM, SIG_IGN); +#ifdef SIGTSTP + SIGNAL(SIGTSTP, SIG_IGN); + SIGNAL(SIGTTIN, SIG_IGN); + SIGNAL(SIGTTOU, SIG_IGN); +#endif + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + break; + } } status = 0; - vec[0] = mhbasename(postproc); - closefds(3); + vec[0] = "spost"; + for (n=3; n{attachment}", - content_type, - (!(cp = strrchr(file_name, '/'))) ? file_name : cp + 1); + cp = (!(cp = strrchr(file_name, '/'))) ? file_name : cp + 1; + fprintf(composition_file, "#%s; name=\"%s\" <> [%s] {attachment}", + content_type, cp, cp); fprintf(composition_file, " %s\n", file_name); @@ -625,17 +641,17 @@ make_mime_composition_file_entry(char *file_name) /* ** The back-end of the message sending back-end. -** Annotate original message, and call `postproc' to send message. +** Annotate original message, and call `spost' to send message. */ static int sendaux(char **vec, int vecp, char *drft, struct stat *st) { pid_t child_id; - int i, status, fd; + int status, fd; char backup[BUFSIZ]; /* - ** fd collects the output of postproc, and is used for the + ** fd collects the output of spost, and is used for the ** failure notice if we need to send one in alert(). */ fd = pushsw ? tmp_fd() : NOTOK; @@ -646,10 +662,7 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) } vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) { - sleep(5); - } - switch (child_id) { + switch (child_id = fork()) { case -1: /* oops -- fork error */ adios("fork", "unable to"); @@ -667,9 +680,9 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) dup2(fd, fileno(stderr)); close(fd); } - execvp(postproc, vec); + execvp(*vec, vec); fprintf(stderr, "unable to exec "); - perror(postproc); + perror(*vec); _exit(-1); break; /* NOT REACHED */ @@ -681,7 +694,7 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) } } else { /* - ** If postproc failed, and we have good fd (which + ** If spost failed, and we have good fd (which ** means we pushed), then mail error message ** (and possibly the draft) back to the user. */ @@ -708,20 +721,16 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) /* ** Mail error notification (and possibly a copy of the -** message) back to the user, using the mailproc +** message) back to the user, using mhmail(1). */ static void alert(char *file, int out) { pid_t child_id; - int i, in; + int in; char buf[BUFSIZ]; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) { - sleep(5); - } - - switch (child_id) { + switch (child_id = fork()) { case NOTOK: /* oops -- fork error */ advise("fork", "unable to"); @@ -756,11 +765,10 @@ alert(char *file, int out) /* create subject for error notification */ snprintf(buf, sizeof(buf), "send failed on %s", forwsw ? "enclosed draft" : file); - - execlp(mailproc, mhbasename(mailproc), getusername(), + execlp("mhmail", "mhmail", getusername(), "-subject", buf, NULL); fprintf(stderr, "unable to exec "); - perror(mailproc); + perror("mhmail"); _exit(-1); default: /* no waiting... */