$NetBSD: patch-ad,v 1.2 1998/08/07 11:14:07 agc Exp $ --- pstree.c.orig Tue Aug 26 17:09:05 1997 +++ pstree.c Sun Jul 19 15:20:24 1998 @@ -2,6 +2,14 @@ /* Copyright 1993-1996 Werner Almesberger. See file COPYING for details. */ +#ifdef __NetBSD__ +#define HAVE_SYS_SYSLIMITS_H +#define BSD_44_PROC +#define BSD_TERMCAP +#else /* Linux */ +#define HAVE_GETOPT_H +#define ENABLE_PRINT_ARGS +#endif #include #include @@ -9,12 +17,17 @@ #include #include #include +#ifdef HAVE_GETOPT_H #include +#endif #include #include #include #include #include +#ifdef HAVE_SYS_SYSLIMITS_H +#include +#endif #include #include @@ -251,7 +264,10 @@ CHILD *walk,*next,**scan; const struct passwd *pw; int lvl,i,add,offset,len,swapped,info,count,comm_len,first; const char *tmp,*here; +#ifdef BSD_TERMCAP + char tbuf[1024], *tbufptr; +#endif char comm_tmp[5]; if (!current) return; @@ -270,7 +286,12 @@ add = out_int(rep)+2; out_string("*["); } +#ifdef BSD_TERMCAP + tbufptr = tbuf; + if (current->highlight && (tmp = tgetstr("md",&tbufptr))) tputs(tmp,1,putchar); +#else if (current->highlight && (tmp = tgetstr("md",NULL))) tputs(tmp,1,putchar); +#endif if (swapped = print_args && current->argc < 0) out_char('('); comm_len = 0; for (here = current->comm; *here; here++) @@ -297,7 +318,12 @@ else (void) out_int(current->uid); } if (info || swapped) out_char(')'); +#ifdef BSD_TERMCAP + tbufptr = tbuf; + if (current->highlight && (tmp = tgetstr("me",&tbufptr))) tputs(tmp,1,putchar); +#else if (current->highlight && (tmp = tgetstr("me",NULL))) tputs(tmp,1,putchar); +#endif if (print_args) { for (i = 0; i < current->argc; i++) { out_char(' '); @@ -387,8 +413,10 @@ char path[PATH_MAX+1],comm[COMM_LEN+1]; char *buffer; pid_t pid,ppid; +#ifndef BSD_44_PROC int fd,size; - int empty,dummy; +#endif + int empty; if (!print_args) buffer = NULL; else if (!(buffer = malloc((size_t) (output_width+1)))) { @@ -402,17 +430,28 @@ empty = 1; while (de = readdir(dir)) if (pid = atoi(de->d_name)) { +#ifdef BSD_44_PROC + sprintf(path,"%s/%d/status",PROC_BASE,pid); +#else sprintf(path,"%s/%d/stat",PROC_BASE,pid); +#endif if (file = fopen(path,"r")) { empty = 0; if (fstat(fileno(file),&st) < 0) { perror(path); exit(1); } - if (fscanf(file,"%d (%[^)]) %c %d",&dummy,comm,(char *) &dummy, - &ppid) == 4) { +#ifdef BSD_44_PROC + if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) { +#else + if (fscanf(file,"%*d (%[^)]) %*c %d",comm,&ppid) == 2) { +#endif if (!print_args) add_proc(comm,pid,ppid,st.st_uid,NULL,0); else { +#ifdef BSD_44_PROC + /* NetBSD 1.3 /proc doesn't seem to do command-lines */ + add_proc(comm,pid,ppid,st.st_uid,buffer,0); +#else sprintf(path,"%s/%d/cmdline",PROC_BASE,pid); if ((fd = open(path,O_RDONLY)) < 0) { perror(path); @@ -426,6 +465,7 @@ (void) close(fd); if (size) buffer[size++] = 0; add_proc(comm,pid,ppid,st.st_uid,buffer,size); +#endif } } (void) fclose(file);