2007-03-09 17:11:22 +03:00
|
|
|
/* $NetBSD: procfs_status.c,v 1.32 2007/03/09 14:11:23 ad Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-01-05 10:51:08 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1993 Jan-Simon Pendry
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1994-01-05 10:51:08 +03:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
|
1994-01-05 10:51:08 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-09 17:11:22 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: procfs_status.c,v 1.32 2007/03/09 14:11:23 ad Exp $");
|
2001-11-10 16:33:40 +03:00
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/resourcevar.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
#include <miscfs/procfs/procfs.h>
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
int
|
2006-10-12 05:30:41 +04:00
|
|
|
procfs_dostatus(
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp *curl,
|
2006-10-12 05:30:41 +04:00
|
|
|
struct lwp *l,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct pfsnode *pfs,
|
2006-10-12 05:30:41 +04:00
|
|
|
struct uio *uio
|
|
|
|
)
|
1994-01-05 10:51:08 +03:00
|
|
|
{
|
|
|
|
struct session *sess;
|
|
|
|
struct tty *tp;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cr;
|
2003-01-18 11:51:40 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1994-01-05 10:51:08 +03:00
|
|
|
char *ps;
|
2005-05-30 01:55:33 +04:00
|
|
|
const char *sep;
|
1994-01-05 10:51:08 +03:00
|
|
|
int pid, ppid, pgid, sid;
|
2002-11-07 11:13:10 +03:00
|
|
|
u_int i;
|
2000-12-31 02:14:52 +03:00
|
|
|
char psbuf[256+MAXHOSTNAMELEN]; /* XXX - conservative */
|
2006-05-15 01:31:52 +04:00
|
|
|
uint16_t ngroups;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
if (uio->uio_rw != UIO_READ)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
2007-03-09 17:11:22 +03:00
|
|
|
mutex_enter(&proclist_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_mutex);
|
|
|
|
|
1994-01-05 10:51:08 +03:00
|
|
|
pid = p->p_pid;
|
|
|
|
ppid = p->p_pptr ? p->p_pptr->p_pid : 0,
|
|
|
|
pgid = p->p_pgrp->pg_id;
|
|
|
|
sess = p->p_pgrp->pg_session;
|
1998-02-14 03:37:26 +03:00
|
|
|
sid = sess->s_sid;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
1995-06-02 02:43:30 +04:00
|
|
|
/* comm pid ppid pgid sid maj,min ctty,sldr start ut st wmsg uid gid groups ... */
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
ps = psbuf;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(ps, p->p_comm, MAXCOMLEN);
|
1994-01-05 10:51:08 +03:00
|
|
|
ps[MAXCOMLEN] = '\0';
|
|
|
|
ps += strlen(ps);
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d %d %d %d ",
|
|
|
|
pid, ppid, pgid, sid);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((p->p_lflag & PL_CONTROLT) && (tp = sess->s_ttyp))
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%d,%d ",
|
|
|
|
major(tp->t_dev), minor(tp->t_dev));
|
1994-01-05 10:51:08 +03:00
|
|
|
else
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%d,%d ",
|
|
|
|
-1, -1);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
|
|
|
sep = "";
|
|
|
|
if (sess->s_ttyvp) {
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%sctty", sep);
|
1994-01-05 10:51:08 +03:00
|
|
|
sep = ",";
|
|
|
|
}
|
|
|
|
if (SESS_LEADER(p)) {
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%ssldr", sep);
|
1994-01-05 10:51:08 +03:00
|
|
|
sep = ",";
|
|
|
|
}
|
|
|
|
if (*sep != ',')
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "noflags");
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
2007-02-18 01:31:36 +03:00
|
|
|
if (l->l_flag & LW_INMEM)
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %ld,%ld",
|
|
|
|
p->p_stats->p_start.tv_sec, p->p_stats->p_start.tv_usec);
|
1994-01-05 10:51:08 +03:00
|
|
|
else
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " -1,-1");
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-05 09:35:42 +04:00
|
|
|
{
|
|
|
|
struct timeval ut, st;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
calcru(p, &ut, &st, (void *) 0, NULL);
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf),
|
|
|
|
" %ld,%ld %ld,%ld", ut.tv_sec, ut.tv_usec, st.tv_sec,
|
|
|
|
st.tv_usec);
|
1994-05-05 09:35:42 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p->p_smutex);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_lock(l);
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %s",
|
2003-01-18 11:51:40 +03:00
|
|
|
(l->l_wchan && l->l_wmesg) ? l->l_wmesg : "nochan");
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2006-05-15 01:31:52 +04:00
|
|
|
cr = p->p_cred;
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2006-05-15 01:31:52 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
|
|
|
|
kauth_cred_geteuid(cr));
|
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
|
|
|
|
kauth_cred_getegid(cr));
|
|
|
|
ngroups = kauth_cred_ngroups(cr);
|
|
|
|
for (i = 0; i < ngroups; i++)
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), ",%d",
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_group(cr, i));
|
2004-04-22 04:31:00 +04:00
|
|
|
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "\n");
|
1994-01-05 10:51:08 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p->p_mutex);
|
2007-03-09 17:11:22 +03:00
|
|
|
mutex_exit(&proclist_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2004-04-22 04:31:00 +04:00
|
|
|
return (uiomove_frombuf(psbuf, ps - psbuf, uio));
|
1994-01-05 10:51:08 +03:00
|
|
|
}
|