summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/main.c b/src/main.c
index f65ceb1..cd4ece4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,7 +19,7 @@
#include <string.h>
#include <time.h>
-#define SECONDS_IN_DAY 86400;
+#define SECONDS_IN_DAY 86400
/**
@@ -170,15 +170,9 @@ int main(int argc, char* argv[]) {
threshold = days * SECONDS_IN_DAY;
lastlogin = fread_long(lastlogin_path);
+ // Set lastlogin to "now" if no lastlogin file is found
if(lastlogin == -1) {
- // Create lastlogin file since it doesn't exist
- printf("Lastlogin file could not be read. Writing\n");
- if(write_lastlogin(lastlogin_path) == 1) {
- printf("Failure writing lastlogin\n");
- return 1;
- }
- // Go ahead and set lastlogin time, since writing it means we're using
- // "now".
+ fprintf(stderr, "Lastlogin file could not be read. Initializing.\n");
lastlogin = time(NULL);
}
@@ -186,22 +180,21 @@ int main(int argc, char* argv[]) {
if((now - lastlogin) > threshold) {
printf("You're dead!\n");
exec_cmd(cmd);
+ return 0;
} else if((lastlogin - now) > SECONDS_IN_DAY) {
- // Abort if last login is too far in the future.
- // This should account for when
- printf(
- "Error: Last login appears to be over one day in the future.\n"
- "This likely means something has gone wrong with the system clock.\n"
- "Unable to determine current time. Aborting terminus check.\n"
+ // Abort if last login is in the future.
+ fprintf(stderr,
+ "ERROR: Last login appears to be in the future. This likely means\n"
+ "something is wrong with the system clock.\n"
);
- return 2;
- } else {
- if(write_lastlogin(lastlogin_path) == 1) {
- printf("Failure writing lastlogin\n");
- return 1;
- }
- printf("You're not dead!\n");
+ return 1;
+ }
+
+ // All other checks passed, update the lastlogin file
+ if(write_lastlogin(lastlogin_path) == 1) {
+ fprintf(stderr, "Failure writing lastlogin\n");
+ return 1;
}
-
+ printf("You're not dead!\n");
return 0;
}

Generated by cgit