Skip to content
Snippets Groups Projects
Commit 6ffb8bc0 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

cleanup the old info memory usage, be smarter at sanitize_system call

parent 42288b4a
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,7 @@ static void set_info(ssexec_t *info)
int r ;
if (!info->skip_opt_tree)
set_treeinfo(info) ;
set_treeinfo(info) ;
r = set_livedir(&info->live) ;
if (!r)
......@@ -80,6 +79,17 @@ static void set_info(ssexec_t *info)
log_die(LOG_EXIT_SYS, "scandir: ", info->scandir.s, " must be an absolute path") ;
}
static void info_clean(ssexec_t *info)
{
info->base.len = 0 ;
info->live.len = 0 ;
info->tree.len = 0 ;
info->scandir.len = 0 ;
info->treename.len = 0 ;
}
int main(int argc, char const *const *argv)
{
......@@ -89,6 +99,7 @@ int main(int argc, char const *const *argv)
}
int r, n = 0, i = 0 ;
uint8_t sanitize = 0 ;
/** 30 options should be large enough */
char opts[30] ;
char const *main = "hv:l:t:T:z" ;
......@@ -99,6 +110,8 @@ int main(int argc, char const *const *argv)
ssexec_func_t_ref func = 0 ;
log_color = &log_color_disable ;
info_clean(&info) ;
info.owner = getuid() ;
info.ownerlen = uid_fmt(info.ownerstr, info.owner) ;
info.ownerstr[info.ownerlen] = 0 ;
......@@ -116,7 +129,7 @@ int main(int argc, char const *const *argv)
info.usage = usage_boot ;
func = &ssexec_boot ;
//sanitize_system(&info) ;
sanitize++ ;
auto_strings(opts, main, OPTS_BOOT) ;
......@@ -129,8 +142,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_enable ;
func = &ssexec_enable ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_ENABLE) ;
} else if (!strcmp(argv[1], "disable")) {
......@@ -142,8 +153,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_disable ;
func = &ssexec_disable ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_DISABLE) ;
} else if (!strcmp(argv[1], "start")) {
......@@ -155,8 +164,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_start ;
func = &ssexec_start ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_START) ;
} else if (!strcmp(argv[1], "stop")) {
......@@ -168,24 +175,9 @@ int main(int argc, char const *const *argv)
info.usage = usage_stop ;
func = &ssexec_stop ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_STOP) ;
} else if (!strcmp(argv[1], "stop")) {
PROG = "stop" ;
nargv[n++] = PROG ;
info.prog = PROG ;
info.help = help_stop ;
info.usage = usage_stop ;
func = &ssexec_stop ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_STOP) ;
} else if (!strcmp(argv[1], "all")) {
} else if (!strcmp(argv[1], "all")) {
PROG = "all" ;
nargv[n++] = PROG ;
......@@ -194,8 +186,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_all ;
func = &ssexec_all ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_ALL) ;
} else if (!strcmp(argv[1], "env")) {
......@@ -207,8 +197,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_env ;
func = &ssexec_env ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_ENV) ;
} else if (!strcmp(argv[1], "init")) {
......@@ -220,8 +208,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_init ;
func = &ssexec_init ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_INIT) ;
} else if (!strcmp(argv[1], "parse")) {
......@@ -233,8 +219,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_parse ;
func = &ssexec_parse ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_PARSE) ;
} else if (!strcmp(argv[1], "reconfigure")) {
......@@ -246,8 +230,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_reconfigure ;
func = &ssexec_reconfigure ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SUBSTART) ;
} else if (!strcmp(argv[1], "reload")) {
......@@ -259,8 +241,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_reload ;
func = &ssexec_reload ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SUBSTART) ;
} else if (!strcmp(argv[1], "restart")) {
......@@ -272,8 +252,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_restart ;
func = &ssexec_restart ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SUBSTART) ;
} else if (!strcmp(argv[1], "unsupervise")) {
......@@ -286,8 +264,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_stop ;
func = &ssexec_stop ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_STOP) ;
} else if (!strcmp(argv[1], "svctl")) {
......@@ -299,8 +275,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_svctl ;
func = &ssexec_svctl ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SVCTL) ;
} else if (!strcmp(argv[1], "tree")) {
......@@ -312,8 +286,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_tree ;
func = &ssexec_tree ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_TREE) ;
} else if (!strcmp(argv[1], "inresolve")) {
......@@ -325,8 +297,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_inresolve ;
func = &ssexec_inresolve ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_INRESOLVE) ;
} else if (!strcmp(argv[1], "instate")) {
......@@ -338,8 +308,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_instate ;
func = &ssexec_instate ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_INSTATE) ;
} else if (!strcmp(argv[1], "intree")) {
......@@ -351,8 +319,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_intree ;
func = &ssexec_intree ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_INTREE) ;
} else if (!strcmp(argv[1], "inservice")) {
......@@ -364,8 +330,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_inservice ;
func = &ssexec_inservice ;
sanitize_system(&info) ;
auto_strings(opts, main, OPTS_INSERVICE) ;
} else if (!strcmp(argv[1], "scanctl")) {
......@@ -377,8 +341,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_scanctl ;
func = &ssexec_scanctl ;
//sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SCANCTL) ;
} else if (!strcmp(argv[1], "scandir")) {
......@@ -390,8 +352,6 @@ int main(int argc, char const *const *argv)
info.usage = usage_scandir ;
func = &ssexec_scandir ;
//sanitize_system(&info) ;
auto_strings(opts, main, OPTS_SCANDIR) ;
} else {
......@@ -449,7 +409,6 @@ int main(int argc, char const *const *argv)
log_die_nomem("stralloc") ;
info.opt_tree = 1 ;
info.skip_opt_tree = 0 ;
break ;
case 'T' :
......@@ -505,6 +464,9 @@ int main(int argc, char const *const *argv)
argc -= l.ind ; argv += l.ind ;
}
if (!sanitize)
sanitize_system(&info) ;
set_info(&info) ;
for (i = 0 ; i < argc ; i++ , argv++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment