From patchwork Wed Apr 5 03:59:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daurnimator X-Patchwork-Id: 747087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vyXHt3p6fz9s8B for ; Wed, 5 Apr 2017 14:03:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="yfBevFUi"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=VaSLNFY9MmJuu2UJQ26fTHlvlDTGLBuXlmXsjm43/wFaIxRJjaH6x MW5l8P9LA8qnr1wwt8C1gptVkEvlOjKIRWGrWgxgpK15cWgLk1dMdwDrclkU5Nm7 +GNNSOidivId1NpFGNKeV76SFTcR8AVyS9HnuREwBPmbVEqlOyN4Ug= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=+ynaRXib4epYCJlAPzPPXhqOHwI=; b=yfBevFUibm2N3buCsX53y5cBtJca gmEmCOEL9ZBUP2h81NekQszNZVYLloTu2FEZXB7rZeHzwwrMfKEzUmUOA14MzNga rFQEOLJOAcdVfwfIkiKf774C9jFo9s35erA5JhKEHzLRsHLxz+1tPoz3N9rvuJCB iWumm+0ReLMrRIQ= Received: (qmail 22301 invoked by alias); 5 Apr 2017 04:00:43 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21446 invoked by uid 89); 5 Apr 2017 03:59:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=sid X-HELO: mail-pf0-f194.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X+1iceerDHYbCgA5FVmIUQub/XejzTfFgS39B4sHdOg=; b=OnBUJWp857/dGl/+AoCAXUFoIQhEZPs+6EvNzE4GzZRFIVSo/g0DR+/ysS0tqFSqDD ixruV1nTxhaGUnr9NEkTaXoZPG2a00dQA2Lg2IFegs/A1gDMokOcH1njNH6dCb54V3uu v7h7FO+w5+q4l/uwQetl/6LHBI7YnFLOwfNpwNOTPfRnCnIuMXmlTixL3NDJJjv24/SY OCcspi5XS7zu4IFABAveARA0shCCLlgaeajzC6kvvnwfd5Qif+x69PiabC4fXg1InhWY W1BDDjZ4+R8K3bTQWHZIAtiMgTxvbLbDXUHMXbOWjAj9X+gcrciXx2VQCJdE97dm5U1Y gkDQ== X-Gm-Message-State: AFeK/H3DTlLBSnGT0cnI6/eJDE9g0zPzu2pFFFM35yiyBeweIWg5bbjvqFShSqYXSi/s1w== X-Received: by 10.84.129.132 with SMTP id b4mr33640550plb.54.1491364787572; Tue, 04 Apr 2017 20:59:47 -0700 (PDT) From: daurnimator To: libc-alpha@sourceware.org Cc: daurnimator Subject: [PATCH v2][BZ 21340] add support for POSIX_SPAWN_SETSID Date: Wed, 5 Apr 2017 13:59:19 +1000 Message-Id: <20170405035919.27651-1-quae@daurnimator.com> This patch adds support for the POSIX_SPAWN_SETSID flag. It was recently accepted by the Austin Group: http://austingroupbugs.net/view.php?id=1044 Checked on x86_64 2017-04-05 Daurnimator [BZ #21340] * conform/data/spawn.h-data: Add POSIX_SPAWN_SETSID flag. * posix/Makefile: Add tst-posix_spawn-setsid to list of tests. * posix/spawn.h: define POSIX_SPAWN_SETSID flag. * posix/spawnattr_setflags.c: Add POSIX_SPAWN_SETSID to valid flags. * posix/tst-posix_spawn-setsid.c: Add test for POSIX_SPAWN_SETSID. * sysdeps/mach/hurd/spawni.c: Implementation of POSIX_SPAWN_SETSID. * sysdeps/posix/spawni.c: Likewise. * sysdeps/unix/sysv/linux/spawni.c: Likewise. --- conform/data/spawn.h-data | 1 + posix/Makefile | 2 +- posix/spawn.h | 1 + posix/spawnattr_setflags.c | 1 + posix/tst-posix_spawn-setsid.c | 65 ++++++++++++++++++++++++++++++++++++++++ sysdeps/mach/hurd/spawni.c | 3 ++ sysdeps/posix/spawni.c | 7 ++++- sysdeps/unix/sysv/linux/spawni.c | 4 +++ 8 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 posix/tst-posix_spawn-setsid.c diff --git a/conform/data/spawn.h-data b/conform/data/spawn.h-data index fb206f7ecf..bcba36c492 100644 --- a/conform/data/spawn.h-data +++ b/conform/data/spawn.h-data @@ -14,6 +14,7 @@ constant POSIX_SPAWN_SETSCHEDPARAM constant POSIX_SPAWN_SETSCHEDULER constant POSIX_SPAWN_SETSIGDEF constant POSIX_SPAWN_SETSIGMASK +constant POSIX_SPAWN_SETSID function int posix_spawnattr_destroy (posix_spawnattr_t*) function int posix_spawnattr_getsigdefault (const posix_spawnattr_t*, sigset_t*) diff --git a/posix/Makefile b/posix/Makefile index ae17646323..a9f53a973d 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -90,7 +90,7 @@ tests := test-errno tstgetopt testfnm runtests runptests \ bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \ tst-pathconf tst-getaddrinfo4 tst-rxspencer-no-utf8 \ tst-fnmatch3 bug-regex36 tst-getaddrinfo5 \ - tst-posix_spawn-fd \ + tst-posix_spawn-fd tst-posix_spawn-setsid \ tst-posix_fadvise tst-posix_fadvise64 xtests := bug-ga2 ifeq (yes,$(build-shared)) diff --git a/posix/spawn.h b/posix/spawn.h index 36e3867e17..8d2ace1b87 100644 --- a/posix/spawn.h +++ b/posix/spawn.h @@ -60,6 +60,7 @@ typedef struct #ifdef __USE_GNU # define POSIX_SPAWN_USEVFORK 0x40 #endif +#define POSIX_SPAWN_SETSID 0x80 __BEGIN_DECLS diff --git a/posix/spawnattr_setflags.c b/posix/spawnattr_setflags.c index 9b3d1e022a..62d2f00c20 100644 --- a/posix/spawnattr_setflags.c +++ b/posix/spawnattr_setflags.c @@ -25,6 +25,7 @@ | POSIX_SPAWN_SETSIGMASK \ | POSIX_SPAWN_SETSCHEDPARAM \ | POSIX_SPAWN_SETSCHEDULER \ + | POSIX_SPAWN_SETSID \ | POSIX_SPAWN_USEVFORK) /* Store flags in the attribute structure. */ diff --git a/posix/tst-posix_spawn-setsid.c b/posix/tst-posix_spawn-setsid.c new file mode 100644 index 0000000000..27d1581f1f --- /dev/null +++ b/posix/tst-posix_spawn-setsid.c @@ -0,0 +1,65 @@ +/* Test that spawn attribute setsid works. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +static int +do_test (void) +{ + posix_spawnattr_t attrp; + int child_pid; + int sid, child_sid; + char *args[2]; + + /* record sid for current process */ + sid = getsid(0); + + posix_spawnattr_init(&attrp); + posix_spawnattr_setflags(&attrp, POSIX_SPAWN_SETSID); + + /* run the program 'true' */ + args[0] = (char *)"true"; + args[1] = NULL; + + int res = posix_spawnp(&child_pid, "true", NULL, &attrp, args, environ); + posix_spawnattr_destroy(&attrp); + if (res) + { + printf("error: posix_spawnp: %m\n"); + return 1; + } + + /* child should have a different sid */ + child_sid = getsid(child_pid); + if (child_sid == sid) + { + printf("error: child sid matches\n"); + return 1; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 284875ac30..74303839e4 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -281,6 +281,9 @@ __spawni (pid_t *pid, const char *file, } #endif + if (!err && (flags & POSIX_SPAWN_SETSID) != 0) + err = __proc_setsid (proc); + /* Set the process group ID. */ if (!err && (flags & POSIX_SPAWN_SETPGROUP) != 0) err = __proc_setpgrp (proc, new_pid, attrp->__pgrp); diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c index 5cc2ad1363..bc23a1e6ab 100644 --- a/sysdeps/posix/spawni.c +++ b/sysdeps/posix/spawni.c @@ -101,7 +101,8 @@ __spawni (pid_t *pid, const char *file, to POSIX. */ || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER - | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0 + | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS + | POSIX_SPAWN_SETSID)) == 0 && file_actions == NULL)) new_pid = __vfork (); else @@ -159,6 +160,10 @@ __spawni (pid_t *pid, const char *file, } #endif + if ((flags & POSIX_SPAWN_SETSID) != 0 + && __setsid () != 0) + _exit (SPAWN_ERROR); + /* Set the process group ID. */ if ((flags & POSIX_SPAWN_SETPGROUP) != 0 && __setpgid (0, attrp->__pgrp) != 0) diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index d7f9e83575..91314be399 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -177,6 +177,10 @@ __spawni_child (void *arguments) } #endif + if ((attr->__flags & POSIX_SPAWN_SETSID) != 0 + && (ret = __setsid ()) != 0) + goto fail; + /* Set the process group ID. */ if ((attr->__flags & POSIX_SPAWN_SETPGROUP) != 0 && (ret = __setpgid (0, attr->__pgrp)) != 0)