diff --git a/sessions.h b/sessions.h index 93c265c..5819417 100644 --- a/sessions.h +++ b/sessions.h @@ -18,9 +18,9 @@ int getpstartts(int pid, unsigned long long* startts) { err(1, "Could not open %s", path); int bytes_read = read(fd, fc, sizeof(fc)); - if (bytes_read < 0) - err(1, "Could not read %s", path); - fc[bytes_read] = '\0'; + if (bytes_read < 0) + err(1, "Could not read %s", path); + fc[bytes_read] = '\0'; close(fd); @@ -72,10 +72,10 @@ int gethandle(int recur) { } void setsession(int pid, unsigned int ts_ttl) { - if (ts_ttl == 0) - return; + if (ts_ttl == 0) + return; - unsigned long long startts; + unsigned long long startts; char path[1024], ts_str[32]; int dirfd = gethandle(0); @@ -94,51 +94,51 @@ void setsession(int pid, unsigned int ts_ttl) { 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) - err(1, "Could not write to %s", path); + if (write(fd, ts_str, strlen(ts_str)) < 0) + err(1, "Could not write to %s", path); - close(fd); + close(fd); return; } int getsession(int pid, unsigned int ts_ttl) { - if (ts_ttl == 0) - return -1; + if (ts_ttl == 0) + return -1; - unsigned long long startts, current; + unsigned long long startts, current; char path[1024], ts_str[32]; - int dirfd = gethandle(0); + int dirfd = gethandle(0); if (dirfd < 0 && errno == 0) return -1; if (getpstartts(pid, &startts) < 0) 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); - if (fd < 0) { - if (errno == ENOENT) - return -1; - err(1, "Could not open %s", path); - } + if (fd < 0) { + if (errno == ENOENT) + return -1; + err(1, "Could not open %s", path); + } - int bytes_read = read(fd, ts_str, sizeof(ts_str)); - if (bytes_read < 0) - err(1, "Could not read %s", path); - ts_str[bytes_read] = '\0'; + int bytes_read = read(fd, ts_str, sizeof(ts_str)); + if (bytes_read < 0) + err(1, "Could not read %s", path); + ts_str[bytes_read] = '\0'; - startts = strtoull(ts_str, NULL, 10); - current = time(NULL); + startts = strtoull(ts_str, NULL, 10); + current = time(NULL); - if (current - startts > ts_ttl) { - unlink(path); - return -1; - } + if (current - startts > ts_ttl) { + unlink(path); + return -1; + } - return 0; + return 0; }