Browse Source

hostname function

master
Aaron Marcher 8 years ago
committed by Aaron Marcher (drkhsh)
parent
commit
2e72b212d3
3 changed files with 25 additions and 0 deletions
  1. +1
    -0
      config.def.h
  2. +23
    -0
      slstatus.c
  3. +1
    -0
      slstatus.h

+ 1
- 0
config.def.h View File

@@ -17,6 +17,7 @@ static unsigned int update_interval = 1;
- datetime (date and time) [argument: format]
- disk_perc (disk usage in percent) [argument: mountpoint]
- entropy (available entropy) [argument: NULL]
- hostname [argument: NULL]
- ip (ip address) [argument: interface]
- ram_perc (ram usage in percent) [argument: NULL]
- temp (temperature in degrees) [argument: temperature file]


+ 23
- 0
slstatus.c View File

@@ -208,6 +208,29 @@ entropy(const char *null)
return smprintf("%d", entropy);
}

/* hostname */
char *
hostname(const char *null)
{
char *hostname = "";
FILE *fp;

/* open hostname file */
if (!(fp = fopen("/proc/sys/kernel/hostname", "r"))) {
fprintf(stderr, "Could not open hostname file.\n");
return smprintf("n/a");
}

/* extract hostname */
fscanf(fp, "%s", hostname);

/* close hostname file */
fclose(fp);

/* return entropy */
return smprintf("%s", hostname);
}

/* ip address */
char *
ip(const char *interface)


+ 1
- 0
slstatus.h View File

@@ -19,6 +19,7 @@ char *cpu_perc(const char *);
char *datetime(const char *);
char *disk_perc(const char *);
char *entropy(const char*);
char *hostname(const char *);
char *ip(const char *);
char *ram_perc(const char *);
char *temp(const char *);


Loading…
Cancel
Save