]> granicus.if.org Git - psmisc/commitdiff
pslog: Define PATH_MAX if required
authorCraig Small <csmall@enc.com.au>
Mon, 13 Aug 2018 11:19:39 +0000 (21:19 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 13 Aug 2018 11:19:39 +0000 (21:19 +1000)
Hurd doesn't define PATH_MAX so we either change things to not use it
or conditionally define it.

References:
 https://bugs.debian.org/905797

ChangeLog
src/pslog.c

index f7ffbf65925c45c19a7741fe1b3bbf1288270590..e9c5c11ea7bcb6207b5a9b45994a737f3ef562f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@ Changes in 23.2
        * killall: look at all namespaces by default
        * killall: Fix -INT option parsing #11
        * killall: change to getopt_long without _only #12
+       * pslog: Define PATH_MAX if required Debian:#905797
+
 Changes in 23.1
 ===============
        * killall: Remove debug output Debian: #864753
index f6612459a92bb1535915acf55618294c4cb273e4..d60723fe51a30b9be0d8bc5301fa85a947a6aced 100644 (file)
@@ -18,6 +18,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
 
 #include <dirent.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stdio.h>
 
 #include "i18n.h"
 
 
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif /* PATH_MAX */
+
 static int
 usage ()
 {
@@ -61,6 +69,7 @@ main(int argc, char const *argv[])
 {
   regex_t re_log;
   regex_t re_pid;
+  char *fullpath = NULL;
 
   if (argc < 2) {
     usage();
@@ -100,12 +109,6 @@ main(int argc, char const *argv[])
 
   struct dirent *namelist;
 
-  char* fullpath = (char*) malloc(PATH_MAX+1);
-  if (!fullpath) {
-    perror ("malloc");
-    return 1;
-  }
-
   char* linkpath = (char*) malloc(PATH_MAX+1);
   if (!linkpath) {
     perror ("malloc");
@@ -117,17 +120,21 @@ main(int argc, char const *argv[])
   DIR *pid_dir;
 
   if (argv[1][0] != '/') {
-    strncpy(fullpath, "/proc/", PATH_MAX);
-    strncat(fullpath, argv[1], PATH_MAX - strlen(fullpath));
-    strncat(fullpath, "/fd/", PATH_MAX - strlen(fullpath));
+    if (asprintf(&fullpath, "/proc/%s/fd/", argv[1]) < 0) {
+      perror ("asprintf");
+      return 1;
+    }
   } else {
-      strncpy(fullpath, argv[1], PATH_MAX);
-      strncat(fullpath, "/fd/", PATH_MAX - strlen(fullpath));
+    if (asprintf(&fullpath, "%s/fd/", argv[1]) < 0) {
+        perror("asprintf");
+        return 1;
     }
+  }
 
   pid_dir = opendir(fullpath);
   if (!pid_dir) {
     perror("opendir");
+    free(fullpath);
     return 1;
   }