Mercurial > dovecot > core-2.2
annotate src/lib/unix-socket-create.c @ 22713:cb108f786fb4
Updated copyright notices to include the year 2018.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Mon, 01 Jan 2018 22:42:08 +0100 |
parents | 2e2563132d5f |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
1 /* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ |
3165 | 2 |
3 #include "lib.h" | |
15187
02451e967a06
Renamed network.[ch] to net.[ch].
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
4 #include "net.h" |
3165 | 5 #include "unix-socket-create.h" |
6 | |
7 #include <unistd.h> | |
8 #include <sys/stat.h> | |
9 | |
10 int unix_socket_create(const char *path, int mode, | |
11 uid_t uid, gid_t gid, int backlog) | |
12 { | |
13 mode_t old_umask; | |
14 int fd; | |
15 | |
16 old_umask = umask(0777 ^ mode); | |
8219
ec83f6dcb585
Added net_listen_unix_unlink_stale() and use it where needed to avoid code duplication.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
17 fd = net_listen_unix_unlink_stale(path, backlog); |
3165 | 18 umask(old_umask); |
19 | |
20 if (fd < 0) { | |
21 i_error("net_listen_unix(%s) failed: %m", path); | |
22 return -1; | |
23 } | |
24 | |
25 if (uid != (uid_t)-1 || gid != (gid_t)-1) { | |
26 /* set correct permissions */ | |
27 if (chown(path, uid, gid) < 0) { | |
28 i_error("chown(%s, %s, %s) failed: %m", | |
29 path, dec2str(uid), dec2str(gid)); | |
16710
3091883c672a
Fixed file descriptor leaks in rather unimportant places.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
30 i_close_fd(&fd); |
3165 | 31 return -1; |
32 } | |
33 } | |
34 return fd; | |
35 } | |
36 |