[hackers] [quark] Do not remove existing socket file || Quentin Rameau

From: <git_AT_suckless.org>
Date: Tue, 25 Jul 2017 22:42:17 +0200 (CEST)

commit ecb0d9e54ee87c488923372e5a0ccb7c052fbce1
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Mon Jul 24 17:43:35 2017 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Jul 25 22:42:13 2017 +0200

    Do not remove existing socket file
    
    Check for its presence and bail out if found.
    If the socket file is present, either a server is already bound to it,
    or the last one errored out and we'd want to inspect this.
    Also it could be an unrelated file given by error.

diff --git a/quark.c b/quark.c
index 11db5be..a201f54 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -938,10 +938,8 @@ getusock(char *udsname, uid_t uid, gid_t gid)
         }
         memcpy(addr.sun_path, udsname, udsnamelen + 1);
 
- unlink(udsname);
-
         if (bind(insock, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
- die("%s: bind: %s\n", argv0, strerror(errno));
+ die("%s: bind %s: %s\n", argv0, udsname, strerror(errno));
         }
 
         if (listen(insock, SOMAXCONN) < 0) {
_AT_@ -1017,6 +1015,11 @@ main(int argc, char *argv[])
                 usage();
         }
 
+ if (udsname && (!access(udsname, F_OK) || errno != ENOENT)) {
+ die("%s: socket file: %s\n",
+ argv0, errno ? strerror(errno) : "file exists");
+ }
+
         /* compile and check the supplied vhost regexes */
         if (vhosts) {
                 for (i = 0; i < LEN(vhost); i++) {
Received on Tue Jul 25 2017 - 22:42:17 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 25 2017 - 22:49:42 CEST