chiark / gitweb /
changelog: finalise 5.0.1~citrix1
[chiark-utils.git] / cprogs / acctdump.c
index 0cd7a4e566b6acabf37c809d3cc5651f0bcaaa14..b9040ac710f91eebe6a83af73262a2027a4e4e29 100644 (file)
@@ -205,17 +205,26 @@ static void printrecord(const struct_acct *as, const char *filename) {
   struct passwd *pw;
   struct group *gr;
   time_t btime;
+  char commbuf[sizeof(as->ac_comm)];
 
   if (raw) {
     printf("%10lu ",(unsigned long)as->ac_btime);
   } else {
     btime= as->ac_btime;
     tm= localtime(&btime);
-    strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tm); buf[sizeof(buf)-1]= 0;
+    if (tm) {
+      strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tm); buf[sizeof(buf)-1]= 0;
+    } else {
+      snprintf(buf,sizeof(buf),"@%lu",(unsigned long)btime);
+    }
     printf("%19s ",buf);
   }
-  
-  printf("%-16.16s ", as->ac_comm);
+
+  for (i=0; i<sizeof(as->ac_comm); i++) {
+    int c=as->ac_comm[i];
+    commbuf[i]= ((c!=0 && c<=32) || c>=127) ? '?' : c;
+  }
+  printf("%-*.*s ", (int)sizeof(commbuf),(int)sizeof(commbuf), commbuf);
   
   pw= raw ? 0 : getpwuid(as->ac_uid);
   if (pw) printf("%-8s ",pw->pw_name);