From patchwork Fri Apr 21 14:13:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 20113 Received: (qmail 119796 invoked by alias); 21 Apr 2017 14:13:14 -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 119770 invoked by uid 89); 21 Apr 2017 14:13:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=1017, countries X-HELO: mail-qt0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=WM5/t9Zn9pf85xa7topm7bkJ2UGoKeuQlToxo7aQlsM=; b=GOj5UN6oAfDvQM3yp+q2P30/xlZbVvm6Yg/HW+YEmuIksEb3I5VM56aSKvxZj47H/a Xnip/GSIYipTKf/rYu3bQd899iprmPo/78G8HwtBRyctET4vYTi7Ca+9juHqpVW9CtX3 71TnguVpx3K23BfYgGg62sKY4WbZZue8Zk5OO61Vqb66xacJRqnMtBhmR8EDxEXNk98t V712id/emP+dFIkInJZPFuuUHlUx2te3K7XU9fJb9YcoEXfp4IW7/yu+Yiu5OTceLKlI G0VIsTB4EXUJF/FqvCMQ7Ii/J3ZEVpoIpX8VxudpVLR+hlp9lH9kkhtJDSxMaF7Wx05T BWNQ== X-Gm-Message-State: AN3rC/7aPhjNjD8RSR7Pcwo+QU1+3B2sSevM7LaPuWfi1v5E2iHF6nRh 6ZTjDFX+yFkMPviX X-Received: by 10.237.42.102 with SMTP id k35mr13284381qtf.28.1492783990796; Fri, 21 Apr 2017 07:13:10 -0700 (PDT) Subject: Re: [PATCH v3][BZ 21340] add support for POSIX_SPAWN_SETSID To: libc-alpha@sourceware.org References: <20170405054116.9007-1-quae@daurnimator.com> <75eb12d0-a3f1-2b37-90d5-0a9a3f7f9a99@redhat.com> Cc: Zack Weinberg , Florian Weimer From: Adhemerval Zanella Message-ID: Date: Fri, 21 Apr 2017 11:13:05 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: On 21/04/2017 02:03, Daurnimator wrote: > On 9 April 2017 at 23:21, Daurnimator wrote: >> On 6 April 2017 at 22:37, Florian Weimer wrote: >>> Would you be willing to assign copyright for this and future changes? >>> >>> If yes, please pick request-assign.future from here: >>> >>> >>> >>> and send the filled-out form to . As far as I understand >>> it, citizens from most countries can complete the process electronically >>> these days. >> >> Sorry, but I'm not willing to link my legal name to this pseudonym. >> >> Please still consider merging my changes (as they should be uncopyrightable). >> However as I understand it, you will have to re-write the test case. > > I'd still love to get this patch merged; is someone willing to rewrite > the test case? > What about now? I have adjusted the testcase using support library and fixed some nits in ChangeLog. --- Daurnimator Adhemerval Zanella [BZ #21340] * conform/data/spawn.h-data: Add POSIX_SPAWN_SETSID flag. * posix/Makefile (tests): Add tst-posix_spawn-setsid to list of tests. * posix/spawn.h: define POSIX_SPAWN_SETSID flag. * posix/spawnattr_setflags.c (ALL_FLAGS): Add POSIX_SPAWN_SETSID to valid flags. * posix/tst-posix_spawn-setsid.c: Add test for POSIX_SPAWN_SETSID. * sysdeps/mach/hurd/spawni.c (__spawni): Implementation of POSIX_SPAWN_SETSID. * sysdeps/posix/spawni.c (__spawni): Likewise. * sysdeps/unix/sysv/linux/spawni.c (__spawni_child): Likewise. --- ChangeLog | 15 +++++++++ conform/data/spawn.h-data | 1 + posix/Makefile | 2 +- posix/spawn.h | 1 + posix/spawnattr_setflags.c | 1 + posix/tst-posix_spawn-setsid.c | 68 ++++++++++++++++++++++++++++++++++++++++ sysdeps/mach/hurd/spawni.c | 3 ++ sysdeps/posix/spawni.c | 7 ++++- sysdeps/unix/sysv/linux/spawni.c | 4 +++ 9 files changed, 100 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 fb206f7..bcba36c 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 a6586ea..0fc509c 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -91,7 +91,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 36e3867..8d2ace1 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 9b3d1e0..62d2f00 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 0000000..246b39f --- /dev/null +++ b/posix/tst-posix_spawn-setsid.c @@ -0,0 +1,68 @@ +/* Test posix_spawn setsid attribute. + 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 + +#include + +static int +do_test (void) +{ + pid_t sid, child_sid; + int res; + + /* Current session ID. */ + sid = getsid(0); + if (sid == (pid_t) -1) + FAIL_EXIT1 ("getsid (0): %m"); + + posix_spawnattr_t attrp; + posix_spawnattr_init (&attrp); + if (posix_spawnattr_setflags (&attrp, POSIX_SPAWN_SETSID)) + FAIL_EXIT1 ("posix_spawnattr_setflags: %m"); + + /* Program to run. */ + char *args[2] = { (char *) "true", NULL }; + pid_t child; + + res = posix_spawnp (&child, "true", NULL, &attrp, args, environ); + /* posix_spawnattr_destroy is noop. */ + posix_spawnattr_destroy (&attrp); + + if (res != 0) + FAIL_EXIT1 ("posix_spawnp: %m"); + + /* Child should have a different session ID than parent. */ + child_sid = getsid (child); + + if (child_sid == (pid_t) -1) + FAIL_EXIT1 ("getsid (%i): %m", child); + + if (child_sid == sid) + FAIL_EXIT1 ("child sid matches parent one"); + + return 0; +} + +#include diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 284875a..7430383 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 5cc2ad1..9cad25c 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 d7f9e83..3cf77d5 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)