Correct ctime arguments
authorAndrew Deason <adeason@sinenomine.net>
Wed, 15 Jul 2009 14:54:32 +0000 (09:54 -0500)
committerRuss Allbery <rra@stanford.edu>
Tue, 21 Jul 2009 15:14:12 +0000 (08:14 -0700)
Corrects a few places throughout the tree where ctime() is incorrectly passed a
pointer to an afs_uint32 or similar fixed-width datatype, instead of a pointer
to a time_t.

FIXES 124538

Reviewed-on: http://gerrit.openafs.org/http://gerrit.openafs.org/100
Tested-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Russ Allbery <rra@stanford.edu>
Reviewed-by: Russ Allbery <rra@stanford.edu>

12 files changed:
src/bozo/smail-notifier.c
src/butc/read_tape.c
src/kauth/kautils.c
src/tviced/state_analyzer.c
src/util/afsutil.h
src/util/test/dtest.c
src/util/test/ktest.c
src/util/test/test_ktime.c
src/vfsck/inode.c
src/viced/callback.c
src/vlserver/vlclient.c
src/volser/vos.c

index b393232..5b82d92 100644 (file)
@@ -41,11 +41,10 @@ main(argc, argv)
     char buf[BUFSIZ], *bufp, *bufp1, *typep, *cmd, *bp;
     register afs_int32 code, c, fd, id, pflags = -1, len, core = 0, lastE = 0;
     char comLine[60], coreName[40], name[40], lastErrorName[50];
-    afs_int32 pid = -1, lastExit = -1, lastSignal = -1, rsTime = -1, rsCount =
-       -1;
-    afs_int32 procStartTime = -1, procStarts = -1;
-    afs_int32 lastAnyExit = -1, lastErrorExit = -1, errorCode =
-       -1, errorSignal = -1, goal = -1;
+    afs_int32 pid = -1, lastExit = -1, lastSignal = -1, rsCount = -1;
+    afs_int32 procStarts = -1;
+    afs_int32 errorCode = -1, errorSignal = -1, goal = -1;
+    time_t procStartTime = -1, rsTime = -1, lastAnyExit = -1, lastErrorExit = -1;
     char *timeStamp;
 
     typep = (char *)malloc(50);
index e7f1fad..96050b0 100644 (file)
@@ -96,18 +96,23 @@ printLabel(struct tapeLabel *tapeLabelPtr)
 
     fprintf(stderr, "\nDUMP       %u\n", tapeLabelPtr->label.dumpid);
     if (printlabels) {
+       time_t t;
+
        fprintf(stderr, "   AFS Tape  Name   : %s\n",
                tapeLabelPtr->label.AFSName);
        fprintf(stderr, "   Permanent Name   : %s\n",
                tapeLabelPtr->label.pName);
        fprintf(stderr, "   Dump Id          : %u\n",
                tapeLabelPtr->label.dumpid);
+       t = tapeLabelPtr->label.dumpid;
        fprintf(stderr, "   Dump Id Time     : %.24s\n",
-               ctime(&(tapeLabelPtr->label.dumpid)));
+               ctime(&t));
+       t = tapeLabelPtr->label.creationTime;
        fprintf(stderr, "   Date Created     : %.24s\n",
-               ctime(&(tapeLabelPtr->label.creationTime)));
+               ctime(&t));
+       t = tapeLabelPtr->label.expirationDate;
        fprintf(stderr, "   Date Expires     : %.24s\n",
-               ctime(&(tapeLabelPtr->label.expirationDate)));
+               ctime(&t));
        fprintf(stderr, "   Version Number   : %d\n",
                tapeLabelPtr->label.structVersion);
        fprintf(stderr, "   Tape Use Count   : %d\n",
@@ -150,33 +155,37 @@ printHeader(struct volumeHeader *headerPtr, afs_int32 *isvolheader)
     headerPtr->cloneDate = ntohl(headerPtr->cloneDate);
 
     if (headerPtr->magic == TC_VOLBEGINMAGIC) {
+       time_t t;
+
        *isvolheader = 1;
        if (verbose)
            fprintf(stderr, "Volume header\n");
+       t = headerPtr->from;
        fprintf(stderr,
                "VOLUME %3d %s (%u) - %s dump from %.24s",
                ++volcount, headerPtr->volumeName, headerPtr->volumeID,
                (headerPtr->level ? "Incr" : "Full"),
-               ((headerPtr->from) ? (char *)ctime(&headerPtr->from) : "0"));
+               (t ? (char *)ctime(&t) : "0"));
         /* do not include two ctime() calls in the same fprintf call as
          * the same string buffer will be returned by each call. */
-        fprintf(stderr, 
-                " till %.24s\n",
-                ctime(&(headerPtr->cloneDate)));
+       t = headerPtr->cloneDate;
+        fprintf(stderr, " till %.24s\n", ctime(&t));
        if (printheaders) {
            fprintf(stderr, "   Volume Name    = %s\n",
                    headerPtr->volumeName);
            fprintf(stderr, "   Volume ID      = %u\n", headerPtr->volumeID);
+           t = headerPtr->cloneDate;
            fprintf(stderr, "   Clone Date     = %.24s\n",
-                   ctime(&headerPtr->cloneDate));
+                   ctime(&t));
            fprintf(stderr, "   Vol Fragment   = %d\n", headerPtr->frag);
            fprintf(stderr, "   Vol Continued  = 0x%x\n", headerPtr->contd);
            fprintf(stderr, "   DumpSet Name   = %s\n",
                    headerPtr->dumpSetName);
            fprintf(stderr, "   Dump ID        = %u\n", headerPtr->dumpID);
            fprintf(stderr, "   Dump Level     = %d\n", headerPtr->level);
+           t = headerPtr->from;
            fprintf(stderr, "   Dump Since     = %.24s\n",
-                   ctime(&headerPtr->from));
+                   ctime(&t));
            fprintf(stderr, "   parent Dump ID = %u\n", headerPtr->parentID);
        }
     } else if (headerPtr->magic == TC_VOLENDMAGIC) {
index f6f1df2..f48fbf1 100644 (file)
@@ -11,6 +11,7 @@
 #include <afs/param.h>
 
 
+#include <afs/afsutil.h>
 #include <afs/stds.h>
 #include <sys/types.h>
 #ifdef AFS_NT40_ENV
index 128e9d8..35e13cf 100644 (file)
@@ -784,8 +784,8 @@ print_cb_help(void)
 /* time */
 #define DPFT(T, name, var) \
     do { \
-        char * last; \
-        printf(T "%s = \"%s\"\n", name, strtok_r(ctime(&(var)), "\r\n", &last)); \
+        time_t t = var; \
+        printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
     } while(0)
 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
index 4b8832e..e4dfead 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdio.h>
 #include <stdarg.h>
+#include <string.h>
 
 extern int LogLevel;
 extern int mrafsStyleLogs;
index e1721d0..5f232f4 100644 (file)
@@ -18,6 +18,7 @@ main(argc, argv)
      char **argv;
 {
     long code, temp;
+    time_t t;
 
     if (argc <= 1) {
        printf("dtest: usage is 'dtest <time to interpret>'\n");
@@ -25,11 +26,12 @@ main(argc, argv)
     }
 
     code = ktime_DateToLong(argv[1], &temp);
+    t = temp;
     if (code) {
        printf("date parse failed with code %d.\n", code);
     } else {
        printf("returned %d, which, run through ctime, yields %s", temp,
-              ctime(&temp));
+              ctime(&t));
     }
     exit(0);
 }
index 8dbb9ee..a62f711 100644 (file)
@@ -19,6 +19,7 @@ main(argc, argv)
 {
     struct ktime ttime;
     long ntime, code;
+    time_t t;
 
     if (argc <= 1) {
        printf("ktest: usage is 'ktest <periodic date to evaluate>'\n");
@@ -32,6 +33,7 @@ main(argc, argv)
     }
 
     ntime = ktime_next(&ttime, 0);
-    printf("time is %d, %s", ntime, ctime(&ntime));
+    t = ntime;
+    printf("time is %d, %s", ntime, ctime(&t));
     exit(0);
 }
index dd37298..b5fe4a5 100644 (file)
@@ -33,22 +33,24 @@ main(argc, argv)
      int argc;
      char *argv[];
 {
-    long code;
+    long code, temp;
     int errors;
-    long t;
+    time_t t;
     struct testTime *tt;
 
     /* should do timezone and daylight savings time correction so this program
      * work in other than EST */
 
     if (argc > 1) {
-       code = util_GetLong(argv[1], &t);
+       code = util_GetLong(argv[1], &temp);
+       t = temp;
        if (code) {             /* assume its a date string */
-           code = ktime_DateToLong(argv[1], &t);
-           printf("The string %s gives %d; ctime yields %s", argv[1], t,
+           code = ktime_DateToLong(argv[1], &temp);
+           t = temp;
+           printf("The string %s gives %d; ctime yields %s", argv[1], temp,
                   ctime(&t));
        } else {
-           printf("The value %d is %s", t, ctime(&t));
+           printf("The value %d is %s", temp, ctime(&t));
        }
        exit(0);
     }
index 5347085..460bf19 100644 (file)
@@ -449,6 +449,7 @@ pinode(ino)
     register char *p;
     struct passwd *pw;
     char *ctime();
+    time_t t;
 
     printf(" I=%u ", ino);
     if (ino < ROOTINO || ino > maxino)
@@ -494,7 +495,8 @@ pinode(ino)
 #else
     printf("SIZE=%ld ", dp->di_size);
 #endif
-    p = ctime(&dp->di_mtime);
+    t = dp->di_mtime;
+    p = ctime(&t);
     printf("MTIME=%12.12s %4.4s ", p + 4, p + 20);
 }
 
index 7860e49..344ffd2 100644 (file)
@@ -2847,8 +2847,8 @@ main(int argc, char **argv)
     }
     now = ReadDump(*argv, timebits);
     if (stats || noptions == 0) {
-       time_t uxtfirst = UXtime(tfirst);
-       printf("The time of the dump was %u %s", (unsigned int) now, ctime(&now));
+       time_t uxtfirst = UXtime(tfirst), tnow = now;
+       printf("The time of the dump was %u %s", (unsigned int) now, ctime(&tnow));
        printf("The last time cleanup ran was %u %s", (unsigned int) uxtfirst,
               ctime(&uxtfirst));
        PrintCallBackStats();
index a3f5d07..cd93d50 100644 (file)
@@ -1293,7 +1293,7 @@ dump_stats(vldstats *stats, vital_vlheader *vital_header)
     char strg[30];
     time_t start_time = stats->start_time;
 
-    strncpy(strg, ctime(&start_time), sizeof(strg));
+    afs_ctime(&start_time, strg, sizeof(strg));
     strg[strlen(strg) - 1] = 0;
     printf("Dynamic statistics stats (starting time: %s):\n", strg);
     printf("OpcodeName\t# Requests\t# Aborts\n");
index f79ae7c..9c5b7a6 100644 (file)
@@ -470,19 +470,13 @@ DumpFunction(struct rx_call *call, void *rock)
     return (error);
 }
 
-static char *
-vos_ctime(afs_int32 *timep)
-{
-    time_t foo = *timep;
-    return ctime(&foo);
-}
-
 static void
 DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
              int *totalOK, int *totalNotOK, int *totalBusy, int fast,
              int longlist, int disp)
 {
     char pname[10];
+    time_t t;
 
     if (fast) {
        fprintf(STDOUT, "%-10lu\n", (unsigned long)pntr->volid);
@@ -515,25 +509,32 @@ DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
                    (unsigned long)pntr->cloneID,
                    (unsigned long)pntr->backupID);
            fprintf(STDOUT, "    MaxQuota %10d K \n", pntr->maxquota);
+           t = pntr->creationDate;
            fprintf(STDOUT, "    Creation    %s",
-                   vos_ctime(& pntr->creationDate));
+                   ctime(&t));
 #ifdef FULL_LISTVOL_SWITCH
+           t = pntr->copyDate;
            fprintf(STDOUT, "    Copy        %s",
-                   vos_ctime( & pntr->copyDate));
-           if (!pntr->backupDate)
+                   ctime(&t));
+
+           t = pntr->backupDate;
+           if (!t)
                fprintf(STDOUT, "    Backup      Never\n");
            else
                fprintf(STDOUT, "    Backup      %s",
-                       vos_ctime( & pntr->backupDate));
-           if (pntr->accessDate)
+                       ctime(&t));
+
+           t = pntr->accessDate;
+           if (t)
                fprintf(STDOUT, "    Last Access %s",
-                       vos_ctime( & pntr->accessDate));
+                       ctime(&t));
 #endif
-           if (!pntr->updateDate)
+           t = pntr->updateDate;
+           if (!t)
                fprintf(STDOUT, "    Last Update Never\n");
            else
                fprintf(STDOUT, "    Last Update %s",
-                       vos_ctime( & pntr->updateDate));
+                       ctime(&t));
            fprintf(STDOUT,
                    "    %d accesses in the past day (i.e., vnode references)\n",
                    pntr->dayUse);
@@ -620,7 +621,7 @@ XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
               int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
               int a_fast, int a_int32, int a_showProblems)
 {                              /*XDisplayFormat */
-
+    time_t t;
     char pname[10];
 
     if (a_fast) {
@@ -662,25 +663,33 @@ XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
                    (unsigned long)a_xInfoP->cloneID,
                    (unsigned long)a_xInfoP->backupID);
            fprintf(STDOUT, "    MaxQuota %10d K \n", a_xInfoP->maxquota);
+
+           t = a_xInfoP->creationDate;
            fprintf(STDOUT, "    Creation    %s",
-                   vos_ctime( & a_xInfoP->creationDate));
+                   ctime(&t));
 #ifdef FULL_LISTVOL_SWITCH
+           t = a_xInfoP->copyDate;
            fprintf(STDOUT, "    Copy        %s",
-                   vos_ctime( & a_xInfoP->copyDate));
-           if (!a_xInfoP->backupDate)
+                   ctime(&t));
+
+           t = a_xInfoP->backupDate;
+           if (!t)
                fprintf(STDOUT, "    Backup      Never\n");
            else
                fprintf(STDOUT, "    Backup      %s",
-                       vos_ctime( & a_xInfoP->backupDate));
-           if (a_xInfoP->accessDate)
+                       ctime(&t));
+
+           t = a_xInfoP->accessDate;
+           if (t)
                fprintf(STDOUT, "    Last Access %s",
-                       vos_ctime( & a_xInfoP->accessDate));
+                       ctime(&t));
 #endif
-           if (!a_xInfoP->updateDate)
+           t = a_xInfoP->updateDate;
+           if (!t)
                fprintf(STDOUT, "    Last Update Never\n");
            else
                fprintf(STDOUT, "    Last Update %s",
-                       vos_ctime( & a_xInfoP->updateDate));
+                       ctime(&t));
            fprintf(STDOUT,
                    "    %d accesses in the past day (i.e., vnode references)\n",
                    a_xInfoP->dayUse);
@@ -846,6 +855,7 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
                int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP,
                int a_fast, int a_int32, int a_showProblems)
 {                              /*XDisplayFormat */
+    time_t t;
     if (a_fast) {
        /*
         * Short & sweet.
@@ -904,21 +914,30 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
                        fprintf(STDOUT, "type\t\t?\n");
                        break;
                }
+               t = a_xInfoP->creationDate;
                fprintf(STDOUT, "creationDate\t%-9lu\t%s", 
                        afs_printable_uint32_lu(a_xInfoP->creationDate),
-                       vos_ctime(&a_xInfoP->creationDate));
+                       ctime(&t));
+
+               t = a_xInfoP->accessDate;
                fprintf(STDOUT, "accessDate\t%-9lu\t%s", 
                        afs_printable_uint32_lu(a_xInfoP->accessDate),
-                       vos_ctime(&a_xInfoP->accessDate));
+                       ctime(&t));
+
+               t = a_xInfoP->updateDate;
                fprintf(STDOUT, "updateDate\t%-9lu\t%s", 
                        afs_printable_uint32_lu(a_xInfoP->updateDate),
-                       vos_ctime(&a_xInfoP->updateDate));
+                       ctime(&t));
+
+               t = a_xInfoP->backupDate;
                fprintf(STDOUT, "backupDate\t%-9lu\t%s", 
                        afs_printable_uint32_lu(a_xInfoP->backupDate),
-                       vos_ctime(&a_xInfoP->backupDate));
+                       ctime(&t));
+
+               t = a_xInfoP->copyDate;
                fprintf(STDOUT, "copyDate\t%-9lu\t%s", 
                        afs_printable_uint32_lu(a_xInfoP->copyDate),
-                       vos_ctime(&a_xInfoP->copyDate));
+                       ctime(&t));
                
                fprintf(STDOUT, "diskused\t%u\n", a_xInfoP->size);
                fprintf(STDOUT, "maxquota\t%u\n", a_xInfoP->maxquota);
@@ -1008,6 +1027,7 @@ DisplayFormat2(long server, long partition, volintInfo *pntr)
 {
     static long server_cache = -1, partition_cache = -1;
     static char hostname[256], address[32], pname[16];
+    time_t t;
 
     if (server != server_cache) {
        struct in_addr s;
@@ -1064,21 +1084,31 @@ DisplayFormat2(long server, long partition, volintInfo *pntr)
        fprintf(STDOUT, "type\t\t?\n");
        break;
     }
+    t = pntr->creationDate;
     fprintf(STDOUT, "creationDate\t%-9lu\t%s", 
            afs_printable_uint32_lu(pntr->creationDate),
-           vos_ctime(&pntr->creationDate));
+           ctime(&t));
+
+    t = pntr->accessDate;
     fprintf(STDOUT, "accessDate\t%-9lu\t%s", 
            afs_printable_uint32_lu(pntr->accessDate),
-           vos_ctime(&pntr->accessDate));
+           ctime(&t));
+
+    t = pntr->updateDate;
     fprintf(STDOUT, "updateDate\t%-9lu\t%s", 
            afs_printable_uint32_lu(pntr->updateDate),
-           vos_ctime(&pntr->updateDate));
+           ctime(&t));
+
+    t = pntr->backupDate;
     fprintf(STDOUT, "backupDate\t%-9lu\t%s", 
            afs_printable_uint32_lu(pntr->backupDate),
-           vos_ctime(&pntr->backupDate));
+           ctime(&t));
+
+    t = pntr->copyDate;
     fprintf(STDOUT, "copyDate\t%-9lu\t%s", 
            afs_printable_uint32_lu(pntr->copyDate),
-           vos_ctime(&pntr->copyDate));
+           ctime(&t));
+
     fprintf(STDOUT, "flags\t\t%#lx\t(Optional)\n", 
            afs_printable_uint32_lu(pntr->flags));
     fprintf(STDOUT, "diskused\t%u\n", pntr->size);
@@ -3912,6 +3942,7 @@ VolserStatus(register struct cmd_syndesc *as, void *arock)
     afs_int32 count;
     int i;
     char pname[10];
+    time_t t;
 
     server = GetServer(as->parms[0].items->data);
     if (!server) {
@@ -3934,8 +3965,9 @@ VolserStatus(register struct cmd_syndesc *as, void *arock)
     for (i = 0; i < count; i++) {
        /*print out the relevant info */
        fprintf(STDOUT, "--------------------------------------\n");
+       t = pntr->time;
        fprintf(STDOUT, "transaction: %lu  created: %s",
-               (unsigned long)pntr->tid, vos_ctime( & pntr->time));
+               (unsigned long)pntr->tid, ctime(&t));
        if (pntr->returnCode) {
            fprintf(STDOUT, "returnCode: %lu\n",
                    (unsigned long)pntr->returnCode);