vol/salvaged.c: Remove unused variable
[openafs.git] / src / vol / salvaged.c
index 1a2a2ca..77f5541 100644 (file)
@@ -1,13 +1,13 @@
 /*
  * Copyright 2006-2007, Sine Nomine Associates 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
  */
 
-/* 
+/*
  * demand attach fs
  * online salvager daemon
  */
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
+
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <errno.h>
 #ifdef AFS_NT40_ENV
-#include <io.h>
 #include <WINNT/afsevent.h>
-#else
-#include <sys/param.h>
-#include <sys/file.h>
-#ifndef ITIMER_REAL
-#include <sys/time.h>
-#endif /* ITIMER_REAL */
 #endif
+
 #ifndef WCOREDUMP
 #define WCOREDUMP(x)   ((x) & 0200)
 #endif
-#include <rx/xdr.h>
+
+#include <afs/opr.h>
+#include <opr/lock.h>
 #include <afs/afsint.h>
-#include <afs/assert.h>
+#include <rx/rx_queue.h>
+
 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
 #if defined(AFS_VFSINCL_ENV)
 #include <sys/vnode.h>
@@ -59,7 +54,7 @@
 #ifdef AFS_OSF_ENV
 #include <ufs/inode.h>
 #else /* AFS_OSF_ENV */
-#if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
+#if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_DARWIN_ENV)
 #include <sys/inode.h>
 #endif
 #endif
 #include <sys/lockf.h>
 #else
 #ifdef AFS_HPUX_ENV
-#include <unistd.h>
 #include <checklist.h>
 #else
 #if defined(AFS_SGI_ENV)
-#include <unistd.h>
-#include <fcntl.h>
 #include <mntent.h>
 #else
 #if    defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
 #ifdef   AFS_SUN5_ENV
-#include <unistd.h>
 #include <sys/mnttab.h>
 #include <sys/mntent.h>
 #else
@@ -91,7 +82,6 @@
 #endif /* AFS_HPUX_ENV */
 #endif
 #endif
-#include <fcntl.h>
 #ifndef AFS_NT40_ENV
 #include <afs/osi_inode.h>
 #endif
 #include <afs/fileutil.h>
 #include <afs/procmgmt.h>      /* signal(), kill(), wait(), etc. */
 #include <afs/dir.h>
-#ifndef AFS_NT40_ENV
-#include <syslog.h>
-#endif
 
 #include "nfs.h"
 #include "lwp.h"
 #include <pthread.h>
 #endif
 
+char *logFileName = NULL;
 
 #if !defined(AFS_DEMAND_ATTACH_FS)
 #error "online salvager only supported for demand attach fileserver"
@@ -179,13 +167,35 @@ struct {
 
 #define DEFAULT_PARALLELISM 4 /* allow 4 parallel salvage workers by default */
 
+enum optionsList {
+    OPT_partition,
+    OPT_volumeid,
+    OPT_debug,
+    OPT_nowrite,
+    OPT_inodes,
+    OPT_oktozap,
+    OPT_rootinodes,
+    OPT_salvagedirs,
+    OPT_blockreads,
+    OPT_parallel,
+    OPT_tmpdir,
+    OPT_showlog,
+    OPT_orphans,
+    OPT_syslog,
+    OPT_syslogfacility,
+    OPT_datelogs,
+    OPT_logfile,
+    OPT_client
+};
+
 static int
-handleit(struct cmd_syndesc *as, void *arock)
+handleit(struct cmd_syndesc *opts, void *arock)
 {
-    struct cmd_item *ti;
-    char pname[100], *temp;
-    afs_int32 seenpart = 0, seenvol = 0, vid = 0;
+    char pname[100];
+    afs_int32 seenpart = 0, seenvol = 0;
+    VolumeId vid = 0;
     struct cmdline_rock *rock = (struct cmdline_rock *)arock;
+    char *optstring = NULL;
 
 #ifdef AFS_SGI_VNODE_GLUE
     if (afs_init_kernel_config(-1) < 0) {
@@ -195,26 +205,18 @@ handleit(struct cmd_syndesc *as, void *arock)
     }
 #endif
 
-    if (as->parms[2].items)    /* -debug */
-       debug = 1;
-    if (as->parms[3].items)    /* -nowrite */
-       Testing = 1;
-    if (as->parms[4].items)    /* -inodes */
-       ListInodeOption = 1;
-    if (as->parms[5].items)    /* -oktozap */
-       OKToZap = 1;
-    if (as->parms[6].items)    /* -rootinodes */
-       ShowRootFiles = 1;
-    if (as->parms[8].items)    /* -ForceReads */
-       forceR = 1;
-    if ((ti = as->parms[9].items)) {   /* -Parallel # */
-       temp = ti->data;
-       if (strncmp(temp, "all", 3) == 0) {
+    cmd_OptionAsFlag(opts, OPT_debug, &debug);
+    cmd_OptionAsFlag(opts, OPT_nowrite, &Testing);
+    cmd_OptionAsFlag(opts, OPT_inodes, &ListInodeOption);
+    cmd_OptionAsFlag(opts, OPT_oktozap, &OKToZap);
+    cmd_OptionAsFlag(opts, OPT_rootinodes, &ShowRootFiles);
+    cmd_OptionAsFlag(opts, OPT_blockreads, &forceR);
+    if (cmd_OptionAsString(opts, OPT_parallel, &optstring) == 0) {
+       if (strncmp(optstring, "all", 3) == 0) {
            PartsPerDisk = 1;
-           temp += 3;
        }
-       if (strlen(temp) != 0) {
-           Parallel = atoi(temp);
+       if (strlen(optstring) != 0) {
+           Parallel = atoi(optstring);
            if (Parallel < 1)
                Parallel = 1;
            if (Parallel > MAXPARALLEL) {
@@ -223,56 +225,66 @@ handleit(struct cmd_syndesc *as, void *arock)
                Parallel = MAXPARALLEL;
            }
        }
+       free(optstring);
+       optstring = NULL;
     } else {
-       Parallel = MIN(DEFAULT_PARALLELISM, MAXPARALLEL);
+       Parallel = min(DEFAULT_PARALLELISM, MAXPARALLEL);
     }
-    if ((ti = as->parms[10].items)) {  /* -tmpdir */
+    if (cmd_OptionAsString(opts, OPT_tmpdir, &optstring) == 0) {
        DIR *dirp;
-
-       tmpdir = ti->data;
-       dirp = opendir(tmpdir);
+       dirp = opendir(optstring);
        if (!dirp) {
            printf
                ("Can't open temporary placeholder dir %s; using current partition \n",
-                tmpdir);
+                optstring);
            tmpdir = NULL;
        } else
            closedir(dirp);
+       free(optstring);
+       optstring = NULL;
     }
-    if ((ti = as->parms[11].items))    /* -showlog */
-       ShowLog = 1;
-    if ((ti = as->parms[12].items)) {  /* -orphans */
+    cmd_OptionAsFlag(opts, OPT_showlog, &ShowLog);
+    if (cmd_OptionAsString(opts, OPT_orphans, &optstring) == 0) {
        if (Testing)
            orphans = ORPH_IGNORE;
-       else if (strcmp(ti->data, "remove") == 0
-                || strcmp(ti->data, "r") == 0)
+       else if (strcmp(optstring, "remove") == 0
+                || strcmp(optstring, "r") == 0)
            orphans = ORPH_REMOVE;
-       else if (strcmp(ti->data, "attach") == 0
-                || strcmp(ti->data, "a") == 0)
+       else if (strcmp(optstring, "attach") == 0
+                || strcmp(optstring, "a") == 0)
            orphans = ORPH_ATTACH;
+       free(optstring);
+       optstring = NULL;
     }
 #ifndef AFS_NT40_ENV           /* ignore options on NT */
-    if ((ti = as->parms[13].items)) {  /* -syslog */
+    if (cmd_OptionPresent(opts, OPT_syslog)) {
        useSyslog = 1;
        ShowLog = 0;
     }
-    if ((ti = as->parms[14].items)) {  /* -syslogfacility */
-       useSyslogFacility = atoi(ti->data);
-    }
+    cmd_OptionAsInt(opts, OPT_syslogfacility, &useSyslogFacility);
 
-    if ((ti = as->parms[15].items)) {  /* -datelogs */
+    if (cmd_OptionPresent(opts, OPT_datelogs)) {
        TimeStampLogFile((char *)AFSDIR_SERVER_SALSRVLOG_FILEPATH);
     }
 #endif
 
-    if ((ti = as->parms[16].items)) {   /* -client */
-       if ((ti = as->parms[0].items)) {        /* -partition */
+    if (cmd_OptionPresent(opts, OPT_client)) {
+       if (cmd_OptionAsString(opts, OPT_partition, &optstring) == 0) {
            seenpart = 1;
-           strlcpy(pname, ti->data, sizeof(pname));
+           strlcpy(pname, optstring, sizeof(pname));
+           free(optstring);
+           optstring = NULL;
        }
-       if ((ti = as->parms[1].items)) {        /* -volumeid */
+       if (cmd_OptionAsString(opts, OPT_volumeid, &optstring) == 0) {
+           char *end;
+           unsigned long vid_l;
            seenvol = 1;
-           vid = atoi(ti->data);
+           vid_l = strtoul(optstring, &end, 10);
+           if (vid_l >= MAX_AFS_UINT32 || vid_l == ULONG_MAX || *end != '\0') {
+               printf("Invalid volume id specified; salvage aborted\n");
+               exit(-1);
+           }
+           vid = (VolumeId)vid_l;
        }
 
        if (ShowLog) {
@@ -313,8 +325,8 @@ main(int argc, char **argv)
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -337,6 +349,9 @@ main(int argc, char **argv)
        exit(2);
     }
 #ifdef AFS_NT40_ENV
+    /* Default to binary mode for fopen() */
+    _set_fmode(_O_BINARY);
+
     main_thread = pthread_self();
     if (spawnDatap && spawnDataLen) {
        /* This is a child per partition salvager. Don't setup log or
@@ -364,46 +379,51 @@ main(int argc, char **argv)
     arock.argc = argc;
     arock.argv = argv;
 
+    logFileName = strdup(AFSDIR_SERVER_SALSRVLOG_FILEPATH);
+
     ts = cmd_CreateSyntax("initcmd", handleit, &arock, "initialize the program");
-    cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
-               "Name of partition to salvage");
-    cmd_AddParm(ts, "-volumeid", CMD_SINGLE, CMD_OPTIONAL,
-               "Volume Id to salvage");
-    cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
-               "Run in Debugging mode");
-    cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
-               "Run readonly/test mode");
-    cmd_AddParm(ts, "-inodes", CMD_FLAG, CMD_OPTIONAL,
-               "Just list affected afs inodes - debugging flag");
-    cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
-               "Give permission to destroy bogus inodes/volumes - debugging flag");
-    cmd_AddParm(ts, "-rootinodes", CMD_FLAG, CMD_OPTIONAL,
-               "Show inodes owned by root - debugging flag");
-    cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL,
-               "Force rebuild/salvage of all directories");
-    cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL,
-               "Read smaller blocks to handle IO/bad blocks");
-    cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
-               "# of max parallel partition salvaging");
-    cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
-               "Name of dir to place tmp files ");
-    cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL,
-               "Show log file upon completion");
-    cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
-               "ignore | remove | attach");
-
-    /* note - syslog isn't avail on NT, but if we make it conditional, have
-     * to deal with screwy offsets for cmd params */
-    cmd_AddParm(ts, "-syslog", CMD_FLAG, CMD_OPTIONAL,
-               "Write salvage log to syslogs");
-    cmd_AddParm(ts, "-syslogfacility", CMD_SINGLE, CMD_OPTIONAL,
-               "Syslog facility number to use");
-    cmd_AddParm(ts, "-datelogs", CMD_FLAG, CMD_OPTIONAL,
+    cmd_AddParmAtOffset(ts, OPT_partition, "-partition", CMD_SINGLE,
+           CMD_OPTIONAL, "Name of partition to salvage");
+    cmd_AddParmAtOffset(ts, OPT_volumeid, "-volumeid", CMD_SINGLE, CMD_OPTIONAL,
+           "Volume Id to salvage");
+    cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG, CMD_OPTIONAL,
+           "Run in Debugging mode");
+    cmd_AddParmAtOffset(ts, OPT_nowrite, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
+           "Run readonly/test mode");
+    cmd_AddParmAtOffset(ts, OPT_inodes, "-inodes", CMD_FLAG, CMD_OPTIONAL,
+           "Just list affected afs inodes - debugging flag");
+    cmd_AddParmAtOffset(ts, OPT_oktozap, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
+           "Give permission to destroy bogus inodes/volumes - debugging flag");
+    cmd_AddParmAtOffset(ts, OPT_rootinodes, "-rootinodes", CMD_FLAG,
+           CMD_OPTIONAL, "Show inodes owned by root - debugging flag");
+    cmd_AddParmAtOffset(ts, OPT_salvagedirs, "-salvagedirs", CMD_FLAG,
+           CMD_OPTIONAL, "Force rebuild/salvage of all directories");
+    cmd_AddParmAtOffset(ts, OPT_blockreads, "-blockreads", CMD_FLAG,
+           CMD_OPTIONAL, "Read smaller blocks to handle IO/bad blocks");
+    cmd_AddParmAtOffset(ts, OPT_parallel, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
+           "# of max parallel partition salvaging");
+    cmd_AddParmAtOffset(ts, OPT_tmpdir, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
+           "Name of dir to place tmp files ");
+    cmd_AddParmAtOffset(ts, OPT_showlog, "-showlog", CMD_FLAG, CMD_OPTIONAL,
+           "Show log file upon completion");
+    cmd_AddParmAtOffset(ts, OPT_orphans, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
+           "ignore | remove | attach");
+
+#if !defined(AFS_NT40_ENV)
+    cmd_AddParmAtOffset(ts, OPT_syslog, "-syslog", CMD_FLAG, CMD_OPTIONAL,
+           "Write salvage log to syslogs");
+    cmd_AddParmAtOffset(ts, OPT_syslogfacility, "-syslogfacility", CMD_SINGLE,
+           CMD_OPTIONAL, "Syslog facility number to use");
+    cmd_AddParmAtOffset(ts, OPT_datelogs, "-datelogs", CMD_FLAG, CMD_OPTIONAL,
                "Include timestamp in logfile filename");
+#endif
 
-    cmd_AddParm(ts, "-client", CMD_FLAG, CMD_OPTIONAL,
+    cmd_AddParmAtOffset(ts, OPT_client, "-client", CMD_FLAG, CMD_OPTIONAL,
                "Use SALVSYNC to ask salvageserver to salvage a volume");
 
+    cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE, CMD_OPTIONAL,
+           "Location of log file ");
+
     err = cmd_Dispatch(argc, argv);
     Exit(err);
     return 0; /* not reached */
@@ -427,7 +447,7 @@ SalvageClient(VolumeId vid, char * pname)
                        "trying to continue anyway\n");
     }
     SALVSYNC_clientInit();
-    
+
     code = SALVSYNC_SalvageVolume(vid, pname, SALVSYNC_SALVAGE, SALVSYNC_OPERATOR, 0, NULL);
     if (code != SYNC_OK) {
        goto sync_error;
@@ -482,7 +502,7 @@ SalvageServer(int argc, char **argv)
      * multiple salvagers appending to the log.
      */
 
-    CheckLogFile((char *)AFSDIR_SERVER_SALSRVLOG_FILEPATH);
+    CheckLogFile(logFileName);
 #ifndef AFS_NT40_ENV
 #ifdef AFS_LINUX20_ENV
     fcntl(fileno(logFile), F_SETFL, O_APPEND); /* Isn't this redundant? */
@@ -500,16 +520,15 @@ SalvageServer(int argc, char **argv)
      * VInitVolumePackage2 (called below) makes sure that a file server or
      * other volume utilities don't interfere with the salvage.
      */
-    
+
     /* even demand attach online salvager
      * still needs this because we don't want
      * a stand-alone salvager to conflict with
      * the salvager daemon */
     ObtainSharedSalvageLock();
 
-    child_slot = (int *) malloc(Parallel * sizeof(int));
-    assert(child_slot != NULL);
-    memset(child_slot, 0, Parallel * sizeof(int));
+    child_slot = calloc(Parallel, sizeof(int));
+    opr_Assert(child_slot != NULL);
 
     /* initialize things */
     VOptDefaults(salvageServer, &opts);
@@ -520,30 +539,25 @@ SalvageServer(int argc, char **argv)
     DInit(10);
     queue_Init(&pending_q);
     queue_Init(&log_cleanup_queue);
-    assert(pthread_mutex_init(&worker_lock, NULL) == 0);
-    assert(pthread_cond_init(&worker_cv, NULL) == 0);
-    assert(pthread_cond_init(&log_cleanup_queue.queue_change_cv, NULL) == 0);
-    assert(pthread_attr_init(&attrs) == 0);
+    opr_mutex_init(&worker_lock);
+    opr_cv_init(&worker_cv);
+    opr_cv_init(&log_cleanup_queue.queue_change_cv);
+    opr_Verify(pthread_attr_init(&attrs) == 0);
 
     /* start up the reaper and log cleaner threads */
-    assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0);
-    assert(pthread_create(&tid, 
-                         &attrs, 
-                         &SalvageChildReaperThread,
-                         NULL) == 0);
-    assert(pthread_create(&tid, 
-                         &attrs, 
-                         &SalvageLogCleanupThread,
-                         NULL) == 0);
-    assert(pthread_create(&tid,
-                         &attrs,
-                         &SalvageLogScanningThread,
-                         NULL) == 0);
+    opr_Verify(pthread_attr_setdetachstate(&attrs,
+                                          PTHREAD_CREATE_DETACHED) == 0);
+    opr_Verify(pthread_create(&tid, &attrs,
+                             &SalvageChildReaperThread, NULL) == 0);
+    opr_Verify(pthread_create(&tid, &attrs,
+                             &SalvageLogCleanupThread, NULL) == 0);
+    opr_Verify(pthread_create(&tid, &attrs,
+                             &SalvageLogScanningThread, NULL) == 0);
 
     /* loop forever serving requests */
     while (1) {
        node = SALVSYNC_getWork();
-       assert(node != NULL);
+       opr_Assert(node != NULL);
 
        Log("dispatching child to salvage volume %u...\n",
            node->command.sop.parent);
@@ -554,7 +568,7 @@ SalvageServer(int argc, char **argv)
          if (!child_slot[slot])
            break;
        }
-       assert (slot < Parallel);
+       opr_Assert (slot < Parallel);
 
     do_fork:
        pid = Fork();
@@ -570,18 +584,18 @@ SalvageServer(int argc, char **argv)
            child_slot[slot] = pid;
            node->pid = pid;
            VOL_UNLOCK;
-           
-           assert(pthread_mutex_lock(&worker_lock) == 0);
+
+           opr_mutex_enter(&worker_lock);
            current_workers++;
-           
+
            /* let the reaper thread know another worker was spawned */
-           assert(pthread_cond_broadcast(&worker_cv) == 0);
-           
+           opr_cv_broadcast(&worker_cv);
+
            /* if we're overquota, wait for the reaper */
            while (current_workers >= Parallel) {
-               assert(pthread_cond_wait(&worker_cv, &worker_lock) == 0);
+               opr_cv_wait(&worker_cv, &worker_lock);
            }
-           assert(pthread_mutex_unlock(&worker_lock) == 0);
+           opr_mutex_exit(&worker_lock);
        }
     }
 }
@@ -599,8 +613,8 @@ DoSalvageVolume(struct SalvageQueueNode * node, int slot)
      * another thread may have held the lock on the FILE
      * structure when fork was called! */
 
-    afs_snprintf(childLog, sizeof(childLog), "%s.%d", 
-                AFSDIR_SERVER_SLVGLOG_FILEPATH, getpid());
+    snprintf(childLog, sizeof(childLog), "%s.%d",
+            AFSDIR_SERVER_SLVGLOG_FILEPATH, getpid());
 
     logFile = afs_fopen(childLog, "a");
     if (!logFile) {            /* still nothing, use stdout */
@@ -612,10 +626,10 @@ DoSalvageVolume(struct SalvageQueueNode * node, int slot)
        Log("salvageServer: invalid volume id specified; salvage aborted\n");
        return 1;
     }
-    
+
     partP = VGetPartition(node->command.sop.partName, 0);
     if (!partP) {
-       Log("salvageServer: Unknown or unmounted partition %s; salvage aborted\n", 
+       Log("salvageServer: Unknown or unmounted partition %s; salvage aborted\n",
            node->command.sop.partName);
        return 1;
     }
@@ -639,19 +653,19 @@ SalvageChildReaperThread(void * args)
     int slot, pid, status;
     struct log_cleanup_node * cleanup;
 
-    assert(pthread_mutex_lock(&worker_lock) == 0);
+    opr_mutex_enter(&worker_lock);
 
     /* loop reaping our children */
     while (1) {
        /* wait() won't block unless we have children, so
         * block on the cond var if we're childless */
        while (current_workers == 0) {
-           assert(pthread_cond_wait(&worker_cv, &worker_lock) == 0);
+           opr_cv_wait(&worker_cv, &worker_lock);
        }
 
-       assert(pthread_mutex_unlock(&worker_lock) == 0);
+       opr_mutex_exit(&worker_lock);
 
-       cleanup = (struct log_cleanup_node *) malloc(sizeof(struct log_cleanup_node));
+       cleanup = malloc(sizeof(struct log_cleanup_node));
 
        while (Reap_Child("salvageserver", &pid, &status) < 0) {
            /* try to prevent livelock if something goes wrong */
@@ -663,23 +677,23 @@ SalvageChildReaperThread(void * args)
            if (child_slot[slot] == pid)
                break;
        }
-       assert(slot < Parallel);
+       opr_Assert(slot < Parallel);
        child_slot[slot] = 0;
        VOL_UNLOCK;
 
        SALVSYNC_doneWorkByPid(pid, status);
 
-       assert(pthread_mutex_lock(&worker_lock) == 0);
+       opr_mutex_enter(&worker_lock);
 
        if (cleanup) {
            cleanup->pid = pid;
            queue_Append(&log_cleanup_queue, cleanup);
-           assert(pthread_cond_signal(&log_cleanup_queue.queue_change_cv) == 0);
+           opr_cv_signal(&log_cleanup_queue.queue_change_cv);
        }
 
        /* ok, we've reaped a child */
        current_workers--;
-       assert(pthread_cond_broadcast(&worker_cv) == 0);
+       opr_cv_broadcast(&worker_cv);
     }
 
     return NULL;
@@ -714,24 +728,24 @@ SalvageLogCleanupThread(void * arg)
 {
     struct log_cleanup_node * cleanup;
 
-    assert(pthread_mutex_lock(&worker_lock) == 0);
+    opr_mutex_enter(&worker_lock);
 
     while (1) {
        while (queue_IsEmpty(&log_cleanup_queue)) {
-           assert(pthread_cond_wait(&log_cleanup_queue.queue_change_cv, &worker_lock) == 0);
+           opr_cv_wait(&log_cleanup_queue.queue_change_cv, &worker_lock);
        }
 
        while (queue_IsNotEmpty(&log_cleanup_queue)) {
            cleanup = queue_First(&log_cleanup_queue, log_cleanup_node);
            queue_Remove(cleanup);
-           assert(pthread_mutex_unlock(&worker_lock) == 0);
+           opr_mutex_exit(&worker_lock);
            SalvageLogCleanup(cleanup->pid);
            free(cleanup);
-           assert(pthread_mutex_lock(&worker_lock) == 0);
-       }           
+           opr_mutex_enter(&worker_lock);
+       }
     }
 
-    assert(pthread_mutex_unlock(&worker_lock) == 0);
+    opr_mutex_exit(&worker_lock);
     return NULL;
 }
 
@@ -743,9 +757,9 @@ SalvageLogCleanup(int pid)
     char fn[AFSDIR_PATH_MAX];
     static char buf[LOG_XFER_BUF_SIZE];
 
-    afs_snprintf(fn, sizeof(fn), "%s.%d", 
-                AFSDIR_SERVER_SLVGLOG_FILEPATH, pid);
-    
+    snprintf(fn, sizeof(fn), "%s.%d",
+            AFSDIR_SERVER_SLVGLOG_FILEPATH, pid);
+
 
     pidlog = open(fn, O_RDONLY);
     unlink(fn);
@@ -789,11 +803,11 @@ SalvageLogScanningThread(void * arg)
        char prefix[AFSDIR_PATH_MAX];
        size_t prefix_len;
 
-       afs_snprintf(prefix, sizeof(prefix), "%s.", AFSDIR_SLVGLOG_FILE);
+       snprintf(prefix, sizeof(prefix), "%s.", AFSDIR_SLVGLOG_FILE);
        prefix_len = strlen(prefix);
 
        dp = opendir(AFSDIR_LOGS_DIR);
-       assert(dp);
+       opr_Assert(dp);
 
        while ((dirp = readdir(dp)) != NULL) {
            pid_t pid;
@@ -827,8 +841,7 @@ SalvageLogScanningThread(void * arg)
                continue;
            }
 
-           cleanup =
-               (struct log_cleanup_node *) malloc(sizeof(struct log_cleanup_node));
+           cleanup = malloc(sizeof(struct log_cleanup_node));
            cleanup->pid = pid;
 
            queue_Append(&log_watch_queue, cleanup);
@@ -859,7 +872,7 @@ ScanLogs(struct rx_queue *log_watch_queue)
 {
     struct log_cleanup_node *cleanup, *next;
 
-    assert(pthread_mutex_lock(&worker_lock) == 0);
+    opr_mutex_enter(&worker_lock);
 
     for (queue_Scan(log_watch_queue, cleanup, next, log_cleanup_node)) {
        /* if a process is still running, assume it's the salvage process
@@ -867,9 +880,9 @@ ScanLogs(struct rx_queue *log_watch_queue)
        if (kill(cleanup->pid, 0) < 0 && errno == ESRCH) {
            queue_Remove(cleanup);
            queue_Append(&log_cleanup_queue, cleanup);
-           assert(pthread_cond_signal(&log_cleanup_queue.queue_change_cv) == 0);
+           opr_cv_signal(&log_cleanup_queue.queue_change_cv);
        }
     }
 
-    assert(pthread_mutex_unlock(&worker_lock) == 0);
+    opr_mutex_exit(&worker_lock);
 }