Avoid closing on bad file descriptors
This commit is contained in:
parent
d44301d8fa
commit
df1cb0d70c
1 changed files with 1 additions and 6 deletions
|
@ -14,10 +14,8 @@ int getpstartts(int pid, unsigned long long* startts) {
|
|||
snprintf(path, sizeof(path), "/proc/%d/stat", pid);
|
||||
int fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
close(fd);
|
||||
if (fd < 0)
|
||||
err(1, "Could not open %s", path);
|
||||
}
|
||||
|
||||
int bytes_read = read(fd, fc, sizeof(fc));
|
||||
|
||||
|
@ -57,7 +55,6 @@ int ensuredir(int recur) {
|
|||
int fd = open("/run/rdo", O_RDONLY, O_DIRECTORY | O_NOFOLLOW);
|
||||
|
||||
if (fd < 0) {
|
||||
close(fd);
|
||||
if (errno == ENOENT) {
|
||||
if (mkdir("/run/rdo", 0700) < 0)
|
||||
err(1, "Could not create /run/rdo");
|
||||
|
@ -94,7 +91,6 @@ void setsession(int pid, unsigned int ts_ttl) {
|
|||
|
||||
int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0700);
|
||||
if (fd < 0) {
|
||||
close(fd);
|
||||
if (errno == EEXIST)
|
||||
return;
|
||||
err(1, "Could not open %s", path);
|
||||
|
@ -126,7 +122,6 @@ int getsession(int pid, unsigned int ts_ttl) {
|
|||
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
close(fd);
|
||||
if (errno == ENOENT)
|
||||
return -1;
|
||||
err(1, "Could not open %s", path);
|
||||
|
|
Loading…
Add table
Reference in a new issue