From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Differences between container used by "guix build" and "guix environment -C -N" Date: Sat, 01 Jul 2017 14:59:25 +0200 Message-ID: <87vancfh3m.fsf@gnu.org> References: <20170618144350.67710ce2@scratchpost.org> <20170619205808.4ec56691@scratchpost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRHzp-0000d1-03 for guix-devel@gnu.org; Sat, 01 Jul 2017 08:59:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRHzk-0007TB-Lv for guix-devel@gnu.org; Sat, 01 Jul 2017 08:59:33 -0400 In-Reply-To: <20170619205808.4ec56691@scratchpost.org> (Danny Milosavljevic's message of "Mon, 19 Jun 2017 20:58:08 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Danny Milosavljevic Cc: guix-devel@gnu.org Hi, Danny Milosavljevic 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 =3D subprocess.Popen(["cat"], stdin=3Dsubprocess.PIPE, stdout=3Dsubproc= ess.PIPE) > > signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGINT]) > > os.kill(p.pid, signal.SIGINT) > stdout, stderr =3D p.communicate(b"hello\n", timeout=3D1) > assert stdout =3D=3D 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 th= e 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 inherite= d. > let mut cmd =3D Command::new(OsStr::new("cat")); > > let mut set: libc::sigset_t =3D mem::uninitialized(); > let mut old_set: libc::sigset_t =3D 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 ol= d_set))); > > cmd.stdin(Stdio::MakePipe); > cmd.stdout(Stdio::MakePipe); > > let (mut cat, mut pipes) =3D t!(cmd.spawn(Stdio::Null, true)); > let stdin_write =3D pipes.stdin.take().unwrap(); > let stdout_read =3D 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 _ =3D stdin_write.write(b"Hello"); > drop(stdin_write); > > // Either EOF or failure (EPIPE) is okay. > let mut buf =3D [0; 5]; > if let Ok(ret) =3D stdout_read.read(&mut buf) { > assert!(ret =3D=3D 0); > } > > t!(cat.wait()); > } > > ------------------------------------------------------ > > and the implementation that clears the mask is https://github.com/rust-la= ng/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 =E2=80=98cmd.spawn=E2=80=99 relies on= /bin/sh to spawn processes, in which case =E2=80=9C/bin/sh=E2=80=9D would need patchin= g like we do for the =E2=80=98system=E2=80=99 function in libc and in other similar situ= ations. That doesn=E2=80=99t seem to be the case at first sight. Ludo=E2=80=99.