mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-16 04:02:15 +00:00
gid_name, uid_name: outsource sub object parsing and convert to callbacks.print
This commit is contained in:
parent
4ba0f9ff4f
commit
68a09f7a02
17
src/conky.c
17
src/conky.c
@ -722,6 +722,9 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
buff_in[0] = 0;
|
buff_in[0] = 0;
|
||||||
#endif /* HAVE_ICONV */
|
#endif /* HAVE_ICONV */
|
||||||
|
|
||||||
|
/* \o/ */
|
||||||
|
(void)cur;
|
||||||
|
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
obj = root.next;
|
obj = root.next;
|
||||||
while (obj && p_max_size > 0) {
|
while (obj && p_max_size > 0) {
|
||||||
@ -798,20 +801,6 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
OBJ(text) {
|
OBJ(text) {
|
||||||
snprintf(p, p_max_size, "%s", obj->data.s);
|
snprintf(p, p_max_size, "%s", obj->data.s);
|
||||||
}
|
}
|
||||||
OBJ(gid_name) {
|
|
||||||
char buf[max_user_text];
|
|
||||||
|
|
||||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
|
||||||
obj->data.s = buf;
|
|
||||||
print_gid_name(obj, p, p_max_size);
|
|
||||||
}
|
|
||||||
OBJ(uid_name) {
|
|
||||||
char buf[max_user_text];
|
|
||||||
|
|
||||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
|
||||||
obj->data.s = buf;
|
|
||||||
print_uid_name(obj, p, p_max_size);
|
|
||||||
}
|
|
||||||
OBJ(updates) {
|
OBJ(updates) {
|
||||||
snprintf(p, p_max_size, "%d", total_updates);
|
snprintf(p, p_max_size, "%d", total_updates);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
#include "tailhead.h"
|
#include "tailhead.h"
|
||||||
#include "timeinfo.h"
|
#include "timeinfo.h"
|
||||||
#include "top.h"
|
#include "top.h"
|
||||||
|
#include "user.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
|
|
||||||
#ifdef NCURSES
|
#ifdef NCURSES
|
||||||
@ -944,8 +945,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
obj->callbacks.print = &print_pid_fsgid;
|
obj->callbacks.print = &print_pid_fsgid;
|
||||||
END OBJ_ARG(gid_name, 0, "gid_name needs a gid as argument")
|
END OBJ_ARG(gid_name, 0, "gid_name needs a gid as argument")
|
||||||
extract_object_args_to_sub(obj, arg);
|
extract_object_args_to_sub(obj, arg);
|
||||||
|
obj->callbacks.print = &print_gid_name;
|
||||||
END OBJ_ARG(uid_name, 0, "uid_name needs a uid as argument")
|
END OBJ_ARG(uid_name, 0, "uid_name needs a uid as argument")
|
||||||
extract_object_args_to_sub(obj, arg);
|
extract_object_args_to_sub(obj, arg);
|
||||||
|
obj->callbacks.print = &print_uid_name;
|
||||||
END OBJ_ARG(pid_read, 0, "pid_read needs a pid as argument")
|
END OBJ_ARG(pid_read, 0, "pid_read needs a pid as argument")
|
||||||
extract_object_args_to_sub(obj, arg);
|
extract_object_args_to_sub(obj, arg);
|
||||||
obj->callbacks.print = &print_pid_read;
|
obj->callbacks.print = &print_pid_read;
|
||||||
|
14
src/user.c
14
src/user.c
@ -38,10 +38,13 @@ void print_uid_name(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
char* firstinvalid;
|
char* firstinvalid;
|
||||||
|
char objbuf[max_user_text];
|
||||||
|
|
||||||
|
generate_text_internal(objbuf, max_user_text, *obj->sub, &info);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
uid = strtol(obj->data.s, &firstinvalid, 10);
|
uid = strtol(objbuf, &firstinvalid, 10);
|
||||||
if (errno == 0 && obj->data.s != firstinvalid) {
|
if (errno == 0 && objbuf != firstinvalid) {
|
||||||
pw = getpwuid(uid);
|
pw = getpwuid(uid);
|
||||||
if(pw != NULL) {
|
if(pw != NULL) {
|
||||||
snprintf(p, p_max_size, "%s", pw->pw_name);
|
snprintf(p, p_max_size, "%s", pw->pw_name);
|
||||||
@ -57,10 +60,13 @@ void print_gid_name(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
struct group *grp;
|
struct group *grp;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
char* firstinvalid;
|
char* firstinvalid;
|
||||||
|
char objbuf[max_user_text];
|
||||||
|
|
||||||
|
generate_text_internal(objbuf, max_user_text, *obj->sub, &info);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
gid = strtol(obj->data.s, &firstinvalid, 10);
|
gid = strtol(objbuf, &firstinvalid, 10);
|
||||||
if (errno == 0 && obj->data.s != firstinvalid) {
|
if (errno == 0 && objbuf != firstinvalid) {
|
||||||
grp = getgrgid(gid);
|
grp = getgrgid(gid);
|
||||||
if(grp != NULL) {
|
if(grp != NULL) {
|
||||||
snprintf(p, p_max_size, "%s", grp->gr_name);
|
snprintf(p, p_max_size, "%s", grp->gr_name);
|
||||||
|
@ -28,5 +28,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _USER_H
|
||||||
|
#define _USER_H
|
||||||
|
|
||||||
void print_gid_name(struct text_object *obj, char *p, int p_max_size);
|
void print_gid_name(struct text_object *obj, char *p, int p_max_size);
|
||||||
void print_uid_name(struct text_object *obj, char *p, int p_max_size);
|
void print_uid_name(struct text_object *obj, char *p, int p_max_size);
|
||||||
|
|
||||||
|
#endif /* _USER_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user