From 8f88961c748766097b125dab7667c6e0b665d155 Mon Sep 17 00:00:00 2001 From: Marc Payne Date: Wed, 26 Aug 2015 13:16:27 -0600 Subject: [PATCH] Do not try to remove kdeinit: from process name When we parse /proc//* in order to populate the process struct, it isn't necessary to try to remove any instance of "kdeinit: " anymore (IMO). Here is why: * If the user chooses to display full command lines (top_name_verbose = true), then we should show full command lines without stripping useful info. * The new basename entry already has a stripped down command. For example, if the command line is "kdeinit4: kded4 [kdeinit]", then basename is "kded4". * The code does not account for "kdeinit{4,5}: ", resulting in undesired behavior, e.g. "kdeinit4: kded4 [kdeinit]" becomes "kdeinit4:". * The code does not account for NUL separated arguments. * The code opens /proc//cmdline a second time, so this commit is a minor optimization. I think it is best to remove this code altogether. If anyone disagrees, please comment or send me some hate mail with reasons why we should keep it. The commit is easy enough to revert. :) --- src/linux.cc | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/linux.cc b/src/linux.cc index 28d149f7..181da2f4 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -2739,38 +2739,6 @@ static void process_parse_stat(struct process *process) if (state[0] == 'R') ++ info.run_procs; - /* remove any "kdeinit: " */ - if (procname == strstr(procname, "kdeinit")) { - snprintf(filename, sizeof(filename), PROCFS_CMDLINE_TEMPLATE, - process->pid); - - ps = open(filename, O_RDONLY); - if (ps < 0) { - /* The process must have finished in the last few jiffies! */ - return; - } - - endl = read(ps, line, BUFFER_LEN - 1); - close(ps); - if(endl < 0) - return; - line[endl] = 0; - - /* account for "kdeinit: " */ - if ((char *) line == strstr(line, "kdeinit: ")) { - r = ((char *) line) + 9; - } else { - r = (char *) line; - } - - q = procname; - /* stop at space */ - while (*r && *r != ' ') { - *q++ = *r++; - } - *q = 0; - } - free_and_zero(process->name); free_and_zero(process->basename); process->name = strndup(procname, text_buffer_size.get(*::state));