diff options
author | Aaron Marcher <info@nulltime.net> | 2016-06-13 18:49:50 +0200 |
---|---|---|
committer | Aaron Marcher (drkhsh) <info@nulltime.net> | 2016-06-13 18:49:50 +0200 |
commit | 16716dd1307af81103b40c6a48a028d1328bbdf8 (patch) | |
tree | dcd0d37f4d8f9153438544ec9c6dba30a1b87780 | |
parent | fb524b60508dd8adee66ae30e834632fd6b4402c (diff) |
added, username, gid, uid
-rw-r--r-- | config.def.h | 3 | ||||
-rw-r--r-- | slstatus.c | 62 | ||||
-rw-r--r-- | slstatus.h | 3 |
3 files changed, 68 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index 0fa4825..b272a66 100644 --- a/config.def.h +++ b/config.def.h @@ -20,6 +20,7 @@ static unsigned int update_interval = 1; - disk_total (disk usage in percent) [argument: mountpoint] - disk_used (disk usage in percent) [argument: mountpoint] - entropy (available entropy) [argument: NULL] +- gid (gid of current user) [argument: NULL] - hostname [argument: NULL] - ip (ip address) [argument: interface] - ram_free (ram usage in percent) [argument: NULL] @@ -27,6 +28,8 @@ static unsigned int update_interval = 1; - ram_total (ram usage in percent) [argument: NULL] - ram_used (ram usage in percent) [argument: NULL] - temp (temperature in degrees) [argument: temperature file] +- uid (uid of current user) [argument: NULL] +- username (username of current user) [argument: NULL] - vol_perc (alsa volume and mute status in percent) [argument: soundcard] - wifi_perc (wifi signal in percent) [argument: wifi card interface name] */ static const struct arg args[] = { @@ -8,6 +8,7 @@ #include <limits.h> #include <locale.h> #include <netdb.h> +#include <pwd.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -257,6 +258,22 @@ entropy(const char *null) return smprintf("%d", entropy); } +/* gid */ +char * +gid(const char *null) +{ + gid_t gid; + + if ((gid = getgid()) < 0) { + fprintf(stderr, "Could no get gid."); + return smprintf("n/a"); + } else { + return smprintf("%d", gid); + } + + return smprintf("n/a"); +} + /* hostname */ char * hostname(const char *null) @@ -450,6 +467,51 @@ temp(const char *file) return smprintf("%d°C", temperature / 1000); } +/* username */ +char * +username(const char *null) +{ + register struct passwd *pw; + register uid_t uid; + + /* get the values */ + uid = geteuid (); + pw = getpwuid (uid); + + /* if it worked, return */ + if (pw) { + return smprintf("%s", pw->pw_name); + } + else { + fprintf(stderr, "Could not get username.\n"); + return smprintf("n/a"); + } + + return smprintf("n/a"); +} + +/* uid */ +char * +uid(const char *null) +{ + register uid_t uid; + + /* get the values */ + uid = geteuid (); + + /* if it worked, return */ + if (uid) { + return smprintf("%d", uid); + } + else { + fprintf(stderr, "Could not get uid.\n"); + return smprintf("n/a"); + } + + return smprintf("n/a"); +} + + /* alsa volume percentage */ char * vol_perc(const char *soundcard) @@ -22,6 +22,7 @@ char *disk_perc(const char *); char *disk_total(const char *); char *disk_used(const char *); char *entropy(const char*); +char *gid(const char*); char *hostname(const char *); char *ip(const char *); char *ram_free(const char *); @@ -29,5 +30,7 @@ char *ram_perc(const char *); char *ram_used(const char *); char *ram_total(const char *); char *temp(const char *); +char *uid(const char*); +char *username(const char*); char *vol_perc(const char *); char *wifi_perc(const char *); |