Fix some more whitespaces...
I should probably switch IDEs
This commit is contained in:
parent
6cabebefed
commit
5ba40256a0
1 changed files with 31 additions and 31 deletions
62
sessions.h
62
sessions.h
|
@ -18,9 +18,9 @@ int getpstartts(int pid, unsigned long long* startts) {
|
||||||
err(1, "Could not open %s", path);
|
err(1, "Could not open %s", path);
|
||||||
|
|
||||||
int bytes_read = read(fd, fc, sizeof(fc));
|
int bytes_read = read(fd, fc, sizeof(fc));
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
err(1, "Could not read %s", path);
|
err(1, "Could not read %s", path);
|
||||||
fc[bytes_read] = '\0';
|
fc[bytes_read] = '\0';
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ int gethandle(int recur) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setsession(int pid, unsigned int ts_ttl) {
|
void setsession(int pid, unsigned int ts_ttl) {
|
||||||
if (ts_ttl == 0)
|
if (ts_ttl == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned long long startts;
|
unsigned long long startts;
|
||||||
char path[1024], ts_str[32];
|
char path[1024], ts_str[32];
|
||||||
|
|
||||||
int dirfd = gethandle(0);
|
int dirfd = gethandle(0);
|
||||||
|
@ -94,51 +94,51 @@ void setsession(int pid, unsigned int ts_ttl) {
|
||||||
err(1, "Could not open %s", path);
|
err(1, "Could not open %s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(ts_str, sizeof(ts_str), "%llu", (unsigned long long)time(NULL));
|
snprintf(ts_str, sizeof(ts_str), "%llu", (unsigned long long)time(NULL));
|
||||||
|
|
||||||
if (write(fd, ts_str, strlen(ts_str)) < 0)
|
if (write(fd, ts_str, strlen(ts_str)) < 0)
|
||||||
err(1, "Could not write to %s", path);
|
err(1, "Could not write to %s", path);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getsession(int pid, unsigned int ts_ttl) {
|
int getsession(int pid, unsigned int ts_ttl) {
|
||||||
if (ts_ttl == 0)
|
if (ts_ttl == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
unsigned long long startts, current;
|
unsigned long long startts, current;
|
||||||
char path[1024], ts_str[32];
|
char path[1024], ts_str[32];
|
||||||
|
|
||||||
int dirfd = gethandle(0);
|
int dirfd = gethandle(0);
|
||||||
if (dirfd < 0 && errno == 0)
|
if (dirfd < 0 && errno == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getpstartts(pid, &startts) < 0)
|
if (getpstartts(pid, &startts) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "/run/rdo/%d-%llu", pid, startts);
|
snprintf(path, sizeof(path), "/run/rdo/%d-%llu", pid, startts);
|
||||||
|
|
||||||
int fd = openat(dirfd, path, O_RDONLY);
|
int fd = openat(dirfd, path, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return -1;
|
return -1;
|
||||||
err(1, "Could not open %s", path);
|
err(1, "Could not open %s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_read = read(fd, ts_str, sizeof(ts_str));
|
int bytes_read = read(fd, ts_str, sizeof(ts_str));
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
err(1, "Could not read %s", path);
|
err(1, "Could not read %s", path);
|
||||||
ts_str[bytes_read] = '\0';
|
ts_str[bytes_read] = '\0';
|
||||||
|
|
||||||
startts = strtoull(ts_str, NULL, 10);
|
startts = strtoull(ts_str, NULL, 10);
|
||||||
current = time(NULL);
|
current = time(NULL);
|
||||||
|
|
||||||
if (current - startts > ts_ttl) {
|
if (current - startts > ts_ttl) {
|
||||||
unlink(path);
|
unlink(path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue