From owner-freebsd-hackers Wed May 22 1:55: 5 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from gate.nentec.de (gate2.nentec.de [194.25.215.66]) by hub.freebsd.org (Postfix) with ESMTP id 84E2937B400 for ; Wed, 22 May 2002 01:54:49 -0700 (PDT) Received: from nenny.nentec.de (root@nenny.nentec.de [153.92.64.1]) by gate.nentec.de (8.11.3/8.9.3) with ESMTP id g4M8sll12872 for ; Wed, 22 May 2002 10:54:47 +0200 Received: from nentec.de (andromeda.nentec.de [153.92.64.34]) by nenny.nentec.de (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) with ESMTP id g4M8svZ11788 for ; Wed, 22 May 2002 10:54:57 +0200 Message-ID: <3CEB5CE1.8050002@nentec.de> Date: Wed, 22 May 2002 10:54:57 +0200 From: Andy Sporner User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:0.9.8) Gecko/20020204 X-Accept-Language: de-at, de, en, en-us MIME-Version: 1.0 To: freebsd-hackers Subject: RFC- Kernel patches for process tracking (read more in body) Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS-perl11-milter (http://amavis.org/) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi hackers, I had a need to track all processes including daemons that become owned by init that started from a process for my statistics collection function of my clustering software. The basic idea is to add a structure to the 'proc' structure to keep current and future data in and to be able to set (at least today) the application ID into this structure via a shell command using a syscall(). Please give me comments on the patches. *** /usr/src/sys/kern/kern_fork.c.orig Thu May 10 19:54:16 2001 --- /usr/src/sys/kern/kern_fork.c Thu Jan 10 16:50:25 2002 *************** *** 362,367 **** --- 362,369 ---- crhold(p1->p_ucred); uihold(p1->p_cred->p_uidinfo); + bcopy(&p1->p_csed, &p2->p_csed, sizeof(p2->p_csed)); + if (p2->p_prison) { p2->p_prison->pr_ref++; p2->p_flag |= P_JAILED; *** /usr/src/sys/sys/proc.h.orig Thu Jan 10 16:56:13 2002 --- /usr/src/sys/sys/proc.h Thu Jan 10 17:00:22 2002 *************** *** 53,58 **** --- 53,59 ---- #endif #include #include /* For struct klist */ + #include /* * One structure allocated per session. *************** *** 144,149 **** --- 145,151 ---- char p_stat; /* S* process status. */ char p_pad1[3]; + struct csed p_csed; /* Virtual Application Descriptor */ pid_t p_pid; /* Process identifier. */ LIST_ENTRY(proc) p_hash; /* Hash chain. */ LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp. */ *** /usr/src/sys/conf/files.orig Thu Jan 10 17:07:21 2002 --- /usr/src/sys/conf/files Thu Jan 10 17:07:35 2002 *************** *** 575,580 **** --- 575,581 ---- kern/subr_scanf.c standard kern/subr_taskqueue.c standard kern/subr_xxx.c standard + kern/sys_cse.c standard kern/sys_generic.c standard kern/sys_pipe.c standard kern/sys_process.c standard *** /usr/src/sys/kern/syscalls.master.orig Thu Jan 10 17:10:01 2002 --- /usr/src/sys/kern/syscalls.master Thu Jan 10 17:10:27 2002 *************** *** 520,522 **** --- 520,523 ---- const struct kevent *changelist, int nchanges, \ struct kevent *eventlist, int nevents, \ const struct timespec *timeout); } + ZZZ STD BSD { int cse_set_id(int id_num, pid_t pid); } (NOTE 'ZZZ' changed by install script to be the next available #) (HERE IS 'sys_cse.c') #include "opt_ktrace.h" #include #include #include #include #include #include #include #include #include /* * CSE system call. */ #ifndef _SYS_SYSPROTO_H_ struct cse_set_id_args { int id_num; pid_t pid; }; #endif int cse_set_id(p, uap) struct proc *p; register struct cse_set_id_args *uap; { struct proc *px; if ((px = pfind(uap->pid)) == NULL) { return (ESRCH); } px->p_csed.cse_c_id = uap->id_num; return (0); } (PATCHES TO 'PS' TO MAKE USE OF THIS) *** /usr/src/bin/ps/ps.c.orig Wed Aug 1 07:06:23 2001 --- /usr/src/bin/ps/ps.c Thu Jan 10 18:34:12 2002 *************** *** 103,109 **** static void usage __P((void)); static uid_t *getuids(const char *, int *); ! char dfmt[] = "pid tt state time command"; char jfmt[] = "user pid ppid pgid sess jobc state tt time command"; char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command"; char o1[] = "pid"; --- 103,109 ---- static void usage __P((void)); static uid_t *getuids(const char *, int *); ! char dfmt[] = "pid tt vapp state time command"; char jfmt[] = "user pid ppid pgid sess jobc state tt time command"; char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command"; char o1[] = "pid"; *** /usr/src/bin/ps/extern.h.orig Sat Aug 28 01:14:50 1999 --- /usr/src/bin/ps/extern.h Thu Jan 10 18:34:42 2002 *************** *** 59,64 **** --- 59,65 ---- void maxrss __P((KINFO *, VARENT *)); void nlisterr __P((struct nlist *)); void p_rssize __P((KINFO *, VARENT *)); + void p_vapp __P((KINFO *, VARENT *)); void pagein __P((KINFO *, VARENT *)); void parsefmt __P((char *)); void pcpu __P((KINFO *, VARENT *)); *** /usr/src/bin/ps/keyword.c.orig Wed Feb 14 19:55:31 2001 --- /usr/src/bin/ps/keyword.c Thu Jan 10 18:33:40 2002 *************** *** 185,190 **** --- 185,191 ---- {"upr", "UPR", NULL, 0, pvar, NULL, 3, POFF(p_usrpri), CHAR, "d"}, {"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN}, {"usrpri", "", "upr"}, + {"vapp", "VAPP", NULL, 0, p_vapp, NULL, 2}, {"vsize", "", "vsz"}, {"vsz", "VSZ", NULL, 0, vsize, NULL, 5}, {"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6}, *** /usr/src/bin/ps/print.c.orig Wed Sep 20 04:16:11 2000 --- /usr/src/bin/ps/print.c Thu Jan 10 18:33:13 2002 *************** *** 48,53 **** --- 48,54 ---- #include #include #include + #include #include #include *************** *** 446,451 **** --- 447,468 ---- v = ve->var; (void)printf("%*ld", v->width, (long)pgtok(KI_EPROC(k)->e_vm.vm_rssize))+ } + + void + p_vapp(k, ve) /* doesn't account for text */ + KINFO *k; + VARENT *ve; + { + VAR *v; + struct proc *p; + struct csed *c; + + p = KI_PROC(k); + c = &p->p_csed; + + v = ve->var; + (void)printf("%*ld", v->width, c->cse_c_id); } void (USERLAND CODE) #include #include #include #include #include "cse.h" void sigsys_handler(int signum); /* * * main(int argc, char **argv) * * parameters: * 0 'cse' * 1 set_id * 2 pid * 3 appid */ int main(int argc, char **argv) { int mon_status; int need_flush; signal (SIGSYS, sigsys_handler); if (argc < 3) { fprintf(stderr, "Insufficient parameters...\n"); exit (1); } /* if */ if (syscall(SYS_cse_set_id, atoi(argv[3]), atoi(argv[2])) == -1) { fprintf(stderr, "Failured to set id\n"); exit(1); } /* if */ exit (0); } /* main() */ void sigsys_handler(int signum) { fprintf(stderr, "Sorry, no kernel support for this function\n"); exit(1); } /* sigsys_handler() */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message