sta
minimal & simple status monitoring app.
git clone https://git.pi66.xyz/sta
About | Files | Commits | Refs | License
fix: clean up stale socket on unexpected termination
Author: pi66
Date: 2026-03-28 19:43
commit: 269cce4b
Stat
| M | sta.c | 8 | +6 | -2 |
Diff
diff --git a/sta.c b/sta.c
index b54071f..a69c75d 100644
--- a/sta.c
+++ b/sta.c
@@ -235,8 +235,12 @@ int main(int argc, char const *argv[])
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--server")) {
- if (access(SOCKET_PATH, F_OK) == 0)
- die("ERROR: socket exists in " SOCKET_PATH);
+ 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);
+ }
run_server(&addr, sock, list);
}
}