3253507
diff -up smartmontools-5.38/os_linux.cpp.cloexec smartmontools-5.38/os_linux.cpp
64c7371
--- smartmontools-5.38/os_linux.cpp.cloexec	2008-03-04 23:09:47.000000000 +0100
64c7371
+++ smartmontools-5.38/os_linux.cpp	2008-03-18 08:28:20.000000000 +0100
64c7371
@@ -171,14 +171,13 @@ static char prev_scsi_dev[128];
3253507
 
3253507
 // equivalent to open(path, flags)
3253507
 int deviceopen(const char *pathname, char *type){
3253507
-  int fd;
3253507
+  int fd = -1;
3253507
 
3253507
   if (0 == strcmp(type,"SCSI")) {
3253507
     strncpy(prev_scsi_dev, pathname, sizeof(prev_scsi_dev) - 1);
64c7371
     fd = open(pathname, O_RDWR | O_NONBLOCK);
64c7371
     if (fd < 0 && errno == EROFS)
64c7371
       fd = open(pathname, O_RDONLY | O_NONBLOCK);
64c7371
-    return fd;
64c7371
   } else if (0 == strcmp(type,"ATA")) {
64c7371
     // smartd re-opens SCSI devices with "type"==ATA for some reason.
64c7371
     // If that was a SCSI generic device (e.g. /dev/sg0) then the
64c7371
@@ -186,9 +185,9 @@ int deviceopen(const char *pathname, cha
3253507
     // The purpose of the next code line is to limit the scope of
3253507
     // this change as a release is pending (and smartd needs a rewrite).
3253507
     if (0 == strncmp(pathname, prev_scsi_dev, sizeof(prev_scsi_dev)))
3253507
-      return open(pathname, O_RDWR | O_NONBLOCK);
3253507
+      fd = open(pathname, O_RDWR | O_NONBLOCK);
3253507
     else
3253507
-      return open(pathname, O_RDONLY | O_NONBLOCK);
3253507
+      fd = open(pathname, O_RDONLY | O_NONBLOCK);
3253507
   } else if (0 == strcmp(type,"ATA_3WARE_9000")) {
3253507
     // the device nodes for this controller are dynamically assigned,
3253507
     // so we need to check that they exist with the correct major
64c7371
@@ -198,7 +197,7 @@ int deviceopen(const char *pathname, cha
3253507
         errno=ENXIO;
3253507
       return -1;
3253507
     }
3253507
-    return open(pathname, O_RDONLY | O_NONBLOCK);
3253507
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
3253507
   }
3253507
   else if (0 == strcmp(type,"ATA_3WARE_678K")) {
3253507
     // the device nodes for this controller are dynamically assigned,
64c7371
@@ -209,15 +208,17 @@ int deviceopen(const char *pathname, cha
3253507
         errno=ENXIO;
3253507
       return -1;
3253507
     }
3253507
-    return open(pathname, O_RDONLY | O_NONBLOCK);
3253507
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
3253507
   }
3253507
   else if(0 == strcmp(type, "CCISS")) {
3253507
     // the device is a cciss smart array device.
3253507
-    return open(pathname, O_RDWR | O_NONBLOCK);
3253507
+    fd = open(pathname, O_RDWR | O_NONBLOCK);
3253507
   }
3253507
-  else
3253507
-    return -1;
3253507
 
3253507
+  if (fd != -1) {
3253507
+    fcntl(fd, F_SETFD, FD_CLOEXEC);
3253507
+  }
3253507
+  return fd;
3253507
 }
3253507
 
3253507
 // equivalent to close(file descriptor)