1/* 2 * Copyright (c) 1993 Jan-Simon Pendry 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Jan-Simon Pendry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 38 * 39 * From: 40 * $Id: procfs_status.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
| 1/* 2 * Copyright (c) 1993 Jan-Simon Pendry 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Jan-Simon Pendry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 38 * 39 * From: 40 * $Id: procfs_status.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
|
41 * $FreeBSD: head/sys/fs/procfs/procfs_status.c 90717 2002-02-16 05:59:26Z bde $
| 41 * $FreeBSD: head/sys/fs/procfs/procfs_status.c 91140 2002-02-23 11:12:57Z tanimura $
|
42 */ 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/exec.h> 47#include <sys/lock.h> 48#include <sys/mutex.h> 49#include <sys/jail.h> 50#include <sys/malloc.h>
| 42 */ 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/exec.h> 47#include <sys/lock.h> 48#include <sys/mutex.h> 49#include <sys/jail.h> 50#include <sys/malloc.h>
|
| 51#include <sys/mutex.h> 52#include <sys/sx.h>
|
51#include <sys/proc.h> 52#include <sys/resourcevar.h> 53#include <sys/sbuf.h> 54#include <sys/tty.h> 55 56#include <vm/vm.h> 57#include <vm/pmap.h> 58#include <vm/vm_param.h> 59 60#include <fs/pseudofs/pseudofs.h> 61#include <fs/procfs/procfs.h> 62 63int 64procfs_doprocstatus(PFS_FILL_ARGS) 65{ 66 struct session *sess; 67 struct thread *tdfirst; 68 struct tty *tp; 69 struct ucred *cr; 70 char *pc; 71 char *sep; 72 int pid, ppid, pgid, sid; 73 int i; 74 75 pid = p->p_pid; 76 PROC_LOCK(p); 77 ppid = p->p_pptr ? p->p_pptr->p_pid : 0;
| 53#include <sys/proc.h> 54#include <sys/resourcevar.h> 55#include <sys/sbuf.h> 56#include <sys/tty.h> 57 58#include <vm/vm.h> 59#include <vm/pmap.h> 60#include <vm/vm_param.h> 61 62#include <fs/pseudofs/pseudofs.h> 63#include <fs/procfs/procfs.h> 64 65int 66procfs_doprocstatus(PFS_FILL_ARGS) 67{ 68 struct session *sess; 69 struct thread *tdfirst; 70 struct tty *tp; 71 struct ucred *cr; 72 char *pc; 73 char *sep; 74 int pid, ppid, pgid, sid; 75 int i; 76 77 pid = p->p_pid; 78 PROC_LOCK(p); 79 ppid = p->p_pptr ? p->p_pptr->p_pid : 0;
|
78 PROC_UNLOCK(p);
| |
79 pgid = p->p_pgrp->pg_id; 80 sess = p->p_pgrp->pg_session;
| 80 pgid = p->p_pgrp->pg_id; 81 sess = p->p_pgrp->pg_session;
|
| 82 SESS_LOCK(sess);
|
81 sid = sess->s_leader ? sess->s_leader->p_pid : 0; 82 83/* comm pid ppid pgid sid maj,min ctty,sldr start ut st wmsg 84 euid ruid rgid,egid,groups[1 .. NGROUPS] 85*/ 86 87 pc = p->p_comm; 88 do { 89 if (*pc < 33 || *pc > 126 || *pc == '\\') 90 sbuf_printf(sb, "\\%03o", *pc); 91 else 92 sbuf_putc(sb, *pc); 93 } while (*++pc); 94 sbuf_printf(sb, " %d %d %d %d ", pid, ppid, pgid, sid); 95 if ((p->p_flag&P_CONTROLT) && (tp = sess->s_ttyp)) 96 sbuf_printf(sb, "%d,%d ", major(tp->t_dev), minor(tp->t_dev)); 97 else 98 sbuf_printf(sb, "%d,%d ", -1, -1); 99 100 sep = ""; 101 if (sess->s_ttyvp) { 102 sbuf_printf(sb, "%sctty", sep); 103 sep = ","; 104 } 105 if (SESS_LEADER(p)) { 106 sbuf_printf(sb, "%ssldr", sep); 107 sep = ","; 108 }
| 83 sid = sess->s_leader ? sess->s_leader->p_pid : 0; 84 85/* comm pid ppid pgid sid maj,min ctty,sldr start ut st wmsg 86 euid ruid rgid,egid,groups[1 .. NGROUPS] 87*/ 88 89 pc = p->p_comm; 90 do { 91 if (*pc < 33 || *pc > 126 || *pc == '\\') 92 sbuf_printf(sb, "\\%03o", *pc); 93 else 94 sbuf_putc(sb, *pc); 95 } while (*++pc); 96 sbuf_printf(sb, " %d %d %d %d ", pid, ppid, pgid, sid); 97 if ((p->p_flag&P_CONTROLT) && (tp = sess->s_ttyp)) 98 sbuf_printf(sb, "%d,%d ", major(tp->t_dev), minor(tp->t_dev)); 99 else 100 sbuf_printf(sb, "%d,%d ", -1, -1); 101 102 sep = ""; 103 if (sess->s_ttyvp) { 104 sbuf_printf(sb, "%sctty", sep); 105 sep = ","; 106 } 107 if (SESS_LEADER(p)) { 108 sbuf_printf(sb, "%ssldr", sep); 109 sep = ","; 110 }
|
| 111 SESS_UNLOCK(sess); 112 PROC_UNLOCK(p);
|
109 if (*sep != ',') { 110 sbuf_printf(sb, "noflags"); 111 } 112 113 mtx_lock_spin(&sched_lock); 114 if (p->p_sflag & PS_INMEM) { 115 struct timeval ut, st; 116 117 calcru(p, &ut, &st, (struct timeval *) NULL); 118 mtx_unlock_spin(&sched_lock); 119 sbuf_printf(sb, " %lld,%ld %ld,%ld %ld,%ld", 120 (long long)p->p_stats->p_start.tv_sec, 121 p->p_stats->p_start.tv_usec, 122 ut.tv_sec, ut.tv_usec, 123 st.tv_sec, st.tv_usec); 124 } else { 125 mtx_unlock_spin(&sched_lock); 126 sbuf_printf(sb, " -1,-1 -1,-1 -1,-1"); 127 } 128 129 if (p->p_flag & P_KSES) 130 sbuf_printf(sb, " %s", "-kse- "); 131 else { 132 tdfirst = FIRST_THREAD_IN_PROC(p); /* XXX diff from td? */ 133 sbuf_printf(sb, " %s", 134 (tdfirst->td_wchan && tdfirst->td_wmesg) ? 135 tdfirst->td_wmesg : "nochan"); 136 } 137 138 cr = p->p_ucred; 139 140 sbuf_printf(sb, " %lu %lu %lu", 141 (u_long)cr->cr_uid, 142 (u_long)cr->cr_ruid, 143 (u_long)cr->cr_rgid); 144 145 /* egid (cr->cr_svgid) is equal to cr_ngroups[0] 146 see also getegid(2) in /sys/kern/kern_prot.c */ 147 148 for (i = 0; i < cr->cr_ngroups; i++) { 149 sbuf_printf(sb, ",%lu", (u_long)cr->cr_groups[i]); 150 } 151 152 if (jailed(p->p_ucred)) { 153 mtx_lock(&p->p_ucred->cr_prison->pr_mtx); 154 sbuf_printf(sb, " %s", p->p_ucred->cr_prison->pr_host); 155 mtx_unlock(&p->p_ucred->cr_prison->pr_mtx); 156 } else { 157 sbuf_printf(sb, " -"); 158 } 159 sbuf_printf(sb, "\n"); 160 161 return (0); 162} 163 164int 165procfs_doproccmdline(PFS_FILL_ARGS) 166{ 167 struct ps_strings pstr; 168 int error, i; 169 170 /* 171 * If we are using the ps/cmdline caching, use that. Otherwise 172 * revert back to the old way which only implements full cmdline 173 * for the currept process and just p->p_comm for all other 174 * processes. 175 * Note that if the argv is no longer available, we deliberately 176 * don't fall back on p->p_comm or return an error: the authentic 177 * Linux behaviour is to return zero-length in this case. 178 */ 179 180 if (p->p_args && (ps_argsopen || !p_cansee(td->td_proc, p))) { 181 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length); 182 } else if (p != td->td_proc) { 183 sbuf_printf(sb, "%.*s", MAXCOMLEN, p->p_comm); 184 } else { 185 error = copyin((void*)PS_STRINGS, &pstr, sizeof(pstr)); 186 if (error) 187 return (error); 188 for (i = 0; i < pstr.ps_nargvstr; i++) { 189 sbuf_copyin(sb, pstr.ps_argvstr[i], 0); 190 sbuf_printf(sb, "%c", '\0'); 191 } 192 } 193 194 return (0); 195}
| 113 if (*sep != ',') { 114 sbuf_printf(sb, "noflags"); 115 } 116 117 mtx_lock_spin(&sched_lock); 118 if (p->p_sflag & PS_INMEM) { 119 struct timeval ut, st; 120 121 calcru(p, &ut, &st, (struct timeval *) NULL); 122 mtx_unlock_spin(&sched_lock); 123 sbuf_printf(sb, " %lld,%ld %ld,%ld %ld,%ld", 124 (long long)p->p_stats->p_start.tv_sec, 125 p->p_stats->p_start.tv_usec, 126 ut.tv_sec, ut.tv_usec, 127 st.tv_sec, st.tv_usec); 128 } else { 129 mtx_unlock_spin(&sched_lock); 130 sbuf_printf(sb, " -1,-1 -1,-1 -1,-1"); 131 } 132 133 if (p->p_flag & P_KSES) 134 sbuf_printf(sb, " %s", "-kse- "); 135 else { 136 tdfirst = FIRST_THREAD_IN_PROC(p); /* XXX diff from td? */ 137 sbuf_printf(sb, " %s", 138 (tdfirst->td_wchan && tdfirst->td_wmesg) ? 139 tdfirst->td_wmesg : "nochan"); 140 } 141 142 cr = p->p_ucred; 143 144 sbuf_printf(sb, " %lu %lu %lu", 145 (u_long)cr->cr_uid, 146 (u_long)cr->cr_ruid, 147 (u_long)cr->cr_rgid); 148 149 /* egid (cr->cr_svgid) is equal to cr_ngroups[0] 150 see also getegid(2) in /sys/kern/kern_prot.c */ 151 152 for (i = 0; i < cr->cr_ngroups; i++) { 153 sbuf_printf(sb, ",%lu", (u_long)cr->cr_groups[i]); 154 } 155 156 if (jailed(p->p_ucred)) { 157 mtx_lock(&p->p_ucred->cr_prison->pr_mtx); 158 sbuf_printf(sb, " %s", p->p_ucred->cr_prison->pr_host); 159 mtx_unlock(&p->p_ucred->cr_prison->pr_mtx); 160 } else { 161 sbuf_printf(sb, " -"); 162 } 163 sbuf_printf(sb, "\n"); 164 165 return (0); 166} 167 168int 169procfs_doproccmdline(PFS_FILL_ARGS) 170{ 171 struct ps_strings pstr; 172 int error, i; 173 174 /* 175 * If we are using the ps/cmdline caching, use that. Otherwise 176 * revert back to the old way which only implements full cmdline 177 * for the currept process and just p->p_comm for all other 178 * processes. 179 * Note that if the argv is no longer available, we deliberately 180 * don't fall back on p->p_comm or return an error: the authentic 181 * Linux behaviour is to return zero-length in this case. 182 */ 183 184 if (p->p_args && (ps_argsopen || !p_cansee(td->td_proc, p))) { 185 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length); 186 } else if (p != td->td_proc) { 187 sbuf_printf(sb, "%.*s", MAXCOMLEN, p->p_comm); 188 } else { 189 error = copyin((void*)PS_STRINGS, &pstr, sizeof(pstr)); 190 if (error) 191 return (error); 192 for (i = 0; i < pstr.ps_nargvstr; i++) { 193 sbuf_copyin(sb, pstr.ps_argvstr[i], 0); 194 sbuf_printf(sb, "%c", '\0'); 195 } 196 } 197 198 return (0); 199}
|