1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | diff --git a/sta/Makefile b/sta/Makefile
index feddd90..4af8b16 100644
--- a/sta/Makefile
+++ b/sta/Makefile
@@ -5,7 +5,7 @@ config.h:
cp config.def.h config.h
install: build
- cp sta /usr/local/bin
+ install -m 755 sta /usr/local/bin/sta
uninstall:
rm -f /usr/local/bin/sta
diff --git a/sta/config.def.h b/sta/config.def.h
index 7fe84e6..98e7a21 100644
--- a/sta/config.def.h
+++ b/sta/config.def.h
@@ -8,14 +8,14 @@
static const Args commands[] = {
// format command id delay
{run_command , " %s " , "date +%H:%M", 1, 60*1000},
- {run_command , " %s ", "date +'%b %d'", 2, 60*1000},
+ {run_command , " %s ", "date +'%b %d'", 2, 60*1000},
{battery_state, " %s " , "BAT1", 3, 1000},
{battery_perc , " %s% │", "BAT1", 4, 60*2000},
- {run_command , " %s │", "brightnessctl | grep Current | awk '{print $4}' | tr -d '()'", 5, 0},
+ {run_command , " %s │" , "brightnessctl | grep Current | awk '{print $4}' | tr -d '()'", 5, 0},
{run_command , " %s │" , "pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}' | head -n1", 6, 0},
- {cpu_perc , " %s% /" , NULL, 7, 1000},
- {temp , " %s │" , "/sys/class/thermal/thermal_zone3/temp", 8, 1000},
{ram_used , " %s │" , NULL, 9, 1000},
{disk_perc , " %s% │", "/home/", 10, 60*1000},
{wifi_essid , " %s │" , "wlan0", 11, 60*1000},
+ {run_command , " %s " , "python /home/pixel/.src/scripts/server.py", 12, 1000},
+
};
diff --git a/sta/sta.c b/sta/sta.c
index a69c75d..4451de8 100644
--- a/sta/sta.c
+++ b/sta/sta.c
@@ -5,7 +5,6 @@
#include <unistd.h>
#include <pthread.h>
#include <string.h>
-#include <signal.h>
#include <errno.h>
#define SOCKET_PATH "/tmp/sta.sock"
@@ -58,7 +57,7 @@ void add_pro(Pros *list, int id, char *name)
list->count++;
list->process = realloc(list->process, sizeof(Pro) * list->count);
if (!list->process) {
- warn("Memory", "memory allocation failed.");
+ warn("Memory: memory allocation failed.");
exit(1);
}
list->process[list->count - 1].name = strdup(name);
@@ -108,13 +107,6 @@ void append(Args *command, Pros *list)
show_pros(list);
}
-void clean_up(int s)
-{
- (void)s;
- unlink(SOCKET_PATH);
- exit(0);
-}
-
void *worker(void *arg)
{
Potato *data = arg;
@@ -130,10 +122,6 @@ void *worker(void *arg)
void run_server(struct sockaddr_un *addr, int sock, Pros *list)
{
- signal(SIGTERM, clean_up);
- signal(SIGINT, clean_up);
- unlink(SOCKET_PATH);
-
int cmds = sizeof(commands) / sizeof(commands[0]);
pthread_t tids[cmds];
for (int i = 0; i < cmds; ++i) {
@@ -148,10 +136,10 @@ void run_server(struct sockaddr_un *addr, int sock, Pros *list)
}
if (bind(sock, (struct sockaddr *)addr, sizeof(*addr)) < 0)
- warn("Bind", "failed: %s", strerror(errno));
+ warn("Bind: failed: %s", strerror(errno));
if (listen(sock, 5) < 0)
- warn("Listen", "failed: %s", strerror(errno));
+ warn("Listen failed: %s", strerror(errno));
while (1) {
int client = accept(sock, NULL, NULL);
@@ -215,7 +203,7 @@ void run_client(int argc, char const *argv[], struct sockaddr_un *addr, int sock
}
if (connect(sock, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
- warn("Connect", "failed: %s", strerror(errno));
+ warn("Connect: failed: %s", strerror(errno));
return;
}
write(sock, buf, strlen(buf));
@@ -229,18 +217,17 @@ int main(int argc, char const *argv[])
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
- warn("Socket", "failed to create socket: %s", strerror(errno));
+ warn("Socket: failed to create socket: %s", strerror(errno));
Pros *list = init();
for (int i = 1; i < argc; ++i) {
- if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--server")) {
+ if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--server") == 0) {
if (access(SOCKET_PATH, F_OK) == 0){
if ( connect(sock, (struct sockaddr *)&addr, sizeof(addr) ) == 0 )
- unlink(SOCKET_PATH);
- else
- die("ERROR: socket exists in " SOCKET_PATH);
- }
+ die("Socket: socket exists and connectable.");
+ }else
+ unlink(SOCKET_PATH);
run_server(&addr, sock, list);
}
}
|