added, username, gid, uid
authorAaron Marcher <info@nulltime.net>
Mon, 13 Jun 2016 16:49:50 +0000 (18:49 +0200)
committerAaron Marcher (drkhsh) <info@nulltime.net>
Mon, 13 Jun 2016 16:49:50 +0000 (18:49 +0200)
config.def.h
slstatus.c
slstatus.h

index 0fa4825a490106f10d298456ed0373f93ff5e454..b272a66898efe59a57efde21209f22ca7133f67c 100644 (file)
@@ -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[] = {
index 7af71e06a001deaba030136923a20e38ee97e4d5..6d56000825a0936616735df0b3f88445a7ffe5d9 100644 (file)
@@ -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)
index 7d764abf7b2ecf7d46495aea84f391650ef320bc..9009dab81b332a7141a6c5f62a616e8ddd9a3ce2 100644 (file)
@@ -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 *);