Close file descriptors earlier
This commit is contained in:
parent
66e2cb0c42
commit
d44301d8fa
1 changed files with 13 additions and 20 deletions
29
sessions.h
29
sessions.h
|
@ -20,14 +20,14 @@ int getpstartts(int pid, unsigned long long* startts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_read = read(fd, fc, sizeof(fc));
|
int bytes_read = read(fd, fc, sizeof(fc));
|
||||||
if (bytes_read < 0) {
|
|
||||||
close(fd);
|
|
||||||
err(1, "Could not read %s", path);
|
|
||||||
}
|
|
||||||
fc[bytes_read] = '\0';
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
if (bytes_read < 0)
|
||||||
|
err(1, "Could not read %s", path);
|
||||||
|
|
||||||
|
fc[bytes_read] = '\0';
|
||||||
|
|
||||||
if (memchr(ptr, '\0', bytes_read) != NULL)
|
if (memchr(ptr, '\0', bytes_read) != NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -57,17 +57,14 @@ int ensuredir(int recur) {
|
||||||
int fd = open("/run/rdo", O_RDONLY, O_DIRECTORY | O_NOFOLLOW);
|
int fd = open("/run/rdo", O_RDONLY, O_DIRECTORY | O_NOFOLLOW);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
close(fd);
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
if (mkdir("/run/rdo", 0700) < 0) {
|
if (mkdir("/run/rdo", 0700) < 0)
|
||||||
close(fd);
|
|
||||||
err(1, "Could not create /run/rdo");
|
err(1, "Could not create /run/rdo");
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
return ensuredir(++recur);
|
return ensuredir(++recur);
|
||||||
} else {
|
|
||||||
close(fd);
|
|
||||||
err(1, "Could not open /run/rdo");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
err(1, "Could not open /run/rdo");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(fd, &st) < 0) {
|
if (fstat(fd, &st) < 0) {
|
||||||
|
@ -97,11 +94,9 @@ void setsession(int pid, unsigned int ts_ttl) {
|
||||||
|
|
||||||
int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0700);
|
int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0700);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EEXIST) {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
if (errno == EEXIST)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
err(1, "Could not open %s", path);
|
err(1, "Could not open %s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +126,9 @@ int getsession(int pid, unsigned int ts_ttl) {
|
||||||
|
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = open(path, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == ENOENT) {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
if (errno == ENOENT)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
err(1, "Could not open %s", path);
|
err(1, "Could not open %s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue