pgrpsys.c (7c478bd9) pgrpsys.c (9acbbeaf)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
22/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23/* All Rights Reserved */
24
25
26/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27/* All Rights Reserved */
28
29
26#ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.78 */
30#pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.78 */
27
28#include <sys/param.h>
29#include <sys/types.h>
30#include <sys/sysmacros.h>
31#include <sys/systm.h>
32#include <sys/errno.h>
33#include <sys/file.h>
34#include <sys/proc.h>
35#include <sys/session.h>
36#include <sys/debug.h>
37
38/* ARGSUSED */
39int
40setpgrp(int flag, int pid, int pgid)
41{
31
32#include <sys/param.h>
33#include <sys/types.h>
34#include <sys/sysmacros.h>
35#include <sys/systm.h>
36#include <sys/errno.h>
37#include <sys/file.h>
38#include <sys/proc.h>
39#include <sys/session.h>
40#include <sys/debug.h>
41
42/* ARGSUSED */
43int
44setpgrp(int flag, int pid, int pgid)
45{
42 register proc_t *p = ttoproc(curthread);
43 register int retval = 0;
46 proc_t *p = curproc;
47 int retval = 0;
48 int sid;
44
45 switch (flag) {
46
47 case 1: /* setpgrp() */
48 mutex_enter(&pidlock);
49 if (p->p_sessp->s_sidp != p->p_pidp && !pgmembers(p->p_pid)) {
50 mutex_exit(&pidlock);
51 sess_create();
52 } else
53 mutex_exit(&pidlock);
49
50 switch (flag) {
51
52 case 1: /* setpgrp() */
53 mutex_enter(&pidlock);
54 if (p->p_sessp->s_sidp != p->p_pidp && !pgmembers(p->p_pid)) {
55 mutex_exit(&pidlock);
56 sess_create();
57 } else
58 mutex_exit(&pidlock);
54 return (p->p_sessp->s_sid);
59 mutex_enter(&p->p_splock);
60 sid = p->p_sessp->s_sid;
61 mutex_exit(&p->p_splock);
62 return (sid);
55
56 case 3: /* setsid() */
57 mutex_enter(&pidlock);
58 if (p->p_pgidp == p->p_pidp || pgmembers(p->p_pid)) {
59 mutex_exit(&pidlock);
60 return (set_errno(EPERM));
61 }
62 mutex_exit(&pidlock);
63 sess_create();
63
64 case 3: /* setsid() */
65 mutex_enter(&pidlock);
66 if (p->p_pgidp == p->p_pidp || pgmembers(p->p_pid)) {
67 mutex_exit(&pidlock);
68 return (set_errno(EPERM));
69 }
70 mutex_exit(&pidlock);
71 sess_create();
64 return (p->p_sessp->s_sid);
72 mutex_enter(&p->p_splock);
73 sid = p->p_sessp->s_sid;
74 mutex_exit(&p->p_splock);
75 return (sid);
65
66 case 5: /* setpgid() */
67 {
68 mutex_enter(&pidlock);
69 if (pid == 0)
70 pid = p->p_pid;
71 else if (pid < 0 || pid >= maxpid) {
72 mutex_exit(&pidlock);

--- 91 unchanged lines hidden ---
76
77 case 5: /* setpgid() */
78 {
79 mutex_enter(&pidlock);
80 if (pid == 0)
81 pid = p->p_pid;
82 else if (pid < 0 || pid >= maxpid) {
83 mutex_exit(&pidlock);

--- 91 unchanged lines hidden ---