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