Author: smh
Date: Wed Jan 13 18:33:12 2016
New Revision: 293835
URL: https://svnweb.freebsd.org/changeset/base/293835

Log:
  Improve non-interactive forth cmd error reporting
  
  Non-interactive forth command errors where silent even for critical issues
  e.g. failing to load a required kernel module or mfs_root.
  
  This resulted in later unexplained and hard to trace errors such as mount
  root failures.
  
  This introduces additional command return codes that are treated
  appropriately by the non-interactive command processor (bf_command).
  * CMD_CRIT = print error
  * CMD_FATAL = panic
  
  Also fix minor style(9) issues with command_load return codes.
  
  MFC after:    2 weeks
  X-MFC-With:   r293268
  Sponsored by: Multiplay

Modified:
  head/sys/boot/common/bootstrap.h
  head/sys/boot/common/interp_forth.c
  head/sys/boot/common/module.c

Modified: head/sys/boot/common/bootstrap.h
==============================================================================
--- head/sys/boot/common/bootstrap.h    Wed Jan 13 17:59:12 2016        
(r293834)
+++ head/sys/boot/common/bootstrap.h    Wed Jan 13 18:33:12 2016        
(r293835)
@@ -56,7 +56,10 @@ typedef int  (bootblk_cmd_t)(int argc, ch
 extern char    *command_errmsg;        
 extern char    command_errbuf[];       /* XXX blah, length */
 #define CMD_OK         0
-#define CMD_ERROR      1
+#define CMD_WARN       1
+#define CMD_ERROR      2
+#define CMD_CRIT       3
+#define CMD_FATAL      4
 
 /* interp.c */
 void   interact(const char *rc);

Modified: head/sys/boot/common/interp_forth.c
==============================================================================
--- head/sys/boot/common/interp_forth.c Wed Jan 13 17:59:12 2016        
(r293834)
+++ head/sys/boot/common/interp_forth.c Wed Jan 13 18:33:12 2016        
(r293835)
@@ -138,13 +138,23 @@ bf_command(FICL_VM *vm)
     } else {
        result=BF_PARSE;
     }
+
+    switch (result) {
+    case CMD_CRIT:
+       printf("%s\n", command_errmsg);
+       break;
+    case CMD_FATAL:
+       panic("%s\n", command_errmsg);
+    }
+
     free(line);
     /*
      * If there was error during nested ficlExec(), we may no longer have
      * valid environment to return.  Throw all exceptions from here.
      */
-    if (result != 0)
+    if (result != CMD_OK)
        vmThrow(vm, result);
+
     /* This is going to be thrown!!! */
     stackPushINT(vm->pStack,result);
 }

Modified: head/sys/boot/common/module.c
==============================================================================
--- head/sys/boot/common/module.c       Wed Jan 13 17:59:12 2016        
(r293834)
+++ head/sys/boot/common/module.c       Wed Jan 13 18:33:12 2016        
(r293835)
@@ -112,7 +112,7 @@ command_load(int argc, char *argv[])
     typestr = NULL;
     if (argc == 1) {
        command_errmsg = "no filename specified";
-       return(CMD_ERROR);
+       return (CMD_CRIT);
     }
     while ((ch = getopt(argc, argv, "kt:")) != -1) {
        switch(ch) {
@@ -126,7 +126,7 @@ command_load(int argc, char *argv[])
        case '?':
        default:
            /* getopt has already reported an error */
-           return(CMD_OK);
+           return (CMD_OK);
        }
     }
     argv += (optind - 1);
@@ -138,33 +138,46 @@ command_load(int argc, char *argv[])
     if (dofile) {
        if ((argc != 2) || (typestr == NULL) || (*typestr == 0)) {
            command_errmsg = "invalid load type";
-           return(CMD_ERROR);
+           return (CMD_CRIT);
        }
 
        fp = file_findfile(argv[1], typestr);
        if (fp) {
                sprintf(command_errbuf, "warning: file '%s' already loaded", 
argv[1]);
-               return (CMD_ERROR);
+               return (CMD_WARN);
        }
 
-       return (file_loadraw(argv[1], typestr, 1) ? CMD_OK : CMD_ERROR);
+       if (file_loadraw(argv[1], typestr, 1) != NULL)
+               return (CMD_OK);
+
+       /* Failing to load mfs_root is never going to end well! */
+       if (strcmp("mfs_root", typestr) == 0)
+               return (CMD_FATAL);
+
+       return (CMD_ERROR);
     }
     /*
      * Do we have explicit KLD load ?
      */
     if (dokld || file_havepath(argv[1])) {
        error = mod_loadkld(argv[1], argc - 2, argv + 2);
-       if (error == EEXIST)
+       if (error == EEXIST) {
            sprintf(command_errbuf, "warning: KLD '%s' already loaded", 
argv[1]);
-       return (error == 0 ? CMD_OK : CMD_ERROR);
+           return (CMD_WARN);
+       }
+       
+       return (error == 0 ? CMD_OK : CMD_CRIT);
     }
     /*
      * Looks like a request for a module.
      */
     error = mod_load(argv[1], NULL, argc - 2, argv + 2);
-    if (error == EEXIST)
+    if (error == EEXIST) {
        sprintf(command_errbuf, "warning: module '%s' already loaded", argv[1]);
-    return (error == 0 ? CMD_OK : CMD_ERROR);
+       return (CMD_WARN);
+    }
+
+    return (error == 0 ? CMD_OK : CMD_CRIT);
 }
 
 COMMAND_SET(load_geli, "load_geli", "load a geli key", command_load_geli);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to