nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] Proposed solution to Debian Bug#143485

2005-08-26 06:19:25
          execlp (mhlproc, mhl, "-form", filter, "-noclear", NULL);
-         fprintf (stderr, "unable to exec ");
-         perror (mhlproc);
+         write(2, "unable to exec ", 15);
+         write(2, mhlproc, strlen(mhlproc));
+         write(2, strerror(errno), strlen(strerror(errno)));

The code you changed there is obviously broken (apart from using printf after
a vfork), but your replacement isn't a lot better - the "strerror(errno)"
calls (which you really should not do twice ... use a variable and save the
result!) the way you have it is getting the errno set from the write(2,
mhlproc, strlen(mhlproc)) sys call, where I suspect that you wanted the
errno from the execlp (which must have failed or the code wouldn't be being
executed).

Hm, I think if write(2, ...) fails, then we are out of luck anyway. We
can't give an error message about being unable to give an error message.
I thought that a successful call of write won't manipulate errno, but after
rereading the documentation of errno it seems that one can't rely on this.
On the other hand it says, that one can detect an error by explictely
setting errno=0 before the call and testing errno afterwards. It also
says that errno is never set to zero by the library. So I'm now a bit
confused about how write is allowed to change errno on success...

write this as
      char *errstr;
      [...]
      execlp(...);
      errstr = strerror(errno);
      write(2,....);
      write(2,....);
/* maybe: write(2, ": ", 2); */
      write(2, errstr, strlen(errstr));
      write(2, "\n", 1);

I agree that this is a better solution. If anybody is going to commit my
patch, he hopefully will incorporate this.

Grüße,
Harald



_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
http://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>