Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments on ProcessesCowan #44

Open
dpk opened this issue Sep 5, 2024 · 3 comments
Open

Comments on ProcessesCowan #44

dpk opened this issue Sep 5, 2024 · 3 comments

Comments

@dpk
Copy link
Contributor

dpk commented Sep 5, 2024

  • process-exec is portable to Windows, though process-fork is not. exec without fork is useful for hot-reloading a running program, among other things. I agree with removing the latter if we’re going to put this in the R7RS Environments.

  • process-terminate-signal should be called something else so as not to be confused with something that has to do (only) with SIGTERM. (Cutesy, not entirely serious suggestion: process-cause-of-death.)

  • I would make process-spawn take a fixed argument list like posix_spawn rather than an ersatz keyword argument structure.

  • open-fds cannot be implemented portably on POSIX. You can get close, but not all the way. (posix_spawn is so close to being the Right Thing, spoiled by the fact they decided child processes should inherit all fds from their parents by default instead of the parent getting to set up the file descriptor table for its child afresh.)

  • Is there any OS where stdin, stdout, and stderr are not 0, 1, and 2 respectively? I think this and the other file descriptor interfaces should be replaced by some kind of specialized file descriptor table type passed as an argument.

  • There’s no way to set a timeout on process-wait. This might be the right thing (lower-case deliberate) since implementing this properly involves the self-pipe trick – but without a select interface you can’t do that yourself so we should provide for it.

@johnwcowan
Copy link
Owner

johnwcowan commented Nov 12, 2024 via email

@dpk
Copy link
Contributor Author

dpk commented Nov 12, 2024

On Thu, Sep 5, 2024, 6:19 PM Daphne Preston-Kendal @.***> wrote:

  • process-exec is portable to Windows, though process-fork is not. exec without fork is useful for hot-reloading a running program, among other things. I agree with removing the latter if we’re going to put this in the R7RS Environments.

There is something on Windows called exec, but it's not equivalent to the Posix syscall family. However, the NT Executive, which líves below both Win32 and Posix, exposes Posix-compatible fork and exec as Nt* functions.

Oh, huh. I assumed since I knew MS-DOS had some kind of chain loading (and probably also because I found exec in section 3 of my manual, not section 2) that Windows must have some way to do it too.

I guess you can’t access the NT executive directly from normal user-mode program code?

  • open-fds cannot be implemented portably on POSIX. You can get close, but not all the way. (posix_spawn is so close to being the Right Thing, spoiled by the fact they decided child processes should inherit all fds from their parents by default instead of the parent getting to set up the file descriptor table for its child afresh.)
  • Is there any OS where stdin, stdout, and stderr are not 0, 1, and 2 respectively?

Not that I know of.

  • I think this and the other file descriptor interfaces should be replaced by some kind of specialized file descriptor table type passed as an argument.
    I don't and understand your reasoning here.

Well, I guess my reasoning depends on whether we want the processes interface to directly reflect the POSIX Worse is Better attitude, or try to do the Right Thing.

As I say above, I think the Right Thing is that the parent specifies a table of file descriptors for the child when it starts the process. In other words, instead of the file_actions mess, posix_spawn should have taken an array mapping file descriptor numbers in the parent to file descriptor numbers for equivalent files in the child. The child doesn’t automatically inherit any fds; it gets only the ones you explicitly pass it. That is what I think the process library should also do if we want it to do the Right Thing, and we should create a special type which contains this file descriptor mapping, passed to process-spawn.

Unfortunately, the Right Thing is not what POSIX gave us. posix_spawn instead repeats the exact same mess that fork+exec has, in terms of controlling what open files a child process has access to based on what gets inherited and what you can dup2. You can use a number of tricks to get close:

  • Just make sure all files you open have FD_CLOEXEC set. This is fine for many programs but as a new process you don’t know what file descriptors you have inherited, so any children you create will get those as well.
  • Use the non-portable posix_spawn_file_actions_addclosefrom_np function. On platforms that support this, you can actually fully simulate the Right Thing. Unfortunately, it’s not portable for reasons I do not understand. The BSDs and apparently Solaris have it, Linux (well, glibc) and Mac OS do not. (The usual objections to closefrom as a general system call do not apply to its use as a file action.)
  • Use a pile of hacks to try to simulate posix_spawn_file_actions_addclosefrom_np on the systems that don’t have it.

So, do we try to do the Right Thing by making implementers implement 90% solutions, or do we just accept that Worse is Better? If we think Worse is Better is the way to go, then we should probably wrap the file actions API more directly, as in sham1’s proposal

@johnwcowan
Copy link
Owner

johnwcowan commented Nov 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants