⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.c

📁 linux进程跟踪的工具和源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> * 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. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * *	$Id: system.c,v 1.19 2001/02/19 13:35:53 wichert Exp $ */#include "defs.h"#ifdef LINUX#define _LINUX_SOCKET_H#define _LINUX_FS_H#define MS_RDONLY   1  /* Mount read-only */#define MS_NOSUID   2  /* Ignore suid and sgid bits */#define MS_NODEV    4  /* Disallow access to device special files */#define MS_NOEXEC   8  /* Disallow program execution */#define MS_SYNCHRONOUS 16  /* Writes are synced at once */#define MS_REMOUNT 32  /* Alter flags of a mounted FS */#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <sys/syscall.h>#ifdef SYS_personality/* Workaround for kernel namespace pollution. */#define _LINUX_PTRACE_H/* Yuck yuck yuck.  We can't include linux/ptrace.h, but personality.h   makes a declaration with struct pt_regs, which is defined there. */struct pt_regs;#define sys_personality kernel_sys_personality#include <linux/personality.h>#undef sys_personality#endif /* SYS_personality */#ifdef SYS_capget#include <linux/capability.h>#endif#ifdef SYS_cacheflush#include <asm/cachectl.h>#endif#include <linux/sysctl.h>static struct xlat mount_flags[] = {	{ MS_RDONLY,	"MS_RDONLY"	},	{ MS_NOSUID,	"MS_NOSUID"	},	{ MS_NODEV,	"MS_NODEV"	},	{ MS_NOEXEC,	"MS_NOEXEC"	},#ifdef MS_SYNCHRONOUS	{ MS_SYNCHRONOUS,"MS_SYNCHRONOUS"},#else	{ MS_SYNC,	"MS_SYNC"	},#endif	{ MS_REMOUNT,	"MS_REMOUNT"	},	{ 0,		NULL		},};intsys_mount(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printpath(tcp, tcp->u_arg[0]);		tprintf(", ");		printpath(tcp, tcp->u_arg[1]);		tprintf(", ");		printpath(tcp, tcp->u_arg[2]);		tprintf(", ");		printflags(mount_flags, tcp->u_arg[3]);		tprintf(", %#lx", tcp->u_arg[4]);	}	return 0;}intsys_umount2(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printstr(tcp, tcp->u_arg[0], -1);		tprintf(", ");		if (tcp->u_arg[1] & 1)			tprintf("MNT_FORCE");		else			tprintf("0");	}	return 0;}static struct xlat personality_options[] = {#ifdef PER_LINUX	{ PER_LINUX,	"PER_LINUX"	},#endif#ifdef PER_LINUX_32BIT	{ PER_LINUX_32BIT,	"PER_LINUX"	},#endif#ifdef PER_SVR4	{ PER_SVR4,	"PER_SVR4"	},#endif#ifdef PER_SVR3	{ PER_SVR3,	"PER_SVR3"	},#endif#ifdef PER_SCOSVR3	{ PER_SCOSVR3,	"PER_SCOSVR3"	},#endif#ifdef PER_WYSEV386	{ PER_WYSEV386,	"PER_WYSEV386"	},#endif#ifdef PER_ISCR4	{ PER_ISCR4,	"PER_ISCR4"	},#endif#ifdef PER_BSD	{ PER_BSD,	"PER_BSD"	},#endif#ifdef PER_XENIX	{ PER_XENIX,	"PER_XENIX"	},#endif	{ 0,		NULL		},};intsys_personality(tcp)struct tcb *tcp;{	if (entering(tcp))		printxval(personality_options, tcp->u_arg[0], "PER_???");	return 0;}#include <linux/reboot.h>static struct xlat bootflags1[] = {	{ LINUX_REBOOT_MAGIC1,	"LINUX_REBOOT_MAGIC1"	},	{ 0,			NULL			},};static struct xlat bootflags2[] = {	{ LINUX_REBOOT_MAGIC2,	"LINUX_REBOOT_MAGIC2"	},	{ LINUX_REBOOT_MAGIC2A,	"LINUX_REBOOT_MAGIC2A"	},	{ LINUX_REBOOT_MAGIC2B,	"LINUX_REBOOT_MAGIC2B"	},	{ 0,			NULL			},};static struct xlat bootflags3[] = {	{ LINUX_REBOOT_CMD_CAD_OFF,	"LINUX_REBOOT_CMD_CAD_OFF"	},	{ LINUX_REBOOT_CMD_RESTART,	"LINUX_REBOOT_CMD_RESTART"	},	{ LINUX_REBOOT_CMD_HALT,	"LINUX_REBOOT_CMD_HALT"		},	{ LINUX_REBOOT_CMD_CAD_ON,	"LINUX_REBOOT_CMD_CAD_ON"	},	{ LINUX_REBOOT_CMD_POWER_OFF,	"LINUX_REBOOT_CMD_POWER_OFF"	},	{ LINUX_REBOOT_CMD_RESTART2,	"LINUX_REBOOT_CMD_RESTART2"	},	{ 0,				NULL				},};intsys_reboot(tcp)struct tcb *tcp;{	if (entering(tcp)) {		if (!printflags(bootflags1, tcp->u_arg[0]))			tprintf("LINUX_REBOOT_MAGIC???");		tprintf(", ");		if (!printflags(bootflags2, tcp->u_arg[1]))			tprintf("LINUX_REBOOT_MAGIC???");		tprintf(", ");		if (!printflags(bootflags3, tcp->u_arg[2]))			tprintf("LINUX_REBOOT_CMD_???");		if (tcp->u_arg[2] == LINUX_REBOOT_CMD_RESTART2) {			tprintf(", ");			printstr(tcp, tcp->u_arg[3], -1);		}	}	return 0;}#ifdef M68Kstatic struct xlat cacheflush_scope[] = {#ifdef FLUSH_SCOPE_LINE	{ FLUSH_SCOPE_LINE,	"FLUSH_SCOPE_LINE" },#endif#ifdef FLUSH_SCOPE_PAGE	{ FLUSH_SCOPE_PAGE,	"FLUSH_SCOPE_PAGE" },#endif#ifdef FLUSH_SCOPE_ALL	{ FLUSH_SCOPE_ALL,	"FLUSH_SCOPE_ALL" },#endif	{ 0,			NULL },};static struct xlat cacheflush_flags[] = {#ifdef FLUSH_CACHE_BOTH	{ FLUSH_CACHE_BOTH,	"FLUSH_CACHE_BOTH" },#endif#ifdef FLUSH_CACHE_DATA	{ FLUSH_CACHE_DATA,	"FLUSH_CACHE_DATA" },#endif#ifdef FLUSH_CACHE_INSN	{ FLUSH_CACHE_INSN,	"FLUSH_CACHE_INSN" },#endif	{ 0,			NULL },};intsys_cacheflush(tcp)struct tcb *tcp;{	if (entering(tcp)) {		/* addr */		tprintf("%#lx, ", tcp->u_arg[0]);		/* scope */		printxval(cacheflush_scope, tcp->u_arg[1], "FLUSH_SCOPE_???");		tprintf(", ");		/* flags */		printflags(cacheflush_flags, tcp->u_arg[2]);		/* len */		tprintf(", %lu", tcp->u_arg[3]);	}	return 0;}#endif /* M68K */#endif /* LINUX */#ifdef SUNOS4#include <sys/reboot.h>#define NFSCLIENT#define LOFS#define RFS#define PCFS#include <sys/mount.h>#include <sys/socket.h>#include <nfs/export.h>#include <rpc/types.h>#include <rpc/auth.h>/*ARGSUSED*/intsys_sync(tcp)struct tcb *tcp;{	return 0;}static struct xlat bootflags[] = {	{ RB_AUTOBOOT,	"RB_AUTOBOOT"	},	/* for system auto-booting itself */	{ RB_ASKNAME,	"RB_ASKNAME"	},	/* ask for file name to reboot from */	{ RB_SINGLE,	"RB_SINGLE"	},	/* reboot to single user only */	{ RB_NOSYNC,	"RB_NOSYNC"	},	/* dont sync before reboot */	{ RB_HALT,	"RB_HALT"	},	/* don't reboot, just halt */	{ RB_INITNAME,	"RB_INITNAME"	},	/* name given for /etc/init */	{ RB_NOBOOTRC,	"RB_NOBOOTRC"	},	/* don't run /etc/rc.boot */	{ RB_DEBUG,	"RB_DEBUG"	},	/* being run under debugger */	{ RB_DUMP,	"RB_DUMP"	},	/* dump system core */	{ RB_WRITABLE,	"RB_WRITABLE"	},	/* mount root read/write */	{ RB_STRING,	"RB_STRING"	},	/* pass boot args to prom monitor */	{ 0,		NULL		},};intsys_reboot(tcp)struct tcb *tcp;{	if (entering(tcp)) {		if (!printflags(bootflags, tcp->u_arg[0]))			tprintf("RB_???");		if (tcp->u_arg[0] & RB_STRING) {			printstr(tcp, tcp->u_arg[1], -1);		}	}	return 0;}intsys_sysacct(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printstr(tcp, tcp->u_arg[0], -1);	}	return 0;}intsys_swapon(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printstr(tcp, tcp->u_arg[0], -1);	}	return 0;}intsys_nfs_svc(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printsock(tcp, tcp->u_arg[0]);	}	return 0;}static struct xlat mountflags[] = {	{ M_RDONLY,	"M_RDONLY"	},	{ M_NOSUID,	"M_NOSUID"	},	{ M_NEWTYPE,	"M_NEWTYPE"	},	{ M_GRPID,	"M_GRPID"	},#ifdef	M_REMOUNT	{ M_REMOUNT,	"M_REMOUNT"	},#endif#ifdef	M_NOSUB	{ M_NOSUB,	"M_NOSUB"	},#endif#ifdef	M_MULTI	{ M_MULTI,	"M_MULTI"	},#endif#ifdef	M_SYS5	{ M_SYS5,	"M_SYS5"	},#endif	{ 0,		NULL		},};static struct xlat nfsflags[] = {	{ NFSMNT_SOFT,		"NFSMNT_SOFT"		},	{ NFSMNT_WSIZE,		"NFSMNT_WSIZE"		},	{ NFSMNT_RSIZE,		"NFSMNT_RSIZE"		},	{ NFSMNT_TIMEO,		"NFSMNT_TIMEO"		},	{ NFSMNT_RETRANS,	"NFSMNT_RETRANS"	},	{ NFSMNT_HOSTNAME,	"NFSMNT_HOSTNAME"	},	{ NFSMNT_INT,		"NFSMNT_INT"		},	{ NFSMNT_NOAC,		"NFSMNT_NOAC"		},	{ NFSMNT_ACREGMIN,	"NFSMNT_ACREGMIN"	},	{ NFSMNT_ACREGMAX,	"NFSMNT_ACREGMAX"	},	{ NFSMNT_ACDIRMIN,	"NFSMNT_ACDIRMIN"	},	{ NFSMNT_ACDIRMAX,	"NFSMNT_ACDIRMAX"	},#ifdef	NFSMNT_SECURE	{ NFSMNT_SECURE,	"NFSMNT_SECURE"		},#endif#ifdef	NFSMNT_NOCTO	{ NFSMNT_NOCTO,		"NFSMNT_NOCTO"		},#endif#ifdef	NFSMNT_POSIX	{ NFSMNT_POSIX,		"NFSMNT_POSIX"		},#endif	{ 0,			NULL			},};intsys_mount(tcp)struct tcb *tcp;{	char type[4];	if (entering(tcp)) {		if (!(tcp->u_arg[2] & M_NEWTYPE) || umovestr(tcp,				tcp->u_arg[0],  sizeof type, type) < 0) {			tprintf("OLDTYPE:#%lx", tcp->u_arg[0]);		} else {			tprintf("\"%s\", ", type);		}		printstr(tcp, tcp->u_arg[1], -1);		tprintf(", ");		if (!printflags(mountflags, tcp->u_arg[2] & ~M_NEWTYPE))			tprintf("0");		tprintf(", ");		if (strcmp(type, "4.2") == 0) {			struct ufs_args a;			if (umove(tcp, tcp->u_arg[3], &a) < 0)				return 0;			printstr(tcp, (int)a.fspec, -1);		} else if (strcmp(type, "lo") == 0) {			struct lo_args a;			if (umove(tcp, tcp->u_arg[3], &a) < 0)				return 0;			printstr(tcp, (int)a.fsdir, -1);		} else if (strcmp(type, "nfs") == 0) {			struct nfs_args a;			if (umove(tcp, tcp->u_arg[3], &a) < 0)				return 0;			tprintf("[");			printsock(tcp, (int) a.addr);			tprintf(", ");			if (!printflags(nfsflags, a.flags))				tprintf("NFSMNT_???");			tprintf(", ws:%u,rs:%u,to:%u,re:%u,",				a.wsize, a.rsize, a.timeo, a.retrans);			if (a.flags & NFSMNT_HOSTNAME && a.hostname)				printstr(tcp, (int)a.hostname, -1);			else				tprintf("%#lx", (unsigned long) a.hostname);			tprintf(",reg-min:%u,max:%u,dir-min:%u,max:%u,",				a.acregmin, a.acregmax, a.acdirmin, a.acdirmax);			if ((a.flags & NFSMNT_SECURE) && a.netname)				printstr(tcp, (int) a.netname, -1);			else				tprintf("%#lx", (unsigned long) a.netname);			tprintf("]");		} else if (strcmp(type, "rfs") == 0) {			struct rfs_args a;			struct token t;			if (umove(tcp, tcp->u_arg[3], &a) < 0)				return 0;			tprintf("[");			printstr(tcp, (int)a.rmtfs, -1);			if (umove(tcp, (int)a.token, &t) < 0)				return 0;			tprintf(", %u, %s]", t.t_id, t.t_uname);		} else if (strcmp(type, "pcfs") == 0) {			struct pc_args a;			if (umove(tcp, tcp->u_arg[3], &a) < 0)				return 0;			printstr(tcp, (int)a.fspec, -1);		}	}	return 0;}intsys_unmount(tcp)struct tcb *tcp;{	if (entering(tcp)) {		printstr(tcp, tcp->u_arg[0], -1);	}	return 0;}intsys_umount(tcp)struct tcb *tcp;{	return sys_unmount(tcp);}intsys_auditsys(tcp)struct tcb *tcp;{	/* XXX - no information available */	return printargs(tcp);}static struct xlat ex_auth_flags[] = {	{ AUTH_UNIX,	"AUTH_UNIX"	},	{ AUTH_DES,	"AUTH_DES"	},	{ 0,		NULL		},};intsys_exportfs(tcp)struct tcb *tcp;{	struct export e;	int i;	if (entering(tcp)) {		printstr(tcp, tcp->u_arg[0], -1);		if (umove(tcp, tcp->u_arg[1], &e) < 0) {			tprintf("%#lx", tcp->u_arg[1]);			return 0;		}		tprintf("{fl:%u, anon:%u, ", e.ex_flags, e.ex_anon);		printxval(ex_auth_flags, e.ex_auth, "AUTH_???");		tprintf(", roots:[");		if (e.ex_auth == AUTH_UNIX) {			for (i=0; i<e.ex_u.exunix.rootaddrs.naddrs; i++) {				printsock(tcp,					(int)&e.ex_u.exunix.rootaddrs.addrvec[i]);			}			tprintf("], writers:[");			for (i=0; i<e.ex_writeaddrs.naddrs; i++) {				printsock(tcp,					(int)&e.ex_writeaddrs.addrvec[i]);			}			tprintf("]");		} else {			for (i=0; i<e.ex_u.exdes.nnames; i++) {				printsock(tcp,					(int)&e.ex_u.exdes.rootnames[i]);				tprintf(", ");			}			tprintf("], window:%u", e.ex_u.exdes.window);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -