NetBSD Problem Report #41673

From www@NetBSD.org  Mon Jul  6 18:40:46 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id A601E63B913
	for <gnats-bugs@gnats.netbsd.org>; Mon,  6 Jul 2009 18:40:46 +0000 (UTC)
Message-Id: <20090706184046.42CFE63B883@www.NetBSD.org>
Date: Mon,  6 Jul 2009 18:40:46 +0000 (UTC)
From: ekamperi@gmail.com
Reply-To: ekamperi@gmail.com
To: gnats-bugs@NetBSD.org
Subject: tcsetpgrp(3) returns EINVAL instead of EPERM
X-Send-Pr-Version: www-1.0

>Number:         41673
>Category:       lib
>Synopsis:       tcsetpgrp(3) returns EINVAL instead of EPERM
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 06 18:45:00 +0000 2009
>Closed-Date:    Mon Mar 19 23:27:51 +0000 2012
>Last-Modified:  Mon Mar 19 23:27:51 +0000 2012
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
>Organization:
Aristotle University of Thessaloniki
>Environment:
NetBSD voyager 5.0_STABLE NetBSD 5.0_STABLE (MYGENERIC) #8: Mon Jul  6 19:55:40 EEST 2009  root@voyager:/usr/obj/sys/arch/i386/compile/MYGENERIC i386

>Description:
The tcsetpgrp(3) function returns EINVAL instead of EPERM, when is
supplied with a pgrp_id that does not match the process group ID of a
process in the same session.


>How-To-Repeat:
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void)
{
        pid_t oldpgid, pid;
        int rv, status;

        /* Make sure we are associated with a  terminal. */
        assert(isatty(STDIN_FILENO) != 0);

        pid = fork();
        assert(pid != -1);

        if (pid != 0) {
                /* We are inside the parent. */
                assert(wait(&status) == pid);
        } else {
                /* We are inside the child. */

                /* The process group ID is inherited. */
                oldpgid = getpgid(0);
                assert(oldpgid != (pid_t)-1);

                /*
                 * The child process ID doesn't match any active
                 * process group ID. So the following call should
                 * fail with EPERM.
                 */
                rv = tcsetpgrp(STDIN_FILENO, getpid());
                if (rv == 0) {
                        /*
                         * This sh
>Fix:

>Release-Note:

>Audit-Trail:
From: Stathis Kamperis <ekamperi@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/41673
Date: Thu, 9 Jul 2009 20:24:00 +0300

 Hey all.

 I don't know my previous code snippet didn't get through all of it, so
 here it is again:

 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>

 int main(void)
 {
 	pid_t oldpgid, pid;
 	int rv, status;

 	pid = fork();
 	assert(pid != -1);

 	if (pid != 0) {
 		/* We are inside the parent. */
 		assert(wait(&status) == pid);
 	} else {
 		/* We are inside the child. */

 		/* The process group ID is inherited. */
 		oldpgid = getpgid(0);
 		assert(oldpgid != (pid_t)-1);

 		/*
 		 * The child process ID also doesn't match any active
 		 * process  group ID. So the following call should
 		 * fail with EPERM.
 		 */
 		rv = tcsetpgrp(STDIN_FILENO, getpid());
 		if (rv == 0) {
 			/*
 			 * This should never happen, but in Linux it does.
 			 * Given that the tcsetpgrp(3) call allegedly
 			 * succeeded, the process group of the child will
 			 * be different from the parent's. Only it isn't.
 			 */
 			assert(getpgid(0) != oldpgid);
 		} else {
 			/*
 			 * NetBSD fails here, returning EINVAL which is
 			 * clearly wrong, since we passed to tcsetpgrp(3)
 			 * a value returned from getpid(3). So it definitely
 			 * was a "valid pgid value".
 			 * Only Solaris gets all of it right.
 			 */
 			assert(errno == EPERM);
 		}
 	}

 	return (EXIT_SUCCESS);
 }

 Best regards,
 Stathis

From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41673 CVS commit: src
Date: Sun, 1 May 2011 11:39:38 +0000

 Module Name:	src
 Committed By:	jruoho
 Date:		Sun May  1 11:39:38 UTC 2011

 Modified Files:
 	src/distrib/sets/lists/tests: mi
 Added Files:
 	src/tests/lib/libc/termios: Makefile t_tcsetpgrp.c

 Log Message:
 Add a test for PR lib/41673 (another trivial errno "bug").


 To generate a diff of this commit:
 cvs rdiff -u -r1.315 -r1.316 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/termios/Makefile \
     src/tests/lib/libc/termios/t_tcsetpgrp.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41673 CVS commit: src/sys/kern
Date: Mon, 12 Mar 2012 14:27:08 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Mon Mar 12 18:27:08 UTC 2012

 Modified Files:
 	src/sys/kern: tty.c

 Log Message:
 PR/41673: Stathis Kamperis: tcsetpgrp returns EINVAL, but should return EPERM.


 To generate a diff of this commit:
 cvs rdiff -u -r1.249 -r1.250 src/sys/kern/tty.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: jruoho@NetBSD.org
State-Changed-When: Sun, 18 Mar 2012 07:15:43 +0000
State-Changed-Why:
Fixed.


State-Changed-From-To: closed->pending-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 18 Mar 2012 15:53:25 +0000
State-Changed-Why:
pullup-6 #128

please don't close PRs until the pullups have been handled.


From: Jukka Ruohonen <jruohonen@iki.fi>
To: gnats-bugs@NetBSD.org
Cc: netbsd-bugs@NetBSD.org, dholland@NetBSD.org
Subject: Re: lib/41673 (tcsetpgrp(3) returns EINVAL instead of EPERM)
Date: Sun, 18 Mar 2012 17:57:27 +0200

 On Sun, Mar 18, 2012 at 03:53:26PM +0000, dholland@NetBSD.org wrote:
 > pullup-6 #128
 > 
 > please don't close PRs until the pullups have been handled.

 So we are supposed to pullup everything and/or never close any PRs?

 Please give also a real world example why this needs a pull-up.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/41673 (tcsetpgrp(3) returns EINVAL instead of EPERM)
Date: Sun, 18 Mar 2012 16:10:58 +0000

 On Sun, Mar 18, 2012 at 04:00:07PM +0000, Jukka Ruohonen wrote:
  >  On Sun, Mar 18, 2012 at 03:53:26PM +0000, dholland@NetBSD.org wrote:
  >  > pullup-6 #128
  >  > 
  >  > please don't close PRs until the pullups have been handled.
  >  
  >  So we are supposed to pullup everything and/or never close any PRs?
  >  
  >  Please give also a real world example why this needs a pull-up.

 Someone ran into the problem somehow. That is sufficient grounds for
 considering it a real problem rather than just standards wankery.

 Furthermore, the PR was reported against a stable branch; the default
 procedure in such cases is to pull up the fix to that branch (that is,
 netbsd-5). I'm not doing that because it is a fairly minor issue.

 However, at this stage in the netbsd-6 release cycle, even minor fixes
 should be pulled up when it is reasonably convenient to do so.

 PRs should be closed when they're fixed, not to make the PR statistics
 look better.

 -- 
 David A. Holland
 dholland@netbsd.org

From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41673 CVS commit: [netbsd-6] src/sys/kern
Date: Mon, 19 Mar 2012 23:23:11 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Mon Mar 19 23:23:11 UTC 2012

 Modified Files:
 	src/sys/kern [netbsd-6]: tty.c

 Log Message:
 Pull up following revision(s) (requested by dholland in ticket #128):
 	sys/kern/tty.c: revision 1.250
 PR/41673: Stathis Kamperis: tcsetpgrp returns EINVAL, but should return EPERM.


 To generate a diff of this commit:
 cvs rdiff -u -r1.249 -r1.249.8.1 src/sys/kern/tty.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 19 Mar 2012 23:27:51 +0000
State-Changed-Why:
Pulled up to netbsd-6. Not really worth doing in -5 I think.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.