Add a function to free all of sysinstall's internal variables from the

environment.  This fixes an annoying bug where hitting Ctrl-C and
telling sysinstall to 'restart' will do no such thing since many of
the options are still set and so you won't be prompted for them
again.

MFC after:	1 week
This commit is contained in:
Murray Stokely 2001-09-22 18:10:56 +00:00
parent 8f217e4c8b
commit eba8393e91
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83820
6 changed files with 74 additions and 6 deletions

View File

@ -771,6 +771,7 @@ extern void variable_unset(char *var);
extern char *variable_get_value(char *var, char *prompt, int dirty);
extern int variable_check(char *data);
extern int dump_variables(dialogMenuItem *self);
extern void free_variables(void);
/* wizard.c */
extern void slice_wizard(Disk *d);

View File

@ -56,7 +56,10 @@ intr_reboot(dialogMenuItem *self)
static int
intr_restart(dialogMenuItem *self)
{
execl(StartName, StartName, (char *)NULL);
int ret;
free_variables();
ret = execl(StartName, StartName, (char *)NULL);
msgDebug("execl failed (%s)\n", strerror(errno));
/* NOTREACHED */
return -1;
}

View File

@ -171,8 +171,8 @@ variable_get_value(char *var, char *prompt, int dirty)
return cp;
}
/* Check if value passed in data (in the form "variable=value") is equal to value of
variable stored in env */
/* Check if value passed in data (in the form "variable=value") is
equal to value of variable stored in env */
int
variable_check(char *data)
{
@ -227,3 +227,33 @@ dump_variables(dialogMenuItem *unused)
return DITEM_SUCCESS;
}
/* Free all of the variables, useful to really start over as when the
user selects "restart" from the interrupt menu. */
void
free_variables(void)
{
Variable *vp;
/* Free the variables from our list, if we have one.. */
if (!VarHead)
return;
else if (!VarHead->next) {
unsetenv(VarHead->name);
safe_free(VarHead->name);
safe_free(VarHead->value);
free(VarHead);
VarHead = NULL;
}
else {
for (vp = VarHead; vp; ) {
Variable *save = vp;
unsetenv(vp->name);
safe_free(vp->name);
safe_free(vp->value);
vp = vp->next;
safe_free(save);
}
VarHead = NULL;
}
}

View File

@ -771,6 +771,7 @@ extern void variable_unset(char *var);
extern char *variable_get_value(char *var, char *prompt, int dirty);
extern int variable_check(char *data);
extern int dump_variables(dialogMenuItem *self);
extern void free_variables(void);
/* wizard.c */
extern void slice_wizard(Disk *d);

View File

@ -56,7 +56,10 @@ intr_reboot(dialogMenuItem *self)
static int
intr_restart(dialogMenuItem *self)
{
execl(StartName, StartName, (char *)NULL);
int ret;
free_variables();
ret = execl(StartName, StartName, (char *)NULL);
msgDebug("execl failed (%s)\n", strerror(errno));
/* NOTREACHED */
return -1;
}

View File

@ -171,8 +171,8 @@ variable_get_value(char *var, char *prompt, int dirty)
return cp;
}
/* Check if value passed in data (in the form "variable=value") is equal to value of
variable stored in env */
/* Check if value passed in data (in the form "variable=value") is
equal to value of variable stored in env */
int
variable_check(char *data)
{
@ -227,3 +227,33 @@ dump_variables(dialogMenuItem *unused)
return DITEM_SUCCESS;
}
/* Free all of the variables, useful to really start over as when the
user selects "restart" from the interrupt menu. */
void
free_variables(void)
{
Variable *vp;
/* Free the variables from our list, if we have one.. */
if (!VarHead)
return;
else if (!VarHead->next) {
unsetenv(VarHead->name);
safe_free(VarHead->name);
safe_free(VarHead->value);
free(VarHead);
VarHead = NULL;
}
else {
for (vp = VarHead; vp; ) {
Variable *save = vp;
unsetenv(vp->name);
safe_free(vp->name);
safe_free(vp->value);
vp = vp->next;
safe_free(save);
}
VarHead = NULL;
}
}