trim trailing whitespace in proc_args

This commit is contained in:
Doug MacEachern 2006-08-25 20:50:47 +00:00
parent 1301c11251
commit 883cfa1586
1 changed files with 16 additions and 3 deletions

View File

@ -992,11 +992,24 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_create(procargs); sigar_proc_args_create(procargs);
while ((ptr < end) && (count-- > 0)) { while ((ptr < end) && (count-- > 0)) {
int alen = strlen(ptr)+1; int slen = strlen(ptr);
char *arg = malloc(alen); int alen = slen+1;
char *arg;
/*
* trim trailing whitespace.
* seen w/ postgresql, probably related
* to messing with argv[0]
*/
while (*(ptr + (slen-1)) == ' ') {
--slen;
}
arg = malloc(slen+1);
SIGAR_PROC_ARGS_GROW(procargs); SIGAR_PROC_ARGS_GROW(procargs);
memcpy(arg, ptr, alen); memcpy(arg, ptr, slen);
*(arg+slen) = '\0';
procargs->data[procargs->number++] = arg; procargs->data[procargs->number++] = arg;