all repos — slstatus @ 16716dd1307af81103b40c6a48a028d1328bbdf8

my build of slstatus (tools.suckless.org/slstatus/)

added, username, gid, uid
Aaron Marcher info@nulltime.net
Mon, 13 Jun 2016 18:49:50 +0200
commit

16716dd1307af81103b40c6a48a028d1328bbdf8

parent

fb524b60508dd8adee66ae30e834632fd6b4402c

3 files changed, 68 insertions(+), 0 deletions(-)

jump to
M config.def.hconfig.def.h

@@ -20,6 +20,7 @@ - disk_perc (disk usage in percent) [argument: mountpoint]

- 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 @@ - ram_perc (ram usage in percent) [argument: NULL]

- 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[] = {
M slstatus.cslstatus.c

@@ -8,6 +8,7 @@ #include <ifaddrs.h>

#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 @@ /* return entropy */

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)

@@ -449,6 +466,51 @@

/* return temperature in degrees */ 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 *
M slstatus.hslstatus.h

@@ -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 *);