cacheout: Improve error handling
authorAndrew Deason <adeason@sinenomine.net>
Fri, 3 Sep 2010 15:59:45 +0000 (10:59 -0500)
committerDerrick Brashear <shadow@dementia.org>
Sun, 5 Sep 2010 15:50:44 +0000 (08:50 -0700)
Bail out when we encounter errors in initialization. Among other
things, this prevents a segfault if we can't read the client
configuration.

Change-Id: I8b35163c5c4750eb05539a225069327051a3f148
Reviewed-on: http://gerrit.openafs.org/2665
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Hutzelman <jhutz@cmu.edu>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/venus/cacheout.c

index b843052..5fbd058 100644 (file)
@@ -252,19 +252,25 @@ MyBeforeProc(struct cmd_syndesc *as, void *arock)
     sprintf(confdir, "%s", AFSDIR_CLIENT_ETC_DIRPATH);
     /* setup to talk to servers */
     code = rx_Init(0);
-    if (code)
+    if (code) {
        printf("Warning: could not initialize network communication.\n");
+       return 1;
+    }
 
     junk = rxnull_NewClientSecurityObject();
     tdir = afsconf_Open(confdir);
-    if (!tdir)
+    if (!tdir) {
        printf("Warning: could not get cell configuration.\n");
+       return 1;
+    }
 
     if (as->parms[2].items)    /* if -cell specified */
        tcell = as->parms[2].items->data;
     code = afsconf_GetCellInfo(tdir, tcell, AFSCONF_VLDBSERVICE, &info);
-    if (info.numServers > MAXSERVERS)
+    if (code || info.numServers > MAXSERVERS) {
        printf("Warning: could not init cell info.\n");
+       return 1;
+    }
 
     for (i = 0; i < info.numServers; ++i)
        serverconns[i] =
@@ -275,8 +281,10 @@ MyBeforeProc(struct cmd_syndesc *as, void *arock)
        serverconns[i] = (struct rx_connection *)0;
     }
     code = ubik_ClientInit(serverconns, &client);
-    if (code)
+    if (code) {
        printf("Warning: could not initialize RPC interface.\n");
+       return 1;
+    }
     return 0;
 }