signal handling to exit gracefully + small coding style fixes
This commit is contained in:
parent
a1c962f8a3
commit
67d3f9c540
1 changed files with 21 additions and 4 deletions
19
slstatus.c
19
slstatus.c
|
@ -8,6 +8,7 @@
|
||||||
#include <linux/wireless.h>
|
#include <linux/wireless.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -62,9 +63,11 @@ static char *username(void);
|
||||||
static char *vol_perc(const char *);
|
static char *vol_perc(const char *);
|
||||||
static char *wifi_perc(const char *);
|
static char *wifi_perc(const char *);
|
||||||
static char *wifi_essid(const char *);
|
static char *wifi_essid(const char *);
|
||||||
|
static void sighandler(const int);
|
||||||
|
|
||||||
static unsigned short int delay;
|
static unsigned short int delay;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
|
static int done = 0;
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -576,6 +579,14 @@ wifi_essid(const char *wificard)
|
||||||
return smprintf("%s", (char *)wreq.u.essid.pointer);
|
return smprintf("%s", (char *)wreq.u.essid.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sighandler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGTERM || signo == SIGINT) {
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
|
@ -583,10 +594,16 @@ main(void)
|
||||||
char status_string[4096];
|
char status_string[4096];
|
||||||
char *res, *element;
|
char *res, *element;
|
||||||
struct arg argument;
|
struct arg argument;
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
|
memset(&act, 0, sizeof(act));
|
||||||
|
act.sa_handler = sighandler;
|
||||||
|
sigaction(SIGINT, &act, 0);
|
||||||
|
sigaction(SIGTERM, &act, 0);
|
||||||
|
|
||||||
dpy = XOpenDisplay(NULL);
|
dpy = XOpenDisplay(NULL);
|
||||||
|
|
||||||
for (;;) {
|
while (!done) {
|
||||||
status_string[0] = '\0';
|
status_string[0] = '\0';
|
||||||
for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) {
|
for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) {
|
||||||
argument = args[i];
|
argument = args[i];
|
||||||
|
|
Loading…
Reference in a new issue