From 3decce2161c6950c3c3b10df275d8271b219648c Mon Sep 17 00:00:00 2001 From: Clifford Wolf <clifford@clifford.at> Date: Mon, 13 Jun 2005 12:38:23 +0000 Subject: [PATCH] Clifford Wolf: Better creation of command info in fl_wrapper for scripts [2005053021305425045] (https://www.rocklinux.net/submaster) git-svn-id: http://www.rocklinux.org/svn/rock-linux/trunk@6101 c5f82cb5-29bc-0310-9cd0-bff59a50e3bc --- misc/tools-source/fl_wrapper.c | 24 ++++++++++++++---------- misc/tools-source/fl_wrapper.c.sh | 25 +++++++++++++++---------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/misc/tools-source/fl_wrapper.c b/misc/tools-source/fl_wrapper.c index 4eace956e..41df7a7fc 100644 --- a/misc/tools-source/fl_wrapper.c +++ b/misc/tools-source/fl_wrapper.c @@ -865,24 +865,27 @@ static int pid2ppid(int pid) static char *getpname(int pid) { static char p[512]; - char buffer[100]=""; + char buffer[513]=""; char *arg=0, *b; int i, fd, rc; sprintf(buffer, "/proc/%d/cmdline", pid); if ( (fd = open(buffer, O_RDONLY, 0)) < 0 ) return "unkown"; - if ( (rc = read(fd, buffer, 99)) > 0) { + if ( (rc = read(fd, buffer, 512)) > 0) { buffer[rc--] = 0; for (i=0; i<rc; i++) - if (!buffer[i]) { arg = buffer+i+1; break; } + if (buffer[i] == 0 && buffer[i+1] != '-') + { arg = buffer+i+1; break; } } close(fd); b = basename(buffer); snprintf(p, 512, "%s", b); - if ( !strcmp(b, "bash") || !strcmp(b, "sh") || !strcmp(b, "perl") ) - if (arg && *arg && *arg != '-') + if ( !strcmp(b, "bash") || !strcmp(b, "sh") || + !strcmp(b, "perl") || !strcmp(b, "python") ) + if (arg && *arg && strlen(arg) < 100 && + !strchr(arg, ' ') && !strchr(arg, ';')) snprintf(p, 512, "%s(%s)", b, basename(arg)); return p; @@ -901,11 +904,12 @@ static void addptree(int *txtpos, char *cmdtxt, int pid, int basepid) p = getpname(pid); - if ( strcmp(l, p) ) - *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "%s%s", - *txtpos ? "." : "", getpname(pid)); - else - *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "*"); + if (*txtpos < 4000) + if ( strcmp(l, p) ) + *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "%s%s", + *txtpos ? "." : "", getpname(pid)); + else + *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "*"); strcpy(l, p); } diff --git a/misc/tools-source/fl_wrapper.c.sh b/misc/tools-source/fl_wrapper.c.sh index e9af2d04e..af42b5c51 100644 --- a/misc/tools-source/fl_wrapper.c.sh +++ b/misc/tools-source/fl_wrapper.c.sh @@ -233,24 +233,28 @@ static int pid2ppid(int pid) static char *getpname(int pid) { static char p[512]; - char buffer[100]=""; + char buffer[513]=""; char *arg=0, *b; int i, fd, rc; sprintf(buffer, "/proc/%d/cmdline", pid); if ( (fd = open(buffer, O_RDONLY, 0)) < 0 ) return "unkown"; - if ( (rc = read(fd, buffer, 99)) > 0) { + if ( (rc = read(fd, buffer, 512)) > 0) { buffer[rc--] = 0; for (i=0; i<rc; i++) - if (!buffer[i]) { arg = buffer+i+1; break; } + if (buffer[i] == 0 && buffer[i+1] != '-') + { arg = buffer+i+1; break; } } close(fd); b = basename(buffer); snprintf(p, 512, "%s", b); - if ( !strcmp(b, "bash") || !strcmp(b, "sh") || !strcmp(b, "perl") ) - if (arg && *arg && *arg != '-') + if ( !strcmp(b, "bash") || !strcmp(b, "sh") || + !strcmp(b, "perl") || !strcmp(b, "python") ) + if ( arg && *arg && + strlen(arg) < 100 && !strchr(arg, '\n') && + !strchr(arg, ' ') && !strchr(arg, ';') ) snprintf(p, 512, "%s(%s)", b, basename(arg)); return p; @@ -269,11 +273,12 @@ static void addptree(int *txtpos, char *cmdtxt, int pid, int basepid) p = getpname(pid); - if ( strcmp(l, p) ) - *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "%s%s", - *txtpos ? "." : "", getpname(pid)); - else - *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "*"); + if (*txtpos < 4000) + if ( strcmp(l, p) ) + *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "%s%s", + *txtpos ? "." : "", getpname(pid)); + else + *txtpos += snprintf(cmdtxt+*txtpos, 4096-*txtpos, "*"); strcpy(l, p); }