aklog: Avoid misleading AFSCELL message
[openafs.git] / src / aklog / aklog.c
index 1eaa95e..988d54c 100644 (file)
@@ -317,9 +317,10 @@ redirect_errors(const char *who, afs_int32 code, const char *fmt, va_list ap)
            krb5_svc_get_msg(code,&str);
 #elif defined(HAVE_KRB5_GET_ERROR_MESSAGE)
            krb5_context context;
-           krb5_init_context(&context);
-           str = krb5_get_error_message(context, code);
-           krb5_free_context(context);
+           if (krb5_init_context(&context) == 0) {
+                str = krb5_get_error_message(context, code);
+                krb5_free_context(context);
+            }
 #else
            ; /* IRIX apparently has neither: use the string we have */
 #endif
@@ -382,19 +383,24 @@ get_cellconfig(const char *config, char *cell,
        exit(AKLOG_AFS);
     }
 
-    if (afsconf_GetLocalCell(configdir, *local_cell, MAXCELLCHARS)) {
-       fprintf(stderr, "%s: can't determine local cell.\n", progname);
-       exit(AKLOG_AFS);
+    if (cell != NULL && cell[0] == '\0') {
+       /* Use the local cell */
+       cell = NULL;
     }
 
-    if ((cell == NULL) || (cell[0] == 0))
-       cell = *local_cell;
-
     /* XXX - This function modifies 'cell' by passing it through lcstring */
     if (afsconf_GetCellInfo(configdir, cell, NULL, cellconfig)) {
-       fprintf(stderr, "%s: Can't get information about cell %s.\n",
-               progname, cell);
+       if (cell != NULL) {
+           fprintf(stderr, "%s: Can't get information about cell %s.\n",
+                   progname, cell);
+       } else {
+           fprintf(stderr, "%s: Can't get information about the local cell.\n",
+                   progname);
+       }
        status = AKLOG_AFS;
+    } else if (afsconf_GetLocalCell(configdir, *local_cell, MAXCELLCHARS)) {
+       fprintf(stderr, "%s: can't determine local cell.\n", progname);
+       exit(AKLOG_AFS);
     }
 
     afsconf_Close(configdir);
@@ -1097,8 +1103,9 @@ auth_to_cell(krb5_context context, const char *config,
         * We don't care about the return value, but need to collect it
         * to avoid compiler warnings.
         */
-       if (write(2,"",0) < 0) /* dummy write */
-           ; /* don't care */
+       if (write(2,"",0) < 0) {
+           /* dummy write, don't care */
+       }
 #endif
        token_setPag(token, afssetpag);
        status = ktc_SetTokenEx(token);