2 * Copyright (c) 1993 Jan-Simon Pendry
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
36 * $Id: procfs_status.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
40 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/systm.h>
45 #include <sys/mutex.h>
47 #include <sys/malloc.h>
48 #include <sys/mutex.h>
51 #include <sys/resourcevar.h>
53 #include <sys/sysent.h>
58 #include <vm/vm_param.h>
60 #include <fs/pseudofs/pseudofs.h>
61 #include <fs/procfs/procfs.h>
64 procfs_doprocstatus(PFS_FILL_ARGS)
67 struct thread *tdfirst;
73 int pid, ppid, pgid, sid;
78 ppid = p->p_pptr ? p->p_pptr->p_pid : 0;
79 pgid = p->p_pgrp->pg_id;
80 sess = p->p_pgrp->pg_session;
82 sid = sess->s_leader ? sess->s_leader->p_pid : 0;
84 /* comm pid ppid pgid sid tty ctty,sldr start ut st wmsg
85 euid ruid rgid,egid,groups[1 .. ngroups]
90 if (*pc < 33 || *pc > 126 || *pc == '\\')
91 sbuf_printf(sb, "\\%03o", *pc);
95 sbuf_printf(sb, " %d %d %d %d ", pid, ppid, pgid, sid);
96 if ((p->p_flag & P_CONTROLT) && (tp = sess->s_ttyp))
97 sbuf_printf(sb, "%s ", devtoname(tp->t_dev));
99 sbuf_printf(sb, "- ");
103 sbuf_printf(sb, "%sctty", sep);
106 if (SESS_LEADER(p)) {
107 sbuf_printf(sb, "%ssldr", sep);
112 sbuf_printf(sb, "noflags");
115 tdfirst = FIRST_THREAD_IN_PROC(p);
116 thread_lock(tdfirst);
117 if (tdfirst->td_wchan != NULL) {
118 KASSERT(tdfirst->td_wmesg != NULL,
119 ("wchan %p has no wmesg", tdfirst->td_wchan));
120 wmesg = tdfirst->td_wmesg;
123 thread_unlock(tdfirst);
125 if (p->p_flag & P_INMEM) {
126 struct timeval start, ut, st;
131 start = p->p_stats->p_start;
132 timevaladd(&start, &boottime);
133 sbuf_printf(sb, " %jd,%ld %jd,%ld %jd,%ld",
134 (intmax_t)start.tv_sec, start.tv_usec,
135 (intmax_t)ut.tv_sec, ut.tv_usec,
136 (intmax_t)st.tv_sec, st.tv_usec);
138 sbuf_printf(sb, " -1,-1 -1,-1 -1,-1");
140 sbuf_printf(sb, " %s", wmesg);
144 sbuf_printf(sb, " %lu %lu %lu",
147 (u_long)cr->cr_rgid);
149 /* egid (cr->cr_svgid) is equal to cr_ngroups[0]
150 see also getegid(2) in /sys/kern/kern_prot.c */
152 for (i = 0; i < cr->cr_ngroups; i++) {
153 sbuf_printf(sb, ",%lu", (u_long)cr->cr_groups[i]);
157 mtx_lock(&cr->cr_prison->pr_mtx);
158 sbuf_printf(sb, " %s",
159 prison_name(td->td_ucred->cr_prison, cr->cr_prison));
160 mtx_unlock(&cr->cr_prison->pr_mtx);
162 sbuf_printf(sb, " -");
165 sbuf_printf(sb, "\n");
171 procfs_doproccmdline(PFS_FILL_ARGS)
175 * If we are using the ps/cmdline caching, use that. Otherwise
176 * read argv from the process space.
177 * Note that if the argv is no longer available, we deliberately
178 * don't fall back on p->p_comm or return an error: the authentic
179 * Linux behaviour is to return zero-length in this case.
183 if (p->p_args && p_cansee(td, p) == 0) {
184 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length);
189 if ((p->p_flag & P_SYSTEM) != 0) {
196 return (proc_getargv(td, p, sb));