mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 12:27:52 +00:00
Add basename support to top
The new top_name_verbose option works in most cases, but it will fail if the executable name contains spaces. Trying to parse command lines from /proc/<pid>/* turned out to be quite complex due to the many edge cases. My solution, once again, is to fall back to 1.9.x behavior. If top_name_verbose is true, use the full command line. Otherwise, use basename. Fixes #131.
This commit is contained in:
parent
99ffe6a0d6
commit
03a5cc5047
16
src/top.cc
16
src/top.cc
@ -32,7 +32,6 @@
|
||||
#include "prioqueue.h"
|
||||
#include "top.h"
|
||||
#include "logging.h"
|
||||
#include <string>
|
||||
|
||||
/* hash table size - always a power of 2 */
|
||||
#define HTABSIZE 256
|
||||
@ -487,7 +486,7 @@ struct top_data {
|
||||
|
||||
static conky::range_config_setting<unsigned int> top_name_width("top_name_width", 0,
|
||||
std::numeric_limits<unsigned int>::max(), 15, true);
|
||||
static conky::simple_config_setting<bool> top_name_verbose("top_name_verbose", false, false);
|
||||
static conky::simple_config_setting<bool> top_name_verbose("top_name_verbose", false, true);
|
||||
|
||||
static void print_top_name(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
@ -497,13 +496,14 @@ static void print_top_name(struct text_object *obj, char *p, int p_max_size)
|
||||
if (!td || !td->list || !td->list[td->num])
|
||||
return;
|
||||
|
||||
std::string top_name = td->list[td->num]->name;
|
||||
if (!top_name_verbose.get(*state)) {
|
||||
top_name = top_name.substr(0, top_name.find_first_of(' '));
|
||||
}
|
||||
|
||||
width = MIN(p_max_size, (int)top_name_width.get(*state) + 1);
|
||||
snprintf(p, width + 1, "%-*s", width, top_name.c_str());
|
||||
if (top_name_verbose.get(*state)) {
|
||||
/* print the full command line */
|
||||
snprintf(p, width + 1, "%-*s", width, td->list[td->num]->name);
|
||||
} else {
|
||||
/* print only the basename (i.e. executable name) */
|
||||
snprintf(p, width + 1, "%-*s", width, td->list[td->num]->basename);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_top_mem(struct text_object *obj, char *p, int p_max_size)
|
||||
|
Loading…
Reference in New Issue
Block a user