8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_exit.c
blobd9fb874cc2879a79eba1a0396d11a2ade6b4a01e
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1997-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/lwp.h>
33 #include "libproc.h"
36 * exit() system call -- executed by subject process.
38 int
39 pr_exit(struct ps_prochandle *Pr, int status)
41 sysret_t rval; /* return value from exit() */
42 argdes_t argd[1]; /* arg descriptors for exit() */
43 argdes_t *adp;
44 int error;
46 if (Pr == NULL) { /* no subject process */
47 exit(status);
48 return (0); /* not reached */
51 adp = &argd[0]; /* status argument */
52 adp->arg_value = status;
53 adp->arg_object = NULL;
54 adp->arg_type = AT_BYVAL;
55 adp->arg_inout = AI_INPUT;
56 adp->arg_size = 0;
58 error = Psyscall(Pr, &rval, SYS_exit, 1, &argd[0]);
59 /* actually -- never returns. Expect ENOENT */
61 if (error < 0) {
62 if (errno == ENOENT) /* expected case */
63 error = ENOENT;
64 else
65 error = ENOSYS;
68 if (error == 0) /* can't happen? */
69 return (rval.sys_rval1);
71 if (error == ENOENT) /* expected case */
72 return (0);
74 errno = error;
75 return (-1);
79 * lwp_exit() system call -- executed by subject lwp.
81 int
82 pr_lwp_exit(struct ps_prochandle *Pr)
84 sysret_t rval; /* return value from lwp_exit() */
85 int error;
87 if (Pr == NULL) { /* no subject process */
88 (void) syscall(SYS_lwp_exit);
89 return (0); /* not reached */
92 error = Psyscall(Pr, &rval, SYS_lwp_exit, 0, NULL);
93 /* actually -- never returns. Expect ENOENT */
95 if (error < 0) {
96 if (errno == ENOENT) /* expected case */
97 error = ENOENT;
98 else
99 error = ENOSYS;
102 if (error == 0) /* can't happen? */
103 return (rval.sys_rval1);
105 if (error == ENOENT) /* expected case */
106 return (0);
108 errno = error;
109 return (-1);