X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Facctdump.c;h=b9040ac710f91eebe6a83af73262a2027a4e4e29;hp=713992293ca0a8fccd20132ec2422c13590a0922;hb=a30213491e687db44dbf5ee15f35932bf8b82394;hpb=a2dd98f3f51c34d2d85a139f1fcaaf76a10fdd10 diff --git a/cprogs/acctdump.c b/cprogs/acctdump.c index 7139922..b9040ac 100644 --- a/cprogs/acctdump.c +++ b/cprogs/acctdump.c @@ -43,6 +43,8 @@ typedef unsigned long long u64; typedef struct acct_v3 struct_acct; #define HAVE_AC_EXITCODE +#define HAVE_AC_FLT +#define FIELD_AC_FLAG(as) ((as)->ac_flag) #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -51,6 +53,8 @@ typedef struct acct_v3 struct_acct; #include typedef struct acctv2 struct_acct; +#define HAVE_AC_IO_MEM +#define FIELD_AC_FLAG(as) ((as)->ac_flagx & ~ANVER) #else @@ -177,8 +181,14 @@ static void printbanner(void) { , stdout); } if (usages) { - fputs(" user time sys time elap time minflt maxflt", - stdout); + fputs(" user time sys time elap time " +#ifdef HAVE_AC_FLT + " minflt maxflt" +#endif +#ifdef HAVE_AC_IO_MEM + " avg.mem io" +#endif + , stdout); } putchar('\n'); checkstdout(); @@ -195,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; iac_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); @@ -241,7 +260,7 @@ static void printrecord(const struct_acct *as, const char *filename) { } } - r= as->ac_flag; + r= FIELD_AC_FLAG(as); for (i=1, fp= "FS4DX"; *fp; fp++, i<<=1) { if (r&i) { putchar(*fp); @@ -289,12 +308,20 @@ static void printrecord(const struct_acct *as, const char *filename) { #endif /*HAVE_AC_EXITCODE*/ if (usages) { - printf(" %10lu %10lu %10lu %8ld %8ld", + printf(" %10lu %10lu %10lu", (unsigned long)as->ac_utime, (unsigned long)as->ac_stime, - (unsigned long)as->ac_etime, + (unsigned long)as->ac_etime); +#ifdef HAVE_AC_FLT + printf(" %8lu %8lu", (unsigned long)as->ac_minflt, (unsigned long)as->ac_majflt); +#endif +#ifdef HAVE_AC_IO_MEM + printf(" %4e %4e", + as->ac_mem, + as->ac_io); +#endif } putchar('\n');