* fuser: Fixed typo for -M flag. Debian #740275
* pstree: by default doesn't show threadnames, use -t to show
as it disables compaction. SF [#33] Debian #815902
- * pstree: PATH_MAX defined for FreeBSD. Debian #750405
+ * pstree: Removed need for PATH_MAX Debian #750405
* pstree: ignores disappeared processes. SF [#34]
* killall: -o and -y work with -r flags. SF [#64]
* m4/gettext.m4: Upgrade to gettext-0.19.4.
#include "i18n.h"
#include "comm.h"
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif /* PATH_MAX */
-
#ifdef WITH_SELINUX
#include <selinux/selinux.h>
#else
{
FILE *file;
char *thread_comm, *endcomm, *threadname;
- char path[PATH_MAX + 1];
+ char *path = NULL;
+ size_t len = 0;
+ int nbytes;
char readbuf[BUFSIZ + 1];
if (! (threadname = malloc(COMM_LEN + 2 + 1))) {
sprintf(threadname, THREAD_FORMAT, COMM_LEN, comm);
return threadname;
}
- if (snprintf(path, PATH_MAX, "%s/%d/task/%d/stat", PROC_BASE, pid, tid) < 0)
- perror("get_threadname: asprintf");
+ len = snprintf(NULL, 0, "%s/%d/task/%d/stat", PROC_BASE, pid, tid);
+ if (len < 0)
+ exit(2);
+ len++;
+ path = malloc(len);
+ if (path == NULL)
+ exit(2);
+ nbytes = snprintf(path, len, "%s/%d/task/%d/stat", PROC_BASE, pid, tid);
+ if (nbytes < 0 || nbytes >= len)
+ perror("get_threadname: snprintf");
if ( (file = fopen(path, "r")) != NULL) {
if (fgets(readbuf, BUFSIZ, file) != NULL) {
if ((thread_comm = strchr(readbuf, '('))
*endcomm = '\0';
sprintf(threadname, THREAD_FORMAT, COMM_LEN, thread_comm);
(void) fclose(file);
+ free(path);
return threadname;
}
}
fclose(file);
}
+ free(path);
/* Fall back to old method */
sprintf(threadname, THREAD_FORMAT, COMM_LEN, comm);