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