mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 01:57:09 +00:00
Add support for basenames (short executable names)
Since we now store a full command line for each process, a few problems are apparent. For example, the names displayed by ${top ...} are verbose. This has been partially addressed by the top_name_verbose option, but it is broken whenever an executable name contains spaces. Another example is ${if_running}, which only matches the input if it exactly matches the entire command line. This commit adds a basename (i.e. executable filename) entry to the process struct. The intention is to store the executable filename from /proc/<pid>/stat, which was the old 1.9.x behavior. This way, we have the best of both worlds. Those who like the full command line can have it, and those who prefer the old way can be satisfied too.
This commit is contained in:
parent
2a778374a5
commit
d8ff24a6f0
@ -2628,6 +2628,7 @@ static void process_parse_stat(struct process *process)
|
||||
{
|
||||
char line[BUFFER_LEN] = { 0 }, filename[BUFFER_LEN], procname[BUFFER_LEN];
|
||||
char cmdline[BUFFER_LEN] = { 0 }, cmdline_filename[BUFFER_LEN], cmdline_procname[BUFFER_LEN];
|
||||
char basename[BUFFER_LEN] = { 0 };
|
||||
char tmpstr[BUFFER_LEN] = { 0 };
|
||||
char state[4];
|
||||
int ps, cmdline_ps;
|
||||
@ -2722,6 +2723,7 @@ static void process_parse_stat(struct process *process)
|
||||
rc = MIN((unsigned)(rparen - lparen - 1), sizeof(procname) - 1);
|
||||
strncpy(procname, lparen + 1, rc);
|
||||
procname[rc] = '\0';
|
||||
strncpy(basename, procname, strlen(procname) + 1);
|
||||
|
||||
if (strlen(procname) < strlen(cmdline_procname))
|
||||
strncpy(procname, cmdline_procname, strlen(cmdline_procname) + 1);
|
||||
@ -2770,7 +2772,9 @@ static void process_parse_stat(struct process *process)
|
||||
}
|
||||
|
||||
free_and_zero(process->name);
|
||||
free_and_zero(process->basename);
|
||||
process->name = strndup(procname, text_buffer_size.get(*::state));
|
||||
process->basename = strndup(basename, text_buffer_size.get(*::state));
|
||||
process->rss *= getpagesize();
|
||||
|
||||
process->total_cpu_time = process->user_time + process->kernel_time;
|
||||
|
@ -117,6 +117,7 @@ void free_all_processes(void)
|
||||
while (pr) {
|
||||
next = pr->next;
|
||||
free_and_zero(pr->name);
|
||||
free_and_zero(pr->basename);
|
||||
free(pr);
|
||||
pr = next;
|
||||
}
|
||||
@ -165,6 +166,7 @@ static struct process *new_process(pid_t pid)
|
||||
|
||||
p->pid = pid;
|
||||
p->name = 0;
|
||||
p->basename = 0;
|
||||
p->amount = 0;
|
||||
p->user_time = 0;
|
||||
p->total = 0;
|
||||
@ -230,6 +232,7 @@ static void delete_process(struct process *p)
|
||||
first_process = p->next;
|
||||
|
||||
free_and_zero(p->name);
|
||||
free_and_zero(p->basename);
|
||||
/* remove the process from the hash table */
|
||||
unhash_process(p);
|
||||
free(p);
|
||||
|
Loading…
Reference in New Issue
Block a user