summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c36
-rw-r--r--util/nvmutil/nvmutil.h1
2 files changed, 29 insertions, 8 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 13e9113a..33d20c9f 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -746,18 +746,18 @@ good_checksum(unsigned long partnum)
void
run_cmd(void)
{
- unsigned long cmd_num;
- struct commands *cmd;
+ unsigned long i = x->i;
+ void (*run)(void) = x->cmd[i].run;
- cmd_num = x->i;
- cmd = &x->cmd[cmd_num];
+ check_command_num(i);
- check_command_num(cmd_num);
+ if (run == NULL)
+ err(EINVAL, "Command %lu: null ptr", i);
- if (cmd->run == NULL)
- err(EINVAL, "Command %lu: null ptr", cmd_num);
+ run();
- cmd->run();
+ for (i = 0; i < items(x->cmd); i++)
+ x->cmd[i].run = cmd_helper_err;
}
void
@@ -1189,9 +1189,29 @@ cmd_helper_cat128(void) {
void
check_cmd(void (*fn)(void), const char *name)
{
+ unsigned long i;
+
if (x->cmd[x->i].run != fn)
err(ECANCELED, "Running %s, but cmd %s is set",
name, x->cmd[x->i].str);
+
+ /*
+ * In addition to making sure we ran
+ * the right command, we now disable
+ * all commands from running again
+ *
+ * the _nop function will just call
+ * err() immediately
+ */
+
+ for (i = 0; i < items(x->cmd); i++)
+ x->cmd[i].run = cmd_helper_err;
+}
+
+void
+cmd_helper_err(void)
+{
+ err(ECANCELED, "Erroneously running command twice");
}
void
diff --git a/util/nvmutil/nvmutil.h b/util/nvmutil/nvmutil.h
index d02d2d7f..ce38772c 100644
--- a/util/nvmutil/nvmutil.h
+++ b/util/nvmutil/nvmutil.h
@@ -389,6 +389,7 @@ void cat(unsigned long nff);
void cat_buf(unsigned char *b);
void check_cmd(void (*fn)(void), const char *name);
+void cmd_helper_err(void);
/*
* After command processing, write