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 (the "License"). 6 * You may not use this file except in compliance with the License. 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 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <unistd.h> 31 #include <errno.h> 32 #include <sys/lx_misc.h> 33 34 int 35 lx_getpgrp(void) 36 { 37 int ret; 38 39 ret = getpgrp(); 40 41 /* 42 * If the pgrp is that of the init process, return the value Linux 43 * expects. 44 */ 45 if (ret == zoneinit_pid) 46 return (LX_INIT_PGID); 47 48 return ((ret == -1) ? -errno : ret); 49 } 50 51 int 52 lx_getpgid(uintptr_t p1) 53 { 54 pid_t spid; 55 int pid = (int)p1; 56 int ret; 57 58 if (pid < 0) 59 return (-ESRCH); 60 61 /* 62 * If the supplied pid matches that of the init process, return 63 * the pgid Linux expects. 64 */ 65 if (pid == zoneinit_pid) 66 return (LX_INIT_PGID); 67 68 if ((ret = lx_lpid_to_spid(pid, &spid)) < 0) 69 return (ret); 70 71 ret = getpgid(spid); 72 73 /* 74 * If the pgid is that of the init process, return the value Linux 75 * expects. 76 */ 77 if (ret == zoneinit_pid) 78 return (LX_INIT_PGID); 79 80 return ((ret == -1) ? -errno : ret); 81 } 82 83 int 84 lx_setpgid(uintptr_t p1, uintptr_t p2) 85 { 86 pid_t pid = (pid_t)p1; 87 pid_t pgid = (pid_t)p2; 88 pid_t spid, spgid; 89 int ret; 90 91 if (pid < 0) 92 return (-ESRCH); 93 94 if (pgid < 0) 95 return (-EINVAL); 96 97 if ((ret = lx_lpid_to_spid(pid, &spid)) < 0) 98 return (ret); 99 100 if (pgid == 0) 101 spgid = spid; 102 else if ((ret = lx_lpid_to_spid(pgid, &spgid)) < 0) 103 return (ret); 104 105 ret = setpgid(spid, spgid); 106 107 return ((ret == 0) ? 0 : -errno); 108 } 109 110 int 111 lx_getsid(uintptr_t p1) 112 { 113 pid_t spid; 114 int pid = (int)p1; 115 int ret; 116 117 if (pid < 0) 118 return (-ESRCH); 119 120 /* 121 * If the supplied matches that of the init process, return the value 122 * Linux expects. 123 */ 124 if (pid == zoneinit_pid) 125 return (LX_INIT_SID); 126 127 if ((ret = lx_lpid_to_spid(pid, &spid)) < 0) 128 return (ret); 129 130 ret = getsid(spid); 131 132 /* 133 * If the sid is that of the init process, return the value Linux 134 * expects. 135 */ 136 if (ret == zoneinit_pid) 137 return (LX_INIT_SID); 138 139 return ((ret == -1) ? -errno : ret); 140 } 141 142 int 143 lx_setsid(void) 144 { 145 int ret; 146 147 ret = setsid(); 148 149 /* 150 * If the pgid is that of the init process, return the value Linux 151 * expects. 152 */ 153 if (ret == zoneinit_pid) 154 return (LX_INIT_SID); 155 156 return ((ret == -1) ? -errno : ret); 157 }