commit 27f8bbfac440d95ef354005d5f7353ec9f3d9294
Author:     Laslo Hunhold <d...@frign.de>
AuthorDate: Sun Aug 23 13:35:49 2020 +0200
Commit:     Laslo Hunhold <d...@frign.de>
CommitDate: Sun Aug 23 13:35:49 2020 +0200

    Refactor sock_get_uds() a bit
    
    This refines the error messages a bit and makes clearer what went
    wrong.
    
    Signed-off-by: Laslo Hunhold <d...@frign.de>

diff --git a/sock.c b/sock.c
index dd99bdb..c1fbd43 100644
--- a/sock.c
+++ b/sock.c
@@ -63,7 +63,7 @@ void
 sock_rem_uds(const char *udsname)
 {
        if (unlink(udsname) < 0) {
-               die("unlink:");
+               die("unlink '%s':", udsname);
        }
 }
 
@@ -74,7 +74,8 @@ sock_get_uds(const char *udsname, uid_t uid, gid_t gid)
                .sun_family = AF_UNIX,
        };
        size_t udsnamelen;
-       int insock, sockmode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
+       int insock, sockmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
+                              S_IROTH | S_IWOTH;
 
        if ((insock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
                die("socket:");
@@ -86,7 +87,7 @@ sock_get_uds(const char *udsname, uid_t uid, gid_t gid)
        memcpy(addr.sun_path, udsname, udsnamelen + 1);
 
        if (bind(insock, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
-               die("bind %s:", udsname);
+               die("bind '%s':", udsname);
        }
 
        if (listen(insock, SOMAXCONN) < 0) {
@@ -96,12 +97,12 @@ sock_get_uds(const char *udsname, uid_t uid, gid_t gid)
 
        if (chmod(udsname, sockmode) < 0) {
                sock_rem_uds(udsname);
-               die("chmod:");
+               die("chmod '%s':", udsname);
        }
 
        if (chown(udsname, uid, gid) < 0) {
                sock_rem_uds(udsname);
-               die("chown:");
+               die("chown '%s':", udsname);
        }
 
        return insock;

Reply via email to