NetBSD-Bugs archive

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

lib/41673: tcsetpgrp(3) returns EINVAL instead of EPERM

>Number:         41673
>Category:       lib
>Synopsis:       tcsetpgrp(3) returns EINVAL instead of EPERM
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 06 18:45:00 +0000 2009
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
Aristotle University of Thessaloniki
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

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.

#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

Home | Main Index | Thread Index | Old Index