[CTDB] Various Patches from Red Hat

Michael Adam obnox at samba.org
Thu Aug 29 15:18:29 MDT 2013


Hi Jose and Sumit,

On 2013-06-14 at 11:11 -0400, Jose Rivera wrote:
> 
> Attached are a variety of patches from Red Hat, courtesy of Sumit Bose. They 
> include:
> 
>  * A collection of suggestions from Coverity
>  * A memory leak fix
>  * An error check
> 
> And more. All but the Coverity-based patch are relatively small changes. 
> Since I did not author the patches themselves, I've CC'ed Sumit to answer 
> any questions you may have.

I have just pushed reviewed and partly modified patches to the
1.0.114 branch.

A few remarks:

The init script patch was applied long ago by ronnie.

In the future, it would be better to have separate patches for
the coverity fixes, instead of one collected patch.
I removed a couple of hunks from the cov patch, picking patches
from master instead which did the same thing already.

Only one hunk of the coverity patches has not been applied,
the banning patch. pnn is set to -1 in places, so we need to
do this differently.

Cheers - Michael

> From c87c8532b354102447fad8910764ccb9a79a7935 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Mon, 19 Nov 2012 11:20:31 +0100
> Subject: [PATCH] Check return value of tdb_delete()
> 
> ---
>  server/ctdb_recover.c | 4 +++-
>  1 Datei ge??ndert, 3 Zeilen hinzugef??gt(+), 1 Zeile entfernt(-)
> 
> diff --git a/server/ctdb_recover.c b/server/ctdb_recover.c
> index e9e7659..cbcb504 100644
> --- a/server/ctdb_recover.c
> +++ b/server/ctdb_recover.c
> @@ -877,7 +877,9 @@ static int delete_tdb_record(struct ctdb_context *ctdb, struct ctdb_db_context *
>  
>  	if (data.dsize < sizeof(struct ctdb_ltdb_header)) {
>  		if (tdb_lock_nonblock(ctdb_db->ltdb->tdb, -1, F_WRLCK) == 0) {
> -			tdb_delete(ctdb_db->ltdb->tdb, key);
> +			if (tdb_delete(ctdb_db->ltdb->tdb, key) != 0) {
> +				DEBUG(DEBUG_CRIT,(__location__ " Failed to delete corrupt record\n"));
> +			}
>  			tdb_unlock(ctdb_db->ltdb->tdb, -1, F_WRLCK);
>  			DEBUG(DEBUG_CRIT,(__location__ " Deleted corrupt record\n"));
>  		}
> -- 
> 1.7.11.7
> 

> From 9d127abaed19b66c5b75cf353800cff0b81941b2 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Tue, 24 Nov 2009 23:11:28 +0100
> Subject: [PATCH] Fixes for init script to meet guidelines
> 
> ---
>  config/ctdb.init |   22 ++++++++++++++--------
>  1 files changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/config/ctdb.init b/config/ctdb.init
> index 2e25cf1..50f29f1 100755
> --- a/config/ctdb.init
> +++ b/config/ctdb.init
> @@ -170,7 +170,7 @@ start() {
>  
>      ctdb ping >/dev/null 2>&1 && {
>  	echo $"CTDB is already running"
> -	return 1
> +	return 0
>      }
>  
>      build_ctdb_options
> @@ -213,7 +213,7 @@ start() {
>      set_ctdb_variables
>  
>      return $RETVAL
> -}	
> +}
>  
>  stop() {
>      echo -n $"Shutting down ctdbd service: "
> @@ -260,20 +260,26 @@ stop() {
>  restart() {
>      stop
>      start
> -}	
> +}
>  
>  status() {
>      echo -n $"Checking for ctdbd service: "
>      ctdb ping >/dev/null 2>&1 || {
>  	RETVAL=$?
> -	echo -n "  ctdbd not running. "
>  	case $init_style in
>  	    suse)
> +		echo -n "  ctdbd not running. "
>  		set_retval $RETVAL
>  		rc_status -v
>  		;;
>  	    redhat)
> -		echo ""
> +		if [ -f /var/lock/subsys/ctdb ]; then
> +			echo $"ctdb dead but subsys locked"
> +			RETVAL=2
> +		else
> +			echo $"ctdb is stopped"
> +			RETVAL=3
> +		fi
>  		;;
>  	esac
>  	return $RETVAL
> @@ -290,13 +296,13 @@ case "$1" in
>      stop)
>    	stop
>  	;;
> -    restart|reload)
> +    restart|reload|force-reload)
>    	restart
>  	;;
>      status)
>    	status
>  	;;
> -    condrestart)
> +    condrestart|try-restart)
>    	ctdb status > /dev/null && restart || :
>  	;;
>      cron)
> @@ -304,7 +310,7 @@ case "$1" in
>    	ctdb status > /dev/null || restart
>  	;;
>      *)
> -	echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
> +	echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
>  	exit 1
>  esac
>  
> -- 
> 1.6.5.2
> 

> From 8fed31b23cfabb48aec6d0f296d1987bdd1679f2 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Wed, 10 Aug 2011 17:53:56 +0200
> Subject: [PATCH] Fixes for various issues found by Coverity
> 
> ---
>  client/ctdb_client.c      |    2 +-
>  common/ctdb_logging.c     |   13 +++++++++++--
>  lib/tdb/common/tdb.c      |    2 +-
>  lib/util/idtree.c         |    2 +-
>  server/ctdb_banning.c     |    2 +-
>  server/ctdb_daemon.c      |    4 ++++
>  server/ctdb_logging.c     |    4 ++++
>  server/ctdb_ltdb_server.c |    5 ++++-
>  server/ctdb_recover.c     |    4 ++--
>  server/ctdb_recoverd.c    |    4 ++--
>  server/eventscript.c      |    4 +++-
>  tcp/tcp_connect.c         |   10 +++++++++-
>  tests/src/ctdb_fetch.c    |    5 +++++
>  13 files changed, 48 insertions(+), 13 deletions(-)
> 
> diff --git a/client/ctdb_client.c b/client/ctdb_client.c
> index 2d3c176..06c0eec 100644
> --- a/client/ctdb_client.c
> +++ b/client/ctdb_client.c
> @@ -3015,7 +3015,7 @@ static void async_callback(struct ctdb_client_control_state *state)
>  	struct ctdb_context *ctdb = talloc_get_type(state->ctdb, struct ctdb_context);
>  	int ret;
>  	TDB_DATA outdata;
> -	int32_t res;
> +	int32_t res = -1;
>  	uint32_t destnode = state->c->hdr.destnode;
>  
>  	/* one more node has responded with recmode data */
> diff --git a/common/ctdb_logging.c b/common/ctdb_logging.c
> index ea4d271..3296a17 100644
> --- a/common/ctdb_logging.c
> +++ b/common/ctdb_logging.c
> @@ -124,7 +124,7 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr
>  		tm = localtime(&log_entries[tmp_entry].t.tv_sec);
>  		strftime(tbuf, sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
>  
> -		if (log_entries[tmp_entry].message) {
> +		if (log_entries[tmp_entry].message[0] != '\0') {
>  			count += fprintf(f, "%s:%s %s", tbuf, get_debug_by_level(log_entries[tmp_entry].level), log_entries[tmp_entry].message);
>  		}
>  
> @@ -135,9 +135,18 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr
>  	}
>  
>  	fsize = ftell(f);
> +	if (fsize < 0) {
> +		fclose(f);
> +		DEBUG(DEBUG_ERR,("Cannot get current file position\n"));
> +                return;
> +	}
>  	rewind(f);
>  	data.dptr = talloc_size(NULL, fsize);
> -	CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
> +
> +	if (data.dptr == NULL) {
> +		fclose(f);
> +		CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
> +	}
>  	data.dsize = fread(data.dptr, 1, fsize, f);
>  	fclose(f);
>  
> diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
> index 4d8c5fc..eeadf2f 100644
> --- a/lib/tdb/common/tdb.c
> +++ b/lib/tdb/common/tdb.c
> @@ -993,7 +993,7 @@ int tdb_repack(struct tdb_context *tdb)
>  bool tdb_write_all(int fd, const void *buf, size_t count)
>  {
>  	while (count) {
> -		size_t ret;
> +		ssize_t ret;
>  		ret = write(fd, buf, count);
>  		if (ret < 0)
>  			return false;
> diff --git a/lib/util/idtree.c b/lib/util/idtree.c
> index 06544e1..108523b 100644
> --- a/lib/util/idtree.c
> +++ b/lib/util/idtree.c
> @@ -104,7 +104,7 @@ static int sub_alloc(struct idr_context *idp, void *ptr, int *starting_id)
>  {
>  	int n, m, sh;
>  	struct idr_layer *p, *new;
> -	struct idr_layer *pa[MAX_LEVEL];
> +	struct idr_layer *pa[MAX_LEVEL+1];
>  	int l, id, oid;
>  	uint32_t bm;
>  
> diff --git a/server/ctdb_banning.c b/server/ctdb_banning.c
> index 35f1784..e7d97c0 100644
> --- a/server/ctdb_banning.c
> +++ b/server/ctdb_banning.c
> @@ -74,7 +74,7 @@ int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata)
>  	DEBUG(DEBUG_INFO,("SET BAN STATE\n"));
>  
>  	if (bantime->pnn != ctdb->pnn) {
> -		if (bantime->pnn < 0 || bantime->pnn >= ctdb->num_nodes) {
> +		if (bantime->pnn >= ctdb->num_nodes) {
>  			DEBUG(DEBUG_ERR,(__location__ " ERROR: Invalid ban request. PNN:%d is invalid. Max nodes %d\n", bantime->pnn, ctdb->num_nodes));
>  			return -1;
>  		}
> diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c
> index fdec5ab..0620f04 100644
> --- a/server/ctdb_daemon.c
> +++ b/server/ctdb_daemon.c
> @@ -813,6 +813,10 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
>  	fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, 
>  			   EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
>  			   ctdb_accept_client, ctdb);
> +	if (fde == NULL) {
> +		DEBUG(DEBUG_CRIT,("Failed to add daemon socket to event loop\n"));
> +		exit(1);
> +	}
>  
>  	/* release any IPs we hold from previous runs of the daemon */
>  	ctdb_release_all_ips(ctdb);
> diff --git a/server/ctdb_logging.c b/server/ctdb_logging.c
> index a7ca1a1..61c38f6 100644
> --- a/server/ctdb_logging.c
> +++ b/server/ctdb_logging.c
> @@ -502,6 +502,10 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb)
>  	/* We'll fail if stderr/stdout not already open; it's simpler. */
>  	old_stdout = dup(STDOUT_FILENO);
>  	old_stderr = dup(STDERR_FILENO);
> +        if (old_stdout < 0 || old_stderr < 0) {
> +		DEBUG(DEBUG_ERR,(__location__ " Failed to copy files descriptors\n"));
> +		return -1;
> +        }
>  	if (dup2(p[1], STDOUT_FILENO) < 0 || dup2(p[1], STDERR_FILENO) < 0) {
>  		int saved_errno = errno;
>  		dup2(old_stdout, STDOUT_FILENO);
> diff --git a/server/ctdb_ltdb_server.c b/server/ctdb_ltdb_server.c
> index f7eee75..6856d78 100644
> --- a/server/ctdb_ltdb_server.c
> +++ b/server/ctdb_ltdb_server.c
> @@ -1030,7 +1030,10 @@ static int ctdb_attach_persistent(struct ctdb_context *ctdb,
>  		int invalid_name = 0;
>  		
>  		s = talloc_strdup(ctdb, de->d_name);
> -		CTDB_NO_MEMORY(ctdb, s);
> +		if (s == NULL) {
> +			closedir(d);
> +			CTDB_NO_MEMORY(ctdb, s);
> +		}
>  
>  		/* only accept names ending in .tdb */
>  		p = strstr(s, ".tdb.");
> diff --git a/server/ctdb_recover.c b/server/ctdb_recover.c
> index ed5c22b..60a0339 100644
> --- a/server/ctdb_recover.c
> +++ b/server/ctdb_recover.c
> @@ -340,8 +340,8 @@ static int traverse_pulldb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
>  	}
>  	params->pulldata = talloc_realloc_size(NULL, params->pulldata, rec->length + params->len);
>  	if (params->pulldata == NULL) {
> -		DEBUG(DEBUG_ERR,(__location__ " Failed to expand pulldb_data to %u (%u records)\n", 
> -			 rec->length + params->len, params->pulldata->count));
> +		DEBUG(DEBUG_ERR,(__location__ " Failed to expand pulldb_data to %u\n",
> +			 rec->length + params->len));
>  		params->failed = true;
>  		return -1;
>  	}
> diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
> index 93af64e..18696c5 100644
> --- a/server/ctdb_recoverd.c
> +++ b/server/ctdb_recoverd.c
> @@ -1079,8 +1079,8 @@ static int traverse_recdb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
>  	}
>  	params->recdata = talloc_realloc_size(NULL, params->recdata, rec->length + params->len);
>  	if (params->recdata == NULL) {
> -		DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n", 
> -			 rec->length + params->len, params->recdata->count));
> +		DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u\n",
> +			 rec->length + params->len));
>  		params->failed = true;
>  		return -1;
>  	}
> diff --git a/server/eventscript.c b/server/eventscript.c
> index 757b254..182aed6 100644
> --- a/server/eventscript.c
> +++ b/server/eventscript.c
> @@ -222,6 +222,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
>  		tree_item = talloc(tree, struct ctdb_script_tree_item);
>  		if (tree_item == NULL) {
>  			DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n"));
> +			closedir(dir);
>  			talloc_free(tmp_ctx);
>  			return NULL;
>  		}
> @@ -234,6 +235,7 @@ static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb,
>  		tree_item->name = talloc_strdup(tree_item, de->d_name);
>  		if (tree_item->name == NULL) {
>  			DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n"));
> +			closedir(dir);
>  			talloc_free(tmp_ctx);
>  			return NULL;
>  		}
> @@ -777,10 +779,10 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call
>  	va_start(ap, fmt);
>  	ret = ctdb_event_script_callback_v(ctdb,
>  			event_script_callback, &status, false, call, fmt, ap);
> +	va_end(ap);
>  	if (ret != 0) {
>  		return ret;
>  	}
> -	va_end(ap);
>  
>  	status.status = -1;
>  	status.done = false;
> diff --git a/tcp/tcp_connect.c b/tcp/tcp_connect.c
> index 43ce850..e3d837a 100644
> --- a/tcp/tcp_connect.c
> +++ b/tcp/tcp_connect.c
> @@ -155,6 +155,10 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
>  	}
>  
>  	tnode->fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
> +	if (tnode->fd == -1) {
> +		DEBUG(DEBUG_ERR, (__location__ " Failed to create socket.\n"));
> +		return;
> +	}
>  	set_nonblocking(tnode->fd);
>  	set_close_on_exec(tnode->fd);
>  
> @@ -197,7 +201,11 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
>  	sock_in.ip.sin_len = sockin_size;
>  	sock_out.ip.sin_len = sockout_size;
>  #endif
> -	bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size);
> +	if (bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size) != 0) {
> +		DEBUG(DEBUG_ERR,(__location__ " Failed to bind() to socket. %s(%d)\n", strerror(errno), errno));
> +		close(tnode->fd);
> +		return;
> +	}
>  
>  	if (connect(tnode->fd, (struct sockaddr *)&sock_out, sockout_size) != 0 &&
>  	    errno != EINPROGRESS) {
> diff --git a/tests/src/ctdb_fetch.c b/tests/src/ctdb_fetch.c
> index 35257e2..6487dc0 100644
> --- a/tests/src/ctdb_fetch.c
> +++ b/tests/src/ctdb_fetch.c
> @@ -84,6 +84,11 @@ static void bench_fetch_1node(struct ctdb_context *ctdb)
>  	data.dptr = (uint8_t *)talloc_asprintf_append((char *)data.dptr, 
>  						      "msg_count=%d on node %d\n",
>  						      msg_count, ctdb_get_pnn(ctdb));
> +	if (data.dptr == NULL) {
> +		printf("Failed to create record\n");
> +		talloc_free(tmp_ctx);
> +		return;
> +	}
>  	data.dsize = strlen((const char *)data.dptr)+1;
>  
>  	ret = ctdb_record_store(h, data);
> -- 
> 1.7.6
> 

> From 57f15e7cbcaa6524bd3696fe87f9a7f67adae1f5 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Mon, 19 Nov 2012 11:13:03 +0100
> Subject: [PATCH] Fix memory leak in ctdb_send_message()
> 
> ---
>  client/ctdb_client.c | 6 +-----
>  1 Datei ge??ndert, 1 Zeile hinzugef??gt(+), 5 Zeilen entfernt(-)
> 
> diff --git a/client/ctdb_client.c b/client/ctdb_client.c
> index 94fc712..ed0d07f 100644
> --- a/client/ctdb_client.c
> +++ b/client/ctdb_client.c
> @@ -526,12 +526,8 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
>  	memcpy(&r->data[0], data.dptr, data.dsize);
>  	
>  	res = ctdb_client_queue_pkt(ctdb, &r->hdr);
> -	if (res != 0) {
> -		return res;
> -	}
> -
>  	talloc_free(r);
> -	return 0;
> +	return res;
>  }
>  
>  
> -- 
> 1.7.11.7
> 

> From 7c17874971823ecc3d9da2c42ed0baa85621f659 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Thu, 1 Sep 2011 15:18:46 +0200
> Subject: [PATCH] IPv6 neighbor solicit cleanup
> 
> ---
>  common/system_linux.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/common/system_linux.c b/common/system_linux.c
> index b8aace4..b36a78d 100644
> --- a/common/system_linux.c
> +++ b/common/system_linux.c
> @@ -75,7 +75,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
>  	struct ether_header *eh;
>  	struct arphdr *ah;
>  	struct ip6_hdr *ip6;
> -	struct icmp6_hdr *icmp6;
> +	struct nd_neighbor_solicit *nd_ns;
>  	struct ifreq if_hwaddr;
>  	unsigned char buffer[78]; /* ipv6 neigh solicitation size */
>  	char *ptr;
> @@ -223,17 +223,18 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
>  
>  		ip6 = (struct ip6_hdr *)(eh+1);
>  		ip6->ip6_vfc  = 0x60;
> -		ip6->ip6_plen = htons(24);
> +		ip6->ip6_plen = htons(sizeof(*nd_ns));
>  		ip6->ip6_nxt  = IPPROTO_ICMPV6;
>  		ip6->ip6_hlim = 255;
>  		ip6->ip6_dst  = addr->ip6.sin6_addr;
>  
> -		icmp6 = (struct icmp6_hdr *)(ip6+1);
> -		icmp6->icmp6_type = ND_NEIGHBOR_SOLICIT;
> -		icmp6->icmp6_code = 0;
> -		memcpy(&icmp6->icmp6_data32[1], &addr->ip6.sin6_addr, 16);
> +		nd_ns = (struct nd_neighbor_solicit *)(ip6+1);
> +		nd_ns->nd_ns_type = ND_NEIGHBOR_SOLICIT;
> +		nd_ns->nd_ns_code = 0;
> +		nd_ns->nd_ns_reserved = 0;
> +		nd_ns->nd_ns_target = addr->ip6.sin6_addr;
>  
> -		icmp6->icmp6_cksum = tcp_checksum6((uint16_t *)icmp6, ntohs(ip6->ip6_plen), ip6);
> +		nd_ns->nd_ns_cksum = tcp_checksum6((uint16_t *)nd_ns, ntohs(ip6->ip6_plen), ip6);
>  
>  		sall.sll_family = AF_PACKET;
>  		sall.sll_halen = 6;
> -- 
> 1.7.6
> 

> From f7f138d9d6cfbd5987fc11546dbc720ec286d8f1 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Mon, 19 Nov 2012 18:45:37 +0100
> Subject: [PATCH] Print deleted nodes as well
> 
> ---
>  tools/ctdb.c | 15 ++++++++++++++-
>  1 Datei ge??ndert, 14 Zeilen hinzugef??gt(+), 1 Zeile entfernt(-)
> 
> diff --git a/tools/ctdb.c b/tools/ctdb.c
> index 904ec31..ef11ab3 100644
> --- a/tools/ctdb.c
> +++ b/tools/ctdb.c
> @@ -499,6 +499,7 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
>  	struct ctdb_node_map *nodemap=NULL;
>  	uint32_t recmode, recmaster;
>  	int mypnn;
> +	int num_deleted_nodes;
>  
>  	mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
>  	if (mypnn == -1) {
> @@ -550,7 +551,19 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
>  		return 0;
>  	}
>  
> -	printf("Number of nodes:%d\n", nodemap->num);
> +	num_deleted_nodes = 0;
> +	for(i=0;i<nodemap->num;i++){
> +		if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
> +			num_deleted_nodes++;
> +		}
> +	}
> +
> +	if (num_deleted_nodes == 0) {
> +		printf("Number of nodes:%d\n", nodemap->num);
> +	} else {
> +		printf("Number of nodes:%d (including %d deleted nodes)\n",
> +		       nodemap->num, num_deleted_nodes);
> +	}
>  	for(i=0;i<nodemap->num;i++){
>  		static const struct {
>  			uint32_t flag;
> -- 
> 1.7.11.7
> 

> From 424f6133941c5846e40555054e7400e4eaa6bea1 Mon Sep 17 00:00:00 2001
> From: Sumit Bose <sbose at redhat.com>
> Date: Wed, 10 Aug 2011 17:14:40 +0200
> Subject: [PATCH] Set FD_CLOEXEC for epoll file descriptors
> 
> ---
>  lib/events/events_standard.c |   13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/events/events_standard.c b/lib/events/events_standard.c
> index 6537d27..79dc1be 100644
> --- a/lib/events/events_standard.c
> +++ b/lib/events/events_standard.c
> @@ -100,7 +100,14 @@ static int epoll_ctx_destructor(struct std_event_context *std_ev)
>  */
>  static void epoll_init_ctx(struct std_event_context *std_ev)
>  {
> +	unsigned v;
> +
>  	std_ev->epoll_fd = epoll_create(64);
> +
> +	/* on exec, don't inherit the fd */
> +	v = fcntl(std_ev->epoll_fd, F_GETFD, 0);
> +        fcntl(std_ev->epoll_fd, F_SETFD, v | FD_CLOEXEC);
> +
>  	std_ev->pid = getpid();
>  	talloc_set_destructor(std_ev, epoll_ctx_destructor);
>  }
> @@ -115,6 +122,7 @@ static void epoll_add_event(struct std_event_context *std_ev, struct fd_event *f
>  static void epoll_check_reopen(struct std_event_context *std_ev)
>  {
>  	struct fd_event *fde;
> +	unsigned v;
>  
>  	if (std_ev->pid == getpid()) {
>  		return;
> @@ -126,6 +134,11 @@ static void epoll_check_reopen(struct std_event_context *std_ev)
>  		DEBUG(0,("Failed to recreate epoll handle after fork\n"));
>  		return;
>  	}
> +
> +	/* on exec, don't inherit the fd */
> +	v = fcntl(std_ev->epoll_fd, F_GETFD, 0);
> +        fcntl(std_ev->epoll_fd, F_SETFD, v | FD_CLOEXEC);
> +
>  	std_ev->pid = getpid();
>  	for (fde=std_ev->fd_events;fde;fde=fde->next) {
>  		epoll_add_event(std_ev, fde);
> -- 
> 1.7.6
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 215 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20130829/7e9a434d/attachment.pgp>


More information about the samba-technical mailing list