unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: guix-devel@gnu.org
Subject: Re: Differences between container used by "guix build" and "guix environment -C -N"
Date: Sat, 01 Jul 2017 14:59:25 +0200	[thread overview]
Message-ID: <87vancfh3m.fsf@gnu.org> (raw)
In-Reply-To: <20170619205808.4ec56691@scratchpost.org> (Danny Milosavljevic's message of "Mon, 19 Jun 2017 20:58:08 +0200")

Hi,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

> it does pretty much the equvalent of this Python program, in Rust:
>
> ------------------------
> #!/usr/bin/env python3
>
> import os
> import subprocess
> import signal
>
> signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGINT])
>
> p = subprocess.Popen(["cat"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
>
> signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGINT])
>
> os.kill(p.pid, signal.SIGINT)
> stdout, stderr = p.communicate(b"hello\n", timeout=1)
> assert stdout == b""
> p.wait()
> ------------------------
>
> The goal of it is to test this feature: Their "Popen" implementation uses something like spawnvp, only they have overwritten it in order to clear the signal mask for the child.
>
> In Rust the test is:
>
> ------------------------------------------------------
>
>     fn test_process_mask() {
>         unsafe {
>             // Test to make sure that a signal mask does not get inherited.
>             let mut cmd = Command::new(OsStr::new("cat"));
>
>             let mut set: libc::sigset_t = mem::uninitialized();
>             let mut old_set: libc::sigset_t = mem::uninitialized();
>             t!(cvt(libc::sigemptyset(&mut set)));
>             t!(cvt(sigaddset(&mut set, libc::SIGINT)));
>             t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set)));
>
>             cmd.stdin(Stdio::MakePipe);
>             cmd.stdout(Stdio::MakePipe);
>
>             let (mut cat, mut pipes) = t!(cmd.spawn(Stdio::Null, true));
>             let stdin_write = pipes.stdin.take().unwrap();
>             let stdout_read = pipes.stdout.take().unwrap();
>
>             t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &old_set,
>                                          ptr::null_mut())));
>
>             t!(cvt(libc::kill(cat.id() as libc::pid_t, libc::SIGINT)));
>             // We need to wait until SIGINT is definitely delivered. The
>             // easiest way is to write something to cat, and try to read it
>             // back: if SIGINT is unmasked, it'll get delivered when cat is
>             // next scheduled.
>             let _ = stdin_write.write(b"Hello");
>             drop(stdin_write);
>
>             // Either EOF or failure (EPIPE) is okay.
>             let mut buf = [0; 5];
>             if let Ok(ret) = stdout_read.read(&mut buf) {
>                 assert!(ret == 0);
>             }
>
>             t!(cat.wait());
>         }
>
> ------------------------------------------------------
>
> and the implementation that clears the mask is https://github.com/rust-lang/rust/blob/1.16.0/src/libstd/sys/unix/process/process_unix.rs#L144 (line 144ff, bottom of "fn do_exec")

I guess the question would be whether ‘cmd.spawn’ relies on /bin/sh to
spawn processes, in which case “/bin/sh” would need patching like we do
for the ‘system’ function in libc and in other similar situations.  That
doesn’t seem to be the case at first sight.

Ludo’.

      reply	other threads:[~2017-07-01 12:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-18 12:43 Differences between container used by "guix build" and "guix environment -C -N" Danny Milosavljevic
2017-06-19  8:21 ` Ludovic Courtès
2017-06-19 18:58 ` Danny Milosavljevic
2017-07-01 12:59   ` Ludovic Courtès [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vancfh3m.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=dannym@scratchpost.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).