mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-19 10:53:58 +00:00
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
This commit is contained in:
parent
1da56163f2
commit
4b09a8fdbc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=293835
@ -56,7 +56,10 @@ typedef int (bootblk_cmd_t)(int argc, char *argv[]);
|
||||
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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user