NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/41673



The following reply was made to PR lib/41673; it has been noted by GNATS.

From: Stathis Kamperis <ekamperi%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
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
 


Home | Main Index | Thread Index | Old Index