Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jan 2016 12:23:25 +0000 (UTC)
From:      Steven Hartland <smh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r294985 - stable/10/sys/boot/common
Message-ID:  <201601281223.u0SCNPXP063335@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: smh
Date: Thu Jan 28 12:23:25 2016
New Revision: 294985
URL: https://svnweb.freebsd.org/changeset/base/294985

Log:
  MFC r293835:
  
  Improve non-interactive forth cmd error reporting
  
  Sponsored by:	Multiplay

Modified:
  stable/10/sys/boot/common/bootstrap.h
  stable/10/sys/boot/common/interp_forth.c
  stable/10/sys/boot/common/module.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/common/bootstrap.h
==============================================================================
--- stable/10/sys/boot/common/bootstrap.h	Thu Jan 28 12:22:15 2016	(r294984)
+++ stable/10/sys/boot/common/bootstrap.h	Thu Jan 28 12:23:25 2016	(r294985)
@@ -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(void);

Modified: stable/10/sys/boot/common/interp_forth.c
==============================================================================
--- stable/10/sys/boot/common/interp_forth.c	Thu Jan 28 12:22:15 2016	(r294984)
+++ stable/10/sys/boot/common/interp_forth.c	Thu Jan 28 12:23:25 2016	(r294985)
@@ -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: stable/10/sys/boot/common/module.c
==============================================================================
--- stable/10/sys/boot/common/module.c	Thu Jan 28 12:22:15 2016	(r294984)
+++ stable/10/sys/boot/common/module.c	Thu Jan 28 12:23:25 2016	(r294985)
@@ -111,7 +111,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) {
@@ -125,7 +125,7 @@ command_load(int argc, char *argv[])
 	case '?':
 	default:
 	    /* getopt has already reported an error */
-	    return(CMD_OK);
+	    return (CMD_OK);
 	}
     }
     argv += (optind - 1);
@@ -137,33 +137,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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601281223.u0SCNPXP063335>