[dovecot-cvs] dovecot/src/lib Makefile.am, 1.46, 1.47 unix-socket-create.c, NONE, 1.1 unix-socket-create.h, NONE, 1.1

cras at dovecot.org cras at dovecot.org
Tue Mar 1 00:15:27 EET 2005


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv21265

Modified Files:
	Makefile.am 
Added Files:
	unix-socket-create.c unix-socket-create.h 
Log Message:
Added unix_socket_create().



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- Makefile.am	8 Nov 2004 02:12:55 -0000	1.46
+++ Makefile.am	28 Feb 2005 22:15:25 -0000	1.47
@@ -62,6 +62,7 @@
 	str-sanitize.c \
 	strescape.c \
 	strfuncs.c \
+	unix-socket-create.c \
 	unlink-directory.c \
 	unlink-lockfiles.c \
 	utc-offset.c \
@@ -121,6 +122,7 @@
 	str-sanitize.h \
 	strescape.h \
 	strfuncs.h \
+	unix-socket-create.h \
 	unlink-directory.h \
 	unlink-lockfiles.h \
 	utc-offset.h \

--- NEW FILE: unix-socket-create.c ---
/* Copyright (c) 2005 Timo Sirainen */

#include "lib.h"
#include "network.h"
#include "unix-socket-create.h"

#include <unistd.h>
#include <sys/stat.h>

int unix_socket_create(const char *path, int mode,
		       uid_t uid, gid_t gid, int backlog)
{
	mode_t old_umask;
	int fd;

	(void)unlink(path);

	old_umask = umask(0777 ^ mode);
	fd = net_listen_unix(path, backlog);
	umask(old_umask);

	if (fd < 0) {
		i_error("net_listen_unix(%s) failed: %m", path);
		return -1;
	}

	if (uid != (uid_t)-1 || gid != (gid_t)-1) {
		/* set correct permissions */
		if (chown(path, uid, gid) < 0) {
			i_error("chown(%s, %s, %s) failed: %m",
				path, dec2str(uid), dec2str(gid));
			return -1;
		}
	}
	return fd;
}


--- NEW FILE: unix-socket-create.h ---
#ifndef __UNIX_SOCKET_CREATE_H
#define __UNIX_SOCKET_CREATE_H

int unix_socket_create(const char *path, int mode,
		       uid_t uid, gid_t gid, int backlog);

#endif



More information about the dovecot-cvs mailing list