int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; #ifdef uts float expand(); #else ulong_t expand(); #endif while (fread(&ab, sizeof(ab), 1, stdin) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, NULL); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ enter(&pb); } output(); exit(0); }
int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; ulong_t expand(); int ver; /* version of acct struct */ int aread(); if ((ur = (struct urec *) calloc(a_usize, sizeof (struct urec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } urlast = ur; if ((sr = (struct srec *) calloc(a_ssize, sizeof (struct srec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } while (--argc > 0) { if (**++argv == '-') switch(*++*argv) { } else { readctmp(*argv); } } if (fread((char *)&ab, sizeof(struct acct), 1, stdin) != 1) exit(1); else if (ab.ac_flag & AEXPND) ver = 2; /* 4.0 acct structure */ else ver = 1; /* 3.x acct structure */ rewind(stdin); while (aread(ver) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, getname(ab.ac_uid, ab.ac_tty, ab.ac_btime)); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc1: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ printf("%ld\t%.*s\t%lu\t%lu\t%u\n", pb.pt_uid, OUTPUT_NSZ, pb.pt_name, pb.pt_cpu[0], pb.pt_cpu[1], pb.pt_mem); } exit(0); }
/* * update tbuf with new time, write ctmp record for end of session */ static void update(struct tbuf *tp) { time_t told, /* last time for tbuf record */ tnew; /* time of this record */ /* Difference is connect time */ told = tp->ttime; tnew = wb.ut_xtime; if (told > tnew) { cftime(time_buf, DATE_FMT, &told); fprintf(stderr, "acctcon: bad times: old: %s", time_buf); cftime(time_buf, DATE_FMT, &tnew); fprintf(stderr, "new: %s", time_buf); exitcode = 1; tp->ttime = tnew; return; } tp->ttime = tnew; switch (wb.ut_type) { case USER_PROCESS: tp->tlsess++; /* * Someone logged in without logging off. Put out record. */ if (tp->tname[0] != '\0') { cb.ct_tty = tp->tdev; CPYN(cb.ct_name, tp->tname); cb.ct_uid = namtouid(cb.ct_name); cb.ct_start = told; if (pnpsplit(cb.ct_start, (ulong_t)(tnew-told), cb.ct_con) == 0) { fprintf(stderr, "acctcon: could not calculate " "prime/non-prime hours\n"); exit(1); } enter(&cb); tp->ttotal += tnew-told; } else /* Someone just logged in */ tp->tlon++; CPYN(tp->tname, wb.ut_name); break; case DEAD_PROCESS: tp->tloff++; if (tp->tname[0] != '\0') { /* Someone logged off */ /* Set up and print ctmp record */ cb.ct_tty = tp->tdev; CPYN(cb.ct_name, tp->tname); cb.ct_uid = namtouid(cb.ct_name); cb.ct_start = told; if (pnpsplit(cb.ct_start, (ulong_t)(tnew-told), cb.ct_con) == 0) { fprintf(stderr, "acctcon: could not calculate " "prime/non-prime hours\n"); exit(1); } enter(&cb); tp->ttotal += tnew-told; tp->tname[0] = '\0'; } } }