[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

bugfix for vacation



The following patch fixes bug #41168 in bsdmainutils (i.e.: vacation does
not send the contents of .vacation.msg)

diff -r -u2 bsdmainutils-4.5.2.orig/vacation.c bsdmainutils-4.5.2/vacation.c
--- bsdmainutils-4.5.2.orig/vacation.c  Thu Mar 25 04:11:53 1999
+++ bsdmainutils-4.5.2/vacation.c       Thu Jul 15 02:38:05 1999
@@ -419,5 +419,5 @@
                exit(1);
        }
-       i = vfork();
+       i = fork();
        if (i < 0) {
                syslog(LOG_ERR, "vacation: fork: %s", strerror(errno));



It took me a crazy 5 hours of debugging to hunt down this one, so I would
like to explain what happens and where the real source of the problem lies.

This is the relevant code (#define VMSG ".vacation.msg")

        mfp = fopen(VMSG, "r");
        if (mfp == NULL) {
                syslog(LOG_NOTICE, "vacation: no ~%s/%s file.\n", myname, VMSG)
                exit(1);
        }
        if (pipe(pvect) < 0) {
                syslog(LOG_ERR, "vacation: pipe: %s", strerror(errno));
                exit(1);
        }
        i = fork();
        if (i < 0) {
                syslog(LOG_ERR, "vacation: fork: %s", strerror(errno));
                exit(1);
        }
        if (i == 0) {
                dup2(pvect[0], 0);
                close(pvect[0]);  
                close(pvect[1]);  
                fclose(mfp);
                execl(_PATH_SENDMAIL, "sendmail", "-f", myname, from, NULL);
                syslog(LOG_ERR, "vacation: can't exec %s: %s",
                        _PATH_SENDMAIL, strerror(errno));
                exit(1);
        }
        close(pvect[0]);
        sfp = fdopen(pvect[1], "w");
        fprintf(sfp, "To: %s\n", from);
        while (fgets(buf, sizeof buf, mfp))
                fputs(buf, sfp);
        fclose(mfp);
        fclose(sfp);


When control reaches the while loop, fgets immediately returns NULL, so
probably mfp is already closed. Nothing of the message file gets written to
the pipe connected with sendmail.

Who is the culprit now?
- Linux vfork implementation
- vacation.c really should use fork instead of vfork
- vacation.c closes too much files. It shouldn't do this when using
  vfork
 

Nils

--
Plug-and-Play is really nice, unfortunately it only works 50% of the time.
To be specific the "Plug" almost always works.            --unknown source

Attachment: pgpL9rPHLYBQK.pgp
Description: PGP signature


Reply to: