LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File zabbix-1.8.3-cloexec.patch of Package zabbix (Project home:L2G:F)

diff -ru zabbix-1.8.3.cloexec/src/libs/zbxcomms/comms.c zabbix-1.8.3/src/libs/zbxcomms/comms.c
--- zabbix-1.8.3.cloexec/src/libs/zbxcomms/comms.c	2010-08-16 01:19:31.000000000 -0700
+++ zabbix-1.8.3/src/libs/zbxcomms/comms.c	2010-09-02 17:11:13.880342510 -0700
@@ -62,6 +62,10 @@
 #	define ZBX_SOCKLEN_T socklen_t
 #endif
 
+#ifndef SOCK_CLOEXEC
+#define SOCK_CLOEXEC 0
+#endif
+
 /******************************************************************************
  *                                                                            *
  * Function: zbx_tcp_strerror                                                 *
@@ -410,12 +414,16 @@
 		goto out;
 	}
 
-	if (ZBX_SOCK_ERROR == (s->socket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)))
+	if (ZBX_SOCK_ERROR == (s->socket = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC, ai->ai_protocol))) {
 	{
 		zbx_set_tcp_strerror("Cannot create socket [%s]:%d [%s]", ip, port, strerror_from_system(zbx_sock_last_error()));
 		goto out;
 	}
 
+#if ! SOCK_CLOEXEC
+	fcntl(s->socket, F_SETFD, FD_CLOEXEC);
+#endif
+
 	if (NULL != source_ip)
 	{
 		memset(&hints, 0x00, sizeof(struct addrinfo));
@@ -475,12 +483,16 @@
 	servaddr_in.sin_addr.s_addr	= ((struct in_addr *)(hp->h_addr))->s_addr;
 	servaddr_in.sin_port		= htons(port);
 
-	if (ZBX_SOCK_ERROR == (s->socket = socket(AF_INET, SOCK_STREAM, 0)))
+	if (ZBX_SOCK_ERROR == (s->socket = socket(AF_INET,SOCK_STREAM | SOCK_CLOEXEC,0))) {
 	{
 		zbx_set_tcp_strerror("Cannot create socket [%s:%d] [%s]", ip, port, strerror_from_system(zbx_sock_last_error()));
 		return FAIL;
 	}
 
+#if ! SOCK_CLOEXEC
+	fcntl(s->socket, F_SETFD, FD_CLOEXEC);
+#endif
+
 	if (NULL != source_ip)
 	{
 		source_addr.sin_family		= AF_INET;
@@ -720,13 +732,17 @@
 				continue;
 
 			if (ZBX_SOCK_ERROR == (s->sockets[s->num_socks] =
-					socket(current_ai->ai_family, current_ai->ai_socktype, current_ai->ai_protocol)))
+					socket(current_ai->ai_family, current_ai->ai_socktype | SOCK_CLOEXEC, current_ai->ai_protocol)))
 			{
 				zbx_set_tcp_strerror("socket() for [[%s]:%s] failed with error %d: %s",
 						ip, port, zbx_sock_last_error(), strerror_from_system(zbx_sock_last_error()));
 				goto out;
 			}
 
+#if ! SOCK_CLOEXEC
+	fcntl(s->socket, F_SETFD, FD_CLOEXEC);
+#endif
+
 			/* Enable address reuse */
 			/* This is to immediately use the address even if it is in TIME_WAIT state */
 			/* http://www-128.ibm.com/developerworks/linux/library/l-sockpit/index.html */
@@ -828,13 +844,17 @@
 			goto out;
 		}
 
-		if (ZBX_SOCK_ERROR == (s->sockets[s->num_socks] = socket(AF_INET, SOCK_STREAM, 0)))
+		if (ZBX_SOCK_ERROR == (s->sockets[s->num_socks] = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)))
 		{
 			zbx_set_tcp_strerror("socket() for [[%s]:%hu] failed with error %d: %s",
 					ip, listen_port, zbx_sock_last_error(), strerror_from_system(zbx_sock_last_error()));
 			goto out;
 		}
 
+#if ! SOCK_CLOEXEC
+	fcntl(s->socket, F_SETFD, FD_CLOEXEC);
+#endif
+
 		/* Enable address reuse */
 		/* This is to immediately use the address even if it is in TIME_WAIT state */
 		/* http://www-128.ibm.com/developerworks/linux/library/l-sockpit/index.html */
diff -ru zabbix-1.8.3.cloexec/src/libs/zbxnix/pid.c zabbix-1.8.3/src/libs/zbxnix/pid.c
--- zabbix-1.8.3.cloexec/src/libs/zbxnix/pid.c	2010-08-16 01:19:31.000000000 -0700
+++ zabbix-1.8.3/src/libs/zbxnix/pid.c	2010-09-02 17:04:35.138342199 -0700
@@ -83,7 +83,11 @@
 	/* lock file */
 	fdpid = fileno(fpid);
 #ifdef HAVE_FCNTL_H
-	if(-1 != fdpid) fcntl(fdpid, F_SETLK, &fl);
+	if(-1 != fdpid)
+	{
+		fcntl(fdpid, F_SETLK, &fl);
+		fcntl(fdpid, F_SETFD, FD_CLOEXEC);
+	}
 #else
 	if(-1 != fdpid) flock(fdpid, LOCK_EX);
 #endif /* HAVE_FCNTL_H */