smartmontools/smartmontools-5.38-cloexec.patch

63 lines
2.3 KiB
Diff
Raw Normal View History

2008-03-10 12:41:02 +00:00
diff -up smartmontools-5.38/os_linux.cpp.cloexec smartmontools-5.38/os_linux.cpp
--- smartmontools-5.38/os_linux.cpp.cloexec 2008-03-04 23:09:47.000000000 +0100
+++ smartmontools-5.38/os_linux.cpp 2008-03-18 08:28:20.000000000 +0100
@@ -171,14 +171,13 @@ static char prev_scsi_dev[128];
2008-03-10 12:41:02 +00:00
// equivalent to open(path, flags)
int deviceopen(const char *pathname, char *type){
- int fd;
+ int fd = -1;
if (0 == strcmp(type,"SCSI")) {
strncpy(prev_scsi_dev, pathname, sizeof(prev_scsi_dev) - 1);
fd = open(pathname, O_RDWR | O_NONBLOCK);
if (fd < 0 && errno == EROFS)
fd = open(pathname, O_RDONLY | O_NONBLOCK);
- return fd;
} else if (0 == strcmp(type,"ATA")) {
// smartd re-opens SCSI devices with "type"==ATA for some reason.
// If that was a SCSI generic device (e.g. /dev/sg0) then the
@@ -186,9 +185,9 @@ int deviceopen(const char *pathname, cha
2008-03-10 12:41:02 +00:00
// The purpose of the next code line is to limit the scope of
// this change as a release is pending (and smartd needs a rewrite).
if (0 == strncmp(pathname, prev_scsi_dev, sizeof(prev_scsi_dev)))
- return open(pathname, O_RDWR | O_NONBLOCK);
+ fd = open(pathname, O_RDWR | O_NONBLOCK);
else
- return open(pathname, O_RDONLY | O_NONBLOCK);
+ fd = open(pathname, O_RDONLY | O_NONBLOCK);
} else if (0 == 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
@@ -198,7 +197,7 @@ int deviceopen(const char *pathname, cha
2008-03-10 12:41:02 +00:00
errno=ENXIO;
return -1;
}
- return open(pathname, O_RDONLY | O_NONBLOCK);
+ fd = open(pathname, O_RDONLY | O_NONBLOCK);
}
else if (0 == strcmp(type,"ATA_3WARE_678K")) {
// the device nodes for this controller are dynamically assigned,
@@ -209,15 +208,17 @@ int deviceopen(const char *pathname, cha
2008-03-10 12:41:02 +00:00
errno=ENXIO;
return -1;
}
- return open(pathname, O_RDONLY | O_NONBLOCK);
+ fd = open(pathname, O_RDONLY | O_NONBLOCK);
}
else if(0 == 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)