9b83439
--- smartmontools-5.36/os_linux.c.cloexec	2006-05-11 09:41:12.000000000 +0200
9b83439
+++ smartmontools-5.36/os_linux.c	2006-11-07 10:02:55.000000000 +0100
9b83439
@@ -183,14 +183,14 @@
9b83439
 
9b83439
 // equivalent to open(path, flags)
9b83439
 int deviceopen(const char *pathname, char *type){
9b83439
+  int fd = -1;
9b83439
   if (!strcmp(type,"SCSI")) {
9b83439
-    int fd = open(pathname, O_RDWR | O_NONBLOCK);
9b83439
+    fd = open(pathname, O_RDWR | O_NONBLOCK);
9b83439
     if (fd < 0 && errno == EROFS)
9b83439
       fd = open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
-    return fd;
9b83439
   }
9b83439
   else if (!strcmp(type,"ATA")) 
9b83439
-    return open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
   else if (!strcmp(type,"ATA_3WARE_9000")) {
9b83439
     // the device nodes for this controller are dynamically assigned,
9b83439
     // so we need to check that they exist with the correct major
9b83439
@@ -200,7 +200,7 @@
9b83439
 	errno=ENXIO;
9b83439
       return -1;
9b83439
     }
9b83439
-    return open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
   }
9b83439
   else if (!strcmp(type,"ATA_3WARE_678K")) {
9b83439
     // the device nodes for this controller are dynamically assigned,
9b83439
@@ -211,17 +211,21 @@
9b83439
 	errno=ENXIO;
9b83439
       return -1;
9b83439
     }
9b83439
-    return open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
9b83439
   }
9b83439
   // cciss+
9b83439
   else if(!strcmp(type, "CCISS"))
9b83439
   {
9b83439
     // the device is a cciss smart array device.
9b83439
-    return open(pathname, O_RDWR | O_NONBLOCK);
9b83439
+    fd = open(pathname, O_RDWR | O_NONBLOCK);
9b83439
   }
9b83439
   else
9b83439
     return -1;
9b83439
 
9b83439
+  if (fd != -1) {
9b83439
+    fcntl(fd, F_SETFD, FD_CLOEXEC);
9b83439
+  }
9b83439
+  return fd;
9b83439
 }
9b83439
 
9b83439
 // equivalent to close(file descriptor)