Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/unix-socket-create.c @ 9451:9fff30644260 HEAD
istream-concat: Fixed a lot of bugs.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 26 Oct 2009 17:06:57 -0400 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8219
diff
changeset
|
1 /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */ |
3165 | 2 |
3 #include "lib.h" | |
4 #include "network.h" | |
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)); | |
30 return -1; | |
31 } | |
32 } | |
33 return fd; | |
34 } | |
35 |