butc: initialize startTime before it is used
[openafs.git] / src / butc / lwps.c
index 441e8f0..f479b78 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <afs/procmgmt.h>
+#include <roken.h>
 
-#include <sys/types.h>
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
 #include <conio.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <netdb.h>
 #endif
 
-#include <afs/procmgmt.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
-#include <time.h>
 #include <lwp.h>
 #include <lock.h>
 #include <afs/tcdata.h>
 #include <afs/bubasics.h>      /* PA */
 #include <afs/budb_client.h>
+#include <afs/bucoord_prototypes.h>
+#include <afs/butm_prototypes.h>
 #include <afs/volser.h>
+#include <afs/volser_prototypes.h>
 #include <afs/com_err.h>
-#include "error_macros.h"
 #include <afs/afsutil.h>
-#include <errno.h>
+
+#include "error_macros.h"
 #include "butc_xbsa.h"
+#include "butc_internal.h"
 
 /* GLOBAL CONFIGURATION PARAMETERS */
-extern int dump_namecheck;
 extern int queryoperator;
 extern int tapemounted;
 extern char *opencallout;
 extern char *closecallout;
 extern char *whoami;
-extern char *extractDumpName();
+extern char *extractDumpName(char *);
 extern int BufferSize;         /* Size in B stored for header info */
-extern char *restoretofile;
 FILE *restoretofilefd;
+#ifdef xbsa
+extern char *restoretofile;
 extern int forcemultiple;
+#endif
 
 /* XBSA Global Parameters */
 afs_int32 xbsaType;
@@ -58,7 +55,7 @@ afs_int32 xbsaType;
 struct butx_transactionInfo butxInfo;
 #endif
 
-struct TapeBlock {             /* A 16KB tapeblock */
+static struct TapeBlock {              /* A 16KB tapeblock */
     char mark[BUTM_HDRSIZE];   /* Header info */
     char data[BUTM_BLKSIZE];   /* data */
 } *bufferBlock;
@@ -119,24 +116,27 @@ extern struct tapeConfig globalTapeConfig;
 extern struct deviceSyncNode *deviceLatch;
 extern char globalCellName[];
 struct timeval tp;
-struct timezone tzp;
 
 /* forward declaration */
-afs_int32 readVolumeHeader( /*char *buffer,afs_int32 bufloc,(struct volumeHeader *)vhptr */ );
+afs_int32 readVolumeHeader(char *, afs_int32, struct volumeHeader *);
+int FindVolTrailer(char *, afs_int32, afs_int32 *, struct volumeHeader *);
+int FindVolTrailer2(char *, afs_int32, afs_int32 *, char *, afs_int32,
+                   afs_int32 *, struct volumeHeader *);
+int SkipVolume(struct tc_restoreDesc *, afs_int32, afs_int32, afs_int32,
+              afs_int32);
+
+
 
 /* The on-disk volume header or trailer can differ in size from platform to platform */
-struct TapeBlock tapeBlock;
+static struct TapeBlock tapeBlock;
 char tapeVolumeHT[sizeof(struct volumeHeader) + 2 * sizeof(char)];
 
 void
-PrintLog(log, error1, error2, str, a, b, c, d, e, f, g, h, i, j)
-     FILE *log;
-     afs_int32 error1, error2;
-     char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j;
+PrintLogStr(FILE *log, afs_int32 error1, afs_int32 error2, char *str)
 {
     char *err1, *err2;
 
-    fprintf(log, str, a, b, c, d, e, f, g, h, i, j);
+    fprintf(log, "%s", str);
     if (error1) {
        err2 = "vols";
        switch (error1) {
@@ -174,8 +174,8 @@ PrintLog(log, error1, error2, str, a, b, c, d, e, f, g, h, i, j)
            err1 = "Volume has moved to another server";
            break;
        default:
-           err1 = (char *)error_message(error1);
-           err2 = (char *)error_table_name(error1);
+           err1 = (char *)afs_error_message(error1);
+           err2 = (char *)afs_error_table_name(error1);
            break;
        }
        if (error1 == -1)
@@ -183,87 +183,122 @@ PrintLog(log, error1, error2, str, a, b, c, d, e, f, g, h, i, j)
        else
            fprintf(log, "     %s: %s", err2, err1);
        if (error2)
-           fprintf(log, ": %s", error_message(error2));
+           fprintf(log, ": %s", afs_error_message(error2));
        fprintf(log, "\n");
     }
     fflush(log);
 }
 
 void
-TapeLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j)
-     int debug;
-     afs_int32 task, error1, error2;
-     char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j;
+TapeLogStr(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2,
+          char *str)
 {
     time_t now;
-    char tbuffer[32], *timestr;
+    char tbuffer[32];
+    struct tm tm;
 
     now = time(0);
-    timestr = afs_ctime(&now, tbuffer, sizeof(tbuffer));
-    timestr[24] = '\0';
+    if (strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+                localtime_r(&now, &tm)) != 0)
+       fprintf(logIO, "%s: ", tbuffer);
 
-    fprintf(logIO, "%s: ", timestr);
     if (task)
        fprintf(logIO, "Task %u: ", task);
-    PrintLog(logIO, error1, error2, str, a, b, c, d, e, f, g, h, i, j);
+    PrintLogStr(logIO, error1, error2, str);
 
     if (lastPass && lastLogIO) {
-       fprintf(lastLogIO, "%s: ", timestr);
+       fprintf(lastLogIO, "%s: ", tbuffer);
        if (task)
            fprintf(lastLogIO, "Task %u: ", task);
-       PrintLog(lastLogIO, error1, error2, str, a, b, c, d, e, f, g, h, i,
-                j);
+       PrintLogStr(lastLogIO, error1, error2, str);
     }
 
     /* Now print to the screen if debug level requires */
     if (debug <= debugLevel)
-       PrintLog(stdout, error1, error2, str, a, b, c, d, e, f, g, h, i, j);
+       PrintLogStr(stdout, error1, error2, str);
 }
 
 void
-TLog(task, str, a, b, c, d, e, f, g, h, i, j)
-     afs_int32 task;
-     char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j;
+TapeLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2,
+       char *fmt, ...)
 {
+    char tmp[1024];
+    va_list ap;
+
+    va_start(ap, fmt);
+    vsnprintf(tmp, sizeof(tmp), fmt, ap);
+    va_end(ap);
+
+    TapeLogStr(debug, task, error1, error2, tmp);
+}
+
+void
+TLog(afs_int32 task, char *fmt, ...)
+{
+    char tmp[1024];
+    va_list ap;
+
+    va_start(ap, fmt);
+    vsnprintf(tmp, sizeof(tmp), fmt, ap);
+    va_end(ap);
+
     /* Sends message to TapeLog and stdout */
-    TapeLog(0, task, 0, 0, str, a, b, c, d, e, f, g, h, i, j);
+    TapeLogStr(0, task, 0, 0, tmp);
 }
 
 void
-ErrorLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j)
-     int debug;
-     afs_int32 task, error1, error2;
-     char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j;
+ErrorLogStr(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2,
+           char *errStr)
 {
     time_t now;
-    char tbuffer[32], *timestr;
+    char tbuffer[32];
+    struct tm tm;
 
     now = time(0);
-    timestr = afs_ctime(&now, tbuffer, sizeof(tbuffer));
-    timestr[24] = '\0';
-    fprintf(ErrorlogIO, "%s: ", timestr);
+    if (strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+                localtime_r(&now, &tm)) != 0)
+       fprintf(ErrorlogIO, "%s: ", tbuffer);
 
     /* Print the time and task number */
     if (task)
        fprintf(ErrorlogIO, "Task %u: ", task);
-    PrintLog(ErrorlogIO, error1, error2, str, a, b, c, d, e, f, g, h, i, j);
 
-    TapeLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j);
+    PrintLogStr(ErrorlogIO, error1, error2, errStr);
+    TapeLogStr(debug, task, error1, error2, errStr);
+}
+
+void
+ErrorLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2,
+        char *fmt, ...)
+{
+    char tmp[1024];
+    va_list ap;
+
+    va_start(ap, fmt);
+    vsnprintf(tmp, sizeof(tmp), fmt, ap);
+    va_end(ap);
+
+    ErrorLogStr(debug, task, error1, error2, tmp);
+
 }
 
 void
-ELog(task, str, a, b, c, d, e, f, g, h, i, j)
-     afs_int32 task;
-     char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j;
+ELog(afs_int32 task, char *fmt, ...)
 {
+    char tmp[1024];
+    va_list ap;
+
+    va_start(ap, fmt);
+    vsnprintf(tmp, sizeof(tmp), fmt, ap);
+    va_end(ap);
+
     /* Sends message to ErrorLog, TapeLog and stdout */
-    ErrorLog(0, task, 0, 0, str, a, b, c, d, e, f, g, h, i, j);
+    ErrorLog(0, task, 0, 0, "%s", tmp);
 }
 
 /* first proc called by anybody who intends to use the device */
 void
-EnterDeviceQueue(devLatch)
-     struct deviceSyncNode *devLatch;
+EnterDeviceQueue(struct deviceSyncNode *devLatch)
 {
     ObtainWriteLock(&(devLatch->lock));
     devLatch->flags = TC_DEVICEINUSE;
@@ -271,8 +306,7 @@ EnterDeviceQueue(devLatch)
 
 /* last proc called by anybody finishing using the device */
 void
-LeaveDeviceQueue(devLatch)
-     struct deviceSyncNode *devLatch;
+LeaveDeviceQueue(struct deviceSyncNode *devLatch)
 {
     devLatch->flags = 0;
     ReleaseWriteLock(&(devLatch->lock));
@@ -281,140 +315,21 @@ LeaveDeviceQueue(devLatch)
 #define BELLTIME 60            /* 60 seconds before a bell rings */
 #define BELLCHAR 7             /* ascii for bell */
 
-
-#ifdef AFS_PTHREAD_ENV
-#ifdef AFS_NT40_ENV
-/* WaitForKeystroke : Wait until a key has been struck or time (secconds)
- * runs out and return to caller. The NT version of this function will return
- * immediately after a key has been pressed (doesn't wait for cr).
- * Input:
- *   seconds: wait for <seconds> seconds before returning. If seconds < 0,
- *            wait infinitely.
- * Return Value:
- *    1:  Keyboard input available
- *    0:  seconds elapsed. Timeout.
- *
- * STOLEN FROM LWP_WaitForKeystroke()
- */
-int
-WaitForKeystroke(int seconds)
-{
-    time_t startTime, nowTime;
-    double timeleft = 1;
-    struct timeval twait;
-
-    time(&startTime);
-    twait.tv_sec = 0;
-    twait.tv_usec = 250;
-    if (seconds >= 0)
-       timeleft = seconds;
-
-    do {
-       /* check if we have a keystroke */
-       if (_kbhit())
-           return 1;
-       if (timeleft == 0)
-           break;
-
-       /* sleep for  LWP_KEYSTROKE_DELAY ms and let other
-        * process run some*/
-       select(0, 0, 0, 0, &twait);
-
-       if (seconds > 0) {      /* we only worry about elapsed time if 
-                                * not looping forever (seconds < 0) */
-           time(&nowTime);
-           timeleft = seconds - difftime(nowTime, startTime);
-       }
-    } while (timeleft > 0);
-    return 0;
-}
-#else /* AFS_NT40)ENV */
-extern int WaitForKeystroke(int);
 /*
- *      STOLEN FROM LWP_WaitForKeystroke()
- */
-int
-WaitForKeystroke(int seconds)
-{
-    fd_set rdfds;
-    int code;
-    struct timeval twait;
-    struct timeval *tp = NULL;
-
-#ifdef AFS_LINUX20_ENV
-    if (stdin->_IO_read_ptr < stdin->_IO_read_end)
-       return 1;
-#else
-    if (stdin->_cnt > 0)
-       return 1;
-#endif
-    FD_ZERO(&rdfds);
-    FD_SET(fileno(stdin), &rdfds);
-
-    if (seconds >= 0) {
-       twait.tv_sec = seconds;
-       twait.tv_usec = 0;
-       tp = &twait;
-    }
-    code = select(1 + fileno(stdin), &rdfds, NULL, NULL, tp);
-    return (code == 1) ? 1 : 0;
-}
-#endif
-
-/* GetResponseKey() - Waits for a specified period of time and
- * returns a char when one has been typed by the user.
- * Input:
- *    seconds - how long to wait for a key press.
- *    *key    - char entered by user
- * Return Values: 
- *    0 - Time ran out before the user typed a key.
- *    1 - Valid char is being returned.
- *
- *    STOLEN FROM LWP_GetResponseKey();
+ * FFlushInput
+ *     flush all input
+ * notes:
+ *     only external clients are in recoverDb.c. Was static. PA
  */
-int
-GetResponseKey(int seconds, char *key)
-{
-    int rc;
-
-    if (key == NULL)
-       return 0;               /* need space to store char */
-    fflush(stdin);             /* flush all existing data and start anew */
-
-    rc = WaitForKeystroke(seconds);
-    if (rc == 0) {             /* time ran out */
-       *key = 0;
-       return rc;
-    }
-
-    /* now read the char. */
-#ifdef AFS_NT40_ENV
-    *key = getche();           /* get char and echo it to screen */
-#else
-    *key = getchar();
-#endif
-    return rc;
-}
-#endif /* AFS_PTHREAD_ENV
-        * 
-        * /* FFlushInput
-        * *     flush all input
-        * * notes:
-        * *     only external clients are in recoverDb.c. Was static. PA
-        */
-FFlushInput()
+void
+FFlushInput(void)
 {
     int w;
 
     fflush(stdin);
 
     while (1) {
-#ifdef AFS_PTHREAD_ENV
-       w = WaitForKeystroke(0);
-#else
        w = LWP_WaitForKeystroke(0);
-#endif /* AFS_PTHREAD_ENV */
-
        if (w) {
 #ifdef AFS_NT40_ENV
            getche();
@@ -428,17 +343,9 @@ FFlushInput()
 }
 
 int
-callOutRoutine(taskId, tapePath, flag, name, dbDumpId, tapecount)
-     afs_int32 taskId;
-     char *tapePath;
-     int flag;
-     char *name;
-     afs_uint32 dbDumpId;
-     int tapecount;
+callOutRoutine(afs_int32 taskId, char *tapePath, int flag, char *name,
+              afs_uint32 dbDumpId, int tapecount)
 {
-    afs_int32 count;
-
-    afs_int32 code = 0;
     int pid;
 
     char StapePath[256];
@@ -546,12 +453,10 @@ callOutRoutine(taskId, tapePath, flag, name, dbDumpId, tapecount)
  *     Regardless of error, the closecallout routine will be called
  *     (unless a tape is not mounted in the first place).
  */
-unmountTape(taskId, tapeInfoPtr)
-     afs_int32 taskId;
-     struct butm_tapeInfo *tapeInfoPtr;
+void
+unmountTape(afs_int32 taskId, struct butm_tapeInfo *tapeInfoPtr)
 {
     afs_int32 code;
-    afs_int32 wcode;
     int cpid, status, rcpid;
 
     code = butm_Dismount(tapeInfoPtr);
@@ -574,7 +479,7 @@ unmountTape(taskId, tapeInfoPtr)
            }
            if (rcpid == -1 && errno != EINTR) {
                tapemounted = 0;
-               com_err(whoami, errno,
+               afs_com_err(whoami, errno,
                        "Error waiting for callout script to terminate.");
                break;
            }
@@ -603,9 +508,7 @@ unmountTape(taskId, tapeInfoPtr)
  */
 
 void static
-PrintPrompt(flag, name, dumpid)
-     int flag;
-     char *name;
+PrintPrompt(int flag, char *name, int dumpid)
 {
     char tapename[BU_MAXTAPELEN + 32];
     char *dn;
@@ -661,7 +564,7 @@ PrintPrompt(flag, name, dumpid)
        break;
 
     case SAVEDBOPCODE:         /* Mount for savedb */
-       printf("Please insert a writeable tape %s for the database dump",
+       printf("Please insert a writable tape %s for the database dump",
               tapename);
        break;
 
@@ -672,21 +575,17 @@ PrintPrompt(flag, name, dumpid)
 }
 
 /* PromptForTape
- *     Prompt the operator to change the tape. 
+ *     Prompt the operator to change the tape.
  *      Use to be a void routine but now returns an error. Some calls
  *      don't use the error code.
  * notes:
  *     only external clients are in recoverDb.c. Was static PA
  */
 afs_int32
-PromptForTape(flag, name, dbDumpId, taskId, tapecount)
-     int flag;
-     char *name;
-     afs_uint32 dbDumpId;      /* Specific dump ID - If non-zero */
-     afs_uint32 taskId;
-     int tapecount;
+PromptForTape(int flag, char *name, afs_uint32 dbDumpId, afs_uint32 taskId,
+             int tapecount)
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
     afs_int32 wcode;
     afs_int32 start = 0;
     char inchr;
@@ -738,11 +637,10 @@ PromptForTape(flag, name, dbDumpId, taskId, tapecount)
            }
            /* if waitpid experienced an error, we prompt */
            if (rcpid == -1 && errno != EINTR) {
-               com_err(whoami, errno,
+               afs_com_err(whoami, errno,
                        "Error waiting for callout script to terminate.");
                TLog(taskId,
-                    "Can't get exit status from callout script. will prompt\n",
-                    wcode);
+                    "Can't get exit status from callout script. will prompt\n");
                CallOut = 0;
                break;
            }
@@ -775,15 +673,11 @@ PromptForTape(flag, name, dbDumpId, taskId, tapecount)
        while (1) {
            if (time(0) > start + BELLTIME) {
                start = time(0);
-               FFlushInput(stdin);
+               FFlushInput();
                putchar(BELLCHAR);
                fflush(stdout);
            }
-#ifdef AFS_PTHREAD_ENV
-           wcode = GetResponseKey(5, &inchr);  /* inchr stores key read */
-#else
            wcode = LWP_GetResponseKey(5, &inchr);      /* inchr stores key read */
-#endif
            if (wcode == 1) {   /* keyboard input is available */
 
                if ((inchr == 'a') || (inchr == 'A')) {
@@ -863,8 +757,8 @@ PromptForTape(flag, name, dbDumpId, taskId, tapecount)
  */
 
 afs_int32
-VolHeaderToHost(hostVolHeader, tapeVolHeader)
-     struct volumeHeader *hostVolHeader, *tapeVolHeader;
+VolHeaderToHost(struct volumeHeader *hostVolHeader,
+               struct volumeHeader *tapeVolHeader)
 {
     switch (ntohl(tapeVolHeader->versionflags)) {
     case TAPE_VERSION_0:
@@ -905,10 +799,9 @@ VolHeaderToHost(hostVolHeader, tapeVolHeader)
 }
 
 afs_int32
-ReadVolHeader(taskId, tapeInfoPtr, volHeaderPtr)
-     afs_int32 taskId;
-     struct butm_tapeInfo *tapeInfoPtr;
-     struct volumeHeader *volHeaderPtr;
+ReadVolHeader(afs_int32 taskId,
+             struct butm_tapeInfo *tapeInfoPtr,
+             struct volumeHeader *volHeaderPtr)
 {
     afs_int32 code = 0;
     afs_int32 nbytes;
@@ -942,12 +835,8 @@ ReadVolHeader(taskId, tapeInfoPtr, volHeaderPtr)
 }
 
 afs_int32 static
-GetVolumeHead(taskId, tapeInfoPtr, position, volName, volId)
-     afs_int32 taskId;
-     struct butm_tapeInfo *tapeInfoPtr;
-     afs_int32 position;
-     char *volName;
-     afs_int32 volId;
+GetVolumeHead(afs_int32 taskId, struct butm_tapeInfo *tapeInfoPtr,
+             afs_int32 position, char *volName, afs_int32 volId)
 {
     afs_int32 code = 0;
     struct volumeHeader tapeVolHeader;
@@ -1016,12 +905,8 @@ GetVolumeHead(taskId, tapeInfoPtr, position, volName, volId)
 }
 
 afs_int32
-GetRestoreTape(taskId, tapeInfoPtr, tname, tapeID, prompt)
-     afs_int32 taskId;
-     struct butm_tapeInfo *tapeInfoPtr;
-     char *tname;
-     afs_int32 tapeID;
-     int prompt;
+GetRestoreTape(afs_int32 taskId, struct butm_tapeInfo *tapeInfoPtr,
+              char *tname, afs_int32 tapeID, int prompt)
 {
     struct butm_tapeLabel tapeLabel;
     afs_int32 code = 0, rc;
@@ -1086,12 +971,11 @@ GetRestoreTape(taskId, tapeInfoPtr, tname, tapeID, prompt)
 }
 
 afs_int32
-xbsaRestoreVolumeData(call, rparamsPtr)
-     register struct rx_call *call;
-     struct restoreParams *rparamsPtr;
+xbsaRestoreVolumeData(struct rx_call *call, void *rock)
 {
     afs_int32 code = 0;
 #ifdef xbsa
+    struct restoreParams *rparamsPtr = (struct restoreParams *)rock;
     afs_int32 curChunk, rc;
     afs_uint32 totalWritten;
     afs_int32 headBytes, tailBytes, w;
@@ -1239,14 +1123,12 @@ xbsaRestoreVolumeData(call, rparamsPtr)
  */
 
 afs_int32
-restoreVolumeData(call, rparamsPtr)
-     register struct rx_call *call;
-     struct restoreParams *rparamsPtr;
+restoreVolumeData(struct rx_call *call, void *rock)
 {
+    struct restoreParams *rparamsPtr = (struct restoreParams *)rock;
     afs_int32 curChunk;
     afs_uint32 totalWritten = 0;
-    afs_uint32 tapeID;
-    afs_int32 code, tcode;
+    afs_int32 code = 0;
     afs_int32 headBytes, tailBytes, w;
     afs_int32 taskId;
     afs_int32 nbytes;          /* # bytes data in last tape block read */
@@ -1346,7 +1228,7 @@ restoreVolumeData(call, rparamsPtr)
        }
 
        /* lastbuf is last block read and it has nbytes of data
-        * startWbuf is the 2nd to last block read 
+        * startWbuf is the 2nd to last block read
         * Seach for the volume trailer in these two blocks.
         */
        if (lastbuf == startWbuf)
@@ -1388,7 +1270,7 @@ restoreVolumeData(call, rparamsPtr)
        if (!tapeVolTrailer.contd)
            break;              /* We've read the entire volume */
 
-       /* Volume is continued on next tape. 
+       /* Volume is continued on next tape.
         * Step to the next volume fragment and prompt for its tape.
         * When a volume has multiple frags, those frags are on different
         * tapes. So we know that we need to prompt for a tape.
@@ -1429,10 +1311,9 @@ restoreVolumeData(call, rparamsPtr)
 /* SkipTape
  *    Find all the volumes on a specific tape and mark them to skip.
  */
-SkipTape(Restore, size, index, tapename, tapeid, taskid)
-     struct tc_restoreDesc *Restore;
-     afs_int32 size, index, tapeid, taskid;
-     char *tapename;
+int
+SkipTape(struct tc_restoreDesc *Restore, afs_int32 size, afs_int32 index,
+        char *tapename, afs_int32 tapeid, afs_int32 taskid)
 {
     afs_int32 i, tid;
 
@@ -1446,14 +1327,15 @@ SkipTape(Restore, size, index, tapename, tapeid, taskid)
            SkipVolume(Restore, size, i, Restore[i].origVid, taskid);
        }
     }
+    return 0;
 }
 
 /* SkipVolume
  *    Find all the entries for a volume and mark them to skip.
  */
-SkipVolume(Restore, size, index, volid, taskid)
-     struct tc_restoreDesc *Restore;
-     afs_int32 size, index, volid, taskid;
+int
+SkipVolume(struct tc_restoreDesc *Restore, afs_int32 size, afs_int32 index,
+          afs_int32 volid, afs_int32 taskid)
 {
     afs_int32 i;
     int report = 1;
@@ -1471,15 +1353,16 @@ SkipVolume(Restore, size, index, volid, taskid)
            }
        }
     }
+    return 0;
 }
 
-xbsaRestoreVolume(taskId, restoreInfo, rparamsPtr)
-     afs_uint32 taskId;
-     struct tc_restoreDesc *restoreInfo;
-     struct restoreParams *rparamsPtr;
+int
+xbsaRestoreVolume(afs_uint32 taskId, struct tc_restoreDesc *restoreInfo,
+                 struct restoreParams *rparamsPtr)
 {
-    afs_int32 code = 0, rc;
+    afs_int32 code = 0;
 #ifdef xbsa
+    afs_int32 rc;
     afs_int32 newServer, newPart, newVolId;
     char *newVolName;
     int restoreflags, havetrans = 0, startread = 0;
@@ -1664,10 +1547,9 @@ xbsaRestoreVolume(taskId, restoreInfo, rparamsPtr)
     return (code);
 }
 
-restoreVolume(taskId, restoreInfo, rparamsPtr)
-     afs_uint32 taskId;
-     struct tc_restoreDesc *restoreInfo;
-     struct restoreParams *rparamsPtr;
+int
+restoreVolume(afs_uint32 taskId, struct tc_restoreDesc *restoreInfo,
+             struct restoreParams *rparamsPtr)
 {
     afs_int32 code = 0, rc;
     afs_int32 newServer, newPart, newVolId;
@@ -1675,7 +1557,6 @@ restoreVolume(taskId, restoreInfo, rparamsPtr)
     int restoreflags;
     afs_uint32 tapeID;
     struct butm_tapeInfo *tapeInfoPtr = rparamsPtr->tapeInfoPtr;
-    struct budb_dumpEntry dumpEntry;
 
     /* Check if we need a tape and prompt for one if so */
     tapeID =
@@ -1742,22 +1623,22 @@ restoreVolume(taskId, restoreInfo, rparamsPtr)
  *     created as a LWP by the server stub, <newNode> is a pointer to all
  *     the parameters Restorer needs
  */
-Restorer(newNode)
-     struct dumpNode *newNode;
-{
-    afs_int32 code = 0, tcode, rc;
+void *
+Restorer(void *param) {
+    struct dumpNode *newNode = (struct dumpNode *) param;
+
+    afs_int32 code = 0, tcode;
     afs_uint32 taskId;
-    afs_uint32 dumpID;
     char *newVolName;
     struct butm_tapeInfo tapeInfo;
     struct tc_restoreDesc *Restore;
     struct tc_restoreDesc *RestoreDesc;
     struct restoreParams rparams;
-    int restoreflags;
     afs_int32 allocbufferSize;
     time_t startTime, endTime;
     afs_int32 goodrestore = 0;
 
+    afs_pthread_setname_self("restorer");
     taskId = newNode->taskID;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -1766,6 +1647,7 @@ Restorer(newNode)
     printf("\n\n");
     TLog(taskId, "Restore\n");
 
+    startTime = time(0);
     memset(&tapeInfo, 0, sizeof(tapeInfo));
     if (!CONF_XBSA) {
        tapeInfo.structVersion = BUTM_MAJORVERSION;
@@ -1801,7 +1683,6 @@ Restorer(newNode)
        ERROR_EXIT(TC_NOMEMORY);
     memset(bufferBlock, 0, allocbufferSize);
 
-    startTime = time(0);
     for (rparams.frag = 0; (rparams.frag < newNode->arraySize);
         rparams.frag++) {
        RestoreDesc = &Restore[rparams.frag];
@@ -1834,7 +1715,7 @@ Restorer(newNode)
 
        /* restoreVolume function takes care of all the related fragments
         * spanning various tapes. On return the complete volume has been
-        * restored 
+        * restored
         */
        if (CONF_XBSA) {
            tcode = xbsaRestoreVolume(taskId, RestoreDesc, &rparams);
@@ -1870,7 +1751,7 @@ Restorer(newNode)
        unmountTape(taskId, &tapeInfo);
     } else {
 #ifdef xbsa
-       rc = InitToServer(taskId, &butxInfo, 0);        /* Return to original server */
+       code = InitToServer(taskId, &butxInfo, 0);      /* Return to original server */
 #endif
     }
 
@@ -1920,18 +1801,16 @@ Restorer(newNode)
 
     FreeNode(taskId);
     LeaveDeviceQueue(deviceLatch);
-    return (code);
+    return (void *)(intptr_t)(code);
 }
 
 /* this is just scaffolding, creates new tape label with name <tapeName> */
 
-GetNewLabel(tapeInfoPtr, pName, AFSName, tapeLabel)
-     struct butm_tapeInfo *tapeInfoPtr;
-     char *pName, *AFSName;
-     struct butm_tapeLabel *tapeLabel;
+void
+GetNewLabel(struct butm_tapeInfo *tapeInfoPtr, char *pName, char *AFSName,
+           struct butm_tapeLabel *tapeLabel)
 {
     struct timeval tp;
-    struct timezone tzp;
     afs_uint32 size;
 
     memset(tapeLabel, 0, sizeof(struct butm_tapeLabel));
@@ -1943,7 +1822,7 @@ GetNewLabel(tapeInfoPtr, pName, AFSName, tapeLabel)
     } else {
        size = 0;               /* no tape size */
     }
-    gettimeofday(&tp, &tzp);
+    gettimeofday(&tp, NULL);
 
     tapeLabel->structVersion = CUR_TAPE_VERSION;
     tapeLabel->creationTime = tp.tv_sec;
@@ -1960,13 +1839,11 @@ GetNewLabel(tapeInfoPtr, pName, AFSName, tapeLabel)
     strcpy(tapeLabel->creator.cell, globalCellName);
 }
 
-/* extracts trailer out of buffer, nbytes is set to total data in buffer - trailer size */
+/* extracts trailer out of buffer, nbytes is set to total data in
+ * buffer - trailer size */
 afs_int32
-ExtractTrailer(buffer, size, nbytes, volTrailerPtr)
-     char *buffer;
-     afs_int32 *nbytes;
-     afs_int32 size;
-     struct volumeHeader *volTrailerPtr;
+ExtractTrailer(char *buffer, afs_int32 size, afs_int32 *nbytes,
+              struct volumeHeader *volTrailerPtr)
 {
     afs_int32 code = 0;
     afs_int32 startPos;
@@ -1994,14 +1871,10 @@ ExtractTrailer(buffer, size, nbytes, volTrailerPtr)
 }
 
 int
-FindVolTrailer(buffer, size, dSize, volTrailerPtr)
-     char *buffer;
-     afs_int32 size;
-     struct volumeHeader *volTrailerPtr;
-     afs_int32 *dSize;         /* dataSize */
+FindVolTrailer(char *buffer, afs_int32 size, afs_int32 *dSize,
+              struct volumeHeader *volTrailerPtr)
 {
     afs_int32 offset, s;
-    afs_int32 code;
     int found;
 
     *dSize = size;
@@ -2019,15 +1892,9 @@ FindVolTrailer(buffer, size, dSize, volTrailerPtr)
 }
 
 int
-FindVolTrailer2(buffera, sizea, dataSizea, bufferb, sizeb, dataSizeb,
-               volTrailerPtr)
-     char *buffera;
-     afs_int32 sizea;
-     afs_int32 *dataSizea;
-     char *bufferb;
-     afs_int32 sizeb;
-     afs_int32 *dataSizeb;
-     struct volumeHeader *volTrailerPtr;
+FindVolTrailer2(char *buffera, afs_int32 sizea, afs_int32 *dataSizea,
+               char *bufferb, afs_int32 sizeb, afs_int32 *dataSizeb,
+               struct volumeHeader *volTrailerPtr)
 {
     afs_int32 offset, s;
     afs_int32 headB, tailB;
@@ -2072,11 +1939,9 @@ FindVolTrailer2(buffera, sizea, dataSizea, bufferb, sizeb, dataSizeb,
     return found;
 }
 
-/* Returns true or false depending on whether the tape is expired or not */
 
 Date
-ExpirationDate(dumpid)
-     afs_int32 dumpid;
+ExpirationDate(afs_int32 dumpid)
 {
     afs_int32 code;
     Date expiration = 0;
@@ -2086,9 +1951,10 @@ ExpirationDate(dumpid)
 
     if (dumpid) {
        /*
-        * Get the expiration date from DB if its there. The expiration of any tape
-        * will be the most future expiration of any dump in the set. Can't use
-        * bcdb_FindTape because dumpid here pertains to the initial dump id.
+        * Get the expiration date from DB if its there. The expiration of
+        * any tape will be the most future expiration of any dump in the
+        * set. Can't use bcdb_FindTape because dumpid here pertains to the
+        * initial dump id.
         */
        code = bcdb_FindLastTape(dumpid, &dumpEntry, &tapeEntry, &volEntry);
        if (!code)
@@ -2097,34 +1963,34 @@ ExpirationDate(dumpid)
     return (expiration);
 }
 
+/* Returns true or false depending on whether the tape is expired or not */
+
 int
-tapeExpired(tapeLabelPtr)
-     struct butm_tapeLabel *tapeLabelPtr;
+tapeExpired(struct butm_tapeLabel *tapeLabelPtr)
 {
     Date expiration;
     struct timeval tp;
-    struct timezone tzp;
 
     expiration = ExpirationDate(tapeLabelPtr->dumpid);
     if (!expiration)
        expiration = tapeLabelPtr->expirationDate;
 
-    gettimeofday(&tp, &tzp);
+    gettimeofday(&tp, NULL);
     return ((expiration < tp.tv_sec) ? 1 : 0);
 }
 
 /* updateTapeLabel
  *     given the label on the tape, delete any old information from the
- *     database. 
+ *     database.
 
  * Deletes all entries that match the volset.dumpnode
  *     and the dump path.
  */
 
-updateTapeLabel(labelIfPtr, tapeInfoPtr, newLabelPtr)
-     struct labelTapeIf *labelIfPtr;
-     struct butm_tapeInfo *tapeInfoPtr;
-     struct butm_tapeLabel *newLabelPtr;
+int
+updateTapeLabel(struct labelTapeIf *labelIfPtr,
+               struct butm_tapeInfo *tapeInfoPtr,
+               struct butm_tapeLabel *newLabelPtr)
 {
     struct butm_tapeLabel oldLabel;
     afs_int32 i, code = 0;
@@ -2160,7 +2026,7 @@ updateTapeLabel(labelIfPtr, tapeInfoPtr, newLabelPtr)
 
            if ((strcmp(newLabelPtr->AFSName, "") != 0)
                && (strcmp(oldLabel.pName, "") != 0)) {
-               /* We are setting the AFS name, yet tape 
+               /* We are setting the AFS name, yet tape
                 * has a permanent name (not allowed).
                 */
                TLog(taskId, "Can't label. Tape has permanent label '%s'\n",
@@ -2227,9 +2093,11 @@ updateTapeLabel(labelIfPtr, tapeInfoPtr, newLabelPtr)
  *     specified by <label>
  */
 
-Labeller(labelIfPtr)
-     struct labelTapeIf *labelIfPtr;
+void *
+Labeller(void *param)
 {
+    struct labelTapeIf *labelIfPtr = (struct labelTapeIf *)param;
+
     struct tc_tapeLabel *label = &labelIfPtr->label;
 
     struct butm_tapeLabel newTapeLabel;
@@ -2237,6 +2105,7 @@ Labeller(labelIfPtr)
     afs_uint32 taskId;
     afs_int32 code = 0;
 
+    afs_pthread_setname_self("labeller");
     taskId = labelIfPtr->taskId;
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -2280,17 +2149,18 @@ Labeller(labelIfPtr)
 
     free(labelIfPtr);
     LeaveDeviceQueue(deviceLatch);
-    return (code);
+    return (void *)(intptr_t)(code);
 }
 
 /* PrintTapeLabel
  *     print out the tape label.
  */
 
-PrintTapeLabel(labelptr)
-     struct butm_tapeLabel *labelptr;
+void
+PrintTapeLabel(struct butm_tapeLabel *labelptr)
 {
     char tapeName[BU_MAXTAPELEN + 32];
+    time_t t;
 
     printf("Tape label\n");
     printf("----------\n");
@@ -2298,9 +2168,12 @@ PrintTapeLabel(labelptr)
     printf("permanent tape name = %s\n", tapeName);
     TAPENAME(tapeName, labelptr->AFSName, labelptr->dumpid);
     printf("AFS tape name = %s\n", tapeName);
-    printf("creationTime = %s", ctime(&labelptr->creationTime));
-    if (labelptr->expirationDate)
-       printf("expirationDate = %s", cTIME(&labelptr->expirationDate));
+    t = labelptr->creationTime;
+    printf("creationTime = %s", ctime(&t));
+    if (labelptr->expirationDate) {
+        t = labelptr->expirationDate;
+       printf("expirationDate = %s", cTIME(&t));
+    }
     printf("cell = %s\n", labelptr->cell);
     printf("size = %u Kbytes\n", labelptr->size);
     printf("dump path = %s\n", labelptr->dumpPath);
@@ -2312,14 +2185,14 @@ PrintTapeLabel(labelptr)
     printf("-- End of tape label --\n\n");
 }
 
-/* ReadLabel 
+/* ReadLabel
  *     Read the label from a tape.
  *     Currently prints out a "detailed" summary of the label but passes
  *     back only selected fields.
  */
 
-ReadLabel(label)
-     struct tc_tapeLabel *label;
+int
+ReadLabel(struct tc_tapeLabel *label)
 {
     struct butm_tapeLabel newTapeLabel;
     struct butm_tapeInfo tapeInfo;
@@ -2408,22 +2281,17 @@ ReadLabel(label)
    into consideration, different word alignment rules.
 */
 afs_int32
-readVolumeHeader(buffer, bufloc, header)
-     /*in */
-     char *buffer;             /* buffer to read header from */
-                               /*in */ afs_int32 bufloc;
-                               /* header's location in buffer */
-                                               /*out */ struct volumeHeader *header;
-                                               /* header structure */
-
+readVolumeHeader(char *buffer,         /* in - buffer to read header from */
+                afs_int32 bufloc,      /* in - header's location in buffer */
+                struct volumeHeader *header) /* out -header structure */
 {
     struct volumeHeader vhptr, *tempvhptr;
-    afs_int32 firstSplice = (afs_int32) & vhptr.pad - (afs_int32) & vhptr;
+    afs_int32 firstSplice = (afs_int32) ((char*)& vhptr.pad - (char*) & vhptr);
     int padLen = sizeof(vhptr.pad);    /* pad to achieve 4 byte alignment */
     int nextSplice = sizeof(struct volumeHeader) - firstSplice - padLen;
 
     /* Four cases are to be handled
-     * 
+     *
      * Volume Header (byte alignment)
      * -----------------------
      * Tape   In Core
@@ -2433,7 +2301,7 @@ readVolumeHeader(buffer, bufloc, header)
      * Case 3:  1       1
      * Case 4:  1       4
      * -----------------------
-     * 
+     *
      * Case 2 and Case 3 are identical cases and handled the same way.
      * Case 1 and Case 4 are separate cases. In one case the pad needs
      * to be removed and in the other, it needs to be spliced in. The
@@ -2456,7 +2324,9 @@ readVolumeHeader(buffer, bufloc, header)
        /* Handle Case 1 */
        memset(&vhptr, 0, sizeof(struct volumeHeader));
        memcpy(&vhptr, buffer + bufloc, firstSplice);
-       memcpy(&vhptr + firstSplice, buffer + bufloc + firstSplice + padLen,
+       /* probably GCC bug 37060; however, no guarantee on length of buffer */
+       tempvhptr = (struct volumeHeader *)(buffer + firstSplice);
+       memcpy(tempvhptr, buffer + bufloc + firstSplice + padLen,
               nextSplice);
        HEADER_CHECKS(vhptr, header);