summaryrefslogtreecommitdiff
path: root/sysutils/psmisc/patches/patch-af
blob: b87aeaa30281b5add59c00130229586277aeb6b3 (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
$NetBSD: patch-af,v 1.7 2020/10/06 00:19:05 mcf Exp $

Need limits.h for PATH_MAX

Fix sscanf usage bug on musl libc and uclibc (upstream commit
https://gitlab.com/psmisc/psmisc/-/commit/ca2b176889729a7347bd95b832b9a5bb39fec229)

--- src/pstree.c.orig	2000-12-18 05:59:23.000000000 +0000
+++ src/pstree.c
@@ -15,19 +15,22 @@
 #include <getopt.h>
 #include <pwd.h>
 #include <dirent.h>
+#include <limits.h>
 #include <termios.h>
+#ifdef HAVE_TERMCAP_H
 #include <termcap.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 
 #include "comm.h"
+#include "procfs.h"
 
 
 #ifndef MAX_DEPTH
 #define MAX_DEPTH    100
 #endif
-#define PROC_BASE    "/proc"
 
 /* UTF-8 defines by Johan Myreen */
 #define UTF_V	"\342\224\202\277"	/* Vertical line drawing char */
@@ -303,6 +306,7 @@ dump_tree (PROC * current, int level, in
   const struct passwd *pw;
   int lvl, i, add, offset, len, swapped, info, count, comm_len, first;
   const char *tmp, *here;
+  char tbuf[1024], *pbuf;
   char comm_tmp[5];
 
   if (!current)
@@ -327,7 +331,8 @@ dump_tree (PROC * current, int level, in
       add = out_int (rep) + 2;
       out_string ("*[");
     }
-  if (current->highlight && (tmp = tgetstr ("md", NULL)))
+  pbuf = tbuf;
+  if (current->highlight && (tmp = tgetstr ("md", &pbuf)))
     tputs (tmp, 1, putchar);
   if ((swapped = print_args) && current->argc < 0)
     out_char ('(');
@@ -366,7 +371,8 @@ dump_tree (PROC * current, int level, in
     }
   if (info || swapped)
     out_char (')');
-  if (current->highlight && (tmp = tgetstr ("me", NULL)))
+  pbuf = tbuf;
+  if (current->highlight && (tmp = tgetstr ("me", &pbuf)))
     tputs (tmp, 1, putchar);
   if (print_args)
     {
@@ -504,7 +510,7 @@ read_proc (void)
   while ((de = readdir (dir)) != NULL)
     if ((pid = atoi (de->d_name)) != 0)
       {
-	sprintf (path, "%s/%d/stat", PROC_BASE, pid);
+	sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE);
 	if ((file = fopen (path, "r")) != NULL)
 	  {
 	    empty = 0;
@@ -513,16 +519,19 @@ read_proc (void)
 		perror (path);
 		exit (1);
 	      }
+#ifdef BSD_44_PROCFS
+	    if (fscanf(file, "%s %*d %d", comm, &ppid) == 2)
+	    { { {
+#else
             fread(readbuf, BUFSIZ, 1, file) ;
             if (ferror(file) == 0) 
             {
               memset(comm, '\0', COMM_LEN+1);
               tmpptr = strrchr(readbuf, ')'); /* find last ) */
-              *tmpptr = '\0';
               /* We now have readbuf with pid and cmd, and tmpptr+2
                * with the rest */
               /*printf("readbuf: %s\n", readbuf);*/
-              if (sscanf(readbuf, "%*d (%15c", comm) == 1)
+              if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1)
               {
                 /*printf("tmpptr: %s\n", tmpptr+2);*/
                 if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1)
@@ -532,11 +541,12 @@ read_proc (void)
 		(file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy,
 		 &ppid) == 4)
 	      */
+#endif
 		if (!print_args)
 		  add_proc (comm, pid, ppid, st.st_uid, NULL, 0);
 		else
 		  {
-		    sprintf (path, "%s/%d/cmdline", PROC_BASE, pid);
+		    sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE);
 		    if ((fd = open (path, O_RDONLY)) < 0)
 		      {
 			perror (path);
@@ -641,7 +651,11 @@ main (int argc, char **argv)
     switch (c)
       {
       case 'a':
+#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE)
+	print_args = 0;
+#else
 	print_args = 1;
+#endif
 	break;
       case 'c':
 	compact = 0;