summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@gmail.com>2025-06-16 20:06:28 -0700
committerNed T. Crigler <crigler@gmail.com>2025-06-17 08:15:03 -0700
commitedb19a321c4e15e660426acb68581578a67c5576 (patch)
tree97e6bdd280b5b91bacea7f32e46b64b8ec84cf9c
parent5af437fe9c99198287eadbc877cef2a0c3202a3c (diff)
Move umask(omask) call after bind
Just wrapping the socket system call with umask doesn't work.
-rw-r--r--master.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/master.c b/master.c
index 376bd54..d5da2c3 100644
--- a/master.c
+++ b/master.c
@@ -193,16 +193,20 @@ create_socket(char *name)
omask = umask(077);
s = socket(PF_UNIX, SOCK_STREAM, 0);
- umask(omask); /* umask always succeeds, errno is untouched. */
if (s < 0)
+ {
+ umask(omask); /* umask always succeeds, errno is untouched. */
return -1;
+ }
sockun.sun_family = AF_UNIX;
strcpy(sockun.sun_path, name);
if (bind(s, (struct sockaddr*)&sockun, sizeof(sockun)) < 0)
{
+ umask(omask); /* umask always succeeds, errno is untouched. */
close(s);
return -1;
}
+ umask(omask); /* umask always succeeds, errno is untouched. */
if (listen(s, 128) < 0)
{
close(s);
@@ -213,7 +217,7 @@ create_socket(char *name)
close(s);
return -1;
}
- /* chmod it to prevent any suprises */
+ /* chmod it to prevent any surprises */
if (chmod(name, 0600) < 0)
{
close(s);