butc: Catch failures to start keep alive thread
[openafs.git] / src / butc / tcudbprocs.c
index 296652c..322c617 100644 (file)
 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
 #endif
 
-#include <rx/xdr.h>
+#include <afs/opr.h>
 #include <rx/rx.h>
 #include <afs/afsint.h>
-#include <afs/afs_assert.h>
 #include <afs/prs_fs.h>
 #include <afs/nfs.h>
 #include <lwp.h>
@@ -272,11 +271,9 @@ GetDBTape(afs_int32 taskId, Date expires, struct butm_tapeInfo *tapeInfoPtr,
        *wroteLabel = 1;
 
        /* Initialize a tapeEntry for later inclusion into the database */
-       listEntryPtr =
-           (struct tapeEntryList *)malloc(sizeof(struct tapeEntryList));
+       listEntryPtr = calloc(1, sizeof(struct tapeEntryList));
        if (!listEntryPtr)
            ERROR_EXIT(TC_NOMEMORY);
-       memset(listEntryPtr, 0, sizeof(struct tapeEntryList));
 
        /* Remember dumpid so we can delete it later */
        if ((oldTapeLabel.structVersion >= TAPE_VERSION_3)
@@ -415,8 +412,10 @@ writeDbDump(struct butm_tapeInfo *tapeInfoPtr, afs_uint32 taskId,
     extern struct tapeConfig globalTapeConfig;
     extern struct udbHandleS udbHandle;
 
+    charList.charListT_val = 0;
+    charList.charListT_len = 0;
     blockSize = BUTM_BLKSIZE;
-    writeBlock = (char *)malloc(BUTM_BLOCKSIZE);
+    writeBlock = malloc(BUTM_BLOCKSIZE);
     if (!writeBlock)
        ERROR_EXIT(TC_NOMEMORY);
 
@@ -445,8 +444,6 @@ writeDbDump(struct butm_tapeInfo *tapeInfoPtr, afs_uint32 taskId,
     writeBufPtr = &writeBuffer[0];
     firstcall = 1;
     sequence = 1;
-    charList.charListT_val = 0;
-    charList.charListT_len = 0;
 
     while (1) {                        /*w */
        /* When no data in buffer, read data from the budb_server */
@@ -493,10 +490,14 @@ writeDbDump(struct butm_tapeInfo *tapeInfoPtr, afs_uint32 taskId,
                AFS_SIGSET_RESTORE();
 #else
                code =
-                   LWP_CreateProcess(KeepAlive, 16384, 1, (void *)NULL,
+                   LWP_CreateProcess(KeepAlive, 16384, 1, NULL,
                                      "Keep-alive process", &alivePid);
 #endif
-               /* XXX should we check code here ??? XXX */
+               if (code) {
+                   ErrorLog(0, taskId, code, 0,
+                            "Failed to create keep alive process\n");
+                   ERROR_EXIT(code);
+               }
            }
            firstcall = 0;
 
@@ -628,7 +629,7 @@ void *
 saveDbToTape(void *param)
 {
     struct saveDbIf *saveDbIfPtr = (struct saveDbIf *)param;
-    afs_int32 code = 0;
+    afs_int32 code;
     afs_int32 i;
     int wroteLabel;
     afs_uint32 taskId;
@@ -643,6 +644,7 @@ saveDbToTape(void *param)
     afs_pthread_setname_self("Db save");
     expires = (saveDbIfPtr->archiveTime ? NEVERDATE : 0);
     taskId = saveDbIfPtr->taskId;
+    dumpEntry.id = 0;
 
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);     /* lock tape device */
@@ -871,11 +873,9 @@ readDbTape(struct butm_tapeInfo *tapeInfoPtr,
 
 
     /* Initialize a tapeEntry for later inclusion into the database */
-    listEntryPtr =
-       (struct tapeEntryList *)malloc(sizeof(struct tapeEntryList));
+    listEntryPtr = calloc(1, sizeof(struct tapeEntryList));
     if (!listEntryPtr)
        ERROR_EXIT(TC_NOMEMORY);
-    memset(listEntryPtr, 0, sizeof(struct tapeEntryList));
 
     /* Fill in tape entry so we can save it later */
     strcpy(tapeEntryPtr->name, TNAME(&oldTapeLabel));
@@ -1348,11 +1348,10 @@ saveTextFile(afs_int32 taskId, afs_int32 textType, char *fileName)
     afs_int32 code = 0;
     int tlock = 0;
 
-    ctPtr = (udbClientTextP) malloc(sizeof(*ctPtr));
+    ctPtr = calloc(1, sizeof(*ctPtr));
     if (!ctPtr)
        ERROR_EXIT(TC_NOMEMORY);
 
-    memset(ctPtr, 0, sizeof(*ctPtr));
     ctPtr->textType = textType;
 
     /* lock the text in the database */
@@ -1413,7 +1412,7 @@ restoreText(struct butm_tapeInfo *tapeInfo,
     udbClientTextP ctPtr = 0;
     afs_int32 textType;
 
-    ctPtr = (udbClientTextP) malloc(sizeof(*ctPtr));
+    ctPtr = malloc(sizeof(*ctPtr));
     if (!ctPtr)
        ERROR_EXIT(TC_NOMEMORY);
 
@@ -1449,7 +1448,7 @@ restoreText(struct butm_tapeInfo *tapeInfo,
 
     /* allocate buffer for text */
     readBlockSize = BUTM_BLKSIZE;
-    readBuffer = (char *)malloc(readBlockSize);
+    readBuffer = malloc(readBlockSize);
     if (!readBuffer)
        ERROR_EXIT(TC_NOMEMORY);
 
@@ -1538,7 +1537,7 @@ getTapeData(struct butm_tapeInfo *tapeInfoPtr,
        ERROR_EXIT(TC_ABORTEDBYREQUEST);
 
     if (!tapeReadBuffer) {
-       tapeReadBuffer = (char *)malloc(BUTM_BLOCKSIZE);
+       tapeReadBuffer = malloc(BUTM_BLOCKSIZE);
        if (!tapeReadBuffer)
            ERROR_EXIT(TC_NOMEMORY);
     }