1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

Add support for $distribution

This commit is contained in:
Nikolas Garofil 2010-04-15 16:05:42 +02:00
parent a734f86071
commit 5ef6de8822
5 changed files with 37 additions and 1 deletions

View File

@ -33,6 +33,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include "text_object.h" #include "text_object.h"
char* readfile(const char* filename, int* total_read, char showerror);
void print_to_bytes(struct text_object *, char *, int); void print_to_bytes(struct text_object *, char *, int);
void add_update_callback(void (*func)(void)); void add_update_callback(void (*func)(void));

View File

@ -1037,6 +1037,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long
END OBJ(processes, &update_total_processes) END OBJ(processes, &update_total_processes)
obj->callbacks.print = &print_processes; obj->callbacks.print = &print_processes;
#ifdef __linux__ #ifdef __linux__
END OBJ(distribution, 0)
obj->callbacks.print = &print_distribution;
END OBJ(running_processes, &update_top) END OBJ(running_processes, &update_top)
top_running = 1; top_running = 1;
obj->callbacks.print = &print_running_processes; obj->callbacks.print = &print_running_processes;

View File

@ -2371,3 +2371,33 @@ void update_diskio(void)
update_diskio_values(&stats, total_reads, total_writes); update_diskio_values(&stats, total_reads, total_writes);
fclose(fp); fclose(fp);
} }
void print_distribution(struct text_object *obj, char *p, int p_max_size)
{
(void)obj;
int i, bytes_read;
char* buf = readfile("/proc/version", &bytes_read, 1);
snprintf(p, p_max_size, "Unknown");
if(buf) {
/* I am assuming the distribution name is the first string in /proc/version that:
- is preceded by a '('
- starts with a capital
- is followed by a space and a number
but i am not sure if this is always true... */
for(i=1; i<bytes_read; i++) {
if(buf[i-1] == '(' && buf[i] >= 'A' && buf[i] <= 'Z') break;
}
if(i < bytes_read) {
snprintf(p, p_max_size, &buf[i]);
for(i=1; p[i]; i++) {
if(p[i-1] == ' ' && p[i] >= '0' && p[i] <= '9') {
p[i-1] = 0;
break;
}
}
}
free(buf);
}
}

View File

@ -53,4 +53,6 @@ int get_entropy_poolsize(unsigned int *);
void update_stat(void); void update_stat(void);
void print_distribution(struct text_object *, char *, int);
#endif /* _LINUX_H */ #endif /* _LINUX_H */

View File

@ -37,7 +37,7 @@
#include <dirent.h> #include <dirent.h>
#include <memory> #include <memory>
char* readfile(char* filename, int* total_read, char showerror) { char* readfile(const char* filename, int* total_read, char showerror) {
FILE* file; FILE* file;
char* buf = NULL; char* buf = NULL;
int bytes_read; int bytes_read;