1
0

added, username, gid, uid

This commit is contained in:
Aaron Marcher 2016-06-13 18:49:50 +02:00 committed by Aaron Marcher (drkhsh)
parent fb524b6050
commit 16716dd130
3 changed files with 68 additions and 0 deletions

View File

@ -20,6 +20,7 @@ static unsigned int update_interval = 1;
- disk_total (disk usage in percent) [argument: mountpoint] - disk_total (disk usage in percent) [argument: mountpoint]
- disk_used (disk usage in percent) [argument: mountpoint] - disk_used (disk usage in percent) [argument: mountpoint]
- entropy (available entropy) [argument: NULL] - entropy (available entropy) [argument: NULL]
- gid (gid of current user) [argument: NULL]
- hostname [argument: NULL] - hostname [argument: NULL]
- ip (ip address) [argument: interface] - ip (ip address) [argument: interface]
- ram_free (ram usage in percent) [argument: NULL] - 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_total (ram usage in percent) [argument: NULL]
- ram_used (ram usage in percent) [argument: NULL] - ram_used (ram usage in percent) [argument: NULL]
- temp (temperature in degrees) [argument: temperature file] - 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] - vol_perc (alsa volume and mute status in percent) [argument: soundcard]
- wifi_perc (wifi signal in percent) [argument: wifi card interface name] */ - wifi_perc (wifi signal in percent) [argument: wifi card interface name] */
static const struct arg args[] = { static const struct arg args[] = {

View File

@ -8,6 +8,7 @@
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <netdb.h> #include <netdb.h>
#include <pwd.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -257,6 +258,22 @@ entropy(const char *null)
return smprintf("%d", 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 */ /* hostname */
char * char *
hostname(const char *null) hostname(const char *null)
@ -450,6 +467,51 @@ temp(const char *file)
return smprintf("%d°C", temperature / 1000); 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 */ /* alsa volume percentage */
char * char *
vol_perc(const char *soundcard) vol_perc(const char *soundcard)

View File

@ -22,6 +22,7 @@ char *disk_perc(const char *);
char *disk_total(const char *); char *disk_total(const char *);
char *disk_used(const char *); char *disk_used(const char *);
char *entropy(const char*); char *entropy(const char*);
char *gid(const char*);
char *hostname(const char *); char *hostname(const char *);
char *ip(const char *); char *ip(const char *);
char *ram_free(const char *); char *ram_free(const char *);
@ -29,5 +30,7 @@ char *ram_perc(const char *);
char *ram_used(const char *); char *ram_used(const char *);
char *ram_total(const char *); char *ram_total(const char *);
char *temp(const char *); char *temp(const char *);
char *uid(const char*);
char *username(const char*);
char *vol_perc(const char *); char *vol_perc(const char *);
char *wifi_perc(const char *); char *wifi_perc(const char *);