]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - login-utils/utmpdump.c
Make the ways of using output stream consistent in usage()
[thirdparty/util-linux.git] / login-utils / utmpdump.c
index 274f0d97aa0d9fd03e6f61ea952fb2e1d3622d7a..ce9ad718b2a5994fa6060a7ce7f99b486dc03b5b 100644 (file)
@@ -108,7 +108,7 @@ static void print_utline(struct utmpx *ut, FILE *out)
                addr_string = inet_ntop(AF_INET, &(ut->ut_addr_v6), buffer, sizeof(buffer));
 
        tv.tv_sec = ut->ut_tv.tv_sec;
-       tv.tv_usec = ut->ut_tv.tv_usec;
+       tv.tv_usec = ut->ut_tv.tv_usec < (int32_t) USEC_PER_SEC ? ut->ut_tv.tv_usec : 0;
 
        if (strtimeval_iso(&tv, ISO_TIMESTAMP_COMMA_GT, time_string,
                           sizeof(time_string)) != 0)
@@ -282,7 +282,12 @@ static void undump(FILE *in, FILE *out)
        while (fgets(linestart, 1023, in)) {
                line = linestart;
                memset(&ut, '\0', sizeof(ut));
-               sscanf(line, "[%hd] [%d] [%4c] ", &ut.ut_type, &ut.ut_pid, ut.ut_id);
+
+               if (sscanf(line, "[%hd] [%d] [%4c] ",
+                               &ut.ut_type, &ut.ut_pid, ut.ut_id) != 3) {
+                       warnx(_("parse error: %s"), line);
+                       continue;
+               }
 
                line += 19;
                line += gettok(line, ut.ut_user, sizeof(ut.ut_user), 1);
@@ -319,9 +324,9 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -f, --follow         output appended data as the file grows\n"), out);
        fputs(_(" -r, --reverse        write back dumped data into utmp file\n"), out);
        fputs(_(" -o, --output <file>  write to file instead of standard output\n"), out);
-       printf(USAGE_HELP_OPTIONS(22));
+       fprintf(out, USAGE_HELP_OPTIONS(22));
 
-       printf(USAGE_MAN_TAIL("utmpdump(1)"));
+       fprintf(out, USAGE_MAN_TAIL("utmpdump(1)"));
        exit(EXIT_SUCCESS);
 }