From: <ssm...@us...> - 2008-08-05 13:08:42
|
Revision: 2942 http://selinux.svn.sourceforge.net/selinux/?rev=2942&view=rev Author: ssmalley Date: 2008-08-05 13:08:39 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Author: Stephen Smalley Email: sd...@ty... Subject: libselinux: make setrans socket descriptor close-on-exec Date: Mon, 04 Aug 2008 12:59:05 -0400 Ensure that the setrans socket descriptor is marked close-on-exec. If supported, use the new SOCK_CLOEXEC flag when the socket is created, as per: http://udrepper.livejournal.com/20407.html Otherwise fall back to using fcntl after the socket has been created. Signed-off-by: Stephen Smalley <sd...@ty...> Modified Paths: -------------- trunk/libselinux/src/setrans_client.c Modified: trunk/libselinux/src/setrans_client.c =================================================================== --- trunk/libselinux/src/setrans_client.c 2008-08-05 13:06:40 UTC (rev 2941) +++ trunk/libselinux/src/setrans_client.c 2008-08-05 13:08:39 UTC (rev 2942) @@ -13,7 +13,7 @@ #include <errno.h> #include <stdlib.h> #include <netdb.h> - +#include <fcntl.h> #include <stdio.h> #include <string.h> #include <ctype.h> @@ -42,11 +42,17 @@ { struct sockaddr_un addr; int fd; - - fd = socket(PF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { +#ifdef SOCK_CLOEXEC + fd = socket(PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0); + if (fd < 0 && errno == EINVAL) +#endif + { + fd = socket(PF_UNIX, SOCK_STREAM, 0); + if (fd >= 0) + fcntl(fd, F_SETFD, FD_CLOEXEC); + } + if (fd < 0) return -1; - } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |