diff options
author | Aaron Ball <nullspoon@oper.io> | 2019-12-29 23:28:17 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2019-12-29 23:28:17 -0700 |
commit | 6c5bf49d5fa94cbeba28eb24663a68b5a9d530fc (patch) | |
tree | 19cf820eb6bf23a70f500b7307016192f1d8d3de | |
parent | 015f6670680bc67dc26eeb1c5076b5c891bec4ae (diff) | |
download | terminus-6c5bf49d5fa94cbeba28eb24663a68b5a9d530fc.tar.gz terminus-6c5bf49d5fa94cbeba28eb24663a68b5a9d530fc.tar.xz |
Simple updates to log messages and logic
Error messages now output to stderr. Also updated logic to default to
updating the lastlogin file outside of the logic tree, since the logic
tree returned early on each failure state.
-rw-r--r-- | src/main.c | 39 |
1 files changed, 16 insertions, 23 deletions
@@ -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; } |