Purpose: Don't use undefined PATH_MAX
Fixes:   Compilation on platforms not having PATH_MAX such as GNU/Hurd
Authur:  Roger Leigh
Status:  Not yet submitted upstream
---
--- a/startpar/proc.c	2012-01-28 11:37:09.325271380 +0000
+++ b/startpar/proc.c	2012-01-28 11:54:43.268729900 +0000
@@ -109,23 +109,38 @@
     char *name = (char*)0;
     struct dirent *dent;
     int fd;
+    char *path = (char *)0;
+    size_t allocpathlen = 0;
 
     fd = dirfd(dir);
     rewinddir(dir);
     while ((dent = readdir(dir))) {
-	char path[PATH_MAX];
 	struct stat st;
+	size_t pathlen = 0;
 	if (fstatat(fd, dent->d_name, &st, 0) < 0)
 	    continue;
 	if (!S_ISCHR(st.st_mode))
 	    continue;
 	if (comparedev != st.st_rdev)
 	    continue;
-	if ((size_t)snprintf(path, sizeof(path), "/dev/%s", dent->d_name) >= sizeof(path))
+	/* Space for d_name, /dev/ and nul */
+	pathlen = strlen(dent->d_name) + 6;
+	if (pathlen > allocpathlen) {
+	    char *newpath = realloc(path, sizeof(char) * pathlen);
+	    if (newpath) {
+		path = newpath;
+	        allocpathlen = pathlen;
+	    }
+	}
+	if (path == NULL)
+	    continue;
+	if ((size_t)snprintf(path, pathlen, "/dev/%s", dent->d_name) >= allocpathlen)
 	    continue;
 	name = realpath(path, NULL);
 	break;
     }
+
+    free(path);
     return name;
 }
 
