chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] Fixing the "process" procedure to be safe against


From: Lassi Kortela
Subject: Re: [Chicken-hackers] Fixing the "process" procedure to be safe against execve() errors
Date: Thu, 25 Jul 2019 21:39:13 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

The the way things are done in the current version of Chicken is wonky because the outline is like this:

      child = fork();
      if (!child) {
          // This code runs in the child process.
          execve(exefile, argv, envp);
          // Not only is the errno value not returned to the parent,
          // but there is no call to exit() at all. So the child
          // keeps running the user's Scheme program after a failed
          // execve() until the program error-exits. Since the parent
          // also continues running the Scheme program, there are now
          // two copies of it running concurrently.
      }

So if you wrap a Scheme exception handler around the (process ...) call to catch and handle execve() errors (e.g. to write an error message or return false from the enclosing procedure), that exception handler is run in the child process (which is supposed to have no other job except to call execve() or die trying). And if you handle the exception instead of letting it propagate all the way up the Scheme stack, then the child Scheme process will eventually exit with success code zero (since your Scheme program succeeded) and the parent process will think exefile succeeded.

TL;DR multiprocessing is complicated :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]