pwdx & libprocps-ng: Hurd does not have MAX_PATH defined
A patch from Debian. Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=485243 Bug-Debian: http://bugs.debian.org/588677 Backported-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
daf4014205
commit
5d29bfedc8
@ -1354,7 +1354,7 @@ proc_data_t *readproctab3 (int(*want_task)(proc_t *buf), PROCTAB *restrict const
|
|||||||
* and filled out proc_t structure.
|
* and filled out proc_t structure.
|
||||||
*/
|
*/
|
||||||
proc_t * get_proc_stats(pid_t pid, proc_t *p) {
|
proc_t * get_proc_stats(pid_t pid, proc_t *p) {
|
||||||
static char path[PATH_MAX], sbuf[1024];
|
static char path[32], sbuf[1024];
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
sprintf(path, "/proc/%d", pid);
|
sprintf(path, "/proc/%d", pid);
|
||||||
|
20
pwdx.c
20
pwdx.c
@ -35,7 +35,6 @@ static void version(void)
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
static char buf[PATH_MAX+1]; // null terminate string via static
|
|
||||||
regex_t re;
|
regex_t re;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -59,6 +58,8 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (regexec(&re, argv[i], 0, NULL, 0) != 0) {
|
if (regexec(&re, argv[i], 0, NULL, 0) != 0) {
|
||||||
|
/* Constant 27 is the length of the error string "pwdx: ... " */
|
||||||
|
char buf[27 + strlen (argv[i]) + 1];
|
||||||
snprintf(buf, sizeof buf, "pwdx: invalid process id: %s\n", argv[i]);
|
snprintf(buf, sizeof buf, "pwdx: invalid process id: %s\n", argv[i]);
|
||||||
buf[sizeof(buf)-1] = '\0';
|
buf[sizeof(buf)-1] = '\0';
|
||||||
die(buf);
|
die(buf);
|
||||||
@ -69,9 +70,14 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
regfree(&re);
|
regfree(&re);
|
||||||
|
|
||||||
|
int alloclen = 128;
|
||||||
|
char *pathbuf = malloc(alloclen);
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
char * s = buf;
|
char * s;
|
||||||
int len;
|
int len;
|
||||||
|
/* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
|
||||||
|
char buf[10 + strlen(argv[i]) + 1];
|
||||||
|
|
||||||
// At this point, all arguments are in the form /proc/nnnn
|
// At this point, all arguments are in the form /proc/nnnn
|
||||||
// or nnnn, so a simple check based on the first char is
|
// or nnnn, so a simple check based on the first char is
|
||||||
@ -83,10 +89,16 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// buf contains /proc/nnnn/cwd symlink name on entry, the
|
// buf contains /proc/nnnn/cwd symlink name on entry, the
|
||||||
// target of that symlink on return
|
// target of that symlink on return
|
||||||
if ((len = readlink(buf, buf, PATH_MAX)) < 0) {
|
while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
|
||||||
|
alloclen *= 2;
|
||||||
|
pathbuf = realloc(pathbuf, alloclen);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len < 0) {
|
||||||
s = strerror(errno == ENOENT ? ESRCH : errno);
|
s = strerror(errno == ENOENT ? ESRCH : errno);
|
||||||
} else {
|
} else {
|
||||||
buf[len] = 0;
|
pathbuf[len] = 0;
|
||||||
|
s = pathbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s: %s\n", argv[i], s);
|
printf("%s: %s\n", argv[i], s);
|
||||||
|
Loading…
Reference in New Issue
Block a user