From owner-svn-src-projects@FreeBSD.ORG Sun Jul 12 16:04:13 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AEC7E106564A; Sun, 12 Jul 2009 16:04:13 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 655628FC0C; Sun, 12 Jul 2009 16:04:13 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6CG4DZ5088993; Sun, 12 Jul 2009 16:04:13 GMT (envelope-from lulf@svn.freebsd.org) Received: (from lulf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6CG4CN1088990; Sun, 12 Jul 2009 16:04:12 GMT (envelope-from lulf@svn.freebsd.org) Message-Id: <200907121604.n6CG4CN1088990@svn.freebsd.org> From: Ulf Lilleengen Date: Sun, 12 Jul 2009 16:04:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195638 - in projects/libprocstat/lib: libprocstat libutil X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jul 2009 16:04:14 -0000 Author: lulf Date: Sun Jul 12 16:04:12 2009 New Revision: 195638 URL: http://svn.freebsd.org/changeset/base/195638 Log: - Add kinfo_getproc and kinfo_getallproc as wrappers for sysctls which can save some work common to many utilities. Added: projects/libprocstat/lib/libprocstat/ projects/libprocstat/lib/libutil/kinfo_getallproc.3 projects/libprocstat/lib/libutil/kinfo_getallproc.c (contents, props changed) projects/libprocstat/lib/libutil/kinfo_getproc.3 projects/libprocstat/lib/libutil/kinfo_getproc.c (contents, props changed) Modified: projects/libprocstat/lib/libutil/Makefile projects/libprocstat/lib/libutil/libutil.h Modified: projects/libprocstat/lib/libutil/Makefile ============================================================================== --- projects/libprocstat/lib/libutil/Makefile Sun Jul 12 13:09:43 2009 (r195637) +++ projects/libprocstat/lib/libutil/Makefile Sun Jul 12 16:04:12 2009 (r195638) @@ -9,7 +9,8 @@ LIB= util SHLIB_MAJOR= 7 SRCS= _secure_path.c auth.c expand_number.c flopen.c fparseln.c gr_util.c \ - hexdump.c humanize_number.c kinfo_getfile.c kinfo_getvmmap.c kld.c \ + hexdump.c humanize_number.c kinfo_getfile.c kinfo_getallproc.c \ + kinfo_getproc.c kinfo_getvmmap.c kld.c \ login.c login_auth.c login_cap.c \ login_class.c login_crypt.c login_ok.c login_times.c login_tty.c \ logout.c logwtmp.c pidfile.c property.c pty.c pw_util.c realhostname.c \ @@ -31,7 +32,8 @@ MAN+= kld.3 login.3 login_auth.3 login_t _secure_path.3 uucplock.3 property.3 auth.3 realhostname.3 \ realhostname_sa.3 trimdomain.3 fparseln.3 humanize_number.3 \ pidfile.3 flopen.3 expand_number.3 hexdump.3 \ - kinfo_getfile.3 kinfo_getvmmap.3 + kinfo_getfile.3 kinfo_getallproc.3 kinfo_getproc.3 \ + kinfo_getvmmap.3 MAN+= login.conf.5 auth.conf.5 MLINKS+= kld.3 kld_isloaded.3 kld.3 kld_load.3 MLINKS+= property.3 properties_read.3 property.3 properties_free.3 Added: projects/libprocstat/lib/libutil/kinfo_getallproc.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/libprocstat/lib/libutil/kinfo_getallproc.3 Sun Jul 12 16:04:12 2009 (r195638) @@ -0,0 +1,74 @@ +.\" +.\" Copyright (c) 2009 Ulf Lilleengen +.\" All rights reserved. +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd July 9, 2009 +.Os +.Dt KINFO_GETALLPROC 3 +.Sh NAME +.Nm kinfo_getallproc +.Nd function for getting process information of all processes from kernel +.Sh LIBRARY +.Lb libutil +.Sh SYNOPSIS +.In sys/types.h +.In libutil.h +.Ft struct kinfo_proc * +.Fn kinfo_getallproc "int *cntp" +.Sh DESCRIPTION +This function is used for obtaining process information of all processes from +the kernel. +.Pp +The +.Ar cntp +field is a pointer containing the number of process structures returned. +This function is a wrapper around +.Xr sysctl 3 +with the +.Dv KERN_PROC_PROC +mib. +While the kernel returns a packed structure, this function expands the +data into a fixed record format. +.Sh RETURN VALUES +On success the +.Fn kinfo_getallproc +function returns a pointer to +.Ar cntp +.Vt struct kinfo_proc +structures as defined by +.In sys/user.h . +The pointer was obtained by an internal call to +.Xr malloc 3 +and must be freed by the caller with a call to +.Xr free 3 . +On failure the +.Fn kinfo_getallproc +function returns +.Dv NULL . +.Sh SEE ALSO +.Xr free 3 , +.Xr malloc 3 , +.Xr sysctl 3 Added: projects/libprocstat/lib/libutil/kinfo_getallproc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/libprocstat/lib/libutil/kinfo_getallproc.c Sun Jul 12 16:04:12 2009 (r195638) @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2007 Robert N. M. Watson + * Copyright (c) 2009 Ulf Lilleengen + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "libutil.h" + + +/* + * Sort processes first by pid and then tid. + */ +static int +kinfo_proc_compare(const void *a, const void *b) +{ + int i; + + i = ((const struct kinfo_proc *)a)->ki_pid - + ((const struct kinfo_proc *)b)->ki_pid; + if (i != 0) + return (i); + i = ((const struct kinfo_proc *)a)->ki_tid - + ((const struct kinfo_proc *)b)->ki_tid; + return (i); +} + +static void +kinfo_proc_sort(struct kinfo_proc *kipp, int count) +{ + + qsort(kipp, count, sizeof(*kipp), kinfo_proc_compare); +} + +struct kinfo_proc * +kinfo_getallproc(int *cntp) +{ + struct kinfo_proc *kipp; + size_t len; + int mib[3]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PROC; + + len = 0; + if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0) + return (NULL); + + kipp = malloc(len); + if (kipp == NULL) + return (NULL); + + if (sysctl(mib, 3, kipp, &len, NULL, 0) < 0) + goto bad; + if (len % sizeof(*kipp) != 0) + goto bad; + if (kipp->ki_structsize != sizeof(*kipp)) + goto bad; + *cntp = len / sizeof(*kipp); + kinfo_proc_sort(kipp, len / sizeof(*kipp)); + return (kipp); +bad: + *cntp = 0; + free(kipp); + return (NULL); +} Added: projects/libprocstat/lib/libutil/kinfo_getproc.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/libprocstat/lib/libutil/kinfo_getproc.3 Sun Jul 12 16:04:12 2009 (r195638) @@ -0,0 +1,73 @@ +.\" +.\" Copyright (c) 2009 Ulf Lilleengen +.\" All rights reserved. +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd July 9, 2009 +.Os +.Dt KINFO_GETPROC 3 +.Sh NAME +.Nm kinfo_getproc +.Nd function for getting process information from kernel +.Sh LIBRARY +.Lb libutil +.Sh SYNOPSIS +.In sys/types.h +.In libutil.h +.Ft struct kinfo_proc * +.Fn kinfo_getproc "pid_t pid" "int *cntp" +.Sh DESCRIPTION +This function is used for obtaining process information from the kernel. +.Pp +The +.Ar pid +field contains the process identifier. +This should be the a process that you have privilige to access. +This function is a wrapper around +.Xr sysctl 3 +with the +.Dv KERN_PROC_PID +mib. +While the kernel returns a packed structure, this function expands the +data into a fixed record format. +.Sh RETURN VALUES +On success the +.Fn kinfo_getproc +function returns a pointer to a +.Vt struct kinfo_proc +structure as defined by +.In sys/user.h . +The pointer was obtained by an internal call to +.Xr malloc 3 +and must be freed by the caller with a call to +.Xr free 3 . +On failure the +.Fn kinfo_getproc +function returns +.Dv NULL . +.Sh SEE ALSO +.Xr free 3 , +.Xr malloc 3 , +.Xr sysctl 3 Added: projects/libprocstat/lib/libutil/kinfo_getproc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/libprocstat/lib/libutil/kinfo_getproc.c Sun Jul 12 16:04:12 2009 (r195638) @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 2009 Ulf Lilleengen + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "libutil.h" + +struct kinfo_proc * +kinfo_getproc(pid_t pid) +{ + struct kinfo_proc *kipp; + int mib[4]; + size_t len; + + len = 0; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = pid; + if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) + return (NULL); + + kipp = malloc(len); + if (kipp == NULL) + return (NULL); + + if (sysctl(mib, 4, kipp, &len, NULL, 0) < 0) + goto bad; + if (len != sizeof(*kipp)) + goto bad; + if (kipp->ki_structsize != sizeof(*kipp)) + goto bad; + if (kipp->ki_pid != pid) + goto bad; + return (kipp); +bad: + free(kipp); + return (NULL); +} Modified: projects/libprocstat/lib/libutil/libutil.h ============================================================================== --- projects/libprocstat/lib/libutil/libutil.h Sun Jul 12 13:09:43 2009 (r195637) +++ projects/libprocstat/lib/libutil/libutil.h Sun Jul 12 16:04:12 2009 (r195638) @@ -65,6 +65,7 @@ struct winsize; struct utmp; struct in_addr; struct kinfo_file; +struct kinfo_proc; struct kinfo_vmentry; __BEGIN_DECLS @@ -106,6 +107,10 @@ struct kinfo_file * kinfo_getfile(pid_t _pid, int *_cntp); struct kinfo_vmentry * kinfo_getvmmap(pid_t _pid, int *_cntp); +struct kinfo_proc * + kinfo_getallproc(int *_cntp); +struct kinfo_proc * + kinfo_getproc(pid_t _pid); #ifdef _STDIO_H_ /* avoid adding new includes */ char *fparseln(FILE *, size_t *, size_t *, const char[3], int); From owner-svn-src-projects@FreeBSD.ORG Mon Jul 13 01:37:48 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF1AC1065673; Mon, 13 Jul 2009 01:37:48 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 933198FC23; Mon, 13 Jul 2009 01:37:48 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6D1bmR1000640; Mon, 13 Jul 2009 01:37:48 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6D1bmfE000639; Mon, 13 Jul 2009 01:37:48 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200907130137.n6D1bmfE000639@svn.freebsd.org> From: Nathan Whitehorn Date: Mon, 13 Jul 2009 01:37:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195651 - projects/ppc64 X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2009 01:37:49 -0000 Author: nwhitehorn Date: Mon Jul 13 01:37:48 2009 New Revision: 195651 URL: http://svn.freebsd.org/changeset/base/195651 Log: Branch head for developing a 64-bit PowerPC port. This follows initial work in the now-broken P4 ppc-g5 branch. Added: projects/ppc64/ (props changed) - copied from r195650, head/ From owner-svn-src-projects@FreeBSD.ORG Mon Jul 13 21:18:54 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4F0A1065670; Mon, 13 Jul 2009 21:18:54 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D36F58FC13; Mon, 13 Jul 2009 21:18:54 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6DLIscH035962; Mon, 13 Jul 2009 21:18:54 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6DLIsDD035957; Mon, 13 Jul 2009 21:18:54 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907132118.n6DLIsDD035957@svn.freebsd.org> From: Stanislav Sedov Date: Mon, 13 Jul 2009 21:18:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195664 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2009 21:18:55 -0000 Author: stas Date: Mon Jul 13 21:18:54 2009 New Revision: 195664 URL: http://svn.freebsd.org/changeset/base/195664 Log: - Work-in-progress work on separating access-independent fstat code from data access routines and attempt to create a generic transparent interface to kernel structures supporting both KVM and sysctl interfaces. This is still very dirty and current fstat is broken in a number of ways (and only ordinary vnodes are supported now). Added: projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h Modified: projects/libprocstat/usr.bin/fstat/Makefile projects/libprocstat/usr.bin/fstat/common.h projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/fuser.c Modified: projects/libprocstat/usr.bin/fstat/Makefile ============================================================================== --- projects/libprocstat/usr.bin/fstat/Makefile Mon Jul 13 20:19:29 2009 (r195663) +++ projects/libprocstat/usr.bin/fstat/Makefile Mon Jul 13 21:18:54 2009 (r195664) @@ -4,12 +4,10 @@ .include PROG= fstat -SRCS= cd9660.c common.c fstat.c main.c msdosfs.c fuser.c +SRCS= cd9660.c common.c fstat.c main.c msdosfs.c fuser.c libprocstat.c LINKS= ${BINDIR}/fstat ${BINDIR}/fuser DPADD= ${LIBKVM} LDADD= -lkvm -lutil -BINGRP= kmem -BINMODE=2555 WARNS?= 6 MAN1= fuser.1 fstat.1 Modified: projects/libprocstat/usr.bin/fstat/common.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.h Mon Jul 13 20:19:29 2009 (r195663) +++ projects/libprocstat/usr.bin/fstat/common.h Mon Jul 13 21:18:54 2009 (r195664) @@ -42,6 +42,12 @@ struct filestat { mode_t mode; u_long size; dev_t rdev; + int vtype; + int type; + char *mntdir; + int flags; + int fflags; + int fd; }; extern int vflg; Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Mon Jul 13 20:19:29 2009 (r195663) +++ projects/libprocstat/usr.bin/fstat/fstat.c Mon Jul 13 21:18:54 2009 (r195664) @@ -87,6 +87,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -104,13 +105,7 @@ __FBSDID("$FreeBSD$"); #include "common.h" #include "functions.h" - -#define TEXT -1 -#define CDIR -2 -#define RDIR -3 -#define TRACE -4 -#define MMAP -5 -#define JDIR -6 +#include "libprocstat.h" int fsflg, /* show files on same filesystem as file(s) argument */ pflg, /* show files open by a particular pid */ @@ -128,27 +123,30 @@ typedef struct devs { DEVS *devs; char *memf, *nlistf; -kvm_t *kd; -static void fstat_kvm(int, int); -static void fstat_sysctl(int, int); -void dofiles(struct kinfo_proc *kp); +static void fstat1(int what, int arg); +static void dofiles(struct procstat *procstat, struct kinfo_proc *p); void dofiles_kinfo(struct kinfo_proc *kp); void dommap(struct kinfo_proc *kp); -void vtrans(struct vnode *vp, int i, int flag); +void vtrans(struct vnode *vp, int i, int flag, const char *uname, const char *cmd, int pid); char *getmnton(struct mount *m); -void pipetrans(struct pipe *pi, int i, int flag); -void socktrans(struct socket *sock, int i); -void ptstrans(struct tty *tp, int i, int flag); +void pipetrans(struct pipe *pi, int i, int flag, const char *uname, const char *cmd, int pid); +void socktrans(struct socket *sock, int i, const char *uname, const char *cmd, int pid); +void ptstrans(struct tty *tp, int i, int flag, const char *uname, const char *cmd, int pid); void getinetproto(int number); int getfname(const char *filename); void usage(void); -static int kinfo_proc_compare(const void *, const void *); -static void kinfo_proc_sort(struct kinfo_proc *, int); -void vtrans_kinfo(struct kinfo_file *, int i, int flag); +void vtrans_kinfo(struct kinfo_file *, int i, int flag, const char *uname, const char *cmd, int pid); +static void print_file_info(struct procstat *procstat, struct filestat *fst, const char *uname, const char *cmd, int pid); -/* XXX: sys/mount.h */ -int statfs(const char *, struct statfs *); +static void +print_socket_info(struct procstat *procstat, struct filestat *fst); +static void +print_pipe_info(struct procstat *procstat, struct filestat *fst); +static void +print_pts_info(struct procstat *procstat, struct filestat *fst); +static void +print_vnode_info(struct procstat *procstat, struct filestat *fst); int do_fstat(int argc, char **argv) @@ -218,17 +216,28 @@ do_fstat(int argc, char **argv) checkfile = 1; } - if (memf != NULL) - fstat_kvm(what, arg); - else - fstat_sysctl(what, arg); + fstat1(what, arg); exit(0); } static void -print_header(void) +fstat1(int what, int arg) { + struct kinfo_proc *p; + struct procstat *procstat; + int cnt; + int i; + + procstat = procstat_open(nlistf, memf); + if (procstat == NULL) + errx(1, "procstat_open()"); + p = procstat_getprocs(procstat, what, arg, &cnt); + if (p == NULL) + errx(1, "procstat_getprocs()"); + /* + * Print header. + */ if (nflg) printf("%s", "USER CMD PID FD DEV INUM MODE SZ|DV R/W"); @@ -239,854 +248,206 @@ print_header(void) printf(" NAME\n"); else putchar('\n'); -} - -static void -fstat_kvm(int what, int arg) -{ - struct kinfo_proc *p, *plast; - char buf[_POSIX2_LINE_MAX]; - int cnt; /* - * Discard setgid privileges if not the running kernel so that bad - * guys can't print interesting stuff from kernel memory. + * Go through the process list. */ - if (nlistf != NULL || memf != NULL) - setgid(getgid()); - - if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) - errx(1, "%s", buf); - setgid(getgid()); - if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) - errx(1, "%s", kvm_geterr(kd)); - print_header(); - for (plast = &p[cnt]; p < plast; ++p) { - if (p->ki_stat == SZOMB) + for (i = 0; i < cnt; i++) { + if (p[i].ki_stat == SZOMB) continue; - dofiles(p); + dofiles(procstat, &p[i]); +/* if (mflg) - dommap(p); + dommap(procstat, &p[i]); +*/ } -} - -/* - * Sort processes first by pid and then tid. - */ -static int -kinfo_proc_compare(const void *a, const void *b) -{ - int i; - - i = ((const struct kinfo_proc *)b)->ki_pid - - ((const struct kinfo_proc *)a)->ki_pid; - if (i != 0) - return (i); - i = ((const struct kinfo_proc *)b)->ki_tid - - ((const struct kinfo_proc *)a)->ki_tid; - return (i); -} - -static void -kinfo_proc_sort(struct kinfo_proc *kipp, int count) -{ - - qsort(kipp, count, sizeof(*kipp), kinfo_proc_compare); + free(p); + procstat_close(procstat); } static void -fstat_sysctl(int what, int arg) +dofiles(struct procstat *procstat, struct kinfo_proc *kp) { - struct kinfo_proc *kipp; - int name[4]; - size_t len; + struct filestat *fst; + unsigned int count; + const char *cmd, *uname; + int pid; unsigned int i; - name[0] = CTL_KERN; - name[1] = KERN_PROC; - name[2] = what; - name[3] = arg; - - len = 0; - if (sysctl(name, 4, NULL, &len, NULL, 0) < 0) - err(-1, "sysctl: kern.proc"); - kipp = malloc(len); - if (kipp == NULL) - err(-1, "malloc"); - - if (sysctl(name, 4, kipp, &len, NULL, 0) < 0) { - free(kipp); - err(-1, "sysctl: kern.proc"); - } - if (len % sizeof(*kipp) != 0) - err(-1, "kinfo_proc mismatch"); - if (kipp->ki_structsize != sizeof(*kipp)) - err(-1, "kinfo_proc structure mismatch"); - kinfo_proc_sort(kipp, len / sizeof(*kipp)); - print_header(); - for (i = 0; i < len / sizeof(*kipp); i++) { - dofiles_kinfo(&kipp[i]); - if (mflg) - dommap(&kipp[i]); - } - free(kipp); -} - -const char *Uname, *Comm; -int Pid; - -#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \ - switch(i) { \ - case TEXT: \ - printf(" text"); \ - break; \ - case CDIR: \ - printf(" wd"); \ - break; \ - case RDIR: \ - printf(" root"); \ - break; \ - case TRACE: \ - printf(" tr"); \ - break; \ - case MMAP: \ - printf(" mmap"); \ - break; \ - case JDIR: \ - printf(" jail"); \ - break; \ - default: \ - printf(" %4d", i); \ - break; \ - } - -/* - * print open files attributed to this process - */ -void -dofiles(struct kinfo_proc *kp) -{ - int i; - struct file file; - struct filedesc filed; - unsigned int nfiles; - struct file **ofiles; - - Uname = user_from_uid(kp->ki_uid, 0); - Pid = kp->ki_pid; - Comm = kp->ki_comm; - - if (kp->ki_fd == NULL) - return; - if (!kvm_read_all(kd, (unsigned long)kp->ki_fd, &filed, - sizeof(filed))) { - dprintf(stderr, "can't read filedesc at %p for pid %d\n", - (void *)kp->ki_fd, Pid); - return; - } - /* - * root directory vnode, if one - */ - if (filed.fd_rdir) - vtrans(filed.fd_rdir, RDIR, FREAD); - /* - * current working directory vnode - */ - if (filed.fd_cdir) - vtrans(filed.fd_cdir, CDIR, FREAD); - /* - * jail root, if any. - */ - if (filed.fd_jdir) - vtrans(filed.fd_jdir, JDIR, FREAD); - /* - * ktrace vnode, if one - */ - if (kp->ki_tracep) - vtrans(kp->ki_tracep, TRACE, FREAD|FWRITE); - /* - * text vnode, if one - */ - if (kp->ki_textvp) - vtrans(kp->ki_textvp, TEXT, FREAD); - /* - * open files - */ -#define FPSIZE (sizeof (struct file *)) -#define MAX_LASTFILE (0x1000000) + uname = user_from_uid(kp->ki_uid, 0); + pid = kp->ki_pid; + cmd = kp->ki_comm; - /* Sanity check on filed.fd_lastfile */ - if (filed.fd_lastfile <= -1 || filed.fd_lastfile > MAX_LASTFILE) + fst = procstat_getfiles(procstat, kp, &count); + if (fst == NULL) return; - nfiles = filed.fd_lastfile + 1; - ofiles = malloc(nfiles * sizeof(struct file *)); - if (ofiles == NULL) { - warn("malloc(%zd)", nfiles * sizeof(struct file *)); - return; - } - if (!kvm_read_all(kd, (unsigned long)filed.fd_ofiles, ofiles, - (filed.fd_lastfile+1) * FPSIZE)) { - dprintf(stderr, - "can't read file structures at %p for pid %d\n", - (void *)filed.fd_ofiles, Pid); - free(ofiles); - return; - } - for (i = 0; i <= filed.fd_lastfile; i++) { - if (ofiles[i] == NULL) - continue; - if (!kvm_read_all(kd, (unsigned long)ofiles[i], &file, - sizeof(struct file))) { - dprintf(stderr, "can't read file %d at %p for pid %d\n", - i, (void *)ofiles[i], Pid); - continue; - } - if (file.f_type == DTYPE_VNODE) - vtrans(file.f_vnode, i, file.f_flag); - else if (file.f_type == DTYPE_SOCKET) { - if (checkfile == 0) - socktrans(file.f_data, i); - } -#ifdef DTYPE_PIPE - else if (file.f_type == DTYPE_PIPE) { - if (checkfile == 0) - pipetrans(file.f_data, i, file.f_flag); - } -#endif -#ifdef DTYPE_FIFO - else if (file.f_type == DTYPE_FIFO) { - if (checkfile == 0) - vtrans(file.f_vnode, i, file.f_flag); - } -#endif -#ifdef DTYPE_PTS - else if (file.f_type == DTYPE_PTS) { - if (checkfile == 0) - ptstrans(file.f_data, i, file.f_flag); - } -#endif - else { - dprintf(stderr, - "unknown file type %d for file %d of pid %d\n", - file.f_type, i, Pid); - } - } - free(ofiles); + for (i = 0; i < count; i++) + print_file_info(procstat, &fst[i], uname, cmd, pid); } -/* - * print open files attributed to this process using kinfo - */ -void -dofiles_kinfo(struct kinfo_proc *kp) -{ - struct kinfo_file *kif, *freep; -#if 0 - struct kinfo_file kifb; -#endif - int i, cnt, fd_type, flags; - - Uname = user_from_uid(kp->ki_uid, 0); - Pid = kp->ki_pid; - Comm = kp->ki_comm; - - if (kp->ki_fd == NULL) - return; - -#if 0 - /* - * ktrace vnode, if one - */ - if (kp->ki_tracep) - vtrans_kin(kp->ki_tracep, TRACE, FREAD|FWRITE); - /* - * text vnode, if one - */ - vtrans(kp->ki_textvp, TEXT, FREAD); - /* Text vnode. */ - if (kp->ki_textvp) { - if (gettextvp(kp, &kifb) == 0) - vtrans_kinfo(&kifb, TEXT, FREAD); - } -#endif - - /* - * open files - */ - freep = kinfo_getfile(kp->ki_pid, &cnt); - if (freep == NULL) - err(1, "kinfo_getfile"); - - for (i = 0; i < cnt; i++) { - kif = &freep[i]; - switch (kif->kf_type) { - case KF_TYPE_VNODE: - if (kif->kf_fd == KF_FD_TYPE_CWD) { - fd_type = CDIR; - flags = FREAD; - } else if (kif->kf_fd == KF_FD_TYPE_ROOT) { - fd_type = RDIR; - flags = FREAD; - } else if (kif->kf_fd == KF_FD_TYPE_JAIL) { - fd_type = JDIR; - flags = FREAD; - } else { - fd_type = i; - flags = kif->kf_flags; - } - /* Only do this if the attributes are valid. */ - if (kif->kf_status & KF_ATTR_VALID) - vtrans_kinfo(kif, fd_type, flags); - break; -#if 0 - case KF_TYPE_PIPE: - if (checkfile == 0) - pipetrans_kinfo(kif, i, kif->kf_flags); - break; - else if (file.f_type == DTYPE_SOCKET) { - if (checkfile == 0) - socktrans(file.f_data, i); - } -#ifdef DTYPE_PIPE - else if (file.f_type == DTYPE_PIPE) { - if (checkfile == 0) - pipetrans(file.f_data, i, file.f_flag); - } -#endif -#ifdef DTYPE_FIFO - else if (file.f_type == DTYPE_FIFO) { - if (checkfile == 0) - vtrans(file.f_vnode, i, file.f_flag); - } -#endif -#ifdef DTYPE_PTS - else if (file.f_type == DTYPE_PTS) { - if (checkfile == 0) - ptstrans(file.f_data, i, file.f_flag); - } -#endif - else { - dprintf(stderr, - "unknown file type %d for file %d of pid %d\n", - file.f_type, i, Pid); - } -#endif - } - } - free(freep); -} -void -dommap(struct kinfo_proc *kp) +static void +print_file_info(struct procstat *procstat, struct filestat *fst, + const char *uname, const char *cmd, int pid) { - vm_map_t map; - struct vmspace vmspace; - struct vm_map_entry entry; - vm_map_entry_t entryp; - struct vm_object object; - vm_object_t objp; - int prot, fflags; - - if (!kvm_read_all(kd, (unsigned long)kp->ki_vmspace, &vmspace, - sizeof(vmspace))) { - dprintf(stderr, - "can't read vmspace at %p for pid %d\n", - (void *)kp->ki_vmspace, Pid); - return; - } - map = &vmspace.vm_map; - - for (entryp = map->header.next; - entryp != &kp->ki_vmspace->vm_map.header; entryp = entry.next) { - if (!kvm_read_all(kd, (unsigned long)entryp, &entry, - sizeof(entry))) { - dprintf(stderr, - "can't read vm_map_entry at %p for pid %d\n", - (void *)entryp, Pid); - return; - } - - if (entry.eflags & MAP_ENTRY_IS_SUB_MAP) - continue; + const char *badtype, *filename; - if ((objp = entry.object.vm_object) == NULL) - continue; + badtype = NULL; + filename = NULL; + if (fst->type == PS_FST_TYPE_VNODE || fst->type == PS_FST_TYPE_FIFO) { + if (fst->flags & PS_FST_FLAG_ERROR) + badtype = "error"; + else if (fst->flags == PS_FST_FLAG_UNKNOWNFS) + badtype = "unknown"; + else if (fst->vtype == PS_FST_VTYPE_VNON) + badtype = "none"; + else if (fst->vtype == PS_FST_VTYPE_VBAD) + badtype = "bad"; + + if (checkfile) { + int fsmatch = 0; + DEVS *d; - for (; objp; objp = object.backing_object) { - if (!kvm_read_all(kd, (unsigned long)objp, &object, - sizeof(object))) { - dprintf(stderr, - "can't read vm_object at %p for pid %d\n", - (void *)objp, Pid); + if (badtype) return; - } - } - - prot = entry.protection; - fflags = (prot & VM_PROT_READ ? FREAD : 0) | - (prot & VM_PROT_WRITE ? FWRITE : 0); - - switch (object.type) { - case OBJT_VNODE: - vtrans((struct vnode *)object.handle, MMAP, fflags); - break; - default: - break; - } - } -} - -void -vtrans(struct vnode *vp, int i, int flag) -{ - struct vnode vn; - struct filestat fst; - char rw[3], mode[15], tagstr[12], *tagptr; - const char *badtype, *filename; - - filename = badtype = NULL; - if (!kvm_read_all(kd, (unsigned long)vp, &vn, sizeof(struct vnode))) { - dprintf(stderr, "can't read vnode at %p for pid %d\n", - (void *)vp, Pid); - return; - } - if (!kvm_read_all(kd, (unsigned long)&vp->v_tag, &tagptr, - sizeof(tagptr)) || !kvm_read_all(kd, (unsigned long)tagptr, tagstr, - sizeof(tagstr))) { - dprintf(stderr, "can't read v_tag at %p for pid %d\n", - (void *)vp, Pid); - return; - } - tagstr[sizeof(tagstr) - 1] = '\0'; - if (vn.v_type == VNON) - badtype = "none"; - else if (vn.v_type == VBAD) - badtype = "bad"; - else { - if (!strcmp("ufs", tagstr)) { - if (!ufs_filestat(kd, &vn, &fst)) - badtype = "error"; - } else if (!strcmp("devfs", tagstr)) { - if (!devfs_filestat(kd, &vn, &fst)) - badtype = "error"; - } else if (!strcmp("nfs", tagstr)) { - if (!nfs_filestat(kd, &vn, &fst)) - badtype = "error"; - } else if (!strcmp("msdosfs", tagstr)) { - if (!msdosfs_filestat(kd, &vn, &fst)) - badtype = "error"; - } else if (!strcmp("isofs", tagstr)) { - if (!isofs_filestat(kd, &vn, &fst)) - badtype = "error"; -#ifdef ZFS - } else if (!strcmp("zfs", tagstr)) { - if (!zfs_filestat(kd, &vn, &fst)) - badtype = "error"; -#endif - } else { - static char unknown[32]; - snprintf(unknown, sizeof unknown, "?(%s)", tagstr); - badtype = unknown; - } - } - if (checkfile) { - int fsmatch = 0; - DEVS *d; - - if (badtype) - return; - for (d = devs; d != NULL; d = d->next) - if (d->fsid == fst.fsid) { - fsmatch = 1; - if (d->ino == fst.fileid) { - filename = d->name; - break; + for (d = devs; d != NULL; d = d->next) + if (d->fsid == fst->fsid) { + fsmatch = 1; + if (d->ino == fst->fileid) { + filename = d->name; + break; + } } - } - if (fsmatch == 0 || (filename == NULL && fsflg == 0)) - return; - } - PREFIX(i); - if (badtype) { - (void)printf(" - - %10s -\n", badtype); + if (fsmatch == 0 || (filename == NULL && fsflg == 0)) + return; + } + } else if (checkfile != 0) return; - } - if (nflg) - (void)printf(" %2d,%-2d", major(fst.fsid), minor(fst.fsid)); - else - (void)printf(" %-8s", getmnton(vn.v_mount)); - if (nflg) - (void)sprintf(mode, "%o", fst.mode); - else - strmode(fst.mode, mode); - (void)printf(" %6ld %10s", fst.fileid, mode); - switch (vn.v_type) { - case VBLK: - case VCHR: { - char *name; - name = kdevtoname(kd, vn.v_rdev); - if (nflg || !name) - printf(" %2d,%-2d", major(fst.rdev), minor(fst.rdev)); - else { - printf(" %6s", name); - free(name); - } + /* + * Print entry prefix. + */ + printf("%-8.8s %-10s %5d", uname, cmd, pid); + switch(fst->fd) { + case PS_FST_FD_TEXT: + printf(" text"); break; - } - default: - printf(" %6lu", fst.size); - } - rw[0] = '\0'; - if (flag & FREAD) - strcat(rw, "r"); - if (flag & FWRITE) - strcat(rw, "w"); - printf(" %2s", rw); - if (filename && !fsflg) - printf(" %s", filename); - putchar('\n'); -} - -void -vtrans_kinfo(struct kinfo_file *kif, int i, int flag) -{ - struct filestat fst; - char rw[3], mode[15]; - const char *badtype, *filename; - struct statfs stbuf; - - filename = badtype = NULL; - fst.fsid = fst.fileid = fst.mode = fst.size = fst.rdev = 0; - bzero(&stbuf, sizeof(struct statfs)); - switch (kif->kf_vnode_type) { - case VNON: - badtype = "none"; + case PS_FST_FD_CDIR: + printf(" wd"); + break; + case PS_FST_FD_RDIR: + printf(" root"); + break; + case PS_FST_FD_TRACE: + printf(" tr"); + break; + case PS_FST_FD_MMAP: + printf(" mmap"); break; - case VBAD: - badtype = "bad"; + case PS_FST_FD_JAIL: + printf(" jail"); break; default: - fst.fsid = kif->kf_file_fsid; - fst.fileid = kif->kf_file_fileid; - fst.mode = kif->kf_file_mode; - fst.size = kif->kf_file_size; - fst.rdev = kif->kf_file_rdev; + printf(" %4d", fst->fd); break; } - if (checkfile) { - int fsmatch = 0; - DEVS *d; - - if (badtype) - return; - for (d = devs; d != NULL; d = d->next) - if (d->fsid == fst.fsid) { - fsmatch = 1; - if (d->ino == fst.fileid) { - filename = d->name; - break; - } - } - if (fsmatch == 0 || (filename == NULL && fsflg == 0)) - return; - } - PREFIX(i); if (badtype) { (void)printf(" - - %10s -\n", badtype); return; } - if (nflg) - (void)printf(" %2d,%-2d", major(fst.fsid), minor(fst.fsid)); - else { - if (strlen(kif->kf_path) > 0) - statfs(kif->kf_path, &stbuf); - (void)printf(" %-8s", stbuf.f_mntonname); - } - if (nflg) - (void)sprintf(mode, "%o", fst.mode); - else { - strmode(fst.mode, mode); - } - (void)printf(" %6ld %10s", fst.fileid, mode); - switch (kif->kf_vnode_type) { - case KF_VTYPE_VBLK: { - char *name; - name = devname(fst.rdev, S_IFBLK); - if (nflg || !name) - printf(" %2d,%-2d", major(fst.rdev), minor(fst.rdev)); - else { - printf(" %6s", name); - } + + /* + * Print type-specific data. + */ + switch (fst->type) { + case PS_FST_TYPE_FIFO: + case PS_FST_TYPE_VNODE: + print_vnode_info(procstat, fst); break; - } - case KF_VTYPE_VCHR: { - char *name; - name = devname(fst.rdev, S_IFCHR); - if (nflg || !name) - printf(" %2d,%-2d", major(fst.rdev), minor(fst.rdev)); - else { - printf(" %6s", name); - } + case PS_FST_TYPE_SOCKET: + print_socket_info(procstat, fst); break; + case PS_FST_TYPE_PIPE: + print_pipe_info(procstat, fst); + break; + case PS_FST_TYPE_PTS: + print_pts_info(procstat, fst); + break; + default: + dprintf(stderr, + "unknown file type %d for file %d of pid %d\n", + fst->type, fst->fd, pid); } - default: - printf(" %6lu", fst.size); - } - rw[0] = '\0'; - if (flag & FREAD) - strcat(rw, "r"); - if (flag & FWRITE) - strcat(rw, "w"); - printf(" %2s", rw); if (filename && !fsflg) printf(" %s", filename); putchar('\n'); } -char * -getmnton(struct mount *m) +static void +print_socket_info(struct procstat *procstat __unused, struct filestat *fst __unused) { - static struct mount mnt; - static struct mtab { - struct mtab *next; - struct mount *m; - char mntonname[MNAMELEN]; - } *mhead = NULL; - struct mtab *mt; - - for (mt = mhead; mt != NULL; mt = mt->next) - if (m == mt->m) - return (mt->mntonname); - if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) { - warnx("can't read mount table at %p", (void *)m); - return (NULL); - } - if ((mt = malloc(sizeof (struct mtab))) == NULL) - err(1, NULL); - mt->m = m; - bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); - mt->next = mhead; - mhead = mt; - return (mt->mntonname); + + printf(" not implemented\n"); } -void -pipetrans(struct pipe *pi, int i, int flag) +static void +print_pipe_info(struct procstat *procstat __unused, struct filestat *fst __unused) { - struct pipe pip; - char rw[3]; - - PREFIX(i); - /* fill in socket */ - if (!kvm_read_all(kd, (unsigned long)pi, &pip, sizeof(struct pipe))) { - dprintf(stderr, "can't read pipe at %p\n", (void *)pi); - goto bad; - } - - printf("* pipe %8lx <-> %8lx", (u_long)pi, (u_long)pip.pipe_peer); - printf(" %6d", (int)pip.pipe_buffer.cnt); - rw[0] = '\0'; - if (flag & FREAD) - strcat(rw, "r"); - if (flag & FWRITE) - strcat(rw, "w"); - printf(" %2s", rw); - putchar('\n'); - return; - -bad: - printf("* error\n"); + printf(" not implemented\n"); } -void -socktrans(struct socket *sock, int i) +static void +print_pts_info(struct procstat *procstat __unused, struct filestat *fst __unused) { - static const char *stypename[] = { - "unused", /* 0 */ - "stream", /* 1 */ - "dgram", /* 2 */ - "raw", /* 3 */ - "rdm", /* 4 */ - "seqpak" /* 5 */ - }; -#define STYPEMAX 5 - struct socket so; - struct protosw proto; - struct domain dom; - struct inpcb inpcb; - struct unpcb unpcb; - int len; - char dname[32]; - - PREFIX(i); - - /* fill in socket */ - if (!kvm_read_all(kd, (unsigned long)sock, &so, - sizeof(struct socket))) { - dprintf(stderr, "can't read sock at %p\n", (void *)sock); - goto bad; - } - - /* fill in protosw entry */ - if (!kvm_read_all(kd, (unsigned long)so.so_proto, &proto, - sizeof(struct protosw))) { - dprintf(stderr, "can't read protosw at %p", - (void *)so.so_proto); - goto bad; - } - - /* fill in domain */ - if (!kvm_read_all(kd, (unsigned long)proto.pr_domain, &dom, - sizeof(struct domain))) { - dprintf(stderr, "can't read domain at %p\n", - (void *)proto.pr_domain); - goto bad; - } - - if ((len = kvm_read(kd, (unsigned long)dom.dom_name, dname, - sizeof(dname) - 1)) < 0) { - dprintf(stderr, "can't read domain name at %p\n", - (void *)dom.dom_name); - dname[0] = '\0'; - } - else - dname[len] = '\0'; - if ((u_short)so.so_type > STYPEMAX) - printf("* %s ?%d", dname, so.so_type); - else - printf("* %s %s", dname, stypename[so.so_type]); - - /* - * protocol specific formatting - * - * Try to find interesting things to print. For tcp, the interesting - * thing is the address of the tcpcb, for udp and others, just the - * inpcb (socket pcb). For unix domain, its the address of the socket - * pcb and the address of the connected pcb (if connected). Otherwise - * just print the protocol number and address of the socket itself. - * The idea is not to duplicate netstat, but to make available enough - * information for further analysis. - */ - switch(dom.dom_family) { - case AF_INET: - case AF_INET6: - getinetproto(proto.pr_protocol); - if (proto.pr_protocol == IPPROTO_TCP ) { - if (so.so_pcb) { - if (kvm_read(kd, (u_long)so.so_pcb, - (char *)&inpcb, sizeof(struct inpcb)) - != sizeof(struct inpcb)) { - dprintf(stderr, - "can't read inpcb at %p\n", - (void *)so.so_pcb); - goto bad; - } - printf(" %lx", (u_long)inpcb.inp_ppcb); - } - } - else if (so.so_pcb) - printf(" %lx", (u_long)so.so_pcb); - break; - case AF_UNIX: - /* print address of pcb and connected pcb */ - if (so.so_pcb) { - printf(" %lx", (u_long)so.so_pcb); - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, - sizeof(struct unpcb)) != sizeof(struct unpcb)){ - dprintf(stderr, "can't read unpcb at %p\n", - (void *)so.so_pcb); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Mon Jul 13 23:01:12 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5ED1D106566B; Mon, 13 Jul 2009 23:01:12 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4D94F8FC12; Mon, 13 Jul 2009 23:01:12 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6DN1Ccm038215; Mon, 13 Jul 2009 23:01:12 GMT (envelope-from gonzo@svn.freebsd.org) Received: (from gonzo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6DN1Ctl038213; Mon, 13 Jul 2009 23:01:12 GMT (envelope-from gonzo@svn.freebsd.org) Message-Id: <200907132301.n6DN1Ctl038213@svn.freebsd.org> From: Oleksandr Tymoshenko Date: Mon, 13 Jul 2009 23:01:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195668 - projects/mips/gnu/usr.bin/cc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2009 23:01:12 -0000 Author: gonzo Date: Mon Jul 13 23:01:12 2009 New Revision: 195668 URL: http://svn.freebsd.org/changeset/base/195668 Log: - Get rid of ugly TARGET_CPU_DEFAULT default. 16 is MASK_DSP and was set there due to my ignroance. Modified: projects/mips/gnu/usr.bin/cc/Makefile.tgt Modified: projects/mips/gnu/usr.bin/cc/Makefile.tgt ============================================================================== --- projects/mips/gnu/usr.bin/cc/Makefile.tgt Mon Jul 13 22:13:13 2009 (r195667) +++ projects/mips/gnu/usr.bin/cc/Makefile.tgt Mon Jul 13 23:01:12 2009 (r195668) @@ -15,9 +15,6 @@ GCC_CPU= ${TARGET_ARCH} .if ${TARGET_ARCH} == "ia64" TARGET_CPU_DEFAULT= MASK_GNU_AS|MASK_GNU_LD .endif -.if ${TARGET_ARCH} == "mips" -TARGET_CPU_DEFAULT= 16 -.endif .if ${TARGET_ARCH} == "sparc64" TARGET_CPU_DEFAULT= TARGET_CPU_ultrasparc .endif From owner-svn-src-projects@FreeBSD.ORG Mon Jul 13 23:03:45 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0F6F81065674; Mon, 13 Jul 2009 23:03:45 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F20408FC24; Mon, 13 Jul 2009 23:03:44 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6DN3iED038296; Mon, 13 Jul 2009 23:03:44 GMT (envelope-from gonzo@svn.freebsd.org) Received: (from gonzo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6DN3idQ038292; Mon, 13 Jul 2009 23:03:44 GMT (envelope-from gonzo@svn.freebsd.org) Message-Id: <200907132303.n6DN3idQ038292@svn.freebsd.org> From: Oleksandr Tymoshenko Date: Mon, 13 Jul 2009 23:03:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195669 - in projects/mips: share/mk sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2009 23:03:45 -0000 Author: gonzo Date: Mon Jul 13 23:03:44 2009 New Revision: 195669 URL: http://svn.freebsd.org/changeset/base/195669 Log: - Remove -mno-dsp from CFLAGS. MIPS DSP ASE is off by default now (as it should be) Modified: projects/mips/share/mk/bsd.cpu.mk projects/mips/sys/conf/Makefile.mips projects/mips/sys/conf/kern.mk Modified: projects/mips/share/mk/bsd.cpu.mk ============================================================================== --- projects/mips/share/mk/bsd.cpu.mk Mon Jul 13 23:01:12 2009 (r195668) +++ projects/mips/share/mk/bsd.cpu.mk Mon Jul 13 23:03:44 2009 (r195669) @@ -210,7 +210,7 @@ CFLAGS += -EL LDFLAGS += -Wl,-EL LD += -EL . endif -CFLAGS += -msoft-float -G0 -mno-dsp -mabicalls +CFLAGS += -msoft-float -G0 -mabicalls .endif # NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk Modified: projects/mips/sys/conf/Makefile.mips ============================================================================== --- projects/mips/sys/conf/Makefile.mips Mon Jul 13 23:01:12 2009 (r195668) +++ projects/mips/sys/conf/Makefile.mips Mon Jul 13 23:03:44 2009 (r195669) @@ -44,7 +44,7 @@ MKMODULESENV+= MACHINE=${MACHINE} MACHIN # We default to the MIPS32 ISA, if none specified in the # kernel configuration file. ARCH_FLAGS?=-march=mips32 -EXTRA_FLAGS=-fno-pic -mno-abicalls -mno-dsp -G0 +EXTRA_FLAGS=-fno-pic -mno-abicalls -G0 HACK_EXTRA_FLAGS=-shared .if defined(TARGET_BIG_ENDIAN) Modified: projects/mips/sys/conf/kern.mk ============================================================================== --- projects/mips/sys/conf/kern.mk Mon Jul 13 23:01:12 2009 (r195668) +++ projects/mips/sys/conf/kern.mk Mon Jul 13 23:03:44 2009 (r195669) @@ -90,7 +90,7 @@ INLINE_LIMIT?= 15000 # disable MIPS DSP ASE Instruction set. # .if ${MACHINE_ARCH} == "mips" -CFLAGS+= -msoft-float -mno-dsp +CFLAGS+= -msoft-float INLINE_LIMIT?= 8000 .endif From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 01:56:19 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0037F1065670; Tue, 14 Jul 2009 01:56:18 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DEAAD8FC0C; Tue, 14 Jul 2009 01:56:18 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6E1uIfe041606; Tue, 14 Jul 2009 01:56:18 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6E1uIWQ041594; Tue, 14 Jul 2009 01:56:18 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200907140156.n6E1uIWQ041594@svn.freebsd.org> From: Nathan Whitehorn Date: Tue, 14 Jul 2009 01:56:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195670 - in projects/ppc64: . contrib/gcc/config/rs6000 gnu/usr.bin/binutils gnu/usr.bin/binutils/as gnu/usr.bin/binutils/as/ppc64-freebsd gnu/usr.bin/binutils/gdb gnu/usr.bin/binutils... X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 01:56:19 -0000 Author: nwhitehorn Date: Tue Jul 14 01:56:18 2009 New Revision: 195670 URL: http://svn.freebsd.org/changeset/base/195670 Log: Get the toolchain able to build 64-bit PowerPC FreeBSD binaries. Obtained from: \\depot\projects\ppc-g5 Added: projects/ppc64/gnu/usr.bin/binutils/as/ppc64-freebsd/ - copied from r195651, projects/ppc64/gnu/usr.bin/binutils/as/powerpc-freebsd/ projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.ppc64 - copied, changed from r195651, projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.powerpc projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.ppc64 - copied, changed from r195651, projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.powerpc projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile.ppc64 projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.ppc64 - copied unchanged from r195651, projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.powerpc Modified: projects/ppc64/Makefile.inc1 projects/ppc64/contrib/gcc/config/rs6000/freebsd.h projects/ppc64/gnu/usr.bin/binutils/Makefile.inc0 projects/ppc64/gnu/usr.bin/binutils/as/Makefile projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile projects/ppc64/gnu/usr.bin/cc/Makefile.tgt projects/ppc64/gnu/usr.bin/cc/cc_tools/Makefile projects/ppc64/gnu/usr.bin/cc/include/Makefile projects/ppc64/share/mk/bsd.endian.mk Modified: projects/ppc64/Makefile.inc1 ============================================================================== --- projects/ppc64/Makefile.inc1 Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/Makefile.inc1 Tue Jul 14 01:56:18 2009 (r195670) @@ -128,7 +128,7 @@ TARGET= ${TARGET_ARCH} TARGET?= ${MACHINE} TARGET_ARCH?= ${MACHINE_ARCH} -KNOWN_ARCHES?= amd64 arm i386 i386/pc98 ia64 mips powerpc sparc64 sparc64/sun4v +KNOWN_ARCHES?= amd64 arm i386 i386/pc98 ia64 mips powerpc ppc64 sparc64 sparc64/sun4v .if ${TARGET} == ${TARGET_ARCH} _t= ${TARGET} .else Modified: projects/ppc64/contrib/gcc/config/rs6000/freebsd.h ============================================================================== --- projects/ppc64/contrib/gcc/config/rs6000/freebsd.h Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/contrib/gcc/config/rs6000/freebsd.h Tue Jul 14 01:56:18 2009 (r195670) @@ -21,13 +21,86 @@ /* Override the defaults, which exist to force the proper definition. */ -#undef CPP_OS_DEFAULT_SPEC -#define CPP_OS_DEFAULT_SPEC "%(cpp_os_freebsd)" +#ifdef IN_LIBGCC2 +#undef TARGET_64BIT +#ifdef __ppc64__ +#define TARGET_64BIT 1 +#else +#define TARGET_64BIT 0 +#endif +#endif + +/* On 64-bit systems, use the AIX ABI like Linux and NetBSD */ + +#undef DEFAULT_ABI +#define DEFAULT_ABI (TARGET_64BIT ? ABI_AIX : ABI_V4) +#undef TARGET_AIX +#define TARGET_AIX TARGET_64BIT + +#undef FBSD_TARGET_CPU_CPP_BUILTINS +#define FBSD_TARGET_CPU_CPP_BUILTINS() \ + do \ + { \ + builtin_define ("__PPC__"); \ + builtin_define ("__ppc__"); \ + builtin_define ("__PowerPC__"); \ + builtin_define ("__powerpc__"); \ + if (TARGET_64BIT) \ + { \ + builtin_define ("__LP64__"); \ + builtin_define ("__ppc64__"); \ + builtin_define ("__powerpc64__"); \ + builtin_define ("__arch64__"); \ + builtin_assert ("cpu=powerpc64"); \ + builtin_assert ("machine=powerpc64"); \ + } else { \ + builtin_assert ("cpu=powerpc"); \ + builtin_assert ("machine=powerpc"); \ + } \ + } \ + while (0) + +#define INVALID_64BIT "-m%s not supported in this configuration" +#define INVALID_32BIT INVALID_64BIT + +#undef SUBSUBTARGET_OVERRIDE_OPTIONS +#define SUBSUBTARGET_OVERRIDE_OPTIONS \ + do \ + { \ + if (!rs6000_explicit_options.alignment) \ + rs6000_alignment_flags = MASK_ALIGN_NATURAL; \ + if (TARGET_64BIT) \ + { \ + if (DEFAULT_ABI != ABI_AIX) \ + { \ + rs6000_current_abi = ABI_AIX; \ + error (INVALID_64BIT, "call"); \ + } \ + dot_symbols = !strcmp (rs6000_abi_name, "aixdesc"); \ + if (target_flags & MASK_RELOCATABLE) \ + { \ + target_flags &= ~MASK_RELOCATABLE; \ + error (INVALID_64BIT, "relocatable"); \ + } \ + if (target_flags & MASK_EABI) \ + { \ + target_flags &= ~MASK_EABI; \ + error (INVALID_64BIT, "eabi"); \ + } \ + if (target_flags & MASK_PROTOTYPE) \ + { \ + target_flags &= ~MASK_PROTOTYPE; \ + error (INVALID_64BIT, "prototype"); \ + } \ + if ((target_flags & MASK_POWERPC64) == 0) \ + { \ + target_flags |= MASK_POWERPC64; \ + error ("64 bit CPU required"); \ + } \ + } \ + } \ + while (0) -#undef CPP_OS_FREEBSD_SPEC -#define CPP_OS_FREEBSD_SPEC "\ - -D__PPC__ -D__ppc__ -D__PowerPC__ -D__powerpc__ \ - -Acpu=powerpc -Amachine=powerpc " #undef STARTFILE_DEFAULT_SPEC #define STARTFILE_DEFAULT_SPEC "%(startfile_freebsd)" @@ -57,7 +130,10 @@ c-common.c, and config//.h. */ #undef SIZE_TYPE -#define SIZE_TYPE "unsigned int" +#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") /* rs6000.h gets this wrong for FreeBSD. We use the GCC defaults instead. */ #undef WCHAR_TYPE Modified: projects/ppc64/gnu/usr.bin/binutils/Makefile.inc0 ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/Makefile.inc0 Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/binutils/Makefile.inc0 Tue Jul 14 01:56:18 2009 (r195670) @@ -9,6 +9,8 @@ VERSION= "2.15 [FreeBSD] 2004-05-23" TARGET_ARCH?= ${MACHINE_ARCH} .if ${TARGET_ARCH} == "amd64" BINUTILS_ARCH=x86_64 +.elif ${TARGET_ARCH} == "ppc64" +BINUTILS_ARCH=powerpc64 .else BINUTILS_ARCH=${TARGET_ARCH} .endif Modified: projects/ppc64/gnu/usr.bin/binutils/as/Makefile ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/as/Makefile Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/binutils/as/Makefile Tue Jul 14 01:56:18 2009 (r195670) @@ -26,7 +26,7 @@ SRCS+= itbl-ops.c itbl-parse.y itbl-lex. .if ${TARGET_ARCH} == "amd64" SRCS+= tc-i386.c -.elif ${TARGET_ARCH} == "powerpc" +.elif ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "ppc64" SRCS+= tc-ppc.c .elif ${TARGET_ARCH} == "sparc64" # change back to tc-sparc.c when new binutils is imported Modified: projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile Tue Jul 14 01:56:18 2009 (r195670) @@ -12,6 +12,8 @@ GDBDIR= ${.CURDIR}/../../../../contrib/g GDB_CPU= sparc .elif ${TARGET_ARCH} == "amd64" GDB_CPU= i386 +.elif ${TARGET_ARCH} == "ppc64" +GDB_CPU= powerpc .else GDB_CPU= ${TARGET_ARCH} .endif Copied and modified: projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.ppc64 (from r195651, projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.powerpc) ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.powerpc Mon Jul 13 01:37:48 2009 (r195651, copy source) +++ projects/ppc64/gnu/usr.bin/binutils/gdb/Makefile.ppc64 Tue Jul 14 01:56:18 2009 (r195670) @@ -2,4 +2,4 @@ XSRCS+= ppcnbsd-nat.c ppc-tdep.c \ core-regset.c -CFLAGS+= -DDEFAULT_BFD_VEC=bfd_elf32_powerpc_vec +CFLAGS+= -DDEFAULT_BFD_VEC=bfd_elf64_powerpc_vec Copied and modified: projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.ppc64 (from r195651, projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.powerpc) ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.powerpc Mon Jul 13 01:37:48 2009 (r195651, copy source) +++ projects/ppc64/gnu/usr.bin/binutils/ld/Makefile.ppc64 Tue Jul 14 01:56:18 2009 (r195670) @@ -1,6 +1,6 @@ # $FreeBSD$ -NATIVE_EMULATION= elf32ppc +NATIVE_EMULATION= elf64ppc SRCS+= e${NATIVE_EMULATION}.c CLEANFILES+= e${NATIVE_EMULATION}.c Modified: projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile ============================================================================== --- projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile Tue Jul 14 01:56:18 2009 (r195670) @@ -25,6 +25,8 @@ SELARCH= SELARCH= &bfd_i386_arch .elif ${TARGET_ARCH} == "sparc64" SELARCH= &bfd_sparc_arch +.elif ${TARGET_ARCH} == "ppc64" +SELARCH= &bfd_powerpc_arch .else .for _a in ${ARCHS} .if ${SELARCH} == "" Added: projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile.ppc64 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/ppc64/gnu/usr.bin/binutils/libbfd/Makefile.ppc64 Tue Jul 14 01:56:18 2009 (r195670) @@ -0,0 +1,25 @@ +# $FreeBSD: src/gnu/usr.bin/binutils/libbfd/Makefile.powerpc,v 1.9 2006/08/24 02:36:21 marcel Exp $ + +ARCHS+= rs6000 + +DEFAULT_VECTOR= bfd_elf64_powerpc_vec + +SRCS+= cpu-powerpc.c \ + cpu-rs6000.c \ + elf32.c \ + elf32-gen.c \ + elf32-ppc.c \ + elf32-target.h \ + elflink.c \ + elf64.c \ + elf64-gen.c \ + elf64-ppc.c \ + elf64-target.h \ + elflink.c \ + ppcboot.c \ + xcofflink.c + +VECS+= ${DEFAULT_VECTOR} \ + bfd_elf64_powerpcle_vec \ + bfd_elf32_powerpc_vec \ + bfd_elf32_powerpcle_vec Copied: projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.ppc64 (from r195651, projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.powerpc) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.ppc64 Tue Jul 14 01:56:18 2009 (r195670, copy of r195651, projects/ppc64/gnu/usr.bin/binutils/libopcodes/Makefile.powerpc) @@ -0,0 +1,4 @@ +# $FreeBSD$ + +SRCS+= ppc-dis.c ppc-opc.c +CFLAGS+= -DARCH_powerpc -DARCH_rs6000 Modified: projects/ppc64/gnu/usr.bin/cc/Makefile.tgt ============================================================================== --- projects/ppc64/gnu/usr.bin/cc/Makefile.tgt Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/cc/Makefile.tgt Tue Jul 14 01:56:18 2009 (r195670) @@ -4,7 +4,7 @@ TARGET_ARCH?= ${MACHINE_ARCH} .if ${TARGET_ARCH} == "amd64" GCC_CPU= i386 -.elif ${TARGET_ARCH} == "powerpc" +.elif ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "ppc64" GCC_CPU= rs6000 .elif ${TARGET_ARCH} == "sparc64" GCC_CPU= sparc @@ -21,3 +21,7 @@ TARGET_CPU_DEFAULT= 16 .if ${TARGET_ARCH} == "sparc64" TARGET_CPU_DEFAULT= TARGET_CPU_ultrasparc .endif +.if ${TARGET_ARCH} == "ppc64" +TARGET_CPU_DEFAULT= \"powerpc64\" +.endif + Modified: projects/ppc64/gnu/usr.bin/cc/cc_tools/Makefile ============================================================================== --- projects/ppc64/gnu/usr.bin/cc/cc_tools/Makefile Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/cc/cc_tools/Makefile Tue Jul 14 01:56:18 2009 (r195670) @@ -56,6 +56,9 @@ TARGET_INC+= ${GCC_CPU}/freebsd.h .if ${TARGET_ARCH} == "amd64" TARGET_INC+= ${GCC_CPU}/freebsd64.h .endif +.if ${TARGET_ARCH} == "ppc64" +TARGET_INC+= ${GCC_CPU}/default64.h +.endif .if ${TARGET_ARCH} == "arm" TARGET_INC+= ${GCC_CPU}/arm.h .endif @@ -171,7 +174,7 @@ OPT_FILES+= ${GCCDIR}/config/${GCC_CPU}/ OPT_FILES+= ${.CURDIR}/${GCC_CPU}-freebsd.opt .endif -.if ${TARGET_ARCH} == "powerpc" +.if ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "ppc64" OPT_FILES+= ${GCCDIR}/config/${GCC_CPU}/sysv4.opt .endif Modified: projects/ppc64/gnu/usr.bin/cc/include/Makefile ============================================================================== --- projects/ppc64/gnu/usr.bin/cc/include/Makefile Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/gnu/usr.bin/cc/include/Makefile Tue Jul 14 01:56:18 2009 (r195670) @@ -10,7 +10,7 @@ INCS= emmintrin.h mmintrin.h pmmintrin.h INCS= ia64intrin.h .elif ${TARGET_ARCH} == "arm" INCS= mmintrin.h -.elif ${TARGET_ARCH} == "powerpc" +.elif ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "ppc64" INCS= ppc-asm.h altivec.h spe.h .endif Modified: projects/ppc64/share/mk/bsd.endian.mk ============================================================================== --- projects/ppc64/share/mk/bsd.endian.mk Mon Jul 13 23:03:44 2009 (r195669) +++ projects/ppc64/share/mk/bsd.endian.mk Tue Jul 14 01:56:18 2009 (r195670) @@ -7,6 +7,7 @@ (${MACHINE_ARCH} == "mips" && !defined(TARGET_BIG_ENDIAN)) TARGET_ENDIANNESS= 1234 .elif ${MACHINE_ARCH} == "powerpc" || \ + ${MACHINE_ARCH} == "ppc64" || \ ${MACHINE_ARCH} == "sparc64" || \ ${MACHINE_ARCH} == "arm" || \ ${MACHINE_ARCH} == "mips" From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 02:19:10 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 463D91065672; Tue, 14 Jul 2009 02:19:10 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 33D0D8FC16; Tue, 14 Jul 2009 02:19:10 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6E2J9T5042059; Tue, 14 Jul 2009 02:19:09 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6E2J9Jh042057; Tue, 14 Jul 2009 02:19:09 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200907140219.n6E2J9Jh042057@svn.freebsd.org> From: Nathan Whitehorn Date: Tue, 14 Jul 2009 02:19:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195671 - projects/ppc64/sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 02:19:10 -0000 Author: nwhitehorn Date: Tue Jul 14 02:19:09 2009 New Revision: 195671 URL: http://svn.freebsd.org/changeset/base/195671 Log: Set INLINE_LIMIT for ppc64. Now, with some symlink hackery, a kernel build for TARGET_ARCH=ppc64 will actually start. Of course, it will not complete... Modified: projects/ppc64/sys/conf/kern.mk Modified: projects/ppc64/sys/conf/kern.mk ============================================================================== --- projects/ppc64/sys/conf/kern.mk Tue Jul 14 01:56:18 2009 (r195670) +++ projects/ppc64/sys/conf/kern.mk Tue Jul 14 02:19:09 2009 (r195671) @@ -80,7 +80,7 @@ INLINE_LIMIT?= 8000 # floating point registers for integer operations which it has a tendency to do. # Also explicitly disable Altivec instructions inside the kernel. # -.if ${MACHINE_ARCH} == "powerpc" +.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "ppc64" CFLAGS+= -msoft-float -mno-altivec INLINE_LIMIT?= 15000 .endif From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 02:50:29 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5ADDB106564A; Tue, 14 Jul 2009 02:50:29 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4980D8FC15; Tue, 14 Jul 2009 02:50:29 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6E2oTaH042722; Tue, 14 Jul 2009 02:50:29 GMT (envelope-from jb@svn.freebsd.org) Received: (from jb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6E2oT6B042718; Tue, 14 Jul 2009 02:50:29 GMT (envelope-from jb@svn.freebsd.org) Message-Id: <200907140250.n6E2oT6B042718@svn.freebsd.org> From: John Birrell Date: Tue, 14 Jul 2009 02:50:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195672 - in projects/jbuild/usr.bin: jbuild/port jdirdep X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 02:50:29 -0000 Author: jb Date: Tue Jul 14 02:50:29 2009 New Revision: 195672 URL: http://svn.freebsd.org/changeset/base/195672 Log: - Don't ignore dependencies when bsd.dirdep.mk is included. - Declare the shell to jcommit. - Bump the port number. Modified: projects/jbuild/usr.bin/jbuild/port/Makefile projects/jbuild/usr.bin/jdirdep/jcommit projects/jbuild/usr.bin/jdirdep/jdirdep.c Modified: projects/jbuild/usr.bin/jbuild/port/Makefile ============================================================================== --- projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 02:19:09 2009 (r195671) +++ projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 02:50:29 2009 (r195672) @@ -5,7 +5,7 @@ PORTNAME= jbuild PORTDIRNAME= ${PORTNAME} -PORTVERSION= 12 +PORTVERSION= 13 CATEGORIES= devel MAINTAINER= rodrigc@FreeBSD.org Modified: projects/jbuild/usr.bin/jdirdep/jcommit ============================================================================== --- projects/jbuild/usr.bin/jdirdep/jcommit Tue Jul 14 02:19:09 2009 (r195671) +++ projects/jbuild/usr.bin/jdirdep/jcommit Tue Jul 14 02:50:29 2009 (r195672) @@ -1,3 +1,4 @@ +#!/bin/sh # # $FreeBSD$ # Modified: projects/jbuild/usr.bin/jdirdep/jdirdep.c ============================================================================== --- projects/jbuild/usr.bin/jdirdep/jdirdep.c Tue Jul 14 02:19:09 2009 (r195671) +++ projects/jbuild/usr.bin/jdirdep/jdirdep.c Tue Jul 14 02:50:29 2009 (r195672) @@ -708,12 +708,6 @@ do_dirdep(const char *srctop, const char /* Whack the trailing newline. */ bufr[strlen(bufr) - 1] = '\0'; - if (bufr[0] != '#' && strstr(bufr, "") != NULL) { - f_dirdep = 0; - f_rewrite = 0; - break; - } - if (bufr[0] != '#' && strstr(bufr, "") != NULL) { f_dirdep = 0; f_rewrite = 0; From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 03:22:07 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4C3FD106564A; Tue, 14 Jul 2009 03:22:07 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 203658FC14; Tue, 14 Jul 2009 03:22:07 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6E3M78H043632; Tue, 14 Jul 2009 03:22:07 GMT (envelope-from jb@svn.freebsd.org) Received: (from jb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6E3M6r6043626; Tue, 14 Jul 2009 03:22:06 GMT (envelope-from jb@svn.freebsd.org) Message-Id: <200907140322.n6E3M6r6043626@svn.freebsd.org> From: John Birrell Date: Tue, 14 Jul 2009 03:22:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195673 - in projects/jbuild/usr.bin: jbuild jbuild/port make X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 03:22:07 -0000 Author: jb Date: Tue Jul 14 03:22:06 2009 New Revision: 195673 URL: http://svn.freebsd.org/changeset/base/195673 Log: Add a JBUILD_VERSION variable to jbuild Added: projects/jbuild/usr.bin/jbuild/jbuild_version Modified: projects/jbuild/usr.bin/jbuild/Buildfile projects/jbuild/usr.bin/jbuild/Makefile projects/jbuild/usr.bin/jbuild/port/Makefile projects/jbuild/usr.bin/make/main.c Modified: projects/jbuild/usr.bin/jbuild/Buildfile ============================================================================== --- projects/jbuild/usr.bin/jbuild/Buildfile Tue Jul 14 02:50:29 2009 (r195672) +++ projects/jbuild/usr.bin/jbuild/Buildfile Tue Jul 14 03:22:06 2009 (r195673) @@ -40,5 +40,6 @@ CFLAGS += -I${.CURDIR}/filemon CFLAGS += -DMAKE_IS_BUILD -DJBUILD .include "${BSDSRCTOP}/usr.bin/jdirdep/Buildfile.common" +.include "${.CURDIR}/jbuild_version" .include Modified: projects/jbuild/usr.bin/jbuild/Makefile ============================================================================== --- projects/jbuild/usr.bin/jbuild/Makefile Tue Jul 14 02:50:29 2009 (r195672) +++ projects/jbuild/usr.bin/jbuild/Makefile Tue Jul 14 03:22:06 2009 (r195673) @@ -30,6 +30,7 @@ CFLAGS += -I${.CURDIR}/filemon .endif .include "${.CURDIR}/../jdirdep/Makefile.common" +.include "${.CURDIR}/jbuild_version" # Make object files which depend on preprocessor symbols defined in # the Makefile which are not compilation options but rather configuration Added: projects/jbuild/usr.bin/jbuild/jbuild_version ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/jbuild/usr.bin/jbuild/jbuild_version Tue Jul 14 03:22:06 2009 (r195673) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +JBUILD_VERSION = 14 + +CFLAGS += -DJBUILD_VERSION=\"${JBUILD_VERSION}\" Modified: projects/jbuild/usr.bin/jbuild/port/Makefile ============================================================================== --- projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 02:50:29 2009 (r195672) +++ projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 03:22:06 2009 (r195673) @@ -3,9 +3,11 @@ # $FreeBSD$ # +.include ${.CURDIR}/../jbuild_version + PORTNAME= jbuild -PORTDIRNAME= ${PORTNAME} -PORTVERSION= 13 +PORTDIRNAME= ${PORTNAME} +PORTVERSION= ${JBUILD_VERSION} CATEGORIES= devel MAINTAINER= rodrigc@FreeBSD.org Modified: projects/jbuild/usr.bin/make/main.c ============================================================================== --- projects/jbuild/usr.bin/make/main.c Tue Jul 14 02:50:29 2009 (r195672) +++ projects/jbuild/usr.bin/make/main.c Tue Jul 14 03:22:06 2009 (r195673) @@ -1126,6 +1126,9 @@ main(int argc, char **argv) #ifdef MAKE_VERSION Var_SetGlobal("MAKE_VERSION", MAKE_VERSION); #endif +#ifdef JBUILD_VERSION + Var_SetGlobal("JBUILD_VERSION", JBUILD_VERSION); +#endif Var_SetGlobal(".newline", "\n"); /* handy for :@ loops */ { char tmp[64]; From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 03:25:11 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44C41106564A; Tue, 14 Jul 2009 03:25:11 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 33A658FC08; Tue, 14 Jul 2009 03:25:11 +0000 (UTC) (envelope-from jb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6E3PBO6043727; Tue, 14 Jul 2009 03:25:11 GMT (envelope-from jb@svn.freebsd.org) Received: (from jb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6E3PBeE043725; Tue, 14 Jul 2009 03:25:11 GMT (envelope-from jb@svn.freebsd.org) Message-Id: <200907140325.n6E3PBeE043725@svn.freebsd.org> From: John Birrell Date: Tue, 14 Jul 2009 03:25:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195674 - projects/jbuild/usr.bin/jbuild/port X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 03:25:11 -0000 Author: jb Date: Tue Jul 14 03:25:10 2009 New Revision: 195674 URL: http://svn.freebsd.org/changeset/base/195674 Log: Fix the .include Modified: projects/jbuild/usr.bin/jbuild/port/Makefile Modified: projects/jbuild/usr.bin/jbuild/port/Makefile ============================================================================== --- projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 03:22:06 2009 (r195673) +++ projects/jbuild/usr.bin/jbuild/port/Makefile Tue Jul 14 03:25:10 2009 (r195674) @@ -3,7 +3,7 @@ # $FreeBSD$ # -.include ${.CURDIR}/../jbuild_version +.include "${.CURDIR}/../jbuild_version" PORTNAME= jbuild PORTDIRNAME= ${PORTNAME} From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 14:41:48 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 664AC106564A; Tue, 14 Jul 2009 14:41:48 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 53A468FC17; Tue, 14 Jul 2009 14:41:48 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6EEfmwr062591; Tue, 14 Jul 2009 14:41:48 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6EEfm7Z062588; Tue, 14 Jul 2009 14:41:48 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <200907141441.n6EEfm7Z062588@svn.freebsd.org> From: Lawrence Stewart Date: Tue, 14 Jul 2009 14:41:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195678 - projects/tcp_cc_8.x/sys/netinet X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 14:41:48 -0000 Author: lstewart Date: Tue Jul 14 14:41:48 2009 New Revision: 195678 URL: http://svn.freebsd.org/changeset/base/195678 Log: Cleanup CUBIC code to prepare for a standalone initial public release. Modified: projects/tcp_cc_8.x/sys/netinet/cc_cubic.c projects/tcp_cc_8.x/sys/netinet/cc_cubic.h Modified: projects/tcp_cc_8.x/sys/netinet/cc_cubic.c ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/cc_cubic.c Tue Jul 14 11:53:21 2009 (r195677) +++ projects/tcp_cc_8.x/sys/netinet/cc_cubic.c Tue Jul 14 14:41:48 2009 (r195678) @@ -61,7 +61,6 @@ __FBSDID("$FreeBSD$"); #include #include -/* function prototypes */ int cubic_mod_init(void); int cubic_cb_init(struct tcpcb *tp); void cubic_cb_destroy(struct tcpcb *tp); @@ -75,15 +74,15 @@ void cubic_conn_init(struct tcpcb *tp); void cubic_record_rtt(struct tcpcb *tp); struct cubic { - /* cwnd at the most recent congestion event */ + /* cwnd at the most recent congestion event. */ u_long max_cwnd; - /* cwnd at the previous congestion event */ + /* cwnd at the previous congestion event. */ u_long prev_max_cwnd; - /* time of last congestion event in ticks */ + /* Time of last congestion event in ticks. */ u_long t_last_cong; - /* minimum observed rtt in ticks */ + /* Minimum observed rtt in ticks. */ u_long min_rtt_ticks; - /* number of congestion events */ + /* Number of congestion events. */ u_long num_cong_events; }; @@ -91,7 +90,6 @@ MALLOC_DECLARE(M_CUBIC); MALLOC_DEFINE(M_CUBIC, "cubic data", "Per connection data required for the CUBIC congestion algorithm"); -/* function pointers for various hooks into the TCP stack */ struct cc_algo cubic_cc_algo = { .name = "cubic", .mod_init = cubic_mod_init, @@ -125,9 +123,7 @@ cubic_conn_init(struct tcpcb *tp) } /* - * Initialise CUBIC on the specified TCP control block. Creates a - * new struct for CUBIC specific data and sticks a pointer to it - * in the control block + * Initialise CUBIC on the specified TCP control block. */ int cubic_cb_init(struct tcpcb *tp) @@ -137,9 +133,9 @@ cubic_cb_init(struct tcpcb *tp) cubic_data = malloc(sizeof(struct cubic), M_CUBIC, M_NOWAIT); if (cubic_data == NULL) - return 1; + return (ENOMEM); - /* init some key cubic values with sensible defaults */ + /* Init some key variables with sensible defaults. */ cubic_data->t_last_cong = ticks; cubic_data->min_rtt_ticks = TCPTV_SRTTBASE; cubic_data->max_cwnd = 0; @@ -147,8 +143,8 @@ cubic_cb_init(struct tcpcb *tp) cubic_data->num_cong_events = 0; CC_DATA(tp) = cubic_data; - - return 0; + + return (0); } /* @@ -163,7 +159,7 @@ cubic_cb_destroy(struct tcpcb *tp) } /* - * Perform any necesary tasks before we enter fast recovery + * Perform any necesary tasks before we enter fast recovery. */ void cubic_pre_fr(struct tcpcb *tp, struct tcphdr *th) @@ -175,12 +171,10 @@ cubic_pre_fr(struct tcpcb *tp, struct tc cubic_ssthresh_update(tp); /* - * record the current cwnd at the point of congestion so it can be used - * as the basis for resetting cwnd after exiting fr + * Record the current cwnd at the point of congestion so it can be used + * as the basis for resetting cwnd after exiting FR. */ cubic_data->max_cwnd = tp->snd_cwnd; - - printf("congestion event started (max_cwnd: %ld)\n", cubic_data->max_cwnd); } /* @@ -191,15 +185,11 @@ cubic_post_fr(struct tcpcb *tp, struct t { struct cubic *cubic_data = CC_DATA(tp); - /* - * grab the current time and record it so we know when the most recent - * congestion event was - */ + /* Record the current time as the most recent congestion event. */ cubic_data->t_last_cong = ticks; - /* fast convergence heuristic */ + /* Fast convergence heuristic. */ if (cubic_data->max_cwnd < cubic_data->prev_max_cwnd) { - printf("fast convergence heuristic kicked in! (max_cwnd: %d\t prev_max_cwnd: %d\n", (int)cubic_data->max_cwnd, (int)cubic_data->prev_max_cwnd); cubic_data->prev_max_cwnd = cubic_data->max_cwnd; cubic_data->max_cwnd = (cubic_data->max_cwnd * CUBIC_FC_FACTOR) >> CUBIC_SHIFT; @@ -208,20 +198,16 @@ cubic_post_fr(struct tcpcb *tp, struct t cubic_data->prev_max_cwnd = cubic_data->max_cwnd; /* - * if inflight data is less than ssthresh, set cwnd conservatively + * If inflight data is less than ssthresh, set cwnd conservatively * to avoid a burst of data, as suggested in the NewReno RFC. * Otherwise, use the CUBIC method. */ if (th && SEQ_GT(th->th_ack + tp->snd_ssthresh, tp->snd_max)) tp->snd_cwnd = tp->snd_max - th->th_ack + tp->t_maxseg; - else { - /* update cwnd based on beta and adjusted max_cwnd */ + else + /* Update cwnd based on beta and adjusted max_cwnd. */ tp->snd_cwnd = max(1,((CUBIC_BETA * cubic_data->max_cwnd) >> CUBIC_SHIFT)); - printf("cubic_post_fr - cwnd: %ld\tmax_cwnd: %ld\n", tp->snd_cwnd, cubic_data->max_cwnd); - } - - printf("congestion event over\n"); } void @@ -230,12 +216,12 @@ cubic_record_rtt(struct tcpcb *tp) struct cubic *cubic_data = CC_DATA(tp); int t_srtt_ticks = tp->t_srtt / TCP_RTT_SCALE; - /* XXX: Should there be some hysteresis for minrtt? */ + /* XXXLS: Should there be some hysteresis for minrtt? */ /* - * record the current SRTT as our minrtt if it's the smallest we've + * Record the current SRTT as our minrtt if it's the smallest we've * seen or minrtt is currently equal to its initialised value. - * Ignore srtt until a min number of samples have been taken + * Ignore srtt until a min number of samples have been taken. */ if ((t_srtt_ticks < cubic_data->min_rtt_ticks || cubic_data->min_rtt_ticks == TCPTV_SRTTBASE) && @@ -251,8 +237,6 @@ cubic_ack_received(struct tcpcb *tp, str { struct cubic *cubic_data = CC_DATA(tp); u_long w_newreno, w_cubic_next, ticks_since_cong; - static u_long last_print_ticks = 0; - int print = 0; cubic_record_rtt(tp); @@ -261,73 +245,46 @@ cubic_ack_received(struct tcpcb *tp, str (cubic_data->min_rtt_ticks == TCPTV_SRTTBASE)) newreno_cc_algo.ack_received(tp, th); else { - /* num ticks since last congestion */ + /* Ticks since last congestion. */ ticks_since_cong = ticks - cubic_data->t_last_cong; - if ((ticks - last_print_ticks) >= (cubic_data->min_rtt_ticks / 2)) { - - print = 1; - last_print_ticks = ticks; - } - - if (print) - printf("rtt_ticks: %ld\tticks_since_cong: %ld\n", cubic_data->min_rtt_ticks, ticks_since_cong); - w_newreno = reno_cwnd( ticks_since_cong, cubic_data->min_rtt_ticks, cubic_data->max_cwnd, tp->t_maxseg ); - if (print) - printf("reno_cwnd(%ld,%ld,%ld,%d): %ld\n", ticks_since_cong, cubic_data->min_rtt_ticks, cubic_data->max_cwnd, tp->t_maxseg, w_newreno); - - //w_cubic = cubic_cwnd(ticks_since_cong, cubic_data->max_cwnd, tp->t_maxseg); - //printf("cubic_cwnd(%ld,%ld,%d): %ld (w_cubic)\n", ticks_since_cong, cubic_data->max_cwnd, tp->t_maxseg, w_cubic); - w_cubic_next = cubic_cwnd( ticks_since_cong + - cubic_data->min_rtt_ticks, + cubic_data->min_rtt_ticks, cubic_data->max_cwnd, tp->t_maxseg ); - - if (print) - printf("cubic_cwnd(%ld,%ld,%d): %ld (w_cubic_next)\n", ticks_since_cong + cubic_data->min_rtt_ticks, cubic_data->max_cwnd, tp->t_maxseg, w_cubic_next); - - if (print) - printf("pre\tmax_cwnd: %ld\tsnd_cwnd: %ld\tw_newreno: %ld\tw_cubic_next: %ld\n", cubic_data->max_cwnd, tp->snd_cwnd, w_newreno, w_cubic_next); - - if (w_cubic_next < w_newreno) { - /* we are in TCP-friendly region, follow reno cwnd growth */ + if (w_cubic_next < w_newreno) + /* TCP-friendly region, follow reno cwnd growth. */ tp->snd_cwnd = w_newreno; - } else if (tp->snd_cwnd < w_cubic_next) { - /* else we are in the concave or convex growth regions */ - if (print) - printf("incr: %lu\n", (w_cubic_next * tp->t_maxseg) / tp->snd_cwnd); - //tp->snd_cwnd += max(1, (w_cubic_next - w_cubic) / tp->snd_cwnd); - //printf("incr: %d\n", max(1, (w_cubic_next - tp->snd_cwnd) / tp->t_maxseg)); - /* XXX: Test under what conditions the following will truncate */ - tp->snd_cwnd += (u_long)(((uint64_t)(w_cubic_next * tp->t_maxseg)) / tp->snd_cwnd); - } + else if (tp->snd_cwnd < w_cubic_next) + /* Concave or convex region, follow CUBIC cwnd growth. + * XXXLS: Test under what conditions + * the following will truncate. + */ + tp->snd_cwnd += (u_long)(((uint64_t)(w_cubic_next + * tp->t_maxseg)) / tp->snd_cwnd); /* - * if we're not in slow start and we're probing for a new cwnd limit + * If we're not in slow start and we're probing for a new cwnd limit * at the start of a connection (happens when hostcache has a relevant entry), - * keep updating our current estimate of the max_cwnd + * keep updating our current estimate of the max_cwnd. */ - if (cubic_data->num_cong_events == 0 && - cubic_data->max_cwnd < tp->snd_cwnd) + if (cubic_data->num_cong_events == 0 + && cubic_data->max_cwnd < tp->snd_cwnd) cubic_data->max_cwnd = tp->snd_cwnd; - - if (print) - printf("post\tmax_cwnd: %ld\tsnd_cwnd: %ld\n\n", cubic_data->max_cwnd, tp->snd_cwnd); } } /* - * Reset the cwnd after a retransmission timeout + * Reset the cwnd after a retransmission timeout. */ void cubic_after_timeout(struct tcpcb *tp) @@ -337,7 +294,7 @@ cubic_after_timeout(struct tcpcb *tp) cubic_ssthresh_update(tp); /* - * grab the current time and record it so we know when the most recent + * Grab the current time and record it so we know when the most recent * congestion event was. Only record it when the timeout has fired more * than once, as there is a reasonable chance the first one is a false alarm * and may not indicate congestion. @@ -355,7 +312,7 @@ void cubic_ssthresh_update(struct tcpcb *tp) { /* - * on the first congestion event, set ssthresh to cwnd * 0.5, on + * On the first congestion event, set ssthresh to cwnd * 0.5, on * subsequent congestion events, set it to cwnd * beta. */ if (tp->snd_ssthresh == (TCP_MAXWIN << TCP_MAX_WINSHIFT)) Modified: projects/tcp_cc_8.x/sys/netinet/cc_cubic.h ============================================================================== --- projects/tcp_cc_8.x/sys/netinet/cc_cubic.h Tue Jul 14 11:53:21 2009 (r195677) +++ projects/tcp_cc_8.x/sys/netinet/cc_cubic.h Tue Jul 14 14:41:48 2009 (r195678) @@ -34,33 +34,30 @@ #ifndef _NETINET_CC_CUBIC_H_ #define _NETINET_CC_CUBIC_H_ -/* needed for rdtsc() (performance analysis) */ -#include - -/* Number of bits of precision for fixed point math calcs */ +/* Number of bits of precision for fixed point math calcs. */ #define CUBIC_SHIFT 8 #define CUBIC_SHIFT_4 32 -/* 0.5 with a shift << 8 */ +/* 0.5 with a shift << 8. */ #define RENO_BETA 128 -/* ~0.8 with a shift << 8 */ +/* ~0.8 with a shift << 8. */ #define CUBIC_BETA 204 -/* ~0.2 with a shift << 8 */ +/* ~0.2 with a shift << 8. */ #define ONE_MINUS_CUBIC_BETA 51 -/* ~0.4 with a shift << 8 */ +/* ~0.4 with a shift << 8. */ #define CUBIC_C_FACTOR 102 -/* CUBIC fast convergence factor ~0.9 with a shift << 8 */ +/* CUBIC fast convergence factor ~0.9 with a shift << 8. */ #define CUBIC_FC_FACTOR 230 -/* Don't trust s_rtt until this many rtt samples have been taken */ +/* Don't trust s_rtt until this many rtt samples have been taken. */ #define CUBIC_MIN_RTT_SAMPLES 8 -/* Userspace only bits */ +/* Userspace only bits. */ #ifndef _KERNEL extern int hz; @@ -89,38 +86,40 @@ theoretical_reno_cwnd( u_long ticks_sinc return (wmax * 0.5) + ((ticks_since_cong/(float)rtt_ticks) * smss); } -#endif /* _KERNEL*/ +#endif /* !_KERNEL */ /* - * calc K (adapted from Apple Computer Technical Report #KT-32) + * Compute the CUBIC K value used in the cwnd calculation, using an + * implementation of equation 2 in draft-rhee-tcpm-cubic-02. The method used + * here is adapted from Apple Computer Technical Report #KT-32. */ static __inline -long cubic_k(u_long wmax_pkts) +int64_t cubic_k(u_long wmax_pkts) { + register int64_t s = 0, K = 0; register uint16_t p = 0; - register long s = 0, K = 0; - /* (wmax * beta)/C with CUBIC_SHIFT worth of precision */ + /* (wmax * beta)/C with CUBIC_SHIFT worth of precision. */ s = ((wmax_pkts * ONE_MINUS_CUBIC_BETA) << CUBIC_SHIFT) / CUBIC_C_FACTOR; - //printf("s: %d\n", s); + /* printf("s: %lld\n", s); */ /* - * rebase s such that it is between 1 and 1/8 with - * a shift of CUBIC_SHIFT + * Rebase s such that it is between 1 and 1/8 with + * a shift of CUBIC_SHIFT. */ while (s >= 256) { - s >>= 3; /* divide by 8 */ + s >>= 3; p++; } - /* s is now between 1/8 and 1 (shifted by CUBIC_SHIFT) */ - - //printf("rebased s: %d\n", s); + /* s is now between 1/8 and 1 (shifted by CUBIC_SHIFT). */ + /* printf("rebased s: %lld\n", s); */ /* - * Some magic constants taken from the Apple TR with appropriate shifts + * Some magic constants taken from the Apple TR with + * appropriate shifts: * 275 == 1.072302 << CUBIC_SHIFT (8) * 98 == 0.3812513 << CUBIC_SHIFT (8) * 120 == 0.46946116 << CUBIC_SHIFT (8) @@ -129,56 +128,55 @@ long cubic_k(u_long wmax_pkts) (((s * s * 120) >> CUBIC_SHIFT) >> CUBIC_SHIFT); /* - * multiply by 2^p to undo the "divide by 8" transform from the - * previous while loop + * Multiply by 2^p to undo the "divide by 8" transform from the + * while loop. */ return (K <<= p); } /* - * Acknowledgments: Kip Macy + * Compute the new CUBIC cwnd value using an implementation of equation 1 in + * draft-rhee-tcpm-cubic-02. + * XXXLS: Characterise bounds for overflow. + * Debugging acknowledgments: Kip Macy */ static __inline u_long cubic_cwnd(u_long ticks_since_cong, u_long wmax, u_int smss) { - long K; - int64_t cwnd; - //int64_t start, end; - - //start = rdtsc(); + int64_t cwnd, K; + /* + * int64_t start, end; + * start = rdtsc(); + */ K = cubic_k(wmax / smss); - //printf("K: %d\n", K); + /* K is in fixed point form with CUBIC_SHIFT worth of precision */ - /* - * we now have K in fixed point form with - * CUBIC_SHIFT worth of precision - */ - - /* t - K, with CUBIC_SHIFT worth of precision */ + /* t - K, with CUBIC_SHIFT worth of precision. */ cwnd = ((int64_t)(ticks_since_cong << CUBIC_SHIFT) - (K * hz)) / hz; - //printf("t-k: %lld\n", cwnd); + /* printf("t-k: %lld\n", cwnd); */ - /* (t - K)^3, with CUBIC_SHIFT^3 worth of precision */ + /* (t - K)^3, with CUBIC_SHIFT^3 worth of precision. */ cwnd *= (cwnd * cwnd); - //printf("(t-k)^3: %lld\n", cwnd); + /* printf("(t-k)^3: %lld\n", cwnd); */ /* * C(t - K)^3 + wmax * The down shift by CUBIC_SHIFT_4 is because cwnd has 4 lots of * CUBIC_SHIFT included in the value. 3 from the cubing of cwnd above, - * and an extra from multiplying through by CUBIC_C_FACTOR + * and an extra from multiplying through by CUBIC_C_FACTOR. */ cwnd = ((cwnd * CUBIC_C_FACTOR * smss) >> CUBIC_SHIFT_4) + wmax; - //printf("final cwnd: %lld\n", cwnd); - - //end = rdtsc(); + /* printf("final cwnd: %lld\n", cwnd); */ - //printf("%lld TSC ticks\n", end - start); + /* + * end = rdtsc(); + * printf("%lld TSC ticks\n", end - start); + */ return ((u_long)cwnd); } @@ -191,7 +189,7 @@ u_long reno_cwnd(u_long ticks_since_cong * Simplified form of equation 4 from I-D * For reno, beta = 0.5, therefore W_tcp(t) = wmax*0.5 + t/RTT * Equation 4 deals with cwnd/wmax in pkts, so because our cwnd is - * in bytes, we have to multiply by smss + * in bytes, we have to multiply by smss. */ return (((wmax * RENO_BETA) + (((ticks_since_cong * smss) << CUBIC_SHIFT) / rtt_ticks)) >> CUBIC_SHIFT); From owner-svn-src-projects@FreeBSD.ORG Tue Jul 14 22:16:32 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86C221065694; Tue, 14 Jul 2009 22:16:32 +0000 (UTC) (envelope-from rodrigc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 746CB8FC22; Tue, 14 Jul 2009 22:16:32 +0000 (UTC) (envelope-from rodrigc@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6EMGW4E072776; Tue, 14 Jul 2009 22:16:32 GMT (envelope-from rodrigc@svn.freebsd.org) Received: (from rodrigc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6EMGWqt072774; Tue, 14 Jul 2009 22:16:32 GMT (envelope-from rodrigc@svn.freebsd.org) Message-Id: <200907142216.n6EMGWqt072774@svn.freebsd.org> From: Craig Rodrigues Date: Tue, 14 Jul 2009 22:16:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195698 - projects/jbuild/usr.bin/jdirdep X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 22:16:33 -0000 Author: rodrigc Date: Tue Jul 14 22:16:32 2009 New Revision: 195698 URL: http://svn.freebsd.org/changeset/base/195698 Log: Set executable. Change repo location. Modified: projects/jbuild/usr.bin/jdirdep/jgetsrc (contents, props changed) Modified: projects/jbuild/usr.bin/jdirdep/jgetsrc ============================================================================== --- projects/jbuild/usr.bin/jdirdep/jgetsrc Tue Jul 14 21:19:13 2009 (r195697) +++ projects/jbuild/usr.bin/jdirdep/jgetsrc Tue Jul 14 22:16:32 2009 (r195698) @@ -1,5 +1,8 @@ #!/bin/sh +# XX: work around ssh X11 forwarding errors +unset DISPLAY + dirs=$* ROOTDIR=`pwd` @@ -24,7 +27,7 @@ if [ ! -d shared -a ! -h shared ]; then fi #JSVN=svn://localhost/EPBG/u/jbirrell/build -JSVN=svn+ssh://localhost/c/cvs2svn/svn/repos/junos-2008/branches/jbuild +JSVN=svn+ssh://danai-29.juniper.net/c/cvs2svn/svn/repos/junos-2008/branches/jbuild rm -f $SVNLOG $MORELOG touch $SVNLOG $MORELOG From owner-svn-src-projects@FreeBSD.ORG Wed Jul 15 17:24:04 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B46C21065674; Wed, 15 Jul 2009 17:24:04 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 643798FC22; Wed, 15 Jul 2009 17:24:04 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6FHO4WC099302; Wed, 15 Jul 2009 17:24:04 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6FHO3Mc099294; Wed, 15 Jul 2009 17:24:03 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907151724.n6FHO3Mc099294@svn.freebsd.org> From: Stanislav Sedov Date: Wed, 15 Jul 2009 17:24:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195711 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2009 17:24:05 -0000 Author: stas Date: Wed Jul 15 17:24:03 2009 New Revision: 195711 URL: http://svn.freebsd.org/changeset/base/195711 Log: - A second (hopefully more successfull attempt) to get a clean separation of fstat code to data retrieval and representation parts. I added a number of independent structural parts (filestat, vnstat, pipestat, ptsstat) which is used to return information about appropiate file descriptors and is supposed to be independent of the access method that was used. Method-specific that can be used to obtain further information later is stored in opaque field of filestat structure. Modified: projects/libprocstat/usr.bin/fstat/Makefile projects/libprocstat/usr.bin/fstat/cd9660.c projects/libprocstat/usr.bin/fstat/common.c projects/libprocstat/usr.bin/fstat/common.h projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h projects/libprocstat/usr.bin/fstat/main.c projects/libprocstat/usr.bin/fstat/msdosfs.c projects/libprocstat/usr.bin/fstat/zfs.c Modified: projects/libprocstat/usr.bin/fstat/Makefile ============================================================================== --- projects/libprocstat/usr.bin/fstat/Makefile Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/Makefile Wed Jul 15 17:24:03 2009 (r195711) @@ -4,11 +4,11 @@ .include PROG= fstat -SRCS= cd9660.c common.c fstat.c main.c msdosfs.c fuser.c libprocstat.c +SRCS= common.c fstat.c main.c libprocstat.c cd9660.c msdosfs.c LINKS= ${BINDIR}/fstat ${BINDIR}/fuser DPADD= ${LIBKVM} LDADD= -lkvm -lutil -WARNS?= 6 +WARNS?= 3 MAN1= fuser.1 fstat.1 Modified: projects/libprocstat/usr.bin/fstat/cd9660.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/cd9660.c Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/cd9660.c Wed Jul 15 17:24:03 2009 (r195711) @@ -49,6 +49,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #define _KERNEL #include @@ -60,28 +62,26 @@ __FBSDID("$FreeBSD$"); #include "common.h" int -isofs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp) +isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct iso_node isonode; struct iso_mnt mnt; if (!kvm_read_all(kd, (unsigned long)VTOI(vp), &isonode, sizeof(isonode))) { - dprintf(stderr, "can't read iso_node at %p\n", + warnx("can't read iso_node at %p", (void *)VTOI(vp)); - return (0); + return (1); } if (!kvm_read_all(kd, (unsigned long)isonode.i_mnt, &mnt, sizeof(mnt))) { - dprintf(stderr, "can't read iso_mnt at %p\n", + warnx("can't read iso_mnt at %p", (void *)VTOI(vp)); - return (0); + return (1); } - fsp->fsid = dev2udev(kd, mnt.im_dev); - fsp->mode = (mode_t)isonode.inode.iso_mode; - fsp->rdev = isonode.inode.iso_rdev; - - fsp->fileid = (long)isonode.i_number; - fsp->size = (u_long)isonode.i_size; - return (1); + vn->vn_fsid = dev2udev(kd, mnt.im_dev); + vn->vn_mode = (mode_t)isonode.inode.iso_mode; + vn->vn_fileid = (long)isonode.i_number; + vn->vn_size = (u_long)isonode.i_size; + return (0); } Modified: projects/libprocstat/usr.bin/fstat/common.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.c Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/common.c Wed Jul 15 17:24:03 2009 (r195711) @@ -129,86 +129,66 @@ kdevtoname(kvm_t *kd, struct cdev *dev) } int -ufs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp) +ufs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct inode inode; if (!kvm_read_all(kd, (unsigned long)VTOI(vp), &inode, sizeof(inode))) { - dprintf(stderr, "can't read inode at %p\n", (void *)VTOI(vp)); - return 0; + warnx("can't read inode at %p", (void *)VTOI(vp)); + return (1); } /* * The st_dev from stat(2) is a dev_t. These kernel structures * contain cdev pointers. We need to convert to dev_t to make * comparisons */ - fsp->fsid = dev2udev(kd, inode.i_dev); - fsp->fileid = (long)inode.i_number; - fsp->mode = (mode_t)inode.i_mode; - fsp->size = (u_long)inode.i_size; -#if should_be_but_is_hard - /* XXX - need to load i_ump and i_din[12] from kernel memory */ - if (inode.i_ump->um_fstype == UFS1) - fsp->rdev = inode.i_din1->di_rdev; - else - fsp->rdev = inode.i_din2->di_rdev; -#else - fsp->rdev = 0; -#endif - - return 1; + vn->vn_fsid = dev2udev(kd, inode.i_dev); + vn->vn_fileid = (long)inode.i_number; + vn->vn_mode = (mode_t)inode.i_mode; + vn->vn_size = (u_long)inode.i_size; + return (0); } int -devfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp) +devfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct devfs_dirent devfs_dirent; struct mount mount; - struct vnode vnode; if (!kvm_read_all(kd, (unsigned long)vp->v_data, &devfs_dirent, sizeof(devfs_dirent))) { - dprintf(stderr, "can't read devfs_dirent at %p\n", + warnx("can't read devfs_dirent at %p", (void *)vp->v_data); - return 0; + return (1); } if (!kvm_read_all(kd, (unsigned long)vp->v_mount, &mount, sizeof(mount))) { - dprintf(stderr, "can't read mount at %p\n", + warnx("can't read mount at %p", (void *)vp->v_mount); - return 0; - } - if (!kvm_read_all(kd, (unsigned long)devfs_dirent.de_vnode, &vnode, - sizeof(vnode))) { - dprintf(stderr, "can't read vnode at %p\n", - (void *)devfs_dirent.de_vnode); - return 0; + return (1); } - fsp->fsid = (long)mount.mnt_stat.f_fsid.val[0]; - fsp->fileid = devfs_dirent.de_inode; - fsp->mode = (devfs_dirent.de_mode & ~S_IFMT) | S_IFCHR; - fsp->size = 0; - fsp->rdev = dev2udev(kd, vnode.v_rdev); - - return 1; + vn->vn_fsid = (long)mount.mnt_stat.f_fsid.val[0]; + vn->vn_fileid = devfs_dirent.de_inode; + vn->vn_mode = (devfs_dirent.de_mode & ~S_IFMT) | S_IFCHR; + vn->vn_size = 0; + return (0); } int -nfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp) +nfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) { struct nfsnode nfsnode; mode_t mode; if (!kvm_read_all(kd, (unsigned long)VTONFS(vp), &nfsnode, sizeof(nfsnode))) { - dprintf(stderr, "can't read nfsnode at %p\n", + warnx("can't read nfsnode at %p", (void *)VTONFS(vp)); - return 0; + return (1); } - fsp->fsid = nfsnode.n_vattr.va_fsid; - fsp->fileid = nfsnode.n_vattr.va_fileid; - fsp->size = nfsnode.n_size; - fsp->rdev = nfsnode.n_vattr.va_rdev; + vn->vn_fsid = nfsnode.n_vattr.va_fsid; + vn->vn_fileid = nfsnode.n_vattr.va_fileid; + vn->vn_size = nfsnode.n_size; mode = (mode_t)nfsnode.n_vattr.va_mode; switch (vp->v_type) { case VREG: @@ -232,14 +212,11 @@ nfs_filestat(kvm_t *kd, struct vnode *vp case VFIFO: mode |= S_IFIFO; break; - case VNON: - case VBAD: - case VMARKER: - return 0; + default: + break; }; - fsp->mode = mode; - - return 1; + vn->vn_mode = mode; + return (0); } /* Modified: projects/libprocstat/usr.bin/fstat/common.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.h Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/common.h Wed Jul 15 17:24:03 2009 (r195711) @@ -36,19 +36,70 @@ #ifndef __COMMON_H__ #define __COMMON_H__ +#if 0 struct filestat { - long fsid; - long fileid; - mode_t mode; - u_long size; - dev_t rdev; - int vtype; + union { + struct { + long fsid; + long fileid; + mode_t mode; + u_long size; + dev_t rdev; + dev_t dev; + int vtype; + char *mntdir; + } vnode; +// struct pipe pipe; + dev_t ttydev; + struct { + int type; + char *domain_name; + int dom_family; + int proto; + caddr_t so_pcb; + caddr_t tcpcb; + caddr_t conntcb; + caddr_t sockaddr; +// struct socket sock; + } socket; + }; int type; - char *mntdir; int flags; int fflags; int fd; }; +#endif + +struct filestat { + int fs_type; /* Descriptor type. */ + int fs_flags; /* filestat specific flags. */ + int fs_fflags; /* Descriptor access flags. */ + int fs_fd; /* File descriptor number. */ + void *fs_typedep; /* Type dependent data. */ + STAILQ_ENTRY(filestat) next; +}; + +struct vnstat { + dev_t vn_dev; + int vn_type; + long vn_fsid; + long vn_fileid; + mode_t vn_mode; + u_long vn_size; + char *mntdir; +}; + +struct ptsstat { + dev_t dev; +}; + +struct pipestat { + caddr_t addr; + caddr_t peer; + size_t buffer_cnt; +}; + +STAILQ_HEAD(filestat_list, filestat); extern int vflg; @@ -61,13 +112,13 @@ int kvm_read_all(kvm_t *kd, unsigned lon /* * Filesystems specific access routines. */ -int devfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); -int isofs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); -int msdosfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); -int nfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); -int ufs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); +int devfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); +int isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); +int msdosfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); +int nfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); +int ufs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); #ifdef ZFS -int zfs_filestat(kvm_t *kd, struct vnode *vp, struct filestat *fsp); +int zfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn); void *getvnodedata(struct vnode *vp); struct mount *getvnodemount(struct vnode *vp); #endif Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/fstat.c Wed Jul 15 17:24:03 2009 (r195711) @@ -147,6 +147,8 @@ static void print_pts_info(struct procstat *procstat, struct filestat *fst); static void print_vnode_info(struct procstat *procstat, struct filestat *fst); +static void +print_access_flags(int flags); int do_fstat(int argc, char **argv) @@ -268,22 +270,22 @@ fstat1(int what, int arg) static void dofiles(struct procstat *procstat, struct kinfo_proc *kp) { - struct filestat *fst; - unsigned int count; - const char *cmd, *uname; + struct filestat_list *head; + const char *cmd; + const char *uname; int pid; - unsigned int i; + struct filestat *fst; uname = user_from_uid(kp->ki_uid, 0); pid = kp->ki_pid; cmd = kp->ki_comm; - fst = procstat_getfiles(procstat, kp, &count); - if (fst == NULL) + head = procstat_getfiles(procstat, kp); + if (head == NULL) return; - for (i = 0; i < count; i++) - print_file_info(procstat, &fst[i], uname, cmd, pid); + STAILQ_FOREACH(fst, head, next) + print_file_info(procstat, fst, uname, cmd, pid); } @@ -291,45 +293,38 @@ static void print_file_info(struct procstat *procstat, struct filestat *fst, const char *uname, const char *cmd, int pid) { - const char *badtype, *filename; + const char *filename; + struct vnstat vn; + int error; + int fsmatch = 0; + DEVS *d; - badtype = NULL; filename = NULL; - if (fst->type == PS_FST_TYPE_VNODE || fst->type == PS_FST_TYPE_FIFO) { - if (fst->flags & PS_FST_FLAG_ERROR) - badtype = "error"; - else if (fst->flags == PS_FST_FLAG_UNKNOWNFS) - badtype = "unknown"; - else if (fst->vtype == PS_FST_VTYPE_VNON) - badtype = "none"; - else if (fst->vtype == PS_FST_VTYPE_VBAD) - badtype = "bad"; - - if (checkfile) { - int fsmatch = 0; - DEVS *d; - - if (badtype) - return; - for (d = devs; d != NULL; d = d->next) - if (d->fsid == fst->fsid) { - fsmatch = 1; - if (d->ino == fst->fileid) { - filename = d->name; - break; - } + if (checkfile != 0) { + if (fst->fs_type != PS_FST_TYPE_VNODE && + fst->fs_type == PS_FST_TYPE_FIFO) + return; + error = procstat_get_vnode_info(procstat, fst, &vn, NULL); + if (error != 0) + return; + + for (d = devs; d != NULL; d = d->next) + if (d->fsid == vn.vn_fsid) { + fsmatch = 1; + if (d->ino == vn.vn_fileid) { + filename = d->name; + break; } - if (fsmatch == 0 || (filename == NULL && fsflg == 0)) - return; - } - } else if (checkfile != 0) - return; + } + if (fsmatch == 0 || (filename == NULL && fsflg == 0)) + return; + } /* * Print entry prefix. */ printf("%-8.8s %-10s %5d", uname, cmd, pid); - switch(fst->fd) { + switch(fst->fs_fd) { case PS_FST_FD_TEXT: printf(" text"); break; @@ -349,18 +344,14 @@ print_file_info(struct procstat *procsta printf(" jail"); break; default: - printf(" %4d", fst->fd); + printf(" %4d", fst->fs_fd); break; } - if (badtype) { - (void)printf(" - - %10s -\n", badtype); - return; - } /* * Print type-specific data. */ - switch (fst->type) { + switch (fst->fs_type) { case PS_FST_TYPE_FIFO: case PS_FST_TYPE_VNODE: print_vnode_info(procstat, fst); @@ -377,7 +368,7 @@ print_file_info(struct procstat *procsta default: dprintf(stderr, "unknown file type %d for file %d of pid %d\n", - fst->type, fst->fd, pid); + fst->fs_type, fst->fs_fd, pid); } if (filename && !fsflg) printf(" %s", filename); @@ -392,60 +383,101 @@ print_socket_info(struct procstat *procs } static void -print_pipe_info(struct procstat *procstat __unused, struct filestat *fst __unused) +print_pipe_info(struct procstat *procstat, struct filestat *fst) { - - printf(" not implemented\n"); + struct pipestat pipe; + char errbuf[_POSIX2_LINE_MAX]; + int error; + + error = procstat_get_pipe_info(procstat, fst, &pipe, errbuf); + if (error != 0) { + printf("* error"); + return; + } + printf("* pipe %8lx <-> %8lx", (u_long)pipe.addr, (u_long)pipe.peer); + printf(" %6zd", pipe.buffer_cnt); + print_access_flags(fst->fs_fflags); } static void -print_pts_info(struct procstat *procstat __unused, struct filestat *fst __unused) +print_pts_info(struct procstat *procstat, struct filestat *fst) { - - printf(" not implemented\n"); + struct ptsstat pts; + char errbuf[_POSIX2_LINE_MAX]; + int error; + + error = procstat_get_pts_info(procstat, fst, &pts, errbuf); + if (error != 0) { + printf("* error"); + return; + } + printf("* pseudo-terminal master "); + if (nflg) { + printf("%10d,%-2d", major(pts.dev), minor(pts.dev)); + } /* else { + printf("%10s", pts.name); + } */ + print_access_flags(fst->fs_fflags); } static void -print_vnode_info(struct procstat *procstat __unused, struct filestat *fst) +print_vnode_info(struct procstat *procstat, struct filestat *fst) { + struct vnstat vn; + char *name; + const char *badtype; + char errbuf[_POSIX2_LINE_MAX]; char mode[15]; - char rw[3]; + int error; + + badtype = NULL; + error = procstat_get_vnode_info(procstat, fst, &vn, errbuf); + if (error != 0) + badtype = errbuf; + else if (vn.vn_type == PS_FST_VTYPE_VBAD) + badtype = "bad"; + else if (vn.vn_type == PS_FST_VTYPE_VNON) + badtype = "none"; + if (badtype != NULL) + printf(" - - %10s -", badtype); if (nflg) - (void)printf(" %2d,%-2d", major(fst->fsid), minor(fst->fsid)); - else if (fst->mntdir != NULL) - (void)printf(" %-8s", fst->mntdir); + printf(" %2d,%-2d", major(vn.vn_fsid), minor(vn.vn_fsid)); + else if (vn.mntdir != NULL) + (void)printf(" %-8s", vn.mntdir); + + /* + * Print access mode. + */ if (nflg) - (void)sprintf(mode, "%o", fst->mode); + (void)snprintf(mode, sizeof(mode), "%o", vn.vn_mode); else { - strmode(fst->mode, mode); + strmode(vn.vn_mode, mode); } - (void)printf(" %6ld %10s", fst->fileid, mode); - switch (fst->vtype) { - case PS_FST_VTYPE_VBLK: - case PS_FST_VTYPE_VCHR: { - char *name; - -#if 0 - name = procstat_devname(procstat, fst->rdev, - fst->vtype = PS_FST_VTYPE_VBLK ? S_IFBLK : S_IFCHR); -#else + (void)printf(" %6ld %10s", vn.vn_fileid, mode); + + if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) { name = NULL; -#endif +// name = fst->vnode.dev.name; if (nflg || !name) - printf(" %2d,%-2d", major(fst->rdev), minor(fst->rdev)); + printf(" %2d,%-2d", major(vn.vn_dev), minor(vn.vn_dev)); else { printf(" %6s", name); } - break; - } - default: - printf(" %6lu", fst->size); - } + } else + printf(" %6lu", vn.vn_size); + print_access_flags(fst->fs_fflags); +} + +static void +print_access_flags(int flags) +{ + char rw[3]; + rw[0] = '\0'; - if (fst->fflags & PS_FST_FFLAG_READ) + if (flags & PS_FST_FFLAG_READ) strcat(rw, "r"); - if (fst->fflags & PS_FST_FFLAG_WRITE) + if (flags & PS_FST_FFLAG_WRITE) strcat(rw, "w"); printf(" %2s", rw); } Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Wed Jul 15 17:07:39 2009 (r195710) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Wed Jul 15 17:24:03 2009 (r195711) @@ -79,6 +79,26 @@ static struct { #define NVFTYPES (sizeof(vt2fst) / sizeof(*vt2fst)) char *getmnton(kvm_t *kd, struct mount *m); +void +socktrans(kvm_t *kd, struct socket *sock, int fd, int flags, struct filestat *fst); +int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst, + struct vnstat *vn, char *errbuf); +int +procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, + char *errbuf); +int +procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, + char *errbuf); +int +procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, + struct pipestat *pipe, char *errbuf); +int +procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts, + char *errbuf); +int +procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, + struct ptsstat *pts, char *errbuf); + /* * Filesystem specific handlers. @@ -87,7 +107,7 @@ char *getmnton(kvm_t *kd, struct mount * struct { const char *tag; int (*handler)(kvm_t *kd, struct vnode *vp, - struct filestat *fsp); + struct vnstat *vn); } fstypes[] = { FSTYPE(ufs), FSTYPE(devfs), @@ -211,31 +231,50 @@ fail: return (NULL); } -struct filestat * -procstat_getfiles(struct procstat *procstat, struct kinfo_proc *kp, - unsigned int *cnt) +struct filestat_list * +procstat_getfiles(struct procstat *procstat, struct kinfo_proc *kp) { if (procstat->type == PROCSTAT_SYSCTL) - return (procstat_getfiles_sysctl(kp, cnt)); + return (procstat_getfiles_sysctl(kp)); else if (procstat->type == PROCSTAT_KVM) - return (procstat_getfiles_kvm(procstat->kd, kp, cnt)); + return (procstat_getfiles_kvm(procstat->kd, kp)); else return (NULL); } -struct filestat * -procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp, unsigned int *cnt) +static struct filestat * +filestat_new_entry(struct vnode *vp, int type, int fd, int fflags) +{ + struct filestat *entry; + + entry = calloc(1, sizeof(*entry)); + if (entry == NULL) { + warn("malloc()"); + return (NULL); + } + entry->fs_typedep = vp; + entry->fs_fflags = fflags; + entry->fs_fd = fd; + entry->fs_type = type; + return (entry); +} + +struct filestat_list * +procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp) { int i; struct file file; struct filedesc filed; - unsigned int nfiles, count, f; + unsigned int nfiles; struct file **ofiles; - struct filestat *fst; + struct filestat *entry; + struct filestat_list *head; + int type; + void *data; assert(kd); - assert(cnt); + if (kp->ki_fd == NULL) return (NULL); if (!kvm_read_all(kd, (unsigned long)kp->ki_fd, &filed, @@ -243,31 +282,50 @@ procstat_getfiles_kvm(kvm_t *kd, struct warnx("can't read filedesc at %p\n", (void *)kp->ki_fd); return (NULL); } - count = 5; /* Allocate additional space for special files. */ - if (filed.fd_lastfile >= 0) - count += filed.fd_lastfile + 1; - fst = malloc(count * sizeof(*fst)); - if (fst == NULL) { - warn("malloc(%zd)", count * sizeof(*fst)); + + /* + * Allocate list head. + */ + head = malloc(sizeof(*head)); + if (head == NULL) return (NULL); - } + STAILQ_INIT(head); /* root directory vnode, if one. */ - f = 0; - if (filed.fd_rdir) - vtrans_kvm(kd, filed.fd_rdir, PS_FST_FD_RDIR, PS_FST_FFLAG_READ, &fst[f++]); + if (filed.fd_rdir) { + entry = filestat_new_entry(filed.fd_rdir, PS_FST_TYPE_VNODE, PS_FST_FD_RDIR, + PS_FST_FFLAG_READ); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } /* current working directory vnode. */ - if (filed.fd_cdir) - vtrans_kvm(kd, filed.fd_cdir, PS_FST_FD_CDIR, PS_FST_FFLAG_READ, &fst[f++]); + if (filed.fd_cdir) { + entry = filestat_new_entry(filed.fd_cdir, PS_FST_TYPE_VNODE, PS_FST_FD_CDIR, + PS_FST_FFLAG_READ); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } /* jail root, if any. */ - if (filed.fd_jdir) - vtrans_kvm(kd, filed.fd_jdir, PS_FST_FD_JAIL, PS_FST_FFLAG_READ, &fst[f++]); + if (filed.fd_jdir) { + entry = filestat_new_entry(filed.fd_jdir, PS_FST_TYPE_VNODE, PS_FST_FD_JAIL, + PS_FST_FFLAG_READ); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } /* ktrace vnode, if one */ - if (kp->ki_tracep) - vtrans_kvm(kd, kp->ki_tracep, PS_FST_FD_TRACE, PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE, &fst[f++]); + if (kp->ki_tracep) { + entry = filestat_new_entry(kp->ki_tracep, PS_FST_TYPE_VNODE, PS_FST_FD_TRACE, + PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } /* text vnode, if one */ - if (kp->ki_textvp) - vtrans_kvm(kd, kp->ki_textvp, PS_FST_FD_TEXT, PS_FST_FFLAG_READ, &fst[f++]); + if (kp->ki_textvp) { + entry = filestat_new_entry(kp->ki_textvp, PS_FST_TYPE_VNODE, PS_FST_FD_TEXT, + PS_FST_FFLAG_READ); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } nfiles = filed.fd_lastfile + 1; ofiles = malloc(nfiles * sizeof(struct file *)); @@ -293,122 +351,45 @@ procstat_getfiles_kvm(kvm_t *kd, struct } switch (file.f_type) { case DTYPE_VNODE: - vtrans_kvm(kd, file.f_vnode, i, file.f_flag, &fst[f++]); + type = PS_FST_TYPE_VNODE; + data = file.f_vnode; break; -/* case DTYPE_SOCKET: - socktrans(file.f_data, i, &fst[f++]); + type = PS_FST_TYPE_SOCKET; + data = file.f_data; break; case DTYPE_PIPE: - pipetrans(file.f_data, i, file.f_flag, &fst[f++]); + type = PS_FST_TYPE_PIPE; + data = file.f_data; break; case DTYPE_FIFO: - vtrans(file.f_vnode, i, file.f_flag, &fst[f++]); + type = PS_FST_TYPE_FIFO; + data = file.f_vnode; break; +#ifdef DTYPE_PTS case DTYPE_PTS: - ptstrans(file.f_data, i, file.f_flag, &fst[f++]); + type = PS_FST_TYPE_PTS; + data = file.f_data; break; -*/ +#endif default: - dprintf(stderr, - "unknown file type %d for file %d\n", + warnx("unknown file type %d for file %d\n", file.f_type, i); + continue; } + entry = filestat_new_entry(data, type, i, + PS_FST_FFLAG_READ); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); } free(ofiles); exit: - *cnt = f; - return (fst); + return (head); } -struct filestat * -procstat_getfiles_sysctl(struct kinfo_proc *kp __unused, unsigned int *cnt __unused) +struct filestat_list * +procstat_getfiles_sysctl(struct kinfo_proc *kp __unused) { -#if 0 - int i; - struct file file; - struct filedesc filed; - unsigned int nfiles, count, f; - struct file **ofiles; - struct filestat *fst; - - assert(kp); - assert(cnt); - - /* - * XXX: special files (TEXTVP, KTRACEVP...) - */ - - /* - * Open files. - */ - freep = kinfo_getfile(kp->ki_pid, &count); - if (freep == NULL) { - warn("kinfo_getfile()"); - return (NULL); - } - if (count == 0) - return (NULL); - - fst = malloc(count * sizeof(*fst)); - if (fst == NULL) { - warn("malloc(%zd)", count * sizeof(*fst)); - return (NULL); - } - f = 0; - for (i = 0; i < count; i++) { - kif = &freep[i]; - switch (kif->kf_type) { - case KF_TYPE_VNODE: - if (kif->kf_fd == KF_FD_TYPE_CWD) { - fd_type = CDIR; - flags = FST_READ; - } else if (kif->kf_fd == KF_FD_TYPE_ROOT) { - fd_type = RDIR; - flags = FST_READ; - } else if (kif->kf_fd == KF_FD_TYPE_JAIL) { - fd_type = JDIR; - flags = FST_READ; - } else { - fd_type = i; - flags = kif->kf_flags; - } - /* Only do this if the attributes are valid. */ - if (kif->kf_status & KF_ATTR_VALID) - vtrans_sysctl(kif, fd_type, flags, &fst[f++]); - break; -#if 0 - case KF_TYPE_PIPE: - if (checkfile == 0) - pipetrans_sysctl(kif, i, kif->kf_flags, &fst[f++]); - break; - case KF_TYPE_SOCKET: - if (checkfile == 0) - socktrans_sysctl(file.f_data, i); - break; - case KF_TYPE_PIPE: - if (checkfile == 0) - pipetrans_sysctl(file.f_data, i, file.f_flag, &fst[f++]); - break; - case KF_TYPE_FIFO: - if (checkfile == 0) - vtrans_sysctl(file.f_vnode, i, file.f_flag, &fst[f++]); - break; - case KF_TYPE_PTS: - if (checkfile == 0) - ptstrans_sysctl(file.f_data, i, file.f_flag, &fst[f++]); - break; -#endif - default: - dprintf(stderr, - "unknown file type %d for file %d\n", - file.f_type, i); - } - } - free(freep); - *cnt = f; - return (fst); -#endif return (NULL); } @@ -427,34 +408,316 @@ vntype2psfsttype(int type) return (fst_type); } +char * +getmnton(kvm_t *kd, struct mount *m) +{ + static struct mount mnt; + static struct mtab { + struct mtab *next; + struct mount *m; + char mntonname[MNAMELEN + 1]; + } *mhead = NULL; + struct mtab *mt; + + for (mt = mhead; mt != NULL; mt = mt->next) + if (m == mt->m) + return (mt->mntonname); + if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) { + warnx("can't read mount table at %p", (void *)m); + return (NULL); + } + if ((mt = malloc(sizeof (struct mtab))) == NULL) + err(1, NULL); + mt->m = m; + bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); + mnt.mnt_stat.f_mntonname[MNAMELEN] = '\0'; + mt->next = mhead; + mhead = mt; + return (mt->mntonname); +} + +void +socktrans(kvm_t *kd __unused, struct socket *sock __unused, int fd __unused, int flags __unused, struct filestat *fst __unused) +{ + +#if 0 + static const char *stypename[] = { + "unused", /* 0 */ + "stream", /* 1 */ + "dgram", /* 2 */ + "raw", /* 3 */ + "rdm", /* 4 */ + "seqpak" /* 5 */ + }; +#define STYPEMAX 5 + struct socket so; + struct protosw proto; + struct domain dom; + struct inpcb inpcb; + struct unpcb unpcb; + int len; + char dname[32]; + + bzero(fst, sizeof(*fst)); + + /* fill in socket */ + if (!kvm_read_all(kd, (unsigned long)sock, &so, + sizeof(struct socket))) { + warnx("can't read sock at %p\n", (void *)sock); + goto bad; + } + /* fill in protosw entry */ + if (!kvm_read_all(kd, (unsigned long)so.so_proto, &proto, + sizeof(struct protosw))) { + dprintf(stderr, "can't read protosw at %p", + (void *)so.so_proto); + goto bad; + } + /* fill in domain */ + if (!kvm_read_all(kd, (unsigned long)proto.pr_domain, &dom, + sizeof(struct domain))) { + dprintf(stderr, "can't read domain at %p\n", + (void *)proto.pr_domain); + goto bad; + } + if ((len = kvm_read(kd, (unsigned long)dom.dom_name, dname, + sizeof(dname) - 1)) < 0) { + dprintf(stderr, "can't read domain name at %p\n", + (void *)dom.dom_name); + dname[0] = '\0'; + } + else + dname[len] = '\0'; + + fst->sock_type = so.so_type; + fst->sock_dname = strdup(dname) + fst->sock_protocol = proto.pr_protocol; + fst->sock = sock; + fst->fflags = flags; + + /* + * protocol specific formatting + * + * Try to find interesting things to print. For tcp, the interesting + * thing is the address of the tcpcb, for udp and others, just the + * inpcb (socket pcb). For unix domain, its the address of the socket + * pcb and the address of the connected pcb (if connected). Otherwise + * just print the protocol number and address of the socket itself. + * The idea is not to duplicate netstat, but to make available enough + * information for further analysis. + */ + switch(dom.dom_family) { + case AF_INET: + case AF_INET6: + getinetproto(proto.pr_protocol); + if (proto.pr_protocol == IPPROTO_TCP ) { + if (so.so_pcb) { + if (kvm_read(kd, (u_long)so.so_pcb, + (char *)&inpcb, sizeof(struct inpcb)) + != sizeof(struct inpcb)) { + dprintf(stderr, + "can't read inpcb at %p\n", + (void *)so.so_pcb); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Wed Jul 15 22:27:36 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 79795106566B; Wed, 15 Jul 2009 22:27:36 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 679AD8FC0C; Wed, 15 Jul 2009 22:27:36 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6FMRa2R005488; Wed, 15 Jul 2009 22:27:36 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6FMRa2j005485; Wed, 15 Jul 2009 22:27:36 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907152227.n6FMRa2j005485@svn.freebsd.org> From: Stanislav Sedov Date: Wed, 15 Jul 2009 22:27:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195713 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2009 22:27:36 -0000 Author: stas Date: Wed Jul 15 22:27:36 2009 New Revision: 195713 URL: http://svn.freebsd.org/changeset/base/195713 Log: - Fix file flags processing. Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Wed Jul 15 17:29:05 2009 (r195712) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Wed Jul 15 22:27:36 2009 (r195713) @@ -78,26 +78,41 @@ static struct { }; #define NVFTYPES (sizeof(vt2fst) / sizeof(*vt2fst)) -char *getmnton(kvm_t *kd, struct mount *m); -void -socktrans(kvm_t *kd, struct socket *sock, int fd, int flags, struct filestat *fst); +static struct { + int flag; + int fst_flag; +} fstflags[] = { + { FREAD, PS_FST_FFLAG_READ }, + { FWRITE, PS_FST_FFLAG_WRITE }, + { O_NONBLOCK, PS_FST_FFLAG_NONBLOCK }, + { O_APPEND, PS_FST_FFLAG_APPEND }, + { O_SHLOCK, PS_FST_FFLAG_SHLOCK }, + { O_EXLOCK, PS_FST_FFLAG_EXLOCK }, + { O_ASYNC, PS_FST_FFLAG_ASYNC }, + { O_SYNC, PS_FST_FFLAG_SYNC }, + { O_NOFOLLOW, PS_FST_FFLAG_NOFOLLOW }, + { O_CREAT, PS_FST_FFLAG_CREAT }, + { O_TRUNC, PS_FST_FFLAG_TRUNC }, + { O_EXCL, PS_FST_FFLAG_EXCL } +}; +#define NFSTFLAGS (sizeof(fstflags) / sizeof(*fstflags)) + +char *getmnton(kvm_t *kd, struct mount *m); +void socktrans(kvm_t *kd, struct socket *sock, int fd, int flags, + struct filestat *fst); int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst, struct vnstat *vn, char *errbuf); -int -procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, +int procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, char *errbuf); -int -procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, - char *errbuf); -int -procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, +int procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, char *errbuf); -int -procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts, +int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, + struct pipestat *pipe, char *errbuf); +int procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts, char *errbuf); -int -procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, +int procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, struct ptsstat *pts, char *errbuf); +static int to_filestat_flags(int flags); /* @@ -378,7 +393,7 @@ procstat_getfiles_kvm(kvm_t *kd, struct continue; } entry = filestat_new_entry(data, type, i, - PS_FST_FFLAG_READ); + to_filestat_flags(file.f_flag)); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -387,6 +402,19 @@ exit: return (head); } +static int +to_filestat_flags(int flags) +{ + int fst_flags; + unsigned int i; + + fst_flags = 0; + for (i = 0; i < NFSTFLAGS; i++) + if (flags & fstflags[i].flag) + fst_flags |= fstflags[i].fst_flag; + return (fst_flags); +} + struct filestat_list * procstat_getfiles_sysctl(struct kinfo_proc *kp __unused) { Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.h Wed Jul 15 17:29:05 2009 (r195712) +++ projects/libprocstat/usr.bin/fstat/libprocstat.h Wed Jul 15 22:27:36 2009 (r195713) @@ -27,8 +27,18 @@ struct procstat { #define PS_FST_FD_TEXT -5 #define PS_FST_FD_MMAP -6 -#define PS_FST_FFLAG_READ 0x01 -#define PS_FST_FFLAG_WRITE 0x02 +#define PS_FST_FFLAG_READ 0x0001 +#define PS_FST_FFLAG_WRITE 0x0002 +#define PS_FST_FFLAG_NONBLOCK 0x0004 +#define PS_FST_FFLAG_APPEND 0x0008 +#define PS_FST_FFLAG_SHLOCK 0x0010 +#define PS_FST_FFLAG_EXLOCK 0x0020 +#define PS_FST_FFLAG_ASYNC 0x0040 +#define PS_FST_FFLAG_SYNC 0x0080 +#define PS_FST_FFLAG_NOFOLLOW 0x0100 +#define PS_FST_FFLAG_CREAT 0x0200 +#define PS_FST_FFLAG_TRUNC 0x0400 +#define PS_FST_FFLAG_EXCL 0x0800 #define PS_FST_FLAG_ERROR 0x01 #define PS_FST_FLAG_UNKNOWNFS 0x02 From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 09:00:41 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8EE09106564A; Thu, 16 Jul 2009 09:00:41 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7C2968FC25; Thu, 16 Jul 2009 09:00:41 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6G90fT9017898; Thu, 16 Jul 2009 09:00:41 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6G90fti017893; Thu, 16 Jul 2009 09:00:41 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907160900.n6G90fti017893@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 09:00:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195715 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 09:00:41 -0000 Author: stas Date: Thu Jul 16 09:00:41 2009 New Revision: 195715 URL: http://svn.freebsd.org/changeset/base/195715 Log: - Add socket support. Modified: projects/libprocstat/usr.bin/fstat/common.h projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h Modified: projects/libprocstat/usr.bin/fstat/common.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.h Thu Jul 16 08:27:12 2009 (r195714) +++ projects/libprocstat/usr.bin/fstat/common.h Thu Jul 16 09:00:41 2009 (r195715) @@ -36,40 +36,6 @@ #ifndef __COMMON_H__ #define __COMMON_H__ -#if 0 -struct filestat { - union { - struct { - long fsid; - long fileid; - mode_t mode; - u_long size; - dev_t rdev; - dev_t dev; - int vtype; - char *mntdir; - } vnode; -// struct pipe pipe; - dev_t ttydev; - struct { - int type; - char *domain_name; - int dom_family; - int proto; - caddr_t so_pcb; - caddr_t tcpcb; - caddr_t conntcb; - caddr_t sockaddr; -// struct socket sock; - } socket; - }; - int type; - int flags; - int fflags; - int fd; -}; -#endif - struct filestat { int fs_type; /* Descriptor type. */ int fs_flags; /* filestat specific flags. */ @@ -99,6 +65,19 @@ struct pipestat { size_t buffer_cnt; }; +struct sockstat { + int type; + int proto; + int dom_family; + caddr_t so_addr; + caddr_t so_pcb; + caddr_t inp_ppcb; + caddr_t unp_conn; + int so_snd_sb_state; + int so_rcv_sb_state; + char dname[32]; +}; + STAILQ_HEAD(filestat_list, filestat); extern int vflg; Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 08:27:12 2009 (r195714) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 09:00:41 2009 (r195715) @@ -376,10 +376,83 @@ print_file_info(struct procstat *procsta } static void -print_socket_info(struct procstat *procstat __unused, struct filestat *fst __unused) +print_socket_info(struct procstat *procstat, struct filestat *fst) { + static const char *stypename[] = { + "unused", /* 0 */ + "stream", /* 1 */ + "dgram", /* 2 */ + "raw", /* 3 */ + "rdm", /* 4 */ + "seqpak" /* 5 */ + }; +#define STYPEMAX 5 + struct sockstat sock; + char errbuf[_POSIX2_LINE_MAX]; + static int isopen; + struct protoent *pe; + int error; + + error = procstat_get_socket_info(procstat, fst, &sock, errbuf); + if (error != 0) { + printf("* error"); + return; + } + if (sock.type > STYPEMAX) + printf("* %s ?%d", sock.dname, sock.type); + else + printf("* %s %s", sock.dname, stypename[sock.type]); - printf(" not implemented\n"); + /* + * protocol specific formatting + * + * Try to find interesting things to print. For tcp, the interesting + * thing is the address of the tcpcb, for udp and others, just the + * inpcb (socket pcb). For unix domain, its the address of the socket + * pcb and the address of the connected pcb (if connected). Otherwise + * just print the protocol number and address of the socket itself. + * The idea is not to duplicate netstat, but to make available enough + * information for further analysis. + */ + switch (sock.dom_family) { + case AF_INET: + case AF_INET6: + if (!isopen) + setprotoent(++isopen); + if ((pe = getprotobynumber(sock.proto)) != NULL) + printf(" %s", pe->p_name); + else + printf(" %d", sock.proto); + if (sock.proto == IPPROTO_TCP ) { + if (sock.inp_ppcb != 0) + printf(" %lx", (u_long)sock.inp_ppcb); + } + else if (sock.so_pcb != 0) + printf(" %lx", (u_long)sock.so_pcb); + break; + case AF_UNIX: + /* print address of pcb and connected pcb */ + if (sock.so_pcb != 0) { + printf(" %lx", (u_long)sock.so_pcb); + if (sock.unp_conn) { + char shoconn[4], *cp; + + cp = shoconn; + if (!(sock.so_rcv_sb_state & SBS_CANTRCVMORE)) + *cp++ = '<'; + *cp++ = '-'; + if (!(sock.so_snd_sb_state & SBS_CANTSENDMORE)) + *cp++ = '>'; + *cp = '\0'; + printf(" %s %lx", shoconn, + (u_long)sock.unp_conn); + } + } + break; + default: + /* print protocol number and socket address */ + printf(" %d %lx", sock.proto, (u_long)sock.so_addr); + } } static void Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 08:27:12 2009 (r195714) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 09:00:41 2009 (r195715) @@ -112,6 +112,10 @@ int procstat_get_pts_info_sysctl(struct char *errbuf); int procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, struct ptsstat *pts, char *errbuf); +int procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock, + char *errbuf); +int procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst, + struct sockstat *sock, char *errbuf); static int to_filestat_flags(int flags); @@ -464,132 +468,6 @@ getmnton(kvm_t *kd, struct mount *m) return (mt->mntonname); } -void -socktrans(kvm_t *kd __unused, struct socket *sock __unused, int fd __unused, int flags __unused, struct filestat *fst __unused) -{ - -#if 0 - static const char *stypename[] = { - "unused", /* 0 */ - "stream", /* 1 */ - "dgram", /* 2 */ - "raw", /* 3 */ - "rdm", /* 4 */ - "seqpak" /* 5 */ - }; -#define STYPEMAX 5 - struct socket so; - struct protosw proto; - struct domain dom; - struct inpcb inpcb; - struct unpcb unpcb; - int len; - char dname[32]; - - bzero(fst, sizeof(*fst)); - - /* fill in socket */ - if (!kvm_read_all(kd, (unsigned long)sock, &so, - sizeof(struct socket))) { - warnx("can't read sock at %p\n", (void *)sock); - goto bad; - } - /* fill in protosw entry */ - if (!kvm_read_all(kd, (unsigned long)so.so_proto, &proto, - sizeof(struct protosw))) { - dprintf(stderr, "can't read protosw at %p", - (void *)so.so_proto); - goto bad; - } - /* fill in domain */ - if (!kvm_read_all(kd, (unsigned long)proto.pr_domain, &dom, - sizeof(struct domain))) { - dprintf(stderr, "can't read domain at %p\n", - (void *)proto.pr_domain); - goto bad; - } - if ((len = kvm_read(kd, (unsigned long)dom.dom_name, dname, - sizeof(dname) - 1)) < 0) { - dprintf(stderr, "can't read domain name at %p\n", - (void *)dom.dom_name); - dname[0] = '\0'; - } - else - dname[len] = '\0'; - - fst->sock_type = so.so_type; - fst->sock_dname = strdup(dname) - fst->sock_protocol = proto.pr_protocol; - fst->sock = sock; - fst->fflags = flags; - - /* - * protocol specific formatting - * - * Try to find interesting things to print. For tcp, the interesting - * thing is the address of the tcpcb, for udp and others, just the - * inpcb (socket pcb). For unix domain, its the address of the socket - * pcb and the address of the connected pcb (if connected). Otherwise - * just print the protocol number and address of the socket itself. - * The idea is not to duplicate netstat, but to make available enough - * information for further analysis. - */ - switch(dom.dom_family) { - case AF_INET: - case AF_INET6: - getinetproto(proto.pr_protocol); - if (proto.pr_protocol == IPPROTO_TCP ) { - if (so.so_pcb) { - if (kvm_read(kd, (u_long)so.so_pcb, - (char *)&inpcb, sizeof(struct inpcb)) - != sizeof(struct inpcb)) { - dprintf(stderr, - "can't read inpcb at %p\n", - (void *)so.so_pcb); - goto bad; - } - printf(" %lx", (u_long)inpcb.inp_ppcb); - } - } - else if (so.so_pcb) - printf(" %lx", (u_long)so.so_pcb); - break; - case AF_UNIX: - /* print address of pcb and connected pcb */ - if (so.so_pcb) { - printf(" %lx", (u_long)so.so_pcb); - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, - sizeof(struct unpcb)) != sizeof(struct unpcb)){ - dprintf(stderr, "can't read unpcb at %p\n", - (void *)so.so_pcb); - goto bad; - } - if (unpcb.unp_conn) { - char shoconn[4], *cp; - - cp = shoconn; - if (!(so.so_rcv.sb_state & SBS_CANTRCVMORE)) - *cp++ = '<'; - *cp++ = '-'; - if (!(so.so_snd.sb_state & SBS_CANTSENDMORE)) - *cp++ = '>'; - *cp = '\0'; - printf(" %s %lx", shoconn, - (u_long)unpcb.unp_conn); - } - } - break; - default: - /* print protocol number and socket address */ - printf(" %d %lx", proto.pr_protocol, (u_long)sock); - } - printf("\n"); - return; -bad: - fst->flags |= PS_FST_FLAG_ERROR; -#endif -} - int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, struct pipestat *pipe, char *errbuf) @@ -781,3 +659,127 @@ procstat_get_vnode_info_sysctl(struct fi snprintf(errbuf, _POSIX2_LINE_MAX, "error"); return (1); } + +int +procstat_get_socket_info(struct procstat *procstat, struct filestat *fst, + struct sockstat *sock, char *errbuf) +{ + + assert(sock); + if (procstat->type == PROCSTAT_KVM) { + return (procstat_get_socket_info_kvm(procstat->kd, fst, sock, + errbuf)); + } else if (procstat->type == PROCSTAT_SYSCTL) { + return (procstat_get_socket_info_sysctl(fst, sock, errbuf)); + } else { + warnx("unknow access method: %d", procstat->type); + snprintf(errbuf, _POSIX2_LINE_MAX, "error"); + return (1); + } +} +int +procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst, + struct sockstat *sock, char *errbuf) +{ + struct socket s; + struct protosw proto; + struct domain dom; + struct inpcb inpcb; + struct unpcb unpcb; + ssize_t len; + void *so; + + assert(kd); + assert(sock); + assert(fst); + bzero(sock, sizeof(*sock)); + so = fst->fs_typedep; + if (so == NULL) + goto fail; + sock->so_addr = (caddr_t)so; + /* fill in socket */ + if (!kvm_read_all(kd, (unsigned long)so, &s, + sizeof(struct socket))) { + warnx("can't read sock at %p", (void *)so); + goto fail; + } + /* fill in protosw entry */ + if (!kvm_read_all(kd, (unsigned long)s.so_proto, &proto, + sizeof(struct protosw))) { + warnx("can't read protosw at %p", (void *)s.so_proto); + goto fail; + } + /* fill in domain */ + if (!kvm_read_all(kd, (unsigned long)proto.pr_domain, &dom, + sizeof(struct domain))) { + warnx("can't read domain at %p", + (void *)proto.pr_domain); + goto fail; + } + if ((len = kvm_read(kd, (unsigned long)dom.dom_name, sock->dname, + sizeof(sock->dname) - 1)) < 0) { + warnx("can't read domain name at %p", (void *)dom.dom_name); + sock->dname[0] = '\0'; + } + else + sock->dname[len] = '\0'; + + /* + * Fill in known data. + */ + sock->type = s.so_type; + sock->proto = proto.pr_protocol; + sock->dom_family = dom.dom_family; + sock->so_pcb = s.so_pcb; + + /* + * Protocol specific data. + */ + switch(dom.dom_family) { + case AF_INET: + case AF_INET6: + if (proto.pr_protocol == IPPROTO_TCP ) { + if (s.so_pcb) { + if (kvm_read(kd, (u_long)s.so_pcb, + (char *)&inpcb, sizeof(struct inpcb)) + != sizeof(struct inpcb)) { + warnx("can't read inpcb at %p\n", + (void *)s.so_pcb); + } else + sock->inp_ppcb = + (caddr_t)inpcb.inp_ppcb; + } + } + break; + case AF_UNIX: + if (s.so_pcb) { + if (kvm_read(kd, (u_long)s.so_pcb, (char *)&unpcb, + sizeof(struct unpcb)) != sizeof(struct unpcb)){ + warnx("can't read unpcb at %p\n", + (void *)s.so_pcb); + } else if (unpcb.unp_conn) { + sock->so_rcv_sb_state = s.so_rcv.sb_state; + sock->so_snd_sb_state = s.so_snd.sb_state; + sock->unp_conn = (caddr_t)unpcb.unp_conn; + } + } + break; + default: + break; + } + return (0); + +fail: + snprintf(errbuf, _POSIX2_LINE_MAX, "error"); + return (1); +} + +int +procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock, + char *errbuf) +{ + + warnx("not implemented: %s:%d", __FUNCTION__, __LINE__); + snprintf(errbuf, _POSIX2_LINE_MAX, "error"); + return (1); +} Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 08:27:12 2009 (r195714) +++ projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 09:00:41 2009 (r195715) @@ -60,3 +60,5 @@ int procstat_get_pts_info(struct procsta struct ptsstat *pts, char *errbuf); int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, struct pipestat *pipe, char *errbuf); +int procstat_get_socket_info(struct procstat *procstat, struct filestat *fst, + struct sockstat *sock, char *errbuf); From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 09:01:38 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 21F52106564A; Thu, 16 Jul 2009 09:01:38 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1123C8FC28; Thu, 16 Jul 2009 09:01:38 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6G91bOi017959; Thu, 16 Jul 2009 09:01:37 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6G91bF1017957; Thu, 16 Jul 2009 09:01:37 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907160901.n6G91bF1017957@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 09:01:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195716 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 09:01:38 -0000 Author: stas Date: Thu Jul 16 09:01:37 2009 New Revision: 195716 URL: http://svn.freebsd.org/changeset/base/195716 Log: - Properly handle bad vnodes. Modified: projects/libprocstat/usr.bin/fstat/fstat.c Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 09:00:41 2009 (r195715) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 09:01:37 2009 (r195716) @@ -511,8 +511,10 @@ print_vnode_info(struct procstat *procst badtype = "bad"; else if (vn.vn_type == PS_FST_VTYPE_VNON) badtype = "none"; - if (badtype != NULL) + if (badtype != NULL) { printf(" - - %10s -", badtype); + return; + } if (nflg) printf(" %2d,%-2d", major(vn.vn_fsid), minor(vn.vn_fsid)); From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 13:03:06 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 06CDE106564A; Thu, 16 Jul 2009 13:03:06 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E97CB8FC15; Thu, 16 Jul 2009 13:03:05 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GD35Au029921; Thu, 16 Jul 2009 13:03:05 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GD350E029920; Thu, 16 Jul 2009 13:03:05 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161303.n6GD350E029920@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 13:03:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195717 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 13:03:06 -0000 Author: stas Date: Thu Jul 16 13:03:05 2009 New Revision: 195717 URL: http://svn.freebsd.org/changeset/base/195717 Log: - Do not try to obtain device id for ordinary vnodes. Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 09:01:37 2009 (r195716) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 13:03:05 2009 (r195717) @@ -642,7 +642,8 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s return (1); } vn->mntdir = getmnton(kd, vnode.v_mount); - vn->vn_dev = dev2udev(kd, vnode.v_rdev); + if (vnode.v_rdev != NULL) + vn->vn_dev = dev2udev(kd, vnode.v_rdev); return (0); fail: From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 13:26:05 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A45621065710; Thu, 16 Jul 2009 13:26:05 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 484088FC27; Thu, 16 Jul 2009 13:26:04 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GDQ4qJ030401; Thu, 16 Jul 2009 13:26:04 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GDQ4VT030396; Thu, 16 Jul 2009 13:26:04 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161326.n6GDQ4VT030396@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 13:26:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195718 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 13:26:06 -0000 Author: stas Date: Thu Jul 16 13:26:03 2009 New Revision: 195718 URL: http://svn.freebsd.org/changeset/base/195718 Log: - Add device name extraction. Modified: projects/libprocstat/usr.bin/fstat/common.c projects/libprocstat/usr.bin/fstat/common.h projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c Modified: projects/libprocstat/usr.bin/fstat/common.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.c Thu Jul 16 13:03:05 2009 (r195717) +++ projects/libprocstat/usr.bin/fstat/common.c Thu Jul 16 13:26:03 2009 (r195718) @@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -118,14 +119,16 @@ kvm_read_all(kvm_t *kd, unsigned long ad return (error == (ssize_t)(nbytes)); } -char * -kdevtoname(kvm_t *kd, struct cdev *dev) +int +kdevtoname(kvm_t *kd, struct cdev *dev, char *buf) { struct cdev si; + assert(buf); if (!kvm_read_all(kd, (unsigned long)dev, &si, sizeof(si))) - return (NULL); - return (strdup(si.__si_namebuf)); + return (1); + strlcpy(buf, si.__si_namebuf, SPECNAMELEN + 1); + return (0); } int @@ -228,6 +231,7 @@ dev2udev(kvm_t *kd, struct cdev *dev) { struct cdev_priv priv; + assert(kd); if (kvm_read_all(kd, (unsigned long)cdev2priv(dev), &priv, sizeof(priv))) { return ((dev_t)priv.cdp_inode); Modified: projects/libprocstat/usr.bin/fstat/common.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.h Thu Jul 16 13:03:05 2009 (r195717) +++ projects/libprocstat/usr.bin/fstat/common.h Thu Jul 16 13:26:03 2009 (r195718) @@ -47,6 +47,7 @@ struct filestat { struct vnstat { dev_t vn_dev; + char vn_devname[SPECNAMELEN + 1]; int vn_type; long vn_fsid; long vn_fileid; @@ -57,6 +58,7 @@ struct vnstat { struct ptsstat { dev_t dev; + char devname[SPECNAMELEN + 1]; }; struct pipestat { @@ -84,7 +86,7 @@ extern int vflg; dev_t dev2udev(kvm_t *kd, struct cdev *dev); void dprintf(FILE *file, const char *fmt, ...); -char *kdevtoname(kvm_t *kd, struct cdev *dev); +int kdevtoname(kvm_t *kd, struct cdev *dev, char *); int kvm_read_all(kvm_t *kd, unsigned long addr, void *buf, size_t nbytes); Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 13:03:05 2009 (r195717) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 13:26:03 2009 (r195718) @@ -485,11 +485,11 @@ print_pts_info(struct procstat *procstat return; } printf("* pseudo-terminal master "); - if (nflg) { + if (nflg || !*pts.devname) { printf("%10d,%-2d", major(pts.dev), minor(pts.dev)); - } /* else { - printf("%10s", pts.name); - } */ + } else { + printf("%10s", pts.devname); + } print_access_flags(fst->fs_fflags); } @@ -497,7 +497,6 @@ static void print_vnode_info(struct procstat *procstat, struct filestat *fst) { struct vnstat vn; - char *name; const char *badtype; char errbuf[_POSIX2_LINE_MAX]; char mode[15]; @@ -532,12 +531,10 @@ print_vnode_info(struct procstat *procst (void)printf(" %6ld %10s", vn.vn_fileid, mode); if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) { - name = NULL; -// name = fst->vnode.dev.name; - if (nflg || !name) + if (nflg || !*vn.vn_devname) printf(" %2d,%-2d", major(vn.vn_dev), minor(vn.vn_dev)); else { - printf(" %6s", name); + printf(" %6s", vn.vn_devname); } } else printf(" %6lu", vn.vn_size); Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 13:03:05 2009 (r195717) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 13:26:03 2009 (r195718) @@ -558,7 +558,10 @@ procstat_get_pts_info_kvm(kvm_t *kd, str warnx("can't read tty at %p", (void *)ttyp); goto fail; } - pts->dev = dev2udev(kd, tty.t_dev); + if (tty.t_dev != NULL) { + pts->dev = dev2udev(kd, tty.t_dev); + (void)kdevtoname(kd, tty.t_dev, pts->devname); + } return (0); fail: @@ -642,8 +645,10 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s return (1); } vn->mntdir = getmnton(kd, vnode.v_mount); - if (vnode.v_rdev != NULL) + if (vnode.v_rdev != NULL) { vn->vn_dev = dev2udev(kd, vnode.v_rdev); + (void)kdevtoname(kd, vnode.v_rdev, vn->vn_devname); + } return (0); fail: From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 14:24:07 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 14DF41065670; Thu, 16 Jul 2009 14:24:07 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03AF08FC15; Thu, 16 Jul 2009 14:24:07 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GEO6VL031641; Thu, 16 Jul 2009 14:24:06 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GEO6WG031639; Thu, 16 Jul 2009 14:24:06 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161424.n6GEO6WG031639@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 14:24:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195719 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 14:24:07 -0000 Author: stas Date: Thu Jul 16 14:24:06 2009 New Revision: 195719 URL: http://svn.freebsd.org/changeset/base/195719 Log: - When retrieving special node data, check if the vnode is actually VCHR/VBLK. Suggested by: kib Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 13:26:03 2009 (r195718) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 14:24:06 2009 (r195719) @@ -558,10 +558,8 @@ procstat_get_pts_info_kvm(kvm_t *kd, str warnx("can't read tty at %p", (void *)ttyp); goto fail; } - if (tty.t_dev != NULL) { - pts->dev = dev2udev(kd, tty.t_dev); - (void)kdevtoname(kd, tty.t_dev, pts->devname); - } + pts->dev = dev2udev(kd, tty.t_dev); + (void)kdevtoname(kd, tty.t_dev, pts->devname); return (0); fail: @@ -645,7 +643,8 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s return (1); } vn->mntdir = getmnton(kd, vnode.v_mount); - if (vnode.v_rdev != NULL) { + if ((vnode.v_type == VBLK || vnode.v_type == VCHR) && + vnode.v_rdev != NULL){ vn->vn_dev = dev2udev(kd, vnode.v_rdev); (void)kdevtoname(kd, vnode.v_rdev, vn->vn_devname); } From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 15:39:55 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 504E4106564A; Thu, 16 Jul 2009 15:39:55 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3D9E08FC13; Thu, 16 Jul 2009 15:39:55 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GFdtlc033188; Thu, 16 Jul 2009 15:39:55 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GFdtYM033180; Thu, 16 Jul 2009 15:39:55 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161539.n6GFdtYM033180@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 15:39:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195720 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 15:39:55 -0000 Author: stas Date: Thu Jul 16 15:39:54 2009 New Revision: 195720 URL: http://svn.freebsd.org/changeset/base/195720 Log: - Cleanup. Added: projects/libprocstat/usr.bin/fstat/common_kvm.c - copied, changed from r195718, projects/libprocstat/usr.bin/fstat/common.c projects/libprocstat/usr.bin/fstat/common_kvm.h - copied, changed from r195718, projects/libprocstat/usr.bin/fstat/common.h Deleted: projects/libprocstat/usr.bin/fstat/common.c projects/libprocstat/usr.bin/fstat/common.h Modified: projects/libprocstat/usr.bin/fstat/Makefile projects/libprocstat/usr.bin/fstat/cd9660.c projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h projects/libprocstat/usr.bin/fstat/main.c projects/libprocstat/usr.bin/fstat/msdosfs.c projects/libprocstat/usr.bin/fstat/zfs.c Modified: projects/libprocstat/usr.bin/fstat/Makefile ============================================================================== --- projects/libprocstat/usr.bin/fstat/Makefile Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/Makefile Thu Jul 16 15:39:54 2009 (r195720) @@ -4,7 +4,7 @@ .include PROG= fstat -SRCS= common.c fstat.c main.c libprocstat.c cd9660.c msdosfs.c +SRCS= cd9660.c common_kvm.c fstat.c libprocstat.c main.c msdosfs.c LINKS= ${BINDIR}/fstat ${BINDIR}/fuser DPADD= ${LIBKVM} LDADD= -lkvm -lutil Modified: projects/libprocstat/usr.bin/fstat/cd9660.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/cd9660.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/cd9660.c Thu Jul 16 15:39:54 2009 (r195720) @@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include "common.h" +#include "common_kvm.h" int isofs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) Copied and modified: projects/libprocstat/usr.bin/fstat/common_kvm.c (from r195718, projects/libprocstat/usr.bin/fstat/common.c) ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.c Thu Jul 16 13:26:03 2009 (r195718, copy source) +++ projects/libprocstat/usr.bin/fstat/common_kvm.c Thu Jul 16 15:39:54 2009 (r195720) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2009 Stanislav Sedov * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * @@ -35,23 +36,9 @@ __FBSDID("$FreeBSD$"); #include -#include -#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _WANT_FILE -#include #include #define _KERNEL #include @@ -65,48 +52,13 @@ __FBSDID("$FreeBSD$"); #include #include - -#include -#include -#include - -#include -#include -#include -#include -#include - #include -#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include - -#include "common.h" - -int vflg = 0; -void -dprintf(FILE *file, const char *fmt, ...) { - va_list ap; - - if (vflg != 0) { - va_start(ap, fmt); - vfprintf(file, fmt, ap); - va_end(ap); - } -} +#include "common_kvm.h" int kvm_read_all(kvm_t *kd, unsigned long addr, void *buf, size_t nbytes) @@ -236,8 +188,8 @@ dev2udev(kvm_t *kd, struct cdev *dev) sizeof(priv))) { return ((dev_t)priv.cdp_inode); } else { - dprintf(stderr, "can't convert cdev *%p to a dev_t\n", dev); - return -1; + warnx("can't convert cdev *%p to a dev_t\n", dev); + return (-1); } } Copied and modified: projects/libprocstat/usr.bin/fstat/common_kvm.h (from r195718, projects/libprocstat/usr.bin/fstat/common.h) ============================================================================== --- projects/libprocstat/usr.bin/fstat/common.h Thu Jul 16 13:26:03 2009 (r195718, copy source) +++ projects/libprocstat/usr.bin/fstat/common_kvm.h Thu Jul 16 15:39:54 2009 (r195720) @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2009 Stanislav Sedov + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,13 +10,6 @@ * 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. - * 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 @@ -33,8 +26,8 @@ * $FreeBSD$ */ -#ifndef __COMMON_H__ -#define __COMMON_H__ +#ifndef __COMMON_KVM_H__ +#define __COMMON_KVM_H__ struct filestat { int fs_type; /* Descriptor type. */ @@ -82,10 +75,7 @@ struct sockstat { STAILQ_HEAD(filestat_list, filestat); -extern int vflg; - dev_t dev2udev(kvm_t *kd, struct cdev *dev); -void dprintf(FILE *file, const char *fmt, ...); int kdevtoname(kvm_t *kd, struct cdev *dev, char *); int kvm_read_all(kvm_t *kd, unsigned long addr, void *buf, size_t nbytes); @@ -104,4 +94,4 @@ void *getvnodedata(struct vnode *vp); struct mount *getvnodemount(struct vnode *vp); #endif -#endif /* __COMMON_H__ */ +#endif /* __COMMON_KVM_H__ */ Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 15:39:54 2009 (r195720) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2009 Stanislav Sedov * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * @@ -31,17 +32,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; -#endif -#endif /* not lint */ #include __FBSDID("$FreeBSD$"); @@ -103,7 +93,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include "common.h" +#include "common_kvm.h" #include "functions.h" #include "libprocstat.h" @@ -113,6 +103,7 @@ int fsflg, /* show files on same filesy int checkfile; /* true if restricting to particular files or filesystems */ int nflg; /* (numerical) display f.s. and rdev as dev_t */ int mflg; /* include memory-mapped files */ +int vflg; /* be verbose */ typedef struct devs { struct devs *next; @@ -366,9 +357,10 @@ print_file_info(struct procstat *procsta print_pts_info(procstat, fst); break; default: - dprintf(stderr, - "unknown file type %d for file %d of pid %d\n", - fst->fs_type, fst->fs_fd, pid); + if (vflg) + fprintf(stderr, + "unknown file type %d for file %d of pid %d\n", + fst->fs_type, fst->fs_fd, pid); } if (filename && !fsflg) printf(" %s", filename); Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 15:39:54 2009 (r195720) @@ -1,3 +1,37 @@ +/*- + * Copyright (c) 2009 Stanislav Sedov + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 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. + */ + #include __FBSDID("$FreeBSD$"); @@ -32,7 +66,6 @@ __FBSDID("$FreeBSD$"); #include #include - #include #include #include @@ -59,9 +92,12 @@ __FBSDID("$FreeBSD$"); #include #include -#include "common.h" +#include "common_kvm.h" #include "libprocstat.h" +/* + * Vnode-to-filestat types translation table. + */ static struct { int vtype; int fst_vtype; @@ -78,6 +114,9 @@ static struct { }; #define NVFTYPES (sizeof(vt2fst) / sizeof(*vt2fst)) +/* + * Descriptor-to-filestat flags translation table. + */ static struct { int flag; int fst_flag; @@ -97,28 +136,6 @@ static struct { }; #define NFSTFLAGS (sizeof(fstflags) / sizeof(*fstflags)) -char *getmnton(kvm_t *kd, struct mount *m); -void socktrans(kvm_t *kd, struct socket *sock, int fd, int flags, - struct filestat *fst); -int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst, - struct vnstat *vn, char *errbuf); -int procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, - char *errbuf); -int procstat_get_pipe_info_sysctl(struct filestat *fst, - struct pipestat *pipe, char *errbuf); -int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, - struct pipestat *pipe, char *errbuf); -int procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts, - char *errbuf); -int procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, - struct ptsstat *pts, char *errbuf); -int procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock, - char *errbuf); -int procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst, - struct sockstat *sock, char *errbuf); -static int to_filestat_flags(int flags); - - /* * Filesystem specific handlers. */ @@ -145,8 +162,32 @@ struct { }; #define NTYPES (sizeof(fstypes) / sizeof(*fstypes)) -#define PROCSTAT_KVM 1 -#define PROCSTAT_SYSCTL 2 +#define PROCSTAT_KVM 1 +#define PROCSTAT_SYSCTL 2 + +static char *getmnton(kvm_t *kd, struct mount *m); +static struct filestat_list *procstat_getfiles_kvm(kvm_t *kd, + struct kinfo_proc *kp); +static struct filestat_list *procstat_getfiles_sysctl( + struct kinfo_proc *kp); +static int procstat_get_pipe_info_sysctl(struct filestat *fst, + struct pipestat *pipe, char *errbuf); +static int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, + struct pipestat *pipe, char *errbuf); +static int procstat_get_pts_info_sysctl(struct filestat *fst, + struct ptsstat *pts, char *errbuf); +static int procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, + struct ptsstat *pts, char *errbuf); +static int procstat_get_socket_info_sysctl(struct filestat *fst, + struct sockstat *sock, char *errbuf); +static int procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst, + struct sockstat *sock, char *errbuf); +static int to_filestat_flags(int flags); +static int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst, + struct vnstat *vn, char *errbuf); +static int procstat_get_vnode_info_sysctl(struct filestat *fst, + struct vnstat *vn, char *errbuf); +static int vntype2psfsttype(int type); void procstat_close(struct procstat *procstat) @@ -279,7 +320,7 @@ filestat_new_entry(struct vnode *vp, int return (entry); } -struct filestat_list * +static struct filestat_list * procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp) { int i; @@ -406,68 +447,12 @@ exit: return (head); } -static int -to_filestat_flags(int flags) -{ - int fst_flags; - unsigned int i; - - fst_flags = 0; - for (i = 0; i < NFSTFLAGS; i++) - if (flags & fstflags[i].flag) - fst_flags |= fstflags[i].fst_flag; - return (fst_flags); -} - -struct filestat_list * +static struct filestat_list * procstat_getfiles_sysctl(struct kinfo_proc *kp __unused) { return (NULL); } -static int -vntype2psfsttype(int type) -{ - unsigned int i, fst_type; - - fst_type = PS_FST_VTYPE_UNKNOWN; - for (i = 0; i < NVFTYPES; i++) { - if (type == vt2fst[i].vtype) { - fst_type = vt2fst[i].fst_vtype; - break; - } - } - return (fst_type); -} - -char * -getmnton(kvm_t *kd, struct mount *m) -{ - static struct mount mnt; - static struct mtab { - struct mtab *next; - struct mount *m; - char mntonname[MNAMELEN + 1]; - } *mhead = NULL; - struct mtab *mt; - - for (mt = mhead; mt != NULL; mt = mt->next) - if (m == mt->m) - return (mt->mntonname); - if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) { - warnx("can't read mount table at %p", (void *)m); - return (NULL); - } - if ((mt = malloc(sizeof (struct mtab))) == NULL) - err(1, NULL); - mt->m = m; - bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); - mnt.mnt_stat.f_mntonname[MNAMELEN] = '\0'; - mt->next = mhead; - mhead = mt; - return (mt->mntonname); -} - int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, struct pipestat *pipe, char *errbuf) @@ -485,7 +470,8 @@ procstat_get_pipe_info(struct procstat * return (1); } } -int + +static int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, struct pipestat *pipe, char *errbuf) { @@ -513,7 +499,7 @@ fail: return (1); } -int +static int procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, char *errbuf) { @@ -540,7 +526,8 @@ procstat_get_pts_info(struct procstat *p return (1); } } -int + +static int procstat_get_pts_info_kvm(kvm_t *kd, struct filestat *fst, struct ptsstat *pts, char *errbuf) { @@ -567,7 +554,7 @@ fail: return (1); } -int +static int procstat_get_pts_info_sysctl(struct filestat *fst, struct ptsstat *pts, char *errbuf) { @@ -595,7 +582,7 @@ procstat_get_vnode_info(struct procstat } } -int +static int procstat_get_vnode_info_kvm(kvm_t *kd, struct filestat *fst, struct vnstat *vn, char *errbuf) { @@ -647,6 +634,8 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s vnode.v_rdev != NULL){ vn->vn_dev = dev2udev(kd, vnode.v_rdev); (void)kdevtoname(kd, vnode.v_rdev, vn->vn_devname); + } else { + vn->vn_dev = -1; } return (0); @@ -655,7 +644,7 @@ fail: return (1); } -int +static int procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, char *errbuf) { @@ -682,7 +671,8 @@ procstat_get_socket_info(struct procstat return (1); } } -int + +static int procstat_get_socket_info_kvm(kvm_t *kd, struct filestat *fst, struct sockstat *sock, char *errbuf) { @@ -779,7 +769,7 @@ fail: return (1); } -int +static int procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock, char *errbuf) { @@ -788,3 +778,59 @@ procstat_get_socket_info_sysctl(struct f snprintf(errbuf, _POSIX2_LINE_MAX, "error"); return (1); } + +static int +to_filestat_flags(int flags) +{ + int fst_flags; + unsigned int i; + + fst_flags = 0; + for (i = 0; i < NFSTFLAGS; i++) + if (flags & fstflags[i].flag) + fst_flags |= fstflags[i].fst_flag; + return (fst_flags); +} + +static int +vntype2psfsttype(int type) +{ + unsigned int i, fst_type; + + fst_type = PS_FST_VTYPE_UNKNOWN; + for (i = 0; i < NVFTYPES; i++) { + if (type == vt2fst[i].vtype) { + fst_type = vt2fst[i].fst_vtype; + break; + } + } + return (fst_type); +} + +static char * +getmnton(kvm_t *kd, struct mount *m) +{ + static struct mount mnt; + static struct mtab { + struct mtab *next; + struct mount *m; + char mntonname[MNAMELEN + 1]; + } *mhead = NULL; + struct mtab *mt; + + for (mt = mhead; mt != NULL; mt = mt->next) + if (m == mt->m) + return (mt->mntonname); + if (!kvm_read_all(kd, (unsigned long)m, &mnt, sizeof(struct mount))) { + warnx("can't read mount table at %p", (void *)m); + return (NULL); + } + if ((mt = malloc(sizeof (struct mtab))) == NULL) + err(1, NULL); + mt->m = m; + bcopy(&mnt.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); + mnt.mnt_stat.f_mntonname[MNAMELEN] = '\0'; + mt->next = mhead; + mhead = mt; + return (mt->mntonname); +} Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 15:39:54 2009 (r195720) @@ -1,3 +1,37 @@ +/*- + * Copyright (c) 2009 Stanislav Sedov + * All rights reserved. + * + * 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. + * + * 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. + * + * $FreeBSD$ + */ + +#ifndef __LIBPROCSTAT_H__ +#define __LIBPROCSTAT_H__ + +/* + * Vnode types. + */ #define PS_FST_VTYPE_VNON 1 #define PS_FST_VTYPE_VREG 2 #define PS_FST_VTYPE_VDIR 3 @@ -9,24 +43,28 @@ #define PS_FST_VTYPE_VBAD 9 #define PS_FST_VTYPE_UNKNOWN 255 +/* + * Descriptor types. + */ #define PS_FST_TYPE_VNODE 1 #define PS_FST_TYPE_FIFO 2 #define PS_FST_TYPE_SOCKET 3 #define PS_FST_TYPE_PIPE 4 #define PS_FST_TYPE_PTS 5 -struct procstat { - int type; - kvm_t *kd; -}; - -#define PS_FST_FD_RDIR -1 -#define PS_FST_FD_CDIR -2 -#define PS_FST_FD_JAIL -3 -#define PS_FST_FD_TRACE -4 -#define PS_FST_FD_TEXT -5 -#define PS_FST_FD_MMAP -6 - +/* + * Special descriptor numbers. + */ +#define PS_FST_FD_RDIR -1 +#define PS_FST_FD_CDIR -2 +#define PS_FST_FD_JAIL -3 +#define PS_FST_FD_TRACE -4 +#define PS_FST_FD_TEXT -5 +#define PS_FST_FD_MMAP -6 + +/* + * Descriptor flags. + */ #define PS_FST_FFLAG_READ 0x0001 #define PS_FST_FFLAG_WRITE 0x0002 #define PS_FST_FFLAG_NONBLOCK 0x0004 @@ -40,25 +78,24 @@ struct procstat { #define PS_FST_FFLAG_TRUNC 0x0400 #define PS_FST_FFLAG_EXCL 0x0800 -#define PS_FST_FLAG_ERROR 0x01 -#define PS_FST_FLAG_UNKNOWNFS 0x02 +struct procstat { + int type; + kvm_t *kd; +}; void procstat_close(struct procstat *procstat); -struct procstat *procstat_open(const char *nlistf, const char *memf); -struct kinfo_proc *procstat_getprocs(struct procstat *procstat, - int what, int arg, unsigned int *count); struct filestat_list *procstat_getfiles(struct procstat *procstat, struct kinfo_proc *kp); -struct filestat_list *procstat_getfiles_sysctl(struct kinfo_proc *kp); -struct filestat_list *procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp); -int vtrans_kvm(kvm_t *kd, struct vnode *vp, int fd, int flags, struct filestat *fst); -char *procstat_kdevtoname(struct procstat *procstat, struct cdev *cdev); -dev_t procstat_dev2udev(struct procstat *procstat, struct cdev *cdev); -int procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst, - struct vnstat *vn, char *errbuf); -int procstat_get_pts_info(struct procstat *procstat, struct filestat *fst, - struct ptsstat *pts, char *errbuf); +struct kinfo_proc *procstat_getprocs(struct procstat *procstat, + int what, int arg, unsigned int *count); int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, struct pipestat *pipe, char *errbuf); +int procstat_get_pts_info(struct procstat *procstat, struct filestat *fst, + struct ptsstat *pts, char *errbuf); int procstat_get_socket_info(struct procstat *procstat, struct filestat *fst, struct sockstat *sock, char *errbuf); +int procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst, + struct vnstat *vn, char *errbuf); +struct procstat *procstat_open(const char *nlistf, const char *memf); + +#endif /* !__LIBPROCSTAT_H__ */ Modified: projects/libprocstat/usr.bin/fstat/main.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/main.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/main.c Thu Jul 16 15:39:54 2009 (r195720) @@ -32,8 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include -int do_fstat(int argc, char *argv[]); -int do_fuser(int argc, char *argv[]); +#include "functions.h" int main(int argc, char *argv[]) Modified: projects/libprocstat/usr.bin/fstat/msdosfs.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/msdosfs.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/msdosfs.c Thu Jul 16 15:39:54 2009 (r195720) @@ -64,7 +64,7 @@ __FBSDID("$FreeBSD$"); */ #define VTODE(vp) ((struct denode *)(vp)->v_data) -#include "common.h" +#include "common_kvm.h" struct dosmount { struct dosmount *next; Modified: projects/libprocstat/usr.bin/fstat/zfs.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/zfs.c Thu Jul 16 14:24:06 2009 (r195719) +++ projects/libprocstat/usr.bin/fstat/zfs.c Thu Jul 16 15:39:54 2009 (r195720) @@ -50,8 +50,7 @@ #include #define ZFS -#undef dprintf -#include "common.h" +#include "common_kvm.h" /* * Offset calculations that are used to get data from znode without having the From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 16:38:41 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78F40106566C; Thu, 16 Jul 2009 16:38:41 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6719F8FC0A; Thu, 16 Jul 2009 16:38:41 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GGcfiY034338; Thu, 16 Jul 2009 16:38:41 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GGcfWY034329; Thu, 16 Jul 2009 16:38:41 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161638.n6GGcfWY034329@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 16:38:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195721 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 16:38:41 -0000 Author: stas Date: Thu Jul 16 16:38:41 2009 New Revision: 195721 URL: http://svn.freebsd.org/changeset/base/195721 Log: - Move libprocstat structures definition to the appropriate header. Modified: projects/libprocstat/usr.bin/fstat/cd9660.c projects/libprocstat/usr.bin/fstat/common_kvm.c projects/libprocstat/usr.bin/fstat/common_kvm.h projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h projects/libprocstat/usr.bin/fstat/msdosfs.c projects/libprocstat/usr.bin/fstat/zfs.c Modified: projects/libprocstat/usr.bin/fstat/cd9660.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/cd9660.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/cd9660.c Thu Jul 16 16:38:41 2009 (r195721) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include "libprocstat.h" #include "common_kvm.h" int Modified: projects/libprocstat/usr.bin/fstat/common_kvm.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/common_kvm.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/common_kvm.c Thu Jul 16 16:38:41 2009 (r195721) @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include "libprocstat.h" #include "common_kvm.h" int Modified: projects/libprocstat/usr.bin/fstat/common_kvm.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/common_kvm.h Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/common_kvm.h Thu Jul 16 16:38:41 2009 (r195721) @@ -29,52 +29,6 @@ #ifndef __COMMON_KVM_H__ #define __COMMON_KVM_H__ -struct filestat { - int fs_type; /* Descriptor type. */ - int fs_flags; /* filestat specific flags. */ - int fs_fflags; /* Descriptor access flags. */ - int fs_fd; /* File descriptor number. */ - void *fs_typedep; /* Type dependent data. */ - STAILQ_ENTRY(filestat) next; -}; - -struct vnstat { - dev_t vn_dev; - char vn_devname[SPECNAMELEN + 1]; - int vn_type; - long vn_fsid; - long vn_fileid; - mode_t vn_mode; - u_long vn_size; - char *mntdir; -}; - -struct ptsstat { - dev_t dev; - char devname[SPECNAMELEN + 1]; -}; - -struct pipestat { - caddr_t addr; - caddr_t peer; - size_t buffer_cnt; -}; - -struct sockstat { - int type; - int proto; - int dom_family; - caddr_t so_addr; - caddr_t so_pcb; - caddr_t inp_ppcb; - caddr_t unp_conn; - int so_snd_sb_state; - int so_rcv_sb_state; - char dname[32]; -}; - -STAILQ_HEAD(filestat_list, filestat); - dev_t dev2udev(kvm_t *kd, struct cdev *dev); int kdevtoname(kvm_t *kd, struct cdev *dev, char *); int kvm_read_all(kvm_t *kd, unsigned long addr, void *buf, Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 16:38:41 2009 (r195721) @@ -93,7 +93,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include "common_kvm.h" #include "functions.h" #include "libprocstat.h" Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 16:38:41 2009 (r195721) @@ -92,8 +92,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include "common_kvm.h" #include "libprocstat.h" +#include "common_kvm.h" /* * Vnode-to-filestat types translation table. Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 16:38:41 2009 (r195721) @@ -82,6 +82,47 @@ struct procstat { int type; kvm_t *kd; }; +struct filestat { + int fs_type; /* Descriptor type. */ + int fs_flags; /* filestat specific flags. */ + int fs_fflags; /* Descriptor access flags. */ + int fs_fd; /* File descriptor number. */ + void *fs_typedep; /* Type dependent data. */ + STAILQ_ENTRY(filestat) next; +}; +struct vnstat { + dev_t vn_dev; + char vn_devname[SPECNAMELEN + 1]; + int vn_type; + long vn_fsid; + long vn_fileid; + mode_t vn_mode; + u_long vn_size; + char *mntdir; +}; +struct ptsstat { + dev_t dev; + char devname[SPECNAMELEN + 1]; +}; +struct pipestat { + caddr_t addr; + caddr_t peer; + size_t buffer_cnt; +}; +struct sockstat { + int type; + int proto; + int dom_family; + caddr_t so_addr; + caddr_t so_pcb; + caddr_t inp_ppcb; + caddr_t unp_conn; + int so_snd_sb_state; + int so_rcv_sb_state; + char dname[32]; +}; + +STAILQ_HEAD(filestat_list, filestat); void procstat_close(struct procstat *procstat); struct filestat_list *procstat_getfiles(struct procstat *procstat, Modified: projects/libprocstat/usr.bin/fstat/msdosfs.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/msdosfs.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/msdosfs.c Thu Jul 16 16:38:41 2009 (r195721) @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); */ #define VTODE(vp) ((struct denode *)(vp)->v_data) +#include "libprocstat.h" #include "common_kvm.h" struct dosmount { Modified: projects/libprocstat/usr.bin/fstat/zfs.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/zfs.c Thu Jul 16 15:39:54 2009 (r195720) +++ projects/libprocstat/usr.bin/fstat/zfs.c Thu Jul 16 16:38:41 2009 (r195721) @@ -50,6 +50,7 @@ #include #define ZFS +#include "libprocstat.h" #include "common_kvm.h" /* From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 16:55:08 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E91C1065670; Thu, 16 Jul 2009 16:55:08 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 63A0C8FC13; Thu, 16 Jul 2009 16:55:08 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GGt8xi034757; Thu, 16 Jul 2009 16:55:08 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GGt8NN034754; Thu, 16 Jul 2009 16:55:08 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161655.n6GGt8NN034754@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 16:55:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195722 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 16:55:08 -0000 Author: stas Date: Thu Jul 16 16:55:08 2009 New Revision: 195722 URL: http://svn.freebsd.org/changeset/base/195722 Log: - Cleanup. Modified: projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 16:38:41 2009 (r195721) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 16:55:08 2009 (r195722) @@ -36,55 +36,24 @@ __FBSDID("$FreeBSD$"); #include -#include -#include #include #include -#include #include #include -#include -#include -#include -#include #include -#include -#include #include -#define _WANT_FILE -#include -#include -#define _KERNEL -#include -#include -#include -#include -#include -#include -#undef _KERNEL -#include -#include -#include - #include #include #include -#include #include -#include -#include -#include #include #include #include -#include #include -#include #include -#include #include #include #include @@ -114,37 +83,30 @@ typedef struct devs { DEVS *devs; char *memf, *nlistf; -static void fstat1(int what, int arg); -static void dofiles(struct procstat *procstat, struct kinfo_proc *p); -void dofiles_kinfo(struct kinfo_proc *kp); -void dommap(struct kinfo_proc *kp); -void vtrans(struct vnode *vp, int i, int flag, const char *uname, const char *cmd, int pid); -char *getmnton(struct mount *m); -void pipetrans(struct pipe *pi, int i, int flag, const char *uname, const char *cmd, int pid); -void socktrans(struct socket *sock, int i, const char *uname, const char *cmd, int pid); -void ptstrans(struct tty *tp, int i, int flag, const char *uname, const char *cmd, int pid); -void getinetproto(int number); -int getfname(const char *filename); -void usage(void); -void vtrans_kinfo(struct kinfo_file *, int i, int flag, const char *uname, const char *cmd, int pid); -static void print_file_info(struct procstat *procstat, struct filestat *fst, const char *uname, const char *cmd, int pid); - -static void -print_socket_info(struct procstat *procstat, struct filestat *fst); -static void -print_pipe_info(struct procstat *procstat, struct filestat *fst); -static void -print_pts_info(struct procstat *procstat, struct filestat *fst); -static void -print_vnode_info(struct procstat *procstat, struct filestat *fst); -static void -print_access_flags(int flags); +static int getfname(const char *filename); +static void dofiles(struct procstat *procstat, struct kinfo_proc *p); +static void dommap(struct procstat *procstat, struct kinfo_proc *p); +static void print_access_flags(int flags); +static void print_file_info(struct procstat *procstat, + struct filestat *fst, const char *uname, const char *cmd, int pid); +static void print_pipe_info(struct procstat *procstat, + struct filestat *fst); +static void print_pts_info(struct procstat *procstat, + struct filestat *fst); +static void print_socket_info(struct procstat *procstat, + struct filestat *fst); +static void print_vnode_info(struct procstat *procstat, + struct filestat *fst); +static void usage(void) __dead2; int do_fstat(int argc, char **argv) { + struct kinfo_proc *p; struct passwd *passwd; + struct procstat *procstat; int arg, ch, what; + int cnt, i; arg = 0; what = KERN_PROC_PROC; @@ -208,18 +170,6 @@ do_fstat(int argc, char **argv) checkfile = 1; } - fstat1(what, arg); - exit(0); -} - -static void -fstat1(int what, int arg) -{ - struct kinfo_proc *p; - struct procstat *procstat; - int cnt; - int i; - procstat = procstat_open(nlistf, memf); if (procstat == NULL) errx(1, "procstat_open()"); @@ -248,13 +198,19 @@ fstat1(int what, int arg) if (p[i].ki_stat == SZOMB) continue; dofiles(procstat, &p[i]); -/* if (mflg) dommap(procstat, &p[i]); -*/ } free(p); procstat_close(procstat); + return (0); +} + +static void +dommap(struct procstat *procstat __unused, struct kinfo_proc *kp __unused) +{ + + fprintf(stderr, "Not implemented\n"); } static void @@ -449,17 +405,17 @@ print_socket_info(struct procstat *procs static void print_pipe_info(struct procstat *procstat, struct filestat *fst) { - struct pipestat pipe; + struct pipestat ps; char errbuf[_POSIX2_LINE_MAX]; int error; - error = procstat_get_pipe_info(procstat, fst, &pipe, errbuf); + error = procstat_get_pipe_info(procstat, fst, &ps, errbuf); if (error != 0) { printf("* error"); return; } - printf("* pipe %8lx <-> %8lx", (u_long)pipe.addr, (u_long)pipe.peer); - printf(" %6zd", pipe.buffer_cnt); + printf("* pipe %8lx <-> %8lx", (u_long)ps.addr, (u_long)ps.peer); + printf(" %6zd", ps.buffer_cnt); print_access_flags(fst->fs_fflags); } @@ -566,7 +522,7 @@ getfname(const char *filename) return (1); } -void +static void usage(void) { (void)fprintf(stderr, Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 16:38:41 2009 (r195721) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 16:55:08 2009 (r195722) @@ -455,15 +455,15 @@ procstat_getfiles_sysctl(struct kinfo_pr int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, - struct pipestat *pipe, char *errbuf) + struct pipestat *ps, char *errbuf) { - assert(pipe); + assert(ps); if (procstat->type == PROCSTAT_KVM) { - return (procstat_get_pipe_info_kvm(procstat->kd, fst, pipe, + return (procstat_get_pipe_info_kvm(procstat->kd, fst, ps, errbuf)); } else if (procstat->type == PROCSTAT_SYSCTL) { - return (procstat_get_pipe_info_sysctl(fst, pipe, errbuf)); + return (procstat_get_pipe_info_sysctl(fst, ps, errbuf)); } else { warnx("unknow access method: %d", procstat->type); snprintf(errbuf, _POSIX2_LINE_MAX, "error"); @@ -473,15 +473,15 @@ procstat_get_pipe_info(struct procstat * static int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, - struct pipestat *pipe, char *errbuf) + struct pipestat *ps, char *errbuf) { struct pipe pi; void *pipep; assert(kd); - assert(pipe); + assert(ps); assert(fst); - bzero(pipe, sizeof(*pipe)); + bzero(ps, sizeof(*ps)); pipep = fst->fs_typedep; if (pipep == NULL) goto fail; @@ -489,9 +489,9 @@ procstat_get_pipe_info_kvm(kvm_t *kd, st warnx("can't read pipe at %p", (void *)pipep); goto fail; } - pipe->addr = (caddr_t)pipep; - pipe->peer = (caddr_t)pi.pipe_peer; - pipe->buffer_cnt = pi.pipe_buffer.cnt; + ps->addr = (caddr_t)pipep; + ps->peer = (caddr_t)pi.pipe_peer; + ps->buffer_cnt = pi.pipe_buffer.cnt; return (0); fail: @@ -500,7 +500,7 @@ fail: } static int -procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, +procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *ps, char *errbuf) { From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 17:31:23 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C5E10106566C; Thu, 16 Jul 2009 17:31:23 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B38488FC16; Thu, 16 Jul 2009 17:31:23 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GHVNbj035513; Thu, 16 Jul 2009 17:31:23 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GHVNfU035509; Thu, 16 Jul 2009 17:31:23 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907161731.n6GHVNfU035509@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 17:31:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195723 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 17:31:24 -0000 Author: stas Date: Thu Jul 16 17:31:23 2009 New Revision: 195723 URL: http://svn.freebsd.org/changeset/base/195723 Log: - Add mmapped files display support. - Cleanup. Modified: projects/libprocstat/usr.bin/fstat/fstat.c projects/libprocstat/usr.bin/fstat/libprocstat.c projects/libprocstat/usr.bin/fstat/libprocstat.h Modified: projects/libprocstat/usr.bin/fstat/fstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 16:55:08 2009 (r195722) +++ projects/libprocstat/usr.bin/fstat/fstat.c Thu Jul 16 17:31:23 2009 (r195723) @@ -43,10 +43,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include -#include - #include #include @@ -85,7 +81,6 @@ char *memf, *nlistf; static int getfname(const char *filename); static void dofiles(struct procstat *procstat, struct kinfo_proc *p); -static void dommap(struct procstat *procstat, struct kinfo_proc *p); static void print_access_flags(int flags); static void print_file_info(struct procstat *procstat, struct filestat *fst, const char *uname, const char *cmd, int pid); @@ -198,8 +193,6 @@ do_fstat(int argc, char **argv) if (p[i].ki_stat == SZOMB) continue; dofiles(procstat, &p[i]); - if (mflg) - dommap(procstat, &p[i]); } free(p); procstat_close(procstat); @@ -207,13 +200,6 @@ do_fstat(int argc, char **argv) } static void -dommap(struct procstat *procstat __unused, struct kinfo_proc *kp __unused) -{ - - fprintf(stderr, "Not implemented\n"); -} - -static void dofiles(struct procstat *procstat, struct kinfo_proc *kp) { struct filestat_list *head; @@ -226,10 +212,9 @@ dofiles(struct procstat *procstat, struc pid = kp->ki_pid; cmd = kp->ki_comm; - head = procstat_getfiles(procstat, kp); + head = procstat_getfiles(procstat, kp, mflg); if (head == NULL) return; - STAILQ_FOREACH(fst, head, next) print_file_info(procstat, fst, uname, cmd, pid); } Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 16:55:08 2009 (r195722) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 17:31:23 2009 (r195723) @@ -167,9 +167,9 @@ struct { static char *getmnton(kvm_t *kd, struct mount *m); static struct filestat_list *procstat_getfiles_kvm(kvm_t *kd, - struct kinfo_proc *kp); + struct kinfo_proc *kp, int mmapped); static struct filestat_list *procstat_getfiles_sysctl( - struct kinfo_proc *kp); + struct kinfo_proc *kp, int mmapped); static int procstat_get_pipe_info_sysctl(struct filestat *fst, struct pipestat *pipe, char *errbuf); static int procstat_get_pipe_info_kvm(kvm_t *kd, struct filestat *fst, @@ -292,13 +292,13 @@ fail: } struct filestat_list * -procstat_getfiles(struct procstat *procstat, struct kinfo_proc *kp) +procstat_getfiles(struct procstat *procstat, struct kinfo_proc *kp, int mmapped) { if (procstat->type == PROCSTAT_SYSCTL) - return (procstat_getfiles_sysctl(kp)); + return (procstat_getfiles_sysctl(kp, mmapped)); else if (procstat->type == PROCSTAT_KVM) - return (procstat_getfiles_kvm(procstat->kd, kp)); + return (procstat_getfiles_kvm(procstat->kd, kp, mmapped)); else return (NULL); } @@ -321,7 +321,7 @@ filestat_new_entry(struct vnode *vp, int } static struct filestat_list * -procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp) +procstat_getfiles_kvm(kvm_t *kd, struct kinfo_proc *kp, int mmapped) { int i; struct file file; @@ -332,6 +332,13 @@ procstat_getfiles_kvm(kvm_t *kd, struct struct filestat_list *head; int type; void *data; + vm_map_t map; + struct vmspace vmspace; + struct vm_map_entry vmentry; + vm_map_entry_t entryp; + struct vm_object object; + vm_object_t objp; + int prot, fflags; assert(kd); @@ -339,7 +346,7 @@ procstat_getfiles_kvm(kvm_t *kd, struct return (NULL); if (!kvm_read_all(kd, (unsigned long)kp->ki_fd, &filed, sizeof(filed))) { - warnx("can't read filedesc at %p\n", (void *)kp->ki_fd); + warnx("can't read filedesc at %p", (void *)kp->ki_fd); return (NULL); } @@ -391,21 +398,21 @@ procstat_getfiles_kvm(kvm_t *kd, struct ofiles = malloc(nfiles * sizeof(struct file *)); if (ofiles == NULL) { warn("malloc(%zd)", nfiles * sizeof(struct file *)); - goto exit; + goto do_mmapped; } if (!kvm_read_all(kd, (unsigned long)filed.fd_ofiles, ofiles, nfiles * sizeof(struct file *))) { - warn("cannot read file structures at %p\n", + warnx("cannot read file structures at %p", (void *)filed.fd_ofiles); free(ofiles); - goto exit; + goto do_mmapped; } for (i = 0; i <= filed.fd_lastfile; i++) { if (ofiles[i] == NULL) continue; if (!kvm_read_all(kd, (unsigned long)ofiles[i], &file, sizeof(struct file))) { - warn("can't read file %d at %p\n", i, + warnx("can't read file %d at %p", i, (void *)ofiles[i]); continue; } @@ -433,7 +440,7 @@ procstat_getfiles_kvm(kvm_t *kd, struct break; #endif default: - warnx("unknown file type %d for file %d\n", + warnx("unknown file type %d for file %d", file.f_type, i); continue; } @@ -443,12 +450,69 @@ procstat_getfiles_kvm(kvm_t *kd, struct STAILQ_INSERT_TAIL(head, entry, next); } free(ofiles); + +do_mmapped: + + /* + * Process mmapped files if requested. + */ + if (mmapped) { + if (!kvm_read_all(kd, (unsigned long)kp->ki_vmspace, &vmspace, + sizeof(vmspace))) { + warnx("can't read vmspace at %p", + (void *)kp->ki_vmspace); + goto exit; + } + map = &vmspace.vm_map; + + for (entryp = map->header.next; + entryp != &kp->ki_vmspace->vm_map.header; + entryp = vmentry.next) { + if (!kvm_read_all(kd, (unsigned long)entryp, &vmentry, + sizeof(vmentry))) { + warnx("can't read vm_map_entry at %p", + (void *)entryp); + continue; + } + if (vmentry.eflags & MAP_ENTRY_IS_SUB_MAP) + continue; + if ((objp = vmentry.object.vm_object) == NULL) + continue; + for (; objp; objp = object.backing_object) { + if (!kvm_read_all(kd, (unsigned long)objp, + &object, sizeof(object))) { + warnx("can't read vm_object at %p", + (void *)objp); + break; + } + } + + /* We want only vnode objects. */ + if (object.type != OBJT_VNODE) + continue; + + prot = vmentry.protection; + fflags = 0; + if (prot & VM_PROT_READ) + fflags = PS_FST_FFLAG_READ; + if (prot & VM_PROT_WRITE) + fflags |= PS_FST_FFLAG_WRITE; + + /* + * Create filestat entry. + */ + entry = filestat_new_entry(object.handle, + PS_FST_TYPE_VNODE, PS_FST_FD_MMAP, fflags); + if (entry != NULL) + STAILQ_INSERT_TAIL(head, entry, next); + } + } exit: return (head); } static struct filestat_list * -procstat_getfiles_sysctl(struct kinfo_proc *kp __unused) +procstat_getfiles_sysctl(struct kinfo_proc *kp __unused, int mmapped) { return (NULL); } @@ -601,7 +665,7 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s goto fail; error = kvm_read_all(kd, (unsigned long)vp, &vnode, sizeof(vnode)); if (error == 0) { - warnx("can't read vnode at %p\n", (void *)vp); + warnx("can't read vnode at %p", (void *)vp); goto fail; } bzero(vn, sizeof(*vn)); @@ -610,7 +674,7 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s return (0); error = kvm_read_all(kd, (unsigned long)vnode.v_tag, tagstr, sizeof(tagstr)); if (error == 0) { - warnx("can't read v_tag at %p\n", (void *)vp); + warnx("can't read v_tag at %p", (void *)vp); goto fail; } tagstr[sizeof(tagstr) - 1] = '\0'; @@ -738,7 +802,7 @@ procstat_get_socket_info_kvm(kvm_t *kd, if (kvm_read(kd, (u_long)s.so_pcb, (char *)&inpcb, sizeof(struct inpcb)) != sizeof(struct inpcb)) { - warnx("can't read inpcb at %p\n", + warnx("can't read inpcb at %p", (void *)s.so_pcb); } else sock->inp_ppcb = @@ -750,7 +814,7 @@ procstat_get_socket_info_kvm(kvm_t *kd, if (s.so_pcb) { if (kvm_read(kd, (u_long)s.so_pcb, (char *)&unpcb, sizeof(struct unpcb)) != sizeof(struct unpcb)){ - warnx("can't read unpcb at %p\n", + warnx("can't read unpcb at %p", (void *)s.so_pcb); } else if (unpcb.unp_conn) { sock->so_rcv_sb_state = s.so_rcv.sb_state; Modified: projects/libprocstat/usr.bin/fstat/libprocstat.h ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 16:55:08 2009 (r195722) +++ projects/libprocstat/usr.bin/fstat/libprocstat.h Thu Jul 16 17:31:23 2009 (r195723) @@ -126,7 +126,7 @@ STAILQ_HEAD(filestat_list, filestat); void procstat_close(struct procstat *procstat); struct filestat_list *procstat_getfiles(struct procstat *procstat, - struct kinfo_proc *kp); + struct kinfo_proc *kp, int mmapped); struct kinfo_proc *procstat_getprocs(struct procstat *procstat, int what, int arg, unsigned int *count); int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst, From owner-svn-src-projects@FreeBSD.ORG Thu Jul 16 22:33:21 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D82C3106566B; Thu, 16 Jul 2009 22:33:21 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AB7DC8FC14; Thu, 16 Jul 2009 22:33:21 +0000 (UTC) (envelope-from stas@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6GMXLjP044874; Thu, 16 Jul 2009 22:33:21 GMT (envelope-from stas@svn.freebsd.org) Received: (from stas@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6GMXLAn044872; Thu, 16 Jul 2009 22:33:21 GMT (envelope-from stas@svn.freebsd.org) Message-Id: <200907162233.n6GMXLAn044872@svn.freebsd.org> From: Stanislav Sedov Date: Thu, 16 Jul 2009 22:33:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195731 - projects/libprocstat/usr.bin/fstat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jul 2009 22:33:22 -0000 Author: stas Date: Thu Jul 16 22:33:21 2009 New Revision: 195731 URL: http://svn.freebsd.org/changeset/base/195731 Log: - Cleanup. - Do not report about unknow file types. Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c Modified: projects/libprocstat/usr.bin/fstat/libprocstat.c ============================================================================== --- projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 22:30:11 2009 (r195730) +++ projects/libprocstat/usr.bin/fstat/libprocstat.c Thu Jul 16 22:33:21 2009 (r195731) @@ -360,36 +360,36 @@ procstat_getfiles_kvm(kvm_t *kd, struct /* root directory vnode, if one. */ if (filed.fd_rdir) { - entry = filestat_new_entry(filed.fd_rdir, PS_FST_TYPE_VNODE, PS_FST_FD_RDIR, - PS_FST_FFLAG_READ); + entry = filestat_new_entry(filed.fd_rdir, PS_FST_TYPE_VNODE, + PS_FST_FD_RDIR, PS_FST_FFLAG_READ); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* current working directory vnode. */ if (filed.fd_cdir) { - entry = filestat_new_entry(filed.fd_cdir, PS_FST_TYPE_VNODE, PS_FST_FD_CDIR, - PS_FST_FFLAG_READ); + entry = filestat_new_entry(filed.fd_cdir, PS_FST_TYPE_VNODE, + PS_FST_FD_CDIR, PS_FST_FFLAG_READ); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* jail root, if any. */ if (filed.fd_jdir) { - entry = filestat_new_entry(filed.fd_jdir, PS_FST_TYPE_VNODE, PS_FST_FD_JAIL, - PS_FST_FFLAG_READ); + entry = filestat_new_entry(filed.fd_jdir, PS_FST_TYPE_VNODE, + PS_FST_FD_JAIL, PS_FST_FFLAG_READ); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* ktrace vnode, if one */ if (kp->ki_tracep) { - entry = filestat_new_entry(kp->ki_tracep, PS_FST_TYPE_VNODE, PS_FST_FD_TRACE, - PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE); + entry = filestat_new_entry(kp->ki_tracep, PS_FST_TYPE_VNODE, + PS_FST_FD_TRACE, PS_FST_FFLAG_READ | PS_FST_FFLAG_WRITE); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } /* text vnode, if one */ if (kp->ki_textvp) { - entry = filestat_new_entry(kp->ki_textvp, PS_FST_TYPE_VNODE, PS_FST_FD_TEXT, - PS_FST_FFLAG_READ); + entry = filestat_new_entry(kp->ki_textvp, PS_FST_TYPE_VNODE, + PS_FST_FD_TEXT, PS_FST_FFLAG_READ); if (entry != NULL) STAILQ_INSERT_TAIL(head, entry, next); } @@ -440,8 +440,6 @@ procstat_getfiles_kvm(kvm_t *kd, struct break; #endif default: - warnx("unknown file type %d for file %d", - file.f_type, i); continue; } entry = filestat_new_entry(data, type, i, @@ -672,7 +670,8 @@ procstat_get_vnode_info_kvm(kvm_t *kd, s vn->vn_type = vntype2psfsttype(vnode.v_type); if (vnode.v_type == VNON || vnode.v_type == VBAD) return (0); - error = kvm_read_all(kd, (unsigned long)vnode.v_tag, tagstr, sizeof(tagstr)); + error = kvm_read_all(kd, (unsigned long)vnode.v_tag, tagstr, + sizeof(tagstr)); if (error == 0) { warnx("can't read v_tag at %p", (void *)vp); goto fail; From owner-svn-src-projects@FreeBSD.ORG Fri Jul 17 02:28:27 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE66F106564A; Fri, 17 Jul 2009 02:28:27 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9CEEC8FC08; Fri, 17 Jul 2009 02:28:27 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6H2SRXg051581; Fri, 17 Jul 2009 02:28:27 GMT (envelope-from gonzo@svn.freebsd.org) Received: (from gonzo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6H2SRLu051579; Fri, 17 Jul 2009 02:28:27 GMT (envelope-from gonzo@svn.freebsd.org) Message-Id: <200907170228.n6H2SRLu051579@svn.freebsd.org> From: Oleksandr Tymoshenko Date: Fri, 17 Jul 2009 02:28:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195732 - projects/mips/sys/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2009 02:28:27 -0000 Author: gonzo Date: Fri Jul 17 02:28:27 2009 New Revision: 195732 URL: http://svn.freebsd.org/changeset/base/195732 Log: - Add DES and Blowfish implementstions to build. Required by crypto(4) Modified: projects/mips/sys/conf/files.mips Modified: projects/mips/sys/conf/files.mips ============================================================================== --- projects/mips/sys/conf/files.mips Thu Jul 16 22:33:21 2009 (r195731) +++ projects/mips/sys/conf/files.mips Fri Jul 17 02:28:27 2009 (r195732) @@ -73,6 +73,8 @@ mips/mips/support.S standard mips/mips/sys_machdep.c standard mips/mips/swtch.S standard mips/mips/uio_machdep.c standard +crypto/blowfish/bf_enc.c optional crypto | ipsec +crypto/des/des_enc.c optional crypto | ipsec | netsmb geom/geom_bsd.c optional geom_bsd geom/geom_bsd_enc.c optional geom_bsd geom/geom_mbr.c optional geom_mbr