diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0e56cf2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config.h
diff --git a/sta.c b/sta.c
index a69c75d..ea7b2cd 100644
--- a/sta.c
+++ b/sta.c
@@ -58,7 +58,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 +108,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 +123,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 +137,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 +204,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 +218,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);
}
}