File apcupsd-3.14.1-cloexec.patch of Package apcupsd.import4958

--- apcupsd-3.14.1/src/apcnis.c.cloexec	2006-08-13 11:00:15.000000000 -0600
+++ apcupsd-3.14.1/src/apcnis.c	2007-08-01 16:26:35.000000000 -0600
@@ -155,6 +155,9 @@
       sleep(5 * 60);
    }
 
+   /* Close the socket on exec - avoid leaked file descriptors */
+   fcntl(sockfd, F_SETFD, FD_CLOEXEC);
+
    /* Reuse old sockets */
 #ifndef HAVE_MINGW
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void*)&turnon, sizeof(turnon)) < 0) {
--- apcupsd-3.14.1/src/apcupsd.c.cloexec	2006-09-23 11:42:47.000000000 -0600
+++ apcupsd-3.14.1/src/apcupsd.c	2007-08-01 16:27:14.000000000 -0600
@@ -280,6 +280,9 @@
       if (ups->event_fd < 0) {
          log_event(ups, LOG_WARNING, "Could not open events file %s: %s\n",
             ups->eventfile, strerror(errno));
+      } else {
+         /* Close the file on exec - avoid leaked file descriptors */
+         fcntl(ups->event_fd, F_SETFD, FD_CLOEXEC);
       }
    }
 
--- apcupsd-3.14.1/src/drivers/usb/linux/linux-usb.c.cloexec	2007-08-01 16:30:28.000000000 -0600
+++ apcupsd-3.14.1/src/drivers/usb/linux/linux-usb.c	2007-08-01 16:42:55.000000000 -0600
@@ -182,8 +182,11 @@
    /* Retry 10 times */
    for (i = 0; i < 10; i++) {
       my_data->fd = open_device(ups->device, ups);
-      if (my_data->fd != -1)
+      if (my_data->fd != -1) {
+         /* Close the device on exec - avoid leaked file descriptors */
+         fcntl(my_data->fd, F_SETFD, FD_CLOEXEC);
          return 1;
+      }
       sleep(1);
    }
 
@@ -206,6 +209,8 @@
             asnprintf(devname, sizeof(devname), "%s%d", hiddev[j], k);
             my_data->fd = open_device(devname, ups);
             if (my_data->fd != -1) {
+               /* Close the device on exec - avoid leaked file descriptors */
+               fcntl(my_data->fd, F_SETFD, FD_CLOEXEC);
                /* Successful open, save device name and return */
                astrncpy(ups->device, devname, sizeof(ups->device));
                return 1;