63a2b3f
--- smartmontools-5.37/os_linux.cpp.fix	2006-10-25 19:01:42.000000000 +0200
63a2b3f
+++ smartmontools-5.37/os_linux.cpp	2007-02-27 13:20:55.000000000 +0100
63a2b3f
@@ -190,14 +190,14 @@
63a2b3f
 
63a2b3f
 // equivalent to open(path, flags)
63a2b3f
 int deviceopen(const char *pathname, char *type){
63a2b3f
+  int fd = -1;
63a2b3f
   if (!strcmp(type,"SCSI")) {
63a2b3f
-    int fd = open(pathname, O_RDWR | O_NONBLOCK);
63a2b3f
+    fd = open(pathname, O_RDWR | O_NONBLOCK);
63a2b3f
     if (fd < 0 && errno == EROFS)
63a2b3f
       fd = open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
-    return fd;
63a2b3f
   }
63a2b3f
   else if (!strcmp(type,"ATA")) 
63a2b3f
-    return open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
   else if (!strcmp(type,"ATA_3WARE_9000")) {
63a2b3f
     // the device nodes for this controller are dynamically assigned,
63a2b3f
     // so we need to check that they exist with the correct major
63a2b3f
@@ -207,7 +207,7 @@
63a2b3f
         errno=ENXIO;
63a2b3f
       return -1;
63a2b3f
     }
63a2b3f
-    return open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
   }
63a2b3f
   else if (!strcmp(type,"ATA_3WARE_678K")) {
63a2b3f
     // the device nodes for this controller are dynamically assigned,
63a2b3f
@@ -218,15 +218,19 @@
63a2b3f
         errno=ENXIO;
63a2b3f
       return -1;
63a2b3f
     }
63a2b3f
-    return open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
+    fd = open(pathname, O_RDONLY | O_NONBLOCK);
63a2b3f
   }
63a2b3f
   else if(!strcmp(type, "CCISS")) {
63a2b3f
     // the device is a cciss smart array device.
63a2b3f
-    return open(pathname, O_RDWR | O_NONBLOCK);
63a2b3f
+    fd = open(pathname, O_RDWR | O_NONBLOCK);
63a2b3f
   }
63a2b3f
   else
63a2b3f
     return -1;
63a2b3f
 
63a2b3f
+  if (fd != -1) {
63a2b3f
+    fcntl(fd, F_SETFD, FD_CLOEXEC);
63a2b3f
+  }
63a2b3f
+  return fd;
63a2b3f
 }
63a2b3f
 
63a2b3f
 // equivalent to close(file descriptor)