summaryrefslogtreecommitdiff
path: root/sysutils/psmisc/patches/patch-ad
blob: 9468e0d2f0183eefc7a4b0e4b9f52704adb5180f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
$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 <stdlib.h>
 #include <stdio.h>
@@ -9,12 +17,17 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#endif
 #include <pwd.h>
 #include <dirent.h>
 #include <termios.h>
 #include <termcap.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_SYSLIMITS_H
+#include <sys/syslimits.h>
+#endif
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 
@@ -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);