diff --git a/INSTALL b/INSTALL index 31a2cf38868eb1027285cb9052b88a1a848c4ab5..d401b6cdb0a5ab4e28419496aaadfafd4f798bbc 100644 --- a/INSTALL +++ b/INSTALL @@ -6,16 +6,11 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.7.0.0 at least commit e99801ab4bdd096b5e2e3e4619f1a8317a8aedf8 - or later: http://skarnet.org/software/skalibs/ - - execline version 2.5.0.1 at least commit 3664d1fdc26a9b5fa1be1e3743b6fb1ff14ebaca - or later: http://skarnet.org/software/execline/ - - s6 version 2.7.2.2 at least commit 6c65c3dd94ce2e6a054d9358795ba1f17de03cad - or later: http://skarnet.org/software/s6/ - - s6-rc version 0.4.1.0 at least commit f01bb649f33d9005e30ec2e82fef05f25b9a8dff - or later: http://skarnet.org/software/s6-rc/ - - s6-portable-utils version 2.2.1.2 at least 8e32ad68593aeb3c9ffd664aabc421d2eddc0467 - or later: http://skarnet.org/software/s6-portable-utils/ + - skalibs version 2.8.0.0 or later: http://skarnet.org/software/skalibs/ + - execline version 2.5.1.0 or later: http://skarnet.org/software/execline/ + - s6 version 2.8.0.0 or later: http://skarnet.org/software/s6/ + - s6-rc version 0.5.0.0 or later: http://skarnet.org/software/s6-rc/ + - s6-portable-utils version 2.2.1.3 or later: http://skarnet.org/software/s6-portable-utils/ - oblibs version 0.0.1.0 or later: https://framagit.org/Obarun/oblibs/ This software will run on any operating system that implements diff --git a/package/deps.mak b/package/deps.mak index 7c518e99a6cf8593228ba55f432a8bf58390165d..96698b294fd0d2542efad1a0681926273868bb18 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -6,7 +6,7 @@ src/include/66/66.h: src/include/66/backup.h src/include/66/config.h src/include src/include/66/backup.h: src/include/66/ssexec.h src/include/66/constants.h: src/include/66/config.h src/include/66/db.h: src/include/66/graph.h src/include/66/ssexec.h -src/include/66/parser.h: src/include/66/enum.h +src/include/66/parser.h: src/include/66/enum.h src/include/66/ssexec.h src/include/66/rc.h: src/include/66/ssexec.h src/include/66/resolve.h: src/include/66/parser.h src/include/66/ssexec.h src/include/66/svc.h: src/include/66/resolve.h src/include/66/ssexec.h @@ -42,10 +42,10 @@ src/lib66/get_userhome.o src/lib66/get_userhome.lo: src/lib66/get_userhome.c src src/lib66/graph.o src/lib66/graph.lo: src/lib66/graph.c src/include/66/constants.h src/include/66/enum.h src/include/66/graph.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/parser.o src/lib66/parser.lo: src/lib66/parser.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h src/lib66/parser_utils.o src/lib66/parser_utils.lo: src/lib66/parser_utils.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h -src/lib66/parser_write.o src/lib66/parser_write.lo: src/lib66/parser_write.c src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/resolve.h src/include/66/utils.h -src/lib66/rc_init.o src/lib66/rc_init.lo: src/lib66/rc_init.c src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h +src/lib66/parser_write.o src/lib66/parser_write.lo: src/lib66/parser_write.c src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h +src/lib66/rc_init.o src/lib66/rc_init.lo: src/lib66/rc_init.c src/include/66/constants.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/rc_send.o src/lib66/rc_send.lo: src/lib66/rc_send.c src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h -src/lib66/resolve.o src/lib66/resolve.lo: src/lib66/resolve.c src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h +src/lib66/resolve.o src/lib66/resolve.lo: src/lib66/resolve.c src/include/66/constants.h src/include/66/enum.h src/include/66/graph.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/scandir_ok.o src/lib66/scandir_ok.lo: src/lib66/scandir_ok.c src/include/66/utils.h src/lib66/scandir_send_signal.o src/lib66/scandir_send_signal.lo: src/lib66/scandir_send_signal.c src/include/66/utils.h src/lib66/set_info.o src/lib66/set_info.lo: src/lib66/set_info.c src/include/66/config.h src/include/66/utils.h @@ -59,7 +59,7 @@ src/lib66/ssexec_disable.o src/lib66/ssexec_disable.lo: src/lib66/ssexec_disable src/lib66/ssexec_enable.o src/lib66/ssexec_enable.lo: src/lib66/ssexec_enable.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/graph.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/lib66/ssexec_free.o src/lib66/ssexec_free.lo: src/lib66/ssexec_free.c src/include/66/ssexec.h src/lib66/ssexec_help.o src/lib66/ssexec_help.lo: src/lib66/ssexec_help.c src/include/66/ssexec.h -src/lib66/ssexec_init.o src/lib66/ssexec_init.lo: src/lib66/ssexec_init.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h +src/lib66/ssexec_init.o src/lib66/ssexec_init.lo: src/lib66/ssexec_init.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/lib66/ssexec_main.o src/lib66/ssexec_main.lo: src/lib66/ssexec_main.c src/include/66/ssexec.h src/include/66/tree.h src/include/66/utils.h src/lib66/ssexec_start.o src/lib66/ssexec_start.lo: src/lib66/ssexec_start.c src/include/66/backup.h src/include/66/config.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h src/lib66/ssexec_stop.o src/lib66/ssexec_stop.lo: src/lib66/ssexec_stop.c src/include/66/backup.h src/include/66/config.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/tree.h src/include/66/utils.h @@ -69,6 +69,7 @@ src/lib66/svc_init.o src/lib66/svc_init.lo: src/lib66/svc_init.c src/include/66/ src/lib66/svc_init_pipe.o src/lib66/svc_init_pipe.lo: src/lib66/svc_init_pipe.c src/include/66/resolve.h src/include/66/svc.h src/include/66/utils.h src/lib66/svc_send.o src/lib66/svc_send.lo: src/lib66/svc_send.c src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/lib66/svc_switch_to.o src/lib66/svc_switch_to.lo: src/lib66/svc_switch_to.c src/include/66/backup.h src/include/66/enum.h src/include/66/ssexec.h src/include/66/utils.h +src/lib66/svc_unsupervise.o src/lib66/svc_unsupervise.lo: src/lib66/svc_unsupervise.c src/include/66/resolve.h src/include/66/ssexec.h src/include/66/svc.h src/include/66/utils.h src/lib66/tree_cmd_state.o src/lib66/tree_cmd_state.lo: src/lib66/tree_cmd_state.c src/include/66/constants.h src/include/66/utils.h src/lib66/tree_copy.o src/lib66/tree_copy.lo: src/lib66/tree_copy.c src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h src/lib66/tree_copy_tmp.o src/lib66/tree_copy_tmp.lo: src/lib66/tree_copy_tmp.c src/include/66/constants.h src/include/66/enum.h src/include/66/ssexec.h src/include/66/tree.h src/include/66/utils.h @@ -81,7 +82,7 @@ src/lib66/tree_switch_current.o src/lib66/tree_switch_current.lo: src/lib66/tree 66-all: EXTRA_LIBS := 66-all: src/66/66-all.o ${LIB66} -loblibs -ls6 -lskarnet 66-dbctl: EXTRA_LIBS := -66-dbctl: src/66/66-dbctl.o ${LIB66} -loblibs -ls6 -lskarnet -ls6rc ${LIBS6RC} +66-dbctl: src/66/66-dbctl.o ${LIB66} -loblibs -ls6 -lskarnet -ls6rc 66-disable: EXTRA_LIBS := 66-disable: src/66/66-disable.o ${LIB66} -loblibs -lexecline -ls6 -lskarnet 66-enable: EXTRA_LIBS := @@ -99,15 +100,15 @@ src/lib66/tree_switch_current.o src/lib66/tree_switch_current.lo: src/lib66/tree 66-svctl: EXTRA_LIBS := 66-svctl: src/66/66-svctl.o ${LIB66} -loblibs -ls6 -lskarnet 66-tree: EXTRA_LIBS := -66-tree: src/66/66-tree.o ${LIB66} -loblibs -lskarnet +66-tree: src/66/66-tree.o ${LIB66} -loblibs -ls6rc -ls6 -lskarnet 66-envfile: EXTRA_LIBS := 66-envfile: src/extra-tools/66-envfile.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} execl-cmdline: EXTRA_LIBS := execl-cmdline: src/extra-tools/execl-cmdline.o -lexecline -loblibs -lskarnet ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_cmd_master.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_get_permissions.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/dir_cmpndel.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/graph.o src/lib66/parser.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/rc_init.o src/lib66/rc_send.o src/lib66/resolve.o src/lib66/scandir_ok.o src/lib66/scandir_send_signal.o src/lib66/set_livedir.o src/lib66/set_livescan.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/ssexec_dbctl.o src/lib66/ssexec_enable.o src/lib66/ssexec_disable.o src/lib66/ssexec_free.o src/lib66/ssexec_help.o src/lib66/ssexec_init.o src/lib66/ssexec_main.o src/lib66/ssexec_start.o src/lib66/ssexec_stop.o src/lib66/ssexec_svctl.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_send.o src/lib66/svc_switch_to.o src/lib66/tree_cmd_state.o src/lib66/tree_copy.o src/lib66/tree_copy_tmp.o src/lib66/tree_find_current.o src/lib66/tree_get_permissions.o src/lib66/tree_sethome.o src/lib66/tree_setname.o src/lib66/tree_switch_current.o +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_cmd_master.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_get_permissions.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/dir_cmpndel.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/graph.o src/lib66/parser.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/rc_init.o src/lib66/rc_send.o src/lib66/resolve.o src/lib66/scandir_ok.o src/lib66/scandir_send_signal.o src/lib66/set_livedir.o src/lib66/set_livescan.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/ssexec_dbctl.o src/lib66/ssexec_enable.o src/lib66/ssexec_disable.o src/lib66/ssexec_free.o src/lib66/ssexec_help.o src/lib66/ssexec_init.o src/lib66/ssexec_main.o src/lib66/ssexec_start.o src/lib66/ssexec_stop.o src/lib66/ssexec_svctl.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_send.o src/lib66/svc_switch_to.o src/lib66/svc_unsupervise.o src/lib66/tree_cmd_state.o src/lib66/tree_copy.o src/lib66/tree_copy_tmp.o src/lib66/tree_find_current.o src/lib66/tree_get_permissions.o src/lib66/tree_sethome.o src/lib66/tree_setname.o src/lib66/tree_switch_current.o else -lib66.a.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_send.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo +lib66.a.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_send.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo endif lib66.so.xyzzy: EXTRA_LIBS := -loblibs -lskarnet -lib66.so.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_send.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo +lib66.so.xyzzy: src/lib66/backup_cmd_switcher.lo src/lib66/backup_make_new.lo src/lib66/backup_realpath_sym.lo src/lib66/db_cmd_master.lo src/lib66/db_compile.lo src/lib66/db_find_compiled_state.lo src/lib66/db_get_permissions.lo src/lib66/db_ok.lo src/lib66/db_switch_to.lo src/lib66/db_update.lo src/lib66/dir_cmpndel.lo src/lib66/get_enum.lo src/lib66/get_uidgid.lo src/lib66/get_userhome.lo src/lib66/graph.lo src/lib66/parser.lo src/lib66/parser_utils.lo src/lib66/parser_write.lo src/lib66/rc_init.lo src/lib66/rc_send.lo src/lib66/resolve.lo src/lib66/scandir_ok.lo src/lib66/scandir_send_signal.lo src/lib66/set_livedir.lo src/lib66/set_livescan.lo src/lib66/set_livetree.lo src/lib66/set_ownerhome.lo src/lib66/set_ownersysdir.lo src/lib66/ssexec_dbctl.lo src/lib66/ssexec_enable.lo src/lib66/ssexec_disable.lo src/lib66/ssexec_free.lo src/lib66/ssexec_help.lo src/lib66/ssexec_init.lo src/lib66/ssexec_main.lo src/lib66/ssexec_start.lo src/lib66/ssexec_stop.lo src/lib66/ssexec_svctl.lo src/lib66/sv_alltype_zero.lo src/lib66/svc_init.lo src/lib66/svc_init_pipe.lo src/lib66/svc_send.lo src/lib66/svc_switch_to.lo src/lib66/svc_unsupervise.lo src/lib66/tree_cmd_state.lo src/lib66/tree_copy.lo src/lib66/tree_copy_tmp.lo src/lib66/tree_find_current.lo src/lib66/tree_get_permissions.lo src/lib66/tree_sethome.lo src/lib66/tree_setname.lo src/lib66/tree_switch_current.lo diff --git a/src/66/66-all.c b/src/66/66-all.c index e1c468e477d28e02b20a102d52e9fe21a00b1783..821e1514fa6503b8de7694d38b0ecc5972a112c1 100644 --- a/src/66/66-all.c +++ b/src/66/66-all.c @@ -243,7 +243,7 @@ int main(int argc, char const *const *argv,char const *const *envp) state[statelen] = 0 ; r = scan_mode(state,S_IFREG) ; - if (r < 0) { errno = EEXIST ; return -1 ; } + if (r < 0) strerr_dief2x(111,"conflict format for: ",state) ; if (!r) strerr_diefu2sys(111,"find: ",state) ; statesize = file_get_size(state) ; @@ -334,10 +334,9 @@ int main(int argc, char const *const *argv,char const *const *envp) strerr_diefu2x(111,"initiate services of tree: ",treename) ; VERBO3 strerr_warnt2x("reload scandir: ",scandir.s) ; - r = s6_svc_writectl(scandir.s, S6_SVSCAN_CTLDIR, "an", 2) ; - if (r < 0) + if (scandir_send_signal(scandir.s,"an") <= 0) { - VERBO3 strerr_warnw3sys("something is wrong with the ",scandir.s, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; + VERBO3 strerr_warnwu2sys("reload scandir: ",scandir.s) ; return -1 ; } } diff --git a/src/66/66-info.c b/src/66/66-info.c index 901020d5900ab1de43b6d09f534b5940c7af41d8..77bd69fda4d9a8df9d917536eeb671a1e0e2e472 100644 --- a/src/66/66-info.c +++ b/src/66/66-info.c @@ -58,7 +58,7 @@ static uid_t owner ; #define TREE_USAGE "66-info -T [ -h ] [ -v verbosity ] [ -r ] [ -d depth ] tree " #define exit_tree_usage() exitusage(TREE_USAGE) -#define SV_USAGE "66-info -S [ -h ] [ -v verbosity ] [ -l live ] [ -p n lines ] [ -r ] [ -d depth ] service" +#define SV_USAGE "66-info -S [ -h ] [ -v verbosity ] [-t tree ] [ -l live ] [ -p n lines ] [ -r ] [ -d depth ] service" #define exit_sv_usage() exitusage(SV_USAGE) unsigned int REVERSE = 0 ; @@ -105,6 +105,7 @@ static inline void sv_help (void) "\n" "options :\n" " -h: print this help\n" +" -t: tree to use\n" " -l: live directory\n" " -p: print n last lines of the associated log file\n" " -r: reserve the dependencies graph\n" @@ -161,7 +162,7 @@ int print_status(ss_resolve_t *res,char const *treename, char const *const *envp if (r != 1) { if (buffer_putsflush(buffer_1,"not running\n") < 0) return 0 ; - return 0 ; + return 1 ; } char const *newargv[3] ; unsigned int m = 0 ; @@ -177,14 +178,9 @@ int print_status(ss_resolve_t *res,char const *treename, char const *const *envp if (wstat) strerr_diefu2x(111,"status for service: ",res->sa.s + res->name) ; } - else - { - if (buffer_putsflush(buffer_1,"nothing to display\n") < 0) return 0 ; - return 0 ; - } - + else if (buffer_putsflush(buffer_1,"nothing to display\n") < 0) return 0 ; + return 1 ; - } /** what = 0 -> only classic @@ -213,8 +209,7 @@ int graph_display(char const *tree,char const *treename,char const *svname,unsig VERBO3 strerr_warnwu2x("resolve source of graph for tree: ",treename) ; e = 0 ; goto err ; } - if (r < 0) - goto empty ; + if (r < 0) goto empty ; if (!graph_build(&g,&sagraph,&tokeep,dir)) { @@ -257,6 +252,8 @@ int tree_args(int argc, char const *const *argv) stralloc tree = STRALLOC_ZERO ; stralloc sacurrent = STRALLOC_ZERO ; stralloc currname = STRALLOC_ZERO ; + stralloc src = STRALLOC_ZERO ; + int todisplay = 0 ; { @@ -289,13 +286,11 @@ int tree_args(int argc, char const *const *argv) if (!tree_setname(&currname,sacurrent.s)) strerr_diefu1x(111,"set the tree name") ; } - size_t baselen = base.len ; - char src[baselen + SS_SYSTEM_LEN + 1] ; - memcpy(src,base.s,baselen) ; - memcpy(src + baselen,SS_SYSTEM, SS_SYSTEM_LEN) ; - src[baselen + SS_SYSTEM_LEN] = 0 ; + if (!stralloc_copy(&src,&base)) goto err ; + if (!stralloc_cats(&src,"/" SS_SYSTEM)) goto err ; + if (!stralloc_0(&src)) goto err ; - if (!dir_get(&gatree, src,SS_BACKUP + 1, S_IFDIR)) goto err ; + if (!dir_get(&gatree, src.s,SS_BACKUP + 1, S_IFDIR)) goto err ; if (genalloc_len(stralist,&gatree)) { for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) @@ -336,7 +331,9 @@ int tree_args(int argc, char const *const *argv) if (buffer_putflush(buffer_1,"\n",1) < 0) goto err ; } + stralloc_free(&live) ; stralloc_free(&tree) ; + stralloc_free(&src) ; stralloc_free(&sacurrent) ; stralloc_free(&currname) ; genalloc_deepfree(stralist,&gatree,stra_free) ; @@ -344,7 +341,9 @@ int tree_args(int argc, char const *const *argv) return 1 ; err: + stralloc_free(&live) ; stralloc_free(&tree) ; + stralloc_free(&src) ; stralloc_free(&sacurrent) ; stralloc_free(&currname) ; genalloc_deepfree(stralist,&gatree,stra_free) ; @@ -356,14 +355,16 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) int r, found ; unsigned int nlog = 0 ; + stralloc treename = STRALLOC_ZERO ; stralloc tree = STRALLOC_ZERO ; genalloc gawhat = GENALLOC_ZERO ;//stralist genalloc gatree = GENALLOC_ZERO ; + stralloc src = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; char const *svname = 0 ; - char const *treename = 0 ; + char const *tname = 0 ; r = found = 0 ; @@ -372,7 +373,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:p:rd:", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:p:rd:t:", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -385,6 +386,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) case 'p' : if (!uint0_scan(l.arg, &nlog)) exit_sv_usage() ; break ; case 'r' : REVERSE = 1 ; break ; case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) exit_sv_usage(); break ; + case 't' : tname = l.arg ; break ; default : exit_sv_usage() ; } } @@ -398,69 +400,87 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (!r) retstralloc(0,"sv_args") ; if (r < 0 ) strerr_dief3x(111,"live: ",live.s," must be an absolute path") ; - size_t baselen = base.len ; size_t newlen ; - char src[MAXSIZE] ; - memcpy(src,base.s,baselen) ; - memcpy(src + baselen,SS_SYSTEM, SS_SYSTEM_LEN) ; - baselen = baselen + SS_SYSTEM_LEN ; - src[baselen] = 0 ; + if (!stralloc_copy(&src,&live)) goto err ; + if (!stralloc_cats(&src,"state/")) goto err ; + newlen = src.len ; + + if (!tname) + { - if (!dir_get(&gatree, src,SS_BACKUP + 1, S_IFDIR)) - strerr_diefu2x(111,"get tree from directory: ",src) ; + if (!stralloc_0(&src)) goto err ; - if (genalloc_len(stralist,&gatree)) - { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) + if (!dir_get(&gatree, src.s,"", S_IFDIR)) + strerr_diefu2x(111,"get tree from directory: ",src.s) ; + + if (genalloc_len(stralist,&gatree)) { - treename = gaistr(&gatree,i) ; - size_t treelen = gaistrlen(&gatree,i) ; - src[baselen] = '/' ; - memcpy(src + baselen + 1,treename,treelen) ; - memcpy(src + baselen + 1 + treelen,SS_SVDIRS,SS_SVDIRS_LEN) ; - newlen = baselen + 1 + treelen + SS_SVDIRS_LEN ; - memcpy(src + baselen + 1 + treelen + SS_SVDIRS_LEN,SS_RESOLVE,SS_RESOLVE_LEN) ; - src[baselen + 1 + treelen + SS_SVDIRS_LEN + SS_RESOLVE_LEN] = 0 ; - if (dir_search(src,svname,S_IFREG)) + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) { - if(!stralloc_cats(&tree,treename)) retstralloc(0,"sv_args") ; - if(!stralloc_0(&tree)) retstralloc(0,"sv_args") ; - src[newlen] = 0 ; - found = 1 ; - break ; + src.len = newlen ; + char *name = gaistr(&gatree,i) ; + if (!stralloc_cats(&src,name)) goto err ; + if (!stralloc_cats(&src,SS_RESOLVE)) goto err ; + if (!stralloc_0(&src)) goto err ; + if (dir_search(src.s,svname,S_IFREG)) + { + if(!stralloc_cats(&treename,name)) retstralloc(0,"sv_args") ; + if(!stralloc_0(&treename)) retstralloc(0,"sv_args") ; + found++ ; + } } } + else + { + if (!bprintf(buffer_1," %s ","nothing to display")) goto err ; + if (buffer_putflush(buffer_1,"\n",1) < 0) goto err ; + goto end ; + } } - else + else { - if (!bprintf(buffer_1," %s ","nothing to display")) goto err ; - if (buffer_putflush(buffer_1,"\n",1) < 0) goto err ; - return 1 ; + if(!stralloc_cats(&treename,tname)) retstralloc(0,"sv_args") ; + if(!stralloc_0(&treename)) retstralloc(0,"sv_args") ; + if (!stralloc_cats(&src,treename.s)) goto err ; + if (!stralloc_cats(&src,SS_RESOLVE)) goto err ; + if (!stralloc_0(&src)) goto err ; + if (dir_search(src.s,svname,S_IFREG)) found++; } + if (!found) { strerr_warnw2x("unknow service: ",svname) ; goto err ; } + else if (found > 1) + { + strerr_warnw2x(svname," is set on divers tree -- please use -t options") ; + goto err ; + } + if (!stralloc_cats(&tree,treename.s)) goto err ; r = tree_sethome(&tree,base.s,MYUID) ; - if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; + if (r<=0) strerr_diefu2sys(111,"find tree: ", tree.s) ; if (!bprintf(buffer_1,"%s%s%s\n","[",svname,"]")) goto err ; - if (!bprintf(buffer_1,"%s%s\n","on tree : ",treename)) goto err ; + if (!bprintf(buffer_1,"%s%s\n","on tree : ",treename.s)) goto err ; - if (!ss_resolve_read(&res,src,svname)) strerr_diefu2sys(111,"read resolve file of: ",svname) ; + src.len = newlen ; + if (!stralloc_cats(&src,treename.s)) goto err ; + if (!stralloc_0(&src)) goto err ; + if (!ss_resolve_read(&res,src.s,svname)) strerr_diefu2sys(111,"read resolve file of: ",svname) ; /** status */ if (buffer_putsflush(buffer_1,"status : ") < 0) goto err ; - print_status(&res,treename,envp) ; - + if (!print_status(&res,treename.s,envp)) goto err ; + /** print the type */ if (!bprintf(buffer_1,"%s %s\n","type :",get_keybyid(res.type))) goto err ; if (!bprintf(buffer_1,"%s %s\n","description :",res.sa.s + res.description)) goto err ; if (!bprintf(buffer_1,"%s%s\n","source : ",res.sa.s + res.src)) goto err ; if (!bprintf(buffer_1,"%s%s\n","run at : ",res.sa.s + res.runat)) goto err ; + if (res.exec_run) { if (!bprintf(buffer_1,"%s%s\n","start script :",res.sa.s + res.exec_run)) goto err ; @@ -471,18 +491,16 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) } /** dependencies */ -// if (res.type > CLASSIC) + if (res.ndeps) { if (res.type == BUNDLE) { if (!bprintf(buffer_1,"%s%i%s\n","[contents:",res.ndeps,"]")) goto err ; } else if (!bprintf(buffer_1,"%s%i%s\n","[dependencies:",res.ndeps,"]")) goto err ; + + if (!graph_display(tree.s,treename.s,svname,2)) strerr_diefu2x(111,"display graph of tree: ", treename.s) ; - if (res.ndeps) - { - if (!graph_display(tree.s,treename,svname,2)) strerr_diefu2x(111,"display graph of tree: ", treename) ; - } } /** logger */ @@ -497,20 +515,30 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) { stralloc log = STRALLOC_ZERO ; /** the file current may not exist if the service was never started*/ - if (!dir_search(res.sa.s + res.dstlog,"current",S_IFREG)){ if (!bprintf(buffer_1,"%s \n","log file is empty")) goto err ; } + if (!dir_search(res.sa.s + res.dstlog,"current",S_IFREG)){ if (!bprintf(buffer_1,"%s \n","unable to find the log file")) goto err ; } else { if (!file_readputsa(&log,res.sa.s + res.dstlog,"current")) retstralloc(0,"sv_args") ; - if (!bprintf(buffer_1,"\n")) goto err ; - if (!bprintf(buffer_1,"%s \n",print_nlog(log.s,nlog))) goto err ; - stralloc_free(&log) ; + if (!log.len) + { + if (!bprintf(buffer_1,"\n")) goto err ; + if (!bprintf(buffer_1,"log file is empty \n")) goto err ; + } + else + { + if (!bprintf(buffer_1,"\n")) goto err ; + if (!bprintf(buffer_1,"%s \n",print_nlog(log.s,nlog))) goto err ; + } } + stralloc_free(&log) ; } } } if (buffer_putsflush(buffer_1,"") < 0) goto err ; + end: stralloc_free(&tree) ; + stralloc_free(&treename) ; genalloc_deepfree(stralist,&gawhat,stra_free) ; genalloc_deepfree(stralist,&gatree,stra_free) ; ss_resolve_free(&res) ; @@ -518,11 +546,13 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) err: stralloc_free(&tree) ; + stralloc_free(&treename) ; genalloc_deepfree(stralist,&gawhat,stra_free) ; genalloc_deepfree(stralist,&gatree,stra_free) ; ss_resolve_free(&res) ; return 0 ; } + int main(int argc, char const *const *argv, char const *const *envp) { int what ; diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index 34a57fed1a50f02a175f170368dbf27d88330c2a..f7322190b5b2159bae9102f1dc6cae3bb4899060 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -695,6 +695,7 @@ int sanitize_live(char const *live, char const *scandir, char const *scanname, u char basescan[scandirlen + 1 + scannamelen + 1] ; char tree[livelen + 4 + 1] ; char baselog[livelen + 3 + 1] ; + char resolve[livelen + SS_STATE_LEN + 1 + 1] ; /** run/66 */ r = scan_mode(live,S_IFDIR) ; if (r < 0) { errno = EEXIST ; return 0 ; } @@ -799,6 +800,35 @@ int sanitize_live(char const *live, char const *scandir, char const *scanname, u return 0 ; } } + /** /run/66/state*/ + memcpy(resolve,live,livelen - 1) ; + memcpy(resolve + livelen - 1, SS_STATE, SS_STATE_LEN) ; + resolve[(livelen - 1) + SS_STATE_LEN] = '/' ; + resolve[(livelen - 1) + SS_STATE_LEN + 1] = 0 ; + r = scan_mode(resolve,S_IFDIR) ; + if (r < 0) { errno = EEXIST ; return 0 ; } + if (!r) + { + VERBO3 strerr_warnt2x("create directory: ",resolve) ; + r = dir_create(resolve,0755) ; + if (!r) + { + VERBO3 strerr_warnwu2sys("create directory: ",resolve) ; + return 0 ; + } + VERBO3 strerr_warnt2x("chmod 1777: ",resolve) ; + if (chmod(resolve,S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) < 0) + { + VERBO3 strerr_warnwu2sys("chmod: ",resolve) ; + return 0 ; + } + VERBO3 strerr_warnt6x("chown directory: ",resolve," to: ",OWNERSTR,":",GIDSTR) ; + if (chown(resolve,OWNER,GIDOWNER) < 0) + { + VERBO3 strerr_warnwu2sys("chown: ",resolve) ; + return 0 ; + } + } return 1 ; } @@ -847,7 +877,7 @@ int main(int argc, char const *const *argv, char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, "hv:bl:t:3:2:e:crus:", &l) ; + int opt = getopt_args(argc,argv, ">hv:bl:t:3:2:e:crus:", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -878,7 +908,7 @@ int main(int argc, char const *const *argv, char const *const *envp) argc -= l.ind ; argv += l.ind ; } - if (argc > 1) exitusage(USAGE) ; + if (argc > 1 || (!create && !remove && !up && !down)) exitusage(USAGE) ; if (!argc) OWNER = MYUID ; else diff --git a/src/66/66-tree.c b/src/66/66-tree.c index e2d34b811aa85ff5763dcd2fe9710f97d1712cfd..6088264c377a3f23c0ec205dd22791122fc45853 100644 --- a/src/66/66-tree.c +++ b/src/66/66-tree.c @@ -34,11 +34,16 @@ #include <66/db.h> #include <66/enum.h> -//#include <stdio.h> +#include <s6/s6-supervise.h> +#include <s6-rc/s6rc-servicedir.h> +#include <s6-rc/s6rc-constants.h> -#define USAGE "66-tree [ -h ] [ -v <em>verbosity</em> ] [ -n|R ] [ -a|d ] [ -c ] [ -E|D ] [ -C clone ] tree" +#include <stdio.h> + +#define USAGE "66-tree [ -h ] [ -v verbosity ] [ -n|R ] [ -a|d ] [ -c ] [ -E|D ] [ -U ] [ -C clone ] tree" unsigned int VERBOSITY = 1 ; +static stralloc reslive = STRALLOC_ZERO ; static inline void info_help (void) { @@ -56,6 +61,7 @@ static inline void info_help (void) " -D: disable the tree\n" " -R: remove the tree\n" " -C: clone the tree\n" +" -U: unsupervise the tree\n" ; if (buffer_putsflush(buffer_1, help) < 0) @@ -194,8 +200,6 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t own return 1 ; } - - int create_tree(char const *tree,char const *treename) { size_t newlen = 0 ; @@ -253,7 +257,7 @@ int create_tree(char const *tree,char const *treename) } VERBO3 strerr_warnt1x("write resolve file of: Master") ; - if (!ss_resolve_write(&res,dst,"Master")) + if (!ss_resolve_write(&res,dst,"Master",SS_SIMPLE)) { VERBO3 strerr_warnwu1sys("write resolve file of: Master") ; ss_resolve_free(&res) ; @@ -414,10 +418,7 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) VERBO3 strerr_warnwu4sys("create file : ",pack," at ",tmp) ; return 0 ; } - else - { - VERBO3 strerr_warnt4x("user: ",pack," is allowed for tree: ",tree) ; - } + VERBO3 strerr_warnt4x("user: ",pack," is allowed for tree: ",tree) ; } return 1 ; } @@ -442,10 +443,180 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) return 1 ; } +int tree_unsupervise(char const *tree, char const *treename,uid_t owner,char const *const *envp) +{ + int r, wstat, reload = 0 ; + pid_t pid ; + size_t treenamelen = strlen(treename) ; + + genalloc gasv = GENALLOC_ZERO ; //stralist + stralloc dtree = STRALLOC_ZERO ; + stralloc livetree = STRALLOC_ZERO ; + stralloc realsym = STRALLOC_ZERO ; + stralloc scandir = STRALLOC_ZERO ; + ss_resolve_t res = RESOLVE_ZERO ; + + char prefix[treenamelen + 2] ; + memcpy(prefix,treename,treenamelen) ; + memcpy(prefix + treenamelen,"-",1) ; + prefix[treenamelen + 1] = 0 ; + + if (!stralloc_cats(&dtree,tree)) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_cats(&dtree,SS_SVDIRS)) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_0(&dtree)) retstralloc(111,"tree_unsupervise") ; + if (!ss_resolve_read(&res,dtree.s,"Master")) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + /** if Master is empty we don't need to bring down any service */ + if (res.ndeps) + { + + if (!stralloc_cats(&scandir,res.sa.s + res.live)) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_cats(&reslive,res.sa.s + res.resolve)) retstralloc(111,"tree_unsupervise") ; + + if (!stralloc_cats(&livetree,res.sa.s + res.live)) retstralloc(111,"tree_unsupervise") ; + r = set_livetree(&livetree,owner) ; + if (!r) retstralloc(111,"tree_unsupervise") ; + /** in use? bring down all db service */ + if (db_find_compiled_state(livetree.s,treename) >=0) + { + reload = 1 ; + char const *newargv[9] ; + unsigned int m = 0 ; + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + + newargv[m++] = SS_BINPREFIX "66-dbctl" ; + newargv[m++] = "-v" ; + newargv[m++] = fmt ; + newargv[m++] = "-l" ; + newargv[m++] = res.sa.s + res.live ; + newargv[m++] = "-t" ; + newargv[m++] = treename ; + newargv[m++] = "-d" ; + newargv[m++] = 0 ; + + pid = child_spawn0(newargv[0],newargv,envp) ; + if (waitpid_nointr(pid,&wstat, 0) < 0) + { + VERBO3 strerr_warnwu2sys("wait for ",newargv[0]) ; + return 0 ; + } + if (wstat) strerr_diefu2sys(111,"stop db service of tree: ",treename) ; + /** unsupervise service into the scandir */ + if (!clean_val(&gasv,res.sa.s + res.deps)) strerr_diefu2sys(111,"clean deps of inner bundle of tree: ", treename) ; + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gasv) ; i++) + { + ss_resolve_t dres = RESOLVE_ZERO ; + ss_resolve_init(&dres) ; + if (!ss_resolve_read(&dres,res.sa.s + res.resolve,gaistr(&gasv,i))) strerr_diefu2sys(111,"read resolve file of: ",gaistr(&gasv,i)) ; + ss_resolve_setflag(&dres,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&dres,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&dres,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&dres,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; + if (!ss_resolve_write(&dres,res.sa.s + res.resolve,gaistr(&gasv,i),SS_DOUBLE)) strerr_diefu2sys(111,"write resolve file of: ", gaistr(&gasv,i)) ; + ss_resolve_free(&dres) ; + } + if (!stra_add(&gasv,S6RC_ONESHOT_RUNNER)) strerr_diefu3sys(111,"add ",S6RC_ONESHOT_RUNNER," as service to unsupervise") ; + if (!stra_add(&gasv,S6RC_FDHOLDER)) strerr_diefu3sys(111,"add ",S6RC_FDHOLDER," as service to unsupervise") ; + + if (!stralloc_cats(&livetree,"/")) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_cats(&livetree,treename)) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_0(&livetree)) retstralloc(111,"tree_unsupervise") ; + + for (unsigned int i=0 ; i < genalloc_len(stralist,&gasv) ;i++) + s6rc_servicedir_unsupervise(livetree.s,prefix,gaistr(&gasv,i),0) ; + + r = sarealpath(&realsym,livetree.s) ; + if (r < 0 ) strerr_diefu2sys(111,"find realpath of: ",livetree.s) ; + if (!stralloc_0(&realsym)) retstralloc(111,"tree_unsupervise") ; + if (rm_rf(realsym.s) < 0) strerr_diefu2sys(111,"remove ", realsym.s) ; + if (rm_rf(livetree.s) < 0) strerr_diefu2sys(111,"remove ", livetree.s) ; + } + } + genalloc_deepfree(stralist,&gasv,stra_free) ; + if (!graph_type_src(&gasv,dtree.s,0)) strerr_diefu2sys(111,"get svc service of tree: ",treename) ; + if (genalloc_len(stralist,&gasv)) + { + genalloc tostop = GENALLOC_ZERO ; + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gasv) ; i++) + { + ss_resolve_init(&res) ; + if (!ss_resolve_read(&res,dtree.s,gaistr(&gasv,i))) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + if (res.run) + { + if (!stra_add(&tostop,gaistr(&gasv,i))) strerr_diefu3sys(111,"add ",gaistr(&gasv,i)," as service to stop") ; + ss_resolve_setflag(&res,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&res,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; + if (!ss_resolve_write(&res,res.sa.s + res.resolve,gaistr(&gasv,i),SS_DOUBLE)) strerr_diefu2sys(111,"set write resolve file of: ", gaistr(&gasv,i)) ; + } + } + if (genalloc_len(stralist,&tostop)) + { + reload = 1 ; + /** if we pass through rc works, set len to 0 + * to avoid double path*/ + scandir.len = 0 ; + if (!stralloc_cats(&scandir,res.sa.s + res.live)) retstralloc(111,"tree_unsupervise") ; + reslive.len = 0 ; + if (!stralloc_cats(&reslive,res.sa.s + res.resolve)) retstralloc(111,"tree_unsupervise") ; + + char const *newargv[9 + genalloc_len(stralist,&tostop)] ; + unsigned int m = 0 ; + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; + + newargv[m++] = SS_BINPREFIX "66-svctl" ; + newargv[m++] = "-v" ; + newargv[m++] = fmt ; + newargv[m++] = "-l" ; + newargv[m++] = res.sa.s + res.live ; + newargv[m++] = "-t" ; + newargv[m++] = treename ; + newargv[m++] = "-D" ; + + for (unsigned int i=0 ; i < genalloc_len(stralist,&tostop) ; i++) + newargv[m++] = gaistr(&tostop,i) ; + + newargv[m++] = 0 ; + + pid = child_spawn0(newargv[0],newargv,envp) ; + if (waitpid_nointr(pid,&wstat, 0) < 0) + strerr_diefu2sys(111,"wait for ",newargv[0]) ; + + if (wstat) strerr_diefu2sys(111,"bring down db service of tree: ",treename) ; + + for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostop) ; i++) + { + res.sa.len = 0 ; + if (!ss_resolve_read(&res,dtree.s,gaistr(&tostop,i))) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + if (rm_rf(res.sa.s + res.runat) < 0) strerr_diefu2sys(111,"remove: ", res.sa.s + res.runat) ; + } + } + genalloc_deepfree(stralist,&tostop,stra_free) ; + } + if (reload) + { + if (!stralloc_0(&reslive)) retstralloc(111,"tree_unsupervise") ; + if (!stralloc_0(&scandir)) retstralloc(111,"tree_unsupervise") ; + if (!set_livescan(&scandir,owner)) strerr_diefu1sys(111,"set scandir") ; + if (scandir_send_signal(scandir.s,"an") <= 0) strerr_diefu2sys(111,"reload scandir: ",scandir.s) ; + } + if (reload) VERBO1 strerr_warni2x("Unsupervised successfully: ",treename) ; + genalloc_deepfree(stralist,&gasv,stra_free) ; + stralloc_free(&livetree) ; + stralloc_free(&dtree) ; + stralloc_free(&realsym) ; + stralloc_free(&scandir) ; + ss_resolve_free(&res) ; + + return 1 ; +} + int main(int argc, char const *const *argv,char const *const *envp) { - int r, current, create, allow, deny, enable, disable, remove, snap ; + int r, current, create, allow, deny, enable, disable, remove, snap, unsupervise ; uid_t owner ; @@ -454,14 +625,14 @@ int main(int argc, char const *const *argv,char const *const *envp) size_t duidn = 0 ; uid_t duids[256] ; - + char const *tree = NULL ; stralloc base = STRALLOC_ZERO ; stralloc dstree = STRALLOC_ZERO ; stralloc clone = STRALLOC_ZERO ; - current = create = allow = deny = enable = disable = remove = snap = 0 ; + current = create = allow = deny = enable = disable = remove = snap = unsupervise = 0 ; PROG = "66-tree" ; { @@ -470,7 +641,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, "hv:na:d:cEDRC:", &l) ; + int opt = getopt_args(argc,argv, "hv:na:d:cEDRC:U", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -489,11 +660,12 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'c' : current = 1 ; break ; case 'E' : enable = 1 ; if (disable) exitusage(USAGE) ; break ; case 'D' : disable = 1 ; if (enable) exitusage (USAGE) ; break ; - case 'R' : remove = 1 ; if (create) exitusage(USAGE) ; break ; + case 'R' : remove = 1 ; unsupervise = 1 ; if (create) exitusage(USAGE) ; break ; case 'C' : if (!stralloc_cats(&clone,l.arg)) retstralloc(111,"main") ; if (!stralloc_0(&clone)) retstralloc(111,"main") ; snap = 1 ; break ; + case 'U' : unsupervise = 1 ; if (create) exitusage(USAGE) ; break ; default : exitusage(USAGE) ; } } @@ -504,7 +676,7 @@ int main(int argc, char const *const *argv,char const *const *envp) tree = argv[0] ; owner = MYUID ; - + if (!set_ownersysdir(&base, owner)) strerr_diefu1sys(111, "set owner directory") ; VERBO2 strerr_warni3x("sanitize ",tree," ..." ) ; @@ -547,6 +719,7 @@ int main(int argc, char const *const *argv,char const *const *envp) } r = 1 ; create = 0 ; + VERBO1 strerr_warni2x("Created successfully tree: ",tree) ; } if ((!r && !create) || (!r && enable)) strerr_diefu2x(111,"find tree: ",dstree.s) ; @@ -558,6 +731,7 @@ int main(int argc, char const *const *argv,char const *const *envp) r = tree_cmd_state(VERBOSITY,"-a",tree) ; if (r != 1) strerr_diefu6x(111,"add: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + VERBO1 strerr_warni2x("Enabled successfully tree: ",tree) ; } if (disable) @@ -565,6 +739,7 @@ int main(int argc, char const *const *argv,char const *const *envp) VERBO2 strerr_warni3x("disable ",dstree.s," ..." ) ; r = tree_cmd_state(VERBOSITY,"-d",tree) ; if (r != 1) strerr_diefu6x(111,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + VERBO1 strerr_warni2x("Disabled successfully tree: ",tree) ; } if (auidn) @@ -581,12 +756,14 @@ int main(int argc, char const *const *argv,char const *const *envp) { VERBO2 strerr_warni3x("make ",dstree.s," as default ..." ) ; if (!tree_switch_current(base.s,tree)) strerr_diefu3sys(111,"set ",dstree.s," as default") ; + VERBO1 strerr_warni3x("Set successfully ",tree," as default") ; } + if (unsupervise) tree_unsupervise(dstree.s,tree,owner,envp) ; if (remove) { - VERBO2 strerr_warni3x("remove ",dstree.s," ..." ) ; - if (rm_rf(dstree.s) < 0) strerr_diefu2sys(111,"remove ", dstree.s) ; + VERBO2 strerr_warni3x("delete ",dstree.s," ..." ) ; + if (rm_rf(dstree.s) < 0) strerr_diefu2sys(111,"delete ", dstree.s) ; size_t treelen = strlen(tree) ; size_t baselen = base.len ; @@ -601,16 +778,23 @@ int main(int argc, char const *const *argv,char const *const *envp) r = scan_mode(treetmp,S_IFDIR) ; if (r || (r < 0)) { - VERBO2 strerr_warni3x("remove backup of tree ",treetmp," ...") ; + VERBO2 strerr_warni3x("delete backup of tree ",treetmp," ...") ; if (rm_rf(treetmp) < 0) { - VERBO3 strerr_warnwu2sys("remove: ",treetmp) ; + VERBO3 strerr_warnwu2sys("delete: ",treetmp) ; return 0 ; } } VERBO2 strerr_warni6x("disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; r = tree_cmd_state(VERBOSITY,"-d",tree) ; - if (r != 1) strerr_diefu6x(111,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + if (r != 1) strerr_diefu6x(111,"delete: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + /** remove /run/66/state/treename directory */ + if (reslive.len) + { + VERBO2 strerr_warni3x("delete ",reslive.s," ..." ) ; + if (rm_rf(reslive.s) < 0) strerr_diefu2sys(111,"delete ",reslive.s) ; + } + VERBO1 strerr_warni2x("Deleted successfully: ",tree) ; } if (snap) @@ -627,11 +811,13 @@ int main(int argc, char const *const *argv,char const *const *envp) if ((r < 0) || r) strerr_dief2x(111,dstree.s,": already exist") ; VERBO2 strerr_warni5x("clone ",dstree.s," as ",tmp," ..." ) ; if (!hiercopy(tmp,dstree.s)) strerr_diefu4sys(111,"copy: ",dstree.s," at: ",clone.s) ; + VERBO1 strerr_warni4x("Cloned successfully: ",tree," to ",clone.s) ; } stralloc_free(&base) ; stralloc_free(&dstree) ; stralloc_free(&clone) ; + return 0 ; } diff --git a/src/66/deps-exe/66-dbctl b/src/66/deps-exe/66-dbctl index 84d5b06473e39727af0c84dab4810b079978d7cc..3357e4d4b41bd9e899dcaacc8591b13abec3b5b8 100644 --- a/src/66/deps-exe/66-dbctl +++ b/src/66/deps-exe/66-dbctl @@ -3,4 +3,4 @@ ${LIB66} -ls6 -lskarnet -ls6rc -${LIBS6RC} + diff --git a/src/66/deps-exe/66-tree b/src/66/deps-exe/66-tree index 9c58365fcec451152a7b10b51a36af3a3612a3fa..b0796a1a0880b8255763119d1af9603f9b94198b 100644 --- a/src/66/deps-exe/66-tree +++ b/src/66/deps-exe/66-tree @@ -1,3 +1,6 @@ ${LIB66} -loblibs +-ls6rc +-ls6 -lskarnet + diff --git a/src/include/66/db.h b/src/include/66/db.h index cf903eae366eec2d65a8d384526633d0f17d80fc..cc80a91d63768ecf65306ff511a944c913b292f0 100644 --- a/src/include/66/db.h +++ b/src/include/66/db.h @@ -25,7 +25,7 @@ extern int db_update_master(int argc, char const *const *argv) ; extern int db_bundle_modif(genalloc *bundle,unsigned int verbosity, char const *src, unsigned int action) ; extern int db_bundle_contents(graph_t *g, char const *name, char const *src, unsigned int verbosity, unsigned int action) ; extern int db_write_contents(genalloc *ga, char const *bundle,char const *dir) ; -extern int db_write_master(ssexec_t *info, genalloc *ga, char const *dir) ; +extern int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both) ; extern int db_compile(char const *workdir, char const *tree, char const *treename,char const *const *envp) ; diff --git a/src/include/66/graph.h b/src/include/66/graph.h index c2431ea6b16679815d235af7d25179fe0bceca53..626a0b96ea23437c574fc989dff400a7e5c00fe5 100644 --- a/src/include/66/graph.h +++ b/src/include/66/graph.h @@ -93,8 +93,6 @@ extern int graph_type_src(genalloc *ga,char const *tree,unsigned int what) ; extern int graph_build(graph_t *g, stralloc *sagraph, genalloc *tokeep,char const *tree) ; -extern int graph_rdepends(genalloc *ga,graph_t *g, char const *name, char const *src) ; - extern int graph_master(genalloc *ga, graph_t *g) ; extern int graph_sort(graph_t *g) ; diff --git a/src/include/66/parser.h b/src/include/66/parser.h index 76179c24a8e9b19989ceb46f897857f4f48dfd2e..19c16a5eb706d655e26c668f36f64d7ddace9ee1 100644 --- a/src/include/66/parser.h +++ b/src/include/66/parser.h @@ -29,6 +29,8 @@ #include <skalibs/types.h> #include <skalibs/avltree.h> +#include <66/ssexec.h> + extern stralloc keep ; extern stralloc deps ; extern stralloc saenv ; @@ -315,7 +317,7 @@ extern int keep_runfinish(sv_exec *exec,keynocheck *nocheck) ; extern int keep_logger(sv_execlog *log,keynocheck *nocheck) ; -extern int write_services(sv_alltype *sv, char const *workdir, unsigned int force) ; +extern int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force) ; extern int write_classic(sv_alltype *sv, char const *dst, unsigned int force) ; diff --git a/src/include/66/rc.h b/src/include/66/rc.h index ff159e386ec2162b5dca7d652cea372fdb62836d..993f0d231103c48574eea4d17c2c8ee5d3ec5635 100644 --- a/src/include/66/rc.h +++ b/src/include/66/rc.h @@ -19,7 +19,8 @@ #include <skalibs/genalloc.h> -extern int rc_init(ssexec_t *info, char const *const *envp) ; +extern int rc_init(ssexec_t *info, genalloc *ga, char const *const *envp) ; extern int rc_send(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) ; +extern int rc_unsupervise(ssexec_t *info, genalloc *ga,char const *sig,char const *const *envp) ; #endif diff --git a/src/include/66/resolve.h b/src/include/66/resolve.h index fa2a8282df675f126d34fe2b7da9e0b365230f5d..6b5d8152ff404883a7fbe9acc6a2ae46b416f0da 100644 --- a/src/include/66/resolve.h +++ b/src/include/66/resolve.h @@ -29,6 +29,18 @@ #define SS_RESOLVE_SRC 1 #define SS_RESOLVE_BACK 2 #define SS_NOTYPE 0 +#define SS_SIMPLE 0 +#define SS_DOUBLE 1 + +#define SS_FLAGS_TRUE 1 +#define SS_FLAGS_FALSE 0 +#define SS_FLAGS_RELOAD 0 +#define SS_FLAGS_DISEN 1 +#define SS_FLAGS_INIT 2 +#define SS_FLAGS_UNSUPERVISE 3 +#define SS_FLAGS_DOWN 4 +#define SS_FLAGS_RUN 5 +#define SS_FLAGS_PID 6 typedef struct ss_resolve_s ss_resolve_t, *ss_resolve_t_ref ; struct ss_resolve_s @@ -43,10 +55,12 @@ struct ss_resolve_s uint32_t logassoc ; uint32_t dstlog ; uint32_t deps ; - uint32_t src ; + uint32_t src ; //etc/service + uint32_t live ; //run/66 uint32_t runat ; //livetree->longrun,scandir->svc - uint32_t tree ; + uint32_t tree ; //var/lib/66/system/tree uint32_t treename ; + uint32_t resolve ; //run/66/state/treename/ uint32_t exec_run ; uint32_t exec_finish ; @@ -60,7 +74,7 @@ struct ss_resolve_s uint32_t run ; uint64_t pid ; } ; -#define RESOLVE_ZERO { 0,STRALLOC_ZERO,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } +#define RESOLVE_ZERO { 0,STRALLOC_ZERO,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } extern ss_resolve_t const ss_resolve_zero ; @@ -71,12 +85,16 @@ extern int ss_resolve_add_uint32(stralloc *sa, uint32_t data) ; extern int ss_resolve_add_uint64(stralloc *sa, uint64_t data) ; extern uint32_t ss_resolve_add_string(ss_resolve_t *res,char const *data) ; extern int ss_resolve_pack(stralloc *sa,ss_resolve_t *res) ; -extern int ss_resolve_write(ss_resolve_t *res,char const *dst,char const *name) ; +extern int ss_resolve_write(ss_resolve_t *res,char const *dst,char const *name,int both) ; extern int ss_resolve_read(ss_resolve_t *res,char const *src,char const *name) ; extern void ss_resolve_free(ss_resolve_t *res) ; extern int ss_resolve_check(ssexec_t *info, char const *name,unsigned int where) ; -extern int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services,ssexec_t *info,char const *dst) ; +extern int ss_resolve_setnwrite(sv_alltype *services,ssexec_t *info,char const *dst) ; extern int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst) ; -extern int ss_resolve_rmfile(ss_resolve_t *res, char const *src,char const *name) ; -extern int ss_resolve_addlogger(ssexec_t *info,genalloc *ga) ; +extern int ss_resolve_rmfile(ss_resolve_t *res, char const *src,char const *name,int both) ; +extern int ss_resolve_add_logger(genalloc *ga,ssexec_t *info) ; +extern int ss_resolve_cmp(genalloc *ga,char const *name) ; +extern void ss_resolve_setflag(ss_resolve_t *res,int flags,int flags_val) ; +extern int ss_resolve_add_deps(genalloc *tokeep,ss_resolve_t *res, ssexec_t *info) ; +extern int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res,ssexec_t *info) ; #endif diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h index b0d4fb4865f78b0e5d907f88db90dbb496e86e84..3c45059f21369524a1e4be7b019444161e0a578a 100644 --- a/src/include/66/ssexec.h +++ b/src/include/66/ssexec.h @@ -29,7 +29,7 @@ struct ssexec_s stralloc treename ; int treeallow ; //1 yes , 0 no uid_t owner ; - unsigned int timeout ; + uint32_t timeout ; char const *prog ; char const *help ; char const *usage ; diff --git a/src/include/66/svc.h b/src/include/66/svc.h index 9419b17b935937982145305348f6de3ce04d8804..1952762bf4ac48ec0fec2a6b52ab0ac62de99dba 100644 --- a/src/include/66/svc.h +++ b/src/include/66/svc.h @@ -23,31 +23,6 @@ #include <66/resolve.h> #include <66/ssexec.h> -typedef struct svstat_s svstat_t, *svstat_t_ref ; -struct svstat_s -{ - int type ; - char const *name ; - size_t namelen ; - int down ; - int reload ; - int init ; - int unsupervise ; - int remove ; -} ; - -#define SVSTAT_ZERO \ -{ \ - .type = 0, \ - .name = 0, \ - .namelen = 0, \ - .down = 0, \ - .init = 0, \ - .reload = 0, \ - .unsupervise = 0, \ - .remove = 0 \ -} - typedef struct ss_resolve_sig_s ss_resolve_sig_t, *ss_resovle_sig_t_ref ; struct ss_resolve_sig_s { @@ -59,6 +34,7 @@ struct ss_resolve_sig_s char *sigtosend ; int sig ; int state ; + pid_t pid ; } ; #define RESOLVE_SIG_ZERO \ @@ -70,7 +46,8 @@ struct ss_resolve_sig_s .ids = 0, \ .sigtosend = 0, \ .sig = 0, \ - .state = -1 \ + .state = -1, \ + .pid = 0 \ } typedef enum state_e state_t, *state_t_ref ; @@ -101,6 +78,7 @@ enum sigactions_e extern int svc_switch_to(ssexec_t *info,unsigned int where) ; extern int svc_init(ssexec_t *info,char const *src, genalloc *ga) ; extern int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv) ; -extern int svc_shutnremove(ssexec_t *info, genalloc *ga,char const *sig, char const *const *envp) ; extern int svc_send(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) ; +extern int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) ; + #endif diff --git a/src/lib66/backup_realpath_sym.c b/src/lib66/backup_realpath_sym.c index f9d5bb5f3546f875226101635fd567fa0ad01280..2eec30946c53742b9ac2138fa0298f93edcc1777 100644 --- a/src/lib66/backup_realpath_sym.c +++ b/src/lib66/backup_realpath_sym.c @@ -54,7 +54,7 @@ int backup_realpath_sym(stralloc *sa, ssexec_t *info,unsigned int type) r = scan_mode(sym,S_IFDIR) ; if(r <= 0) return 0 ; - + sa->len = 0 ; r = sarealpath(sa,sym) ; if (r < 0 ) return 0 ; if (!stralloc_0(sa)) retstralloc(0,"find_current") ; diff --git a/src/lib66/db_cmd_master.c b/src/lib66/db_cmd_master.c index 5bd3330cb2ea082386a25657c8c4ecbd87a04c4e..fac29cdcd0e0678747864ac2cc69341953604556 100644 --- a/src/lib66/db_cmd_master.c +++ b/src/lib66/db_cmd_master.c @@ -351,7 +351,7 @@ int db_write_contents(genalloc *ga, char const *bundle,char const *dir) return 0 ; } -int db_write_master(ssexec_t *info, genalloc *ga, char const *dir) +int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both) { int r ; @@ -376,6 +376,14 @@ int db_write_master(ssexec_t *info, genalloc *ga, char const *dir) memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN, SS_MASTER, SS_MASTER_LEN) ; dst[dirlen + SS_DB_LEN + SS_SRC_LEN + SS_MASTER_LEN] = 0 ; + size_t livelen = info->live.len - 1 ; + char resolve[livelen + SS_STATE_LEN + 1 + info->treename.len + 1] ; + memcpy(resolve,info->live.s,livelen) ; + memcpy(resolve + livelen, SS_STATE,SS_STATE_LEN) ; + resolve[livelen + SS_STATE_LEN] = '/' ; + memcpy(resolve + livelen + SS_STATE_LEN + 1,info->treename.s,info->treename.len) ; + resolve[livelen + SS_STATE_LEN + 1 + info->treename.len] = 0 ; + for (unsigned int i = 0 ; i < genalloc_len(stralist,ga); i++) { @@ -385,7 +393,7 @@ int db_write_master(ssexec_t *info, genalloc *ga, char const *dir) if (!stralloc_cats(&inres,gaistr(ga,i))) goto err ; if (!stralloc_cats(&inres," ")) goto err ; } - inres.len--; + if (genalloc_len(stralist,ga)) inres.len--; if (!stralloc_0(&inres)) goto err ; r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ; @@ -400,16 +408,18 @@ int db_write_master(ssexec_t *info, genalloc *ga, char const *dir) res.description = ss_resolve_add_string(&res,"inner bundle - do not use it") ; res.treename = ss_resolve_add_string(&res,info->treename.s) ; res.tree = ss_resolve_add_string(&res,info->tree.s) ; + res.live = ss_resolve_add_string(&res,info->live.s) ; res.type = BUNDLE ; res.deps = ss_resolve_add_string(&res,inres.s) ; res.ndeps = genalloc_len(stralist,ga) ; - res.runat = ss_resolve_add_string(&res,runat) ; + res.runat = ss_resolve_add_string(&res,runat) ; + res.resolve = ss_resolve_add_string(&res,resolve) ; res.disen = 1 ; res.init = 0 ; res.unsupervise = 0 ; res.reload = 0 ; - if (!ss_resolve_write(&res,dir,"Master")) goto err ; + if (!ss_resolve_write(&res,dir,"Master",both)) goto err ; stralloc_free(&in) ; stralloc_free(&inres) ; diff --git a/src/lib66/db_switch_to.c b/src/lib66/db_switch_to.c index 144b99f31be88f6a7f03deee19834349f75a1d7c..af175dc7aff3fa2cd3414c142e74716a484ae637 100644 --- a/src/lib66/db_switch_to.c +++ b/src/lib66/db_switch_to.c @@ -47,7 +47,7 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu2sys("find origin of db service for: ",info->treename.s) ; + VERBO3 strerr_warnwu2sys("find realpath of symlink for db of tree: ",info->treename.s) ; goto err ; } // point to origin @@ -59,13 +59,13 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu2sys("make a backup of db service for: ",info->treename.s) ; goto err ; } - VERBO3 strerr_warnt3x("switch db service for tree: ",info->treename.s," to backup") ; + VERBO3 strerr_warnt3x("switch db symlink of tree: ",info->treename.s," to backup") ; memcpy(cmd + cmdlen," -s1",4) ; cmd[cmdlen + 4] = 0 ; r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch db service for: ",info->treename.s," to backup") ; + VERBO3 strerr_warnwu3sys("switch db symlink of tree: ",info->treename.s," to backup") ; goto err ; } if (db_ok(info->livetree.s, info->treename.s)) @@ -83,11 +83,13 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch db service for: ",info->treename.s," to source") ; + VERBO3 strerr_warnwu3sys("switch db symlink of tree: ",info->treename.s," to source") ; goto err ; } - db = stralloc_zero ; - if (!backup_realpath_sym(&db,info,LONGRUN)) + //db.len = 0 ; + /** in case of crash s6-rc-update copy again the old db to the + * original place, we need to update only the symlink */ + /*if (!backup_realpath_sym(&db,info,LONGRUN)) { VERBO3 strerr_warnwu2sys("find path of db service for: ",info->treename.s) ; goto err ; @@ -97,19 +99,19 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu3sys("switch: ",info->treename.s," to source") ; VERBO3 strerr_warnwu1sys("unable to rollback the db state, please make a bug report") ; goto err ; - } + }*/ } } } else if (r > 0 && !where) { - VERBO3 strerr_warnt3x("switch db service for tree: ",info->treename.s," to source") ; + VERBO3 strerr_warnt3x("switch db symlink of tree: ",info->treename.s," to source") ; memcpy(cmd + cmdlen," -s0",4) ; cmd[cmdlen + 4] = 0 ; r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch db service for: ",info->treename.s," to source") ; + VERBO3 strerr_warnwu3sys("switch db symlink of tree: ",info->treename.s," to source") ; goto err ; } @@ -132,8 +134,8 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu3sys("switch db service for: ",info->treename.s," to backup") ; goto err ; } - db = stralloc_zero ; - if (!backup_realpath_sym(&db,info,LONGRUN)) + //db.len = 0 ; + /*if (!backup_realpath_sym(&db,info,LONGRUN)) { VERBO3 strerr_warnwu2sys("find path of db: ",info->treename.s) ; goto err ; @@ -143,7 +145,7 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) VERBO3 strerr_warnwu3sys("switch: ",info->treename.s," to source") ; VERBO3 strerr_warnwu1sys("unable to rollback the db state, please make a bug report") ; goto err ; - } + }*/ } } VERBO3 strerr_warnt2x("make a backup of db service for: ",info->treename.s) ; diff --git a/src/lib66/deps-lib/66 b/src/lib66/deps-lib/66 index a9e31498366c35fcabfb9979ad8ce1ed4f59a230..71b81f2337fc5f186b39a82d01deaf50d7813607 100644 --- a/src/lib66/deps-lib/66 +++ b/src/lib66/deps-lib/66 @@ -41,6 +41,7 @@ svc_init.o svc_init_pipe.o svc_send.o svc_switch_to.o +svc_unsupervise.o tree_cmd_state.o tree_copy.o tree_copy_tmp.o diff --git a/src/lib66/graph.c b/src/lib66/graph.c index e80409d3bbc29dc9b88ca00b1939bb18d6a36039..4050b07491d72a559abfa0c9ec8eb2c112ab34b4 100644 --- a/src/lib66/graph.c +++ b/src/lib66/graph.c @@ -261,11 +261,6 @@ int graph_sort(graph_t *g) visit c[color] ; for (unsigned int i = 0 ; i < color; i++) c[i] = WHITE ; if (!len) return 0 ; -/* if (!stack_init(&g->stack,color)) - { - VERBO3 strerr_warnwu1x("iniate stack") ; - return 0; - }*/ for (unsigned int i = 0 ; i < len ; i++) if (c[i] == WHITE && dfs(g,i,&g->stack,c)) return -1 ; @@ -283,77 +278,6 @@ int graph_master(genalloc *ga, graph_t *g) return 1 ; } -int graph_rdepends(genalloc *ga,graph_t *g, char const *name, char const *src) -{ - unsigned int i,k ; - int r ; - - char *string = g->string ; - unsigned int type = graph_search(g,name) ; - /** bundle , we need to check every service set onto it*/ - if (genalloc_s(vertex_graph_t,&g->vertex)[type].type == BUNDLE) - { - - for (k = 0; k < genalloc_s(vertex_graph_t,&g->vertex)[type].ndeps; k++) - { - char *depname = g->string + genalloc_s(vertex_graph_t,&genalloc_s(vertex_graph_t,&g->vertex)[type].dps)[k].name ; - - if (!stra_cmp(ga,depname)) - { - if (!stra_add(ga,depname)) - { - VERBO3 strerr_warnwu3x("add: ",depname," as dependency to remove") ; - return 0 ; - } - } - r = graph_rdepends(ga,g,depname,src) ; - if (!r) - { - VERBO3 strerr_warnwu2x("find services depending on: ",name) ; - return 0 ; - } - if(r == 2) - { - VERBO3 strerr_warnt2x("any services don't depends on: ",name) ; - return 2 ; - } - } - } - - for (i = 0 ; i < g->nvertex ; i++) - { - - char *master = string + genalloc_s(vertex_graph_t,&g->vertex)[i].name ; - if (obstr_equal(name,master)) continue ; - - if (genalloc_s(vertex_graph_t,&g->vertex)[i].ndeps) - { - for (k = 0; k < genalloc_s(vertex_graph_t,&g->vertex)[i].ndeps; k++) - { - char *depname = string + genalloc_s(vertex_graph_t,&genalloc_s(vertex_graph_t,&g->vertex)[i].dps)[k].name ; - - if (obstr_equal(name,depname)) - { - if (!stra_cmp(ga,master)) - { - if (!stra_add(ga,master)) - { - VERBO3 strerr_warnwu3x("add: ",depname," as dependency to remove") ; - return 0 ; - } - r = graph_rdepends(ga,g,master,src) ; - if (!r) return 0 ; - } - } - } - } - } - - if (!genalloc_len(stralist,ga)) return 2 ; - - //genalloc_reverse(stralist,ga) ; - return 1 ; -} /** what = 0 -> only classic * what = 1 -> only atomic * what = 2 -> both diff --git a/src/lib66/parser.c b/src/lib66/parser.c index 9c806e7c8bf5992e093698d5cf09b461dfe704a8..dea65bd608b79c4cccc415830979fe7aa0b2804a 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -95,7 +95,7 @@ static int add_sv(sv_alltype *sv_before,char const *name,unsigned int *nbsv) } (*nbsv)++ ; - VERBO1 strerr_warni2x("Service parsed successfully: ",name) ; + VERBO2 strerr_warni2x("Service parsed successfully: ",name) ; return 1 ; } @@ -513,7 +513,7 @@ int parse_service_before(char const *src,char const *sv,char const *tree, unsign r = avltree_search(&deps_map,newsv.s,&id) ; if (r) { - VERBO1 strerr_warni3x("ignore ",newsv.s," service: already added") ; + VERBO2 strerr_warni3x("ignore ",newsv.s," service: already added") ; sasv->len = 0 ; stralloc_free(&newsv) ; sv_alltype_free(&sv_before) ; diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index fd63f2edd08a5586525f221880e7d1b87e0a44c5..c34b8f6e559a687d5ddd0fb065e95d6b94fb2e98 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -35,6 +35,7 @@ #include <66/utils.h> #include <66/enum.h> #include <66/resolve.h> +#include <66/ssexec.h> #include <s6/config.h>//S6_BINPREFIX #include <execline/config.h>//EXECLINE_BINPREFIX @@ -43,15 +44,26 @@ /** @Return 0 on fail * @Return 1 on success * @Return 2 if the service is ignored */ -int write_services(sv_alltype *sv, char const *workdir, unsigned int force) +int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force) { int r ; + ss_resolve_t res = RESOLVE_ZERO ; + size_t workdirlen = strlen(workdir) ; char *name = keep.s+sv->cname.name ; size_t namelen = strlen(name) ; int type = sv->cname.itype ; + if (ss_resolve_check(info,name,SS_RESOLVE_LIVE)) + { + stralloc sares = STRALLOC_ZERO ; + if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; + if (res.type != type) strerr_dief4x(111,"Detection of incompatible type format -- current: ",get_keybyid(type)," previous: ",get_keybyid(res.type)) ; + stralloc_free(&sares) ; + } + ss_resolve_free(&res) ; + size_t wnamelen ; char wname[workdirlen + SS_SVC_LEN + SS_SRC_LEN + namelen + 1 + 1] ; memcpy(wname,workdir,workdirlen) ; diff --git a/src/lib66/rc_init.c b/src/lib66/rc_init.c index 4e3c46f55f11f560e5bcc1fde290a827ccdcf415..b5753c9a4d23c5f2edbc85362aa62f9b1a59326b 100644 --- a/src/lib66/rc_init.c +++ b/src/lib66/rc_init.c @@ -20,31 +20,93 @@ #include <oblibs/error2.h> #include <skalibs/genalloc.h> +#include <skalibs/djbunix.h> #include <66/resolve.h> #include <66/ssexec.h> +#include <66/constants.h> #include <66/utils.h> -#include <s6/s6-supervise.h> -int rc_init(ssexec_t *info, char const *const *envp) +#include <s6-rc/config.h> + +int rc_init(ssexec_t *info,genalloc *ga, char const *const *envp) { - int r ; + int writein,wstat ; + pid_t pid ; - int nargc = 2 ; - char const *newargv[nargc] ; - unsigned int m = 0 ; + stralloc src = STRALLOC_ZERO ; + + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; + + char svdir[info->tree.len + SS_SVDIRS_LEN + SS_DB_LEN + 1 + info->treename.len + 1] ; + memcpy(svdir,info->tree.s,info->tree.len) ; + memcpy(svdir + info->tree.len ,SS_SVDIRS ,SS_SVDIRS_LEN) ; + memcpy(svdir + info->tree.len + SS_SVDIRS_LEN,SS_DB,SS_DB_LEN) ; + memcpy(svdir + info->tree.len + SS_SVDIRS_LEN + SS_DB_LEN, "/", 1) ; + memcpy(svdir + info->tree.len + SS_SVDIRS_LEN + SS_DB_LEN + 1, info->treename.s,info->treename.len) ; + svdir[info->tree.len + SS_SVDIRS_LEN + SS_DB_LEN + 1 + info->treename.len] = 0 ; - newargv[m++] = "fake_name" ; - newargv[m++] = "d" ; - //newargv[m++] = 0 ; + char ltree[info->livetree.len + 1 + info->treename.len + 1] ; + memcpy(ltree,info->livetree.s,info->livetree.len) ; + ltree[info->livetree.len] = '/' ; + memcpy(ltree + info->livetree.len + 1, info->treename.s, info->treename.len) ; + ltree[info->livetree.len + 1 + info->treename.len] = 0 ; + + char prefix[info->treename.len + 1 + 1] ; + memcpy(prefix,info->treename.s,info->treename.len) ; + memcpy(prefix + info->treename.len, "-",1) ; + prefix[info->treename.len + 1] = 0 ; + + char tt[UINT32_FMT] ; + tt[uint32_fmt(tt,info->timeout)] = 0 ; + + char const *newargv[12] ; + unsigned int m = 0 ; + + newargv[m++] = S6RC_BINPREFIX "s6-rc-init" ; + newargv[m++] = "-l" ; + newargv[m++] = ltree ; + newargv[m++] = "-c" ; + newargv[m++] = svdir ; + newargv[m++] = "-p" ; + newargv[m++] = prefix ; + newargv[m++] = "-t" ; + newargv[m++] = tt ; + newargv[m++] = "--" ; + newargv[m++] = info->scandir.s ; + newargv[m++] = 0 ; + + VERBO3 strerr_warni3x("initiate db of tree: ",info->treename.s," ...") ; + + pid = child_spawn0(newargv[0],newargv,envp) ; + if (waitpid_nointr(pid,&wstat, 0) < 0) + { strerr_warnwu2sys("wait for ",newargv[0]) ; goto err ; } - if (ssexec_init(nargc,newargv,envp,info)) - return 0 ; + if (wstat) { strerr_warnwu2x("init db of tree: ",info->treename.s) ; goto err ; } + if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { strerr_warnwu1x("set revolve pointer to live") ; goto err ; } + + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + { + char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; + char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; + ss_resolve_setflag(&genalloc_s(ss_resolve_t,ga)[i],SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(&genalloc_s(ss_resolve_t,ga)[i],src.s,name,writein)) + { VERBO1 strerr_diefu2sys(111,"write resolve file of: ",name) ; goto err ; } + + VERBO1 strerr_warni2x("Initiated successfully: ",name) ; + } - VERBO3 strerr_warnt2x("reload scandir: ",info->scandir.s) ; - r = s6_svc_writectl(info->scandir.s, S6_SVSCAN_CTLDIR, "an", 2) ; - if (r < 0) return 0 ; + VERBO2 strerr_warnt2x("reload scandir: ",info->scandir.s) ; + if (scandir_send_signal(info->scandir.s,"an") <= 0) goto err ; + stralloc_free(&src) ; return 1 ; + + err: + stralloc_free(&src) ; + return 0 ; } diff --git a/src/lib66/resolve.c b/src/lib66/resolve.c index aa56abad15b3a2a14a9825b7ec0b566068b14b49..d3a756d7f1f181c2646ccdda4abfbcaa7fea7c10 100644 --- a/src/lib66/resolve.c +++ b/src/lib66/resolve.c @@ -35,6 +35,7 @@ #include <66/parser.h>//resolve need to find stralloc keep #include <66/resolve.h> #include <66/ssexec.h> +#include <66/graph.h> #include <s6/s6-supervise.h> #include <stdio.h> @@ -126,9 +127,7 @@ int ss_resolve_pointo(stralloc *sa,ssexec_t *info,unsigned int type, unsigned in if (where == SS_RESOLVE_LIVE) { if (!stralloc_catb(&tmp,info->live.s,info->live.len - 1) || - !stralloc_cats(&tmp,SS_RESOLVE) || - !stralloc_cats(&tmp,"/") || - !stralloc_cats(&tmp,ownerstr) || + !stralloc_cats(&tmp,SS_STATE) || !stralloc_cats(&tmp,"/") || !stralloc_cats(&tmp,info->treename.s)) goto err ; } @@ -287,11 +286,13 @@ int ss_resolve_src(genalloc *ga, stralloc *sasrc, char const *name, char const * return 0 ; } -int ss_resolve_rmfile(ss_resolve_t *res, char const *src,char const *name) +int ss_resolve_rmfile(ss_resolve_t *res, char const *src,char const *name,int both) { + stralloc sa = STRALLOC_ZERO ; + size_t srclen = strlen(src) ; size_t namelen = strlen(name) ; - size_t newlen = srclen + SS_RESOLVE_LEN + 1 ; + char tmp[srclen + SS_RESOLVE_LEN + 1 + namelen +1] ; memcpy(tmp,src,srclen) ; memcpy(tmp + srclen, SS_RESOLVE,SS_RESOLVE_LEN) ; @@ -299,15 +300,23 @@ int ss_resolve_rmfile(ss_resolve_t *res, char const *src,char const *name) memcpy(tmp + srclen + SS_RESOLVE_LEN + 1, name, namelen) ; tmp[srclen + SS_RESOLVE_LEN + 1 + namelen] = 0 ; - if (unlink(tmp) < 0) return 0 ; - if (res->logger) + unlink_void(tmp) ; + if (both) { - size_t loglen = strlen(res->sa.s + res->logger) ; - memcpy(tmp + newlen,res->sa.s + res->logger,loglen) ; - tmp[newlen + loglen] = 0 ; - if (unlink(tmp) < 0) return 0 ; + /** write in src */ + if (!stralloc_cats(&sa,res->sa.s + res->tree)) goto err ; + if (!stralloc_cats(&sa,SS_SVDIRS)) goto err ; + if (!stralloc_cats(&sa,SS_RESOLVE)) goto err ; + if (!stralloc_cats(&sa,"/")) goto err ; + if (!stralloc_cats(&sa,name)) goto err ; + if (!stralloc_0(&sa)) goto err ; + unlink_void(sa.s) ; } + stralloc_free(&sa) ; return 1 ; + err: + stralloc_free(&sa) ; + return 0 ; } int ss_resolve_add_uint32(stralloc *sa, uint32_t data) @@ -349,9 +358,11 @@ int ss_resolve_pack(stralloc *sa, ss_resolve_t *res) !ss_resolve_add_uint32(sa,res->dstlog) || !ss_resolve_add_uint32(sa,res->deps) || !ss_resolve_add_uint32(sa,res->src) || + !ss_resolve_add_uint32(sa,res->live) || !ss_resolve_add_uint32(sa,res->runat) || !ss_resolve_add_uint32(sa,res->tree) || !ss_resolve_add_uint32(sa,res->treename) || + !ss_resolve_add_uint32(sa,res->resolve) || !ss_resolve_add_uint32(sa,res->exec_run) || !ss_resolve_add_uint32(sa,res->exec_finish) || !ss_resolve_add_uint32(sa,res->type) || @@ -367,10 +378,11 @@ int ss_resolve_pack(stralloc *sa, ss_resolve_t *res) return 1 ; } -int ss_resolve_write(ss_resolve_t *res, char const *dst, char const *name) +int ss_resolve_write(ss_resolve_t *res, char const *dst, char const *name,int both) { stralloc sa = STRALLOC_ZERO ; + stralloc sasrc = STRALLOC_ZERO ; size_t dstlen = strlen(dst) ; size_t namelen = strlen(name) ; @@ -383,17 +395,26 @@ int ss_resolve_write(ss_resolve_t *res, char const *dst, char const *name) tmp[dstlen + SS_RESOLVE_LEN + 1 + namelen] = 0 ; if (!ss_resolve_pack(&sa,res)) goto err ; - if (dir_search(tmp,sa.s,S_IFREG)) + if (!openwritenclose_unsafe(tmp,sa.s,sa.len)) goto err ; + if (both) { - if (!ss_resolve_rmfile(res,dst,name)) goto err ; + /** write in src */ + if (!stralloc_cats(&sasrc,res->sa.s + res->tree)) goto err ; + if (!stralloc_cats(&sasrc,SS_SVDIRS)) goto err ; + if (!stralloc_cats(&sasrc,SS_RESOLVE)) goto err ; + if (!stralloc_cats(&sasrc,"/")) goto err ; + if (!stralloc_cats(&sasrc,name)) goto err ; + if (!stralloc_0(&sasrc)) goto err ; + if (!openwritenclose_unsafe(sasrc.s,sa.s,sa.len)) goto err ; } - if (!openwritenclose_unsafe(tmp,sa.s,sa.len)) goto err ; - + stralloc_free(&sa) ; + stralloc_free(&sasrc) ; return 1 ; err: stralloc_free(&sa) ; + stralloc_free(&sasrc) ; return 0 ; } @@ -435,6 +456,8 @@ int ss_resolve_read(ss_resolve_t *res, char const *src, char const *name) global += 4 ; uint32_unpack_big(sa.s + global,&res->src) ; + global += 4 ; + uint32_unpack_big(sa.s + global,&res->live) ; global += 4 ; uint32_unpack_big(sa.s + global,&res->runat) ; global += 4 ; @@ -442,6 +465,8 @@ int ss_resolve_read(ss_resolve_t *res, char const *src, char const *name) global += 4 ; uint32_unpack_big(sa.s + global,&res->treename) ; global += 4 ; + uint32_unpack_big(sa.s + global,&res->resolve) ; + global += 4 ; uint32_unpack_big(sa.s + global,&res->exec_run) ; global += 4 ; uint32_unpack_big(sa.s + global,&res->exec_finish) ; @@ -535,38 +560,39 @@ int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst) res.logreal = ss_resolve_add_string(&res,string + sv->logreal) ; res.logassoc = ss_resolve_add_string(&res,string + sv->name) ; res.dstlog = ss_resolve_add_string(&res,string + sv->dstlog) ; + res.live = ss_resolve_add_string(&res,string + sv->live) ; + res.runat = ss_resolve_add_string(&res,live) ; //res.deps = ss_resolve_add_string(&res,string + sv->name) ; res.tree = ss_resolve_add_string(&res,string + sv->tree) ; res.treename = ss_resolve_add_string(&res,string + sv->treename) ; + res.resolve = ss_resolve_add_string(&res,string + sv->resolve) ; //res.ndeps = 1 ; res.type = sv->type ; - res.reload = sv->reload ; - res.disen = sv->disen ; - res.down = sv->down ; - res.runat = ss_resolve_add_string(&res,live) ; - res.init = sv->init ; - res.reload = sv->reload ; - res.unsupervise = sv->unsupervise ; + ss_resolve_setflag(&res,SS_FLAGS_RELOAD,sv->reload) ; + ss_resolve_setflag(&res,SS_FLAGS_DISEN,sv->disen) ; + ss_resolve_setflag(&res,SS_FLAGS_DOWN,sv->down) ; + ss_resolve_setflag(&res,SS_FLAGS_INIT,sv->init) ; + ss_resolve_setflag(&res,SS_FLAGS_UNSUPERVISE,sv->unsupervise) ; r = s6_svc_ok(res.sa.s + res.runat) ; if (r < 0) { strerr_warnwu2sys("check ", res.sa.s + res.runat) ; goto err ; } if (!r) { - res.pid = 0 ; - res.run = 0 ; + ss_resolve_setflag(&res,SS_FLAGS_PID,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; } else { - res.run = 1 ; + ss_resolve_setflag(&res,SS_FLAGS_RUN,SS_FLAGS_TRUE) ; if (!s6_svstatus_read(res.sa.s + res.runat,&status)) { strerr_warnwu2sys("read status of: ",res.sa.s + res.name) ; goto err ; } - res.pid = status.pid ; + ss_resolve_setflag(&res,SS_FLAGS_PID,(uint32_t)status.pid) ; } - if (!ss_resolve_write(&res,dst,res.sa.s + res.name)) + if (!ss_resolve_write(&res,dst,res.sa.s + res.name,SS_SIMPLE)) { strerr_warnwu5sys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; goto err ; @@ -578,69 +604,61 @@ int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst) return 0 ; } -int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info, char const *dst) +int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) { int r ; + + ss_resolve_t res = RESOLVE_ZERO ; + ss_resolve_init(&res) ; + char *name = keep.s + services->cname.name ; size_t namelen = strlen(name) ; char logname[namelen + SS_LOG_SUFFIX_LEN + 1] ; char logreal[namelen + SS_LOG_SUFFIX_LEN + 1] ; char stmp[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + 1 + namelen + SS_LOG_SUFFIX_LEN + 1] ; - s6_svstatus_t status = S6_SVSTATUS_ZERO ; + size_t livelen = info->live.len - 1 ; + char resolve[livelen + SS_STATE_LEN + 1 + info->treename.len + 1] ; + memcpy(resolve,info->live.s,livelen) ; + memcpy(resolve + livelen, SS_STATE,SS_STATE_LEN) ; + resolve[livelen+ SS_STATE_LEN] = '/' ; + memcpy(resolve + livelen + SS_STATE_LEN + 1,info->treename.s,info->treename.len) ; + resolve[livelen + SS_STATE_LEN + 1 + info->treename.len] = 0 ; - + s6_svstatus_t status = S6_SVSTATUS_ZERO ; + stralloc destlog = STRALLOC_ZERO ; stralloc namedeps = STRALLOC_ZERO ; stralloc final = STRALLOC_ZERO ; - - res->name = ss_resolve_add_string(res,name) ; - res->description = ss_resolve_add_string(res,keep.s + services->cname.description) ; - res->tree = ss_resolve_add_string(res,info->tree.s) ; - res->treename = ss_resolve_add_string(res,info->treename.s) ; - res->src = ss_resolve_add_string(res,keep.s + services->src) ; + + res.name = ss_resolve_add_string(&res,name) ; + res.description = ss_resolve_add_string(&res,keep.s + services->cname.description) ; + res.tree = ss_resolve_add_string(&res,info->tree.s) ; + res.treename = ss_resolve_add_string(&res,info->treename.s) ; + res.live = ss_resolve_add_string(&res,info->live.s) ; + res.resolve = ss_resolve_add_string(&res,resolve) ; + res.src = ss_resolve_add_string(&res,keep.s + services->src) ; if (services->type.classic_longrun.run.exec) - res->exec_run = ss_resolve_add_string(res,keep.s + services->type.classic_longrun.run.exec) ; + res.exec_run = ss_resolve_add_string(&res,keep.s + services->type.classic_longrun.run.exec) ; if (services->type.classic_longrun.finish.exec) - res->exec_finish = ss_resolve_add_string(res,keep.s + services->type.classic_longrun.finish.exec) ; - res->type = services->cname.itype ; - res->ndeps = services->cname.nga ; - res->reload = 1 ; - res->disen = 1 ; - res->unsupervise = 0 ; - if (services->flags[0]) res->down = 1 ; + res.exec_finish = ss_resolve_add_string(&res,keep.s + services->type.classic_longrun.finish.exec) ; + res.type = services->cname.itype ; + res.ndeps = services->cname.nga ; + ss_resolve_setflag(&res,SS_FLAGS_RELOAD,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&res,SS_FLAGS_DISEN,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&res,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + if (services->flags[0]) ss_resolve_setflag(&res,SS_FLAGS_DOWN,SS_FLAGS_TRUE) ; - if (res->type == CLASSIC) + if (res.type == CLASSIC) { memcpy(stmp,info->scandir.s,info->scandir.len) ; stmp[info->scandir.len] = '/' ; memcpy(stmp + info->scandir.len + 1,name,namelen) ; stmp[info->scandir.len + 1 + namelen] = 0 ; - res->runat = ss_resolve_add_string(res,stmp) ; - r = s6_svc_ok(res->sa.s + res->runat) ; - if (r < 0) { strerr_warnwu2sys("check ", res->sa.s + res->runat) ; goto err ; } - if (!r) - { - res->init = 1 ; - res->reload = 0 ; - res->pid = 0 ; - res->run = 0 ; - } - else - { - res->init = 0 ; - res->run = 1 ; - res->reload = 1 ; - if (!s6_svstatus_read(res->sa.s + res->runat,&status)) - { - strerr_warnwu2sys("read status of: ",res->sa.s + res->name) ; - goto err ; - } - res->pid = status.pid ; - } + res.runat = ss_resolve_add_string(&res,stmp) ; } - else if (res->type >= BUNDLE) + else if (res.type >= BUNDLE) { memcpy(stmp,info->livetree.s,info->livetree.len) ; stmp[info->livetree.len] = '/' ; @@ -649,33 +667,33 @@ int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info stmp[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN] = '/' ; memcpy(stmp + info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + 1, name,namelen) ; stmp[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + 1 + namelen] = 0 ; - res->runat = ss_resolve_add_string(res,stmp) ; - r = s6_svc_ok(res->sa.s + res->runat) ; - if (r < 0) { strerr_warnwu2sys("check ", res->sa.s + res->runat) ; goto err ; } - if (!r) - { - res->init = 1 ; - res->reload = 0 ; - res->pid = 0 ; - res->run = 0 ; - } - else - { - res->init = 0 ; - res->run = 1 ; - res->reload = 1 ; - if (!s6_svstatus_read(res->sa.s + res->runat,&status)) - { - strerr_warnwu2sys("read status of: ",res->sa.s + res->name) ; - goto err ; - } - res->pid = status.pid ; + res.runat = ss_resolve_add_string(&res,stmp) ; + } + r = s6_svc_ok(res.sa.s + res.runat) ; + if (r < 0) { strerr_warnwu2sys("check ", res.sa.s + res.runat) ; goto err ; } + if (!r) + { + ss_resolve_setflag(&res,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&res,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_PID,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; + } + else + { + ss_resolve_setflag(&res,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&res,SS_FLAGS_RELOAD,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&res,SS_FLAGS_RUN,SS_FLAGS_TRUE) ; + if (!s6_svstatus_read(res.sa.s + res.runat,&status)) + { + strerr_warnwu2sys("read status of: ",res.sa.s + res.name) ; + goto err ; } + ss_resolve_setflag(&res,SS_FLAGS_PID,(uint32_t)status.pid) ; } - - if (res->ndeps) + + if (res.ndeps) { - for (unsigned int i = 0; i < res->ndeps; i++) + for (unsigned int i = 0; i < res.ndeps; i++) { if (!stralloc_obreplace(&namedeps,deps.s+genalloc_s(unsigned int,&gadeps)[services->cname.idga+i])) goto err ; r = insta_check(namedeps.s) ; @@ -698,7 +716,7 @@ int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info } final.len-- ; if (!stralloc_0(&final)){ warnstralloc("ss_resolve_setnwrite") ; goto err ; } - res->deps = ss_resolve_add_string(res,final.s) ; + res.deps = ss_resolve_add_string(&res,final.s) ; } if (services->opts[0]) @@ -708,22 +726,22 @@ int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info logname[namelen + SS_LOG_SUFFIX_LEN] = 0 ; memcpy(logreal,name,namelen) ; - if (res->type == CLASSIC) + if (res.type == CLASSIC) { memcpy(logreal + namelen,"/log",SS_LOG_SUFFIX_LEN) ; } else memcpy(logreal + namelen,"-log",SS_LOG_SUFFIX_LEN) ; logreal[namelen + SS_LOG_SUFFIX_LEN] = 0 ; - res->logger = ss_resolve_add_string(res,logname) ; - res->logreal = ss_resolve_add_string(res,logreal) ; + res.logger = ss_resolve_add_string(&res,logname) ; + res.logreal = ss_resolve_add_string(&res,logreal) ; if (final.len) final.len--; if (!stralloc_catb(&final," ",1)) { warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&final,res->sa.s + res->logger)) { warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_cats(&final,res.sa.s + res.logger)) { warnstralloc("ss_resolve_setnwrite") ; goto err ; } if (!stralloc_0(&final)){ warnstralloc("ss_resolve_setnwrite") ; goto err ; } - res->deps = ss_resolve_add_string(res,final.s) ; - if (res->type == CLASSIC) res->ndeps = 1 ; - else if (res->type == LONGRUN) res->ndeps += 1 ; + res.deps = ss_resolve_add_string(&res,final.s) ; + if (res.type == CLASSIC) res.ndeps = 1 ; + else if (res.type == LONGRUN) res.ndeps += 1 ; // destination of the logger if (!services->type.classic_longrun.log.destination) { @@ -746,14 +764,14 @@ int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info } if (!stralloc_0(&destlog)) retstralloc(0,"ss_resolve_setnwrite") ; - res->dstlog = ss_resolve_add_string(res,destlog.s) ; + res.dstlog = ss_resolve_add_string(&res,destlog.s) ; - if (!ss_resolve_setlognwrite(res,dst)) goto err ; + if (!ss_resolve_setlognwrite(&res,dst)) goto err ; } - if (!ss_resolve_write(res,dst,res->sa.s + res->name)) + if (!ss_resolve_write(&res,dst,res.sa.s + res.name,SS_SIMPLE)) { - strerr_warnwu5sys("write resolve file: ",dst,SS_RESOLVE,"/",res->sa.s + res->name) ; + strerr_warnwu5sys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; goto err ; } @@ -768,6 +786,7 @@ int ss_resolve_setnwrite(ss_resolve_t *res, sv_alltype *services, ssexec_t *info stralloc_free(&destlog) ; return 0 ; } + int ss_resolve_cmp(genalloc *ga,char const *name) { unsigned int i = 0 ; @@ -780,14 +799,13 @@ int ss_resolve_cmp(genalloc *ga,char const *name) return 0 ; } -int ss_resolve_addlogger(ssexec_t *info,genalloc *ga) +int ss_resolve_add_logger(genalloc *ga,ssexec_t *info) { stralloc tmp = STRALLOC_ZERO ; genalloc gatmp = GENALLOC_ZERO ; - if (!ss_resolve_pointo(&tmp,info,SS_NOTYPE,SS_RESOLVE_SRC)) + if (!ss_resolve_pointo(&tmp,info,SS_NOTYPE,SS_RESOLVE_LIVE)) goto err ; -// if (!genalloc_copy(ss_resolve_t,&gatmp,ga)) goto err ; for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) { @@ -819,3 +837,104 @@ int ss_resolve_addlogger(ssexec_t *info,genalloc *ga) stralloc_free(&tmp) ; return 0 ; } + +void ss_resolve_setflag(ss_resolve_t *res,int flags,int flags_val) +{ + switch (flags) + { + case SS_FLAGS_RELOAD: res->reload = flags_val ; break ; + case SS_FLAGS_DISEN: res->disen = flags_val ; break ; + case SS_FLAGS_INIT: res->init = flags_val ; break ; + case SS_FLAGS_UNSUPERVISE: res->unsupervise = flags_val ; break ; + case SS_FLAGS_DOWN: res->down = flags_val ; break ; + case SS_FLAGS_RUN: res->run = flags_val ; break ; + case SS_FLAGS_PID: res->pid = flags_val ; break ; + default: return ; + } +} + +int ss_resolve_add_deps(genalloc *tokeep,ss_resolve_t *res, ssexec_t *info) +{ + unsigned int i = 0 ; + genalloc tmp = GENALLOC_ZERO ; + size_t srclen = strlen(res->sa.s + res->tree) ; + char src[srclen + SS_SVDIRS_LEN + 1] ; + memcpy(src,res->sa.s + res->tree,srclen) ; + memcpy(src + srclen, SS_SVDIRS,SS_SVDIRS_LEN) ; + src[srclen + SS_SVDIRS_LEN] = 0 ; + + char *name = res->sa.s + res->name ; + char *deps = res->sa.s + res->deps ; + if (!ss_resolve_cmp(tokeep,name)) + if (!genalloc_append(ss_resolve_t,tokeep,res)) goto err ; + + if (res->ndeps) + { + if (!clean_val(&tmp,deps)) return 0 ; + for (;i < genalloc_len(stralist,&tmp) ; i++) + { + + ss_resolve_t dres = RESOLVE_ZERO ; + if (!ss_resolve_check(info,gaistr(&tmp,i),SS_RESOLVE_LIVE)) goto err ; + if (!ss_resolve_read(&dres,src,gaistr(&tmp,i))) goto err ; + if (dres.ndeps) ss_resolve_add_deps(tokeep,&dres,info) ; + + if (!ss_resolve_cmp(tokeep,gaistr(&tmp,i))) + if (!genalloc_append(ss_resolve_t,tokeep,&dres)) goto err ; + } + } + genalloc_deepfree(stralist,&tmp,stra_free) ; + return 1 ; + err: + genalloc_deepfree(stralist,&tmp,stra_free) ; + return 0 ; +} + +int ss_resolve_add_rdeps(genalloc *tokeep, ss_resolve_t *res,ssexec_t *info) +{ + genalloc tmp = GENALLOC_ZERO ; + genalloc nsv = GENALLOC_ZERO ; + int type ; + char *name = res->sa.s + res->name ; + size_t srclen = strlen(res->sa.s + res->tree) ; + char src[srclen + SS_SVDIRS_LEN + 1] ; + memcpy(src,res->sa.s + res->tree,srclen) ; + memcpy(src + srclen, SS_SVDIRS,SS_SVDIRS_LEN) ; + src[srclen + SS_SVDIRS_LEN] = 0 ; + if (res->type == CLASSIC) type = 0 ; + else type = 1 ; + if (!graph_type_src(&nsv,src,type)) goto err ; + if (!ss_resolve_cmp(tokeep,name)) + if (!genalloc_append(ss_resolve_t,tokeep,res)) goto err ; + + for (unsigned int i = 0 ; i < genalloc_len(stralist,&nsv) ; i++) + { + genalloc_deepfree(stralist,&tmp,stra_free) ; + ss_resolve_t dres = RESOLVE_ZERO ; + char *dname = gaistr(&nsv,i) ; + if (obstr_equal(name,dname)) continue ; + if (!ss_resolve_check(info,dname,SS_RESOLVE_LIVE)) goto err ; + if (!ss_resolve_read(&dres,src,gaistr(&nsv,i))) goto err ; + if (dres.ndeps || (dres.type == BUNDLE && dres.ndeps) || (res->type == BUNDLE && res->ndeps)) + { + if (!clean_val(&tmp,dres.sa.s + dres.deps)) goto err ; + for (unsigned int j = 0 ; j < genalloc_len(stralist,&tmp) ; j++) + { + if (obstr_equal(name,gaistr(&tmp,j)) || res->type == BUNDLE) + { + if (!ss_resolve_cmp(tokeep,dname)) + { + if (!genalloc_append(ss_resolve_t,tokeep,&dres)) goto err ; + if (!ss_resolve_add_rdeps(tokeep,&dres,info)) goto err ; + break ; + } + } + } + } + } + genalloc_deepfree(stralist,&tmp,stra_free) ; + return 1 ; + err: + genalloc_deepfree(stralist,&tmp,stra_free) ; + return 0 ; +} diff --git a/src/lib66/ssexec_dbctl.c b/src/lib66/ssexec_dbctl.c index 5081dc42d95cb176076e3c78ca87fe603224ee12..f39fcdf8036511c03da8830fd40807fe7f9495b5 100644 --- a/src/lib66/ssexec_dbctl.c +++ b/src/lib66/ssexec_dbctl.c @@ -42,7 +42,7 @@ #include <66/resolve.h> #include <66/ssexec.h> -//#include <stdio.h> +#include <stdio.h> static unsigned int DEADLINE = 0 ; @@ -54,7 +54,7 @@ static pid_t send(genalloc *gasv, char const *livetree, char const *signal,char tain_now_g() ; tain_add_g(&deadline, &deadline) ; - char const *newargv[10 + genalloc_len(stralist,gasv)] ; + char const *newargv[10 + genalloc_len(ss_resolve_t,gasv)] ; unsigned int m = 0 ; char fmt[UINT_FMT] ; fmt[uint_fmt(fmt, VERBOSITY)] = 0 ; @@ -72,8 +72,8 @@ static pid_t send(genalloc *gasv, char const *livetree, char const *signal,char newargv[m++] = signal ; newargv[m++] = "change" ; - for (unsigned int i = 0 ; i<genalloc_len(stralist,gasv); i++) - newargv[m++] = gaistr(gasv,i) ; + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,gasv); i++) + newargv[m++] = genalloc_s(ss_resolve_t,gasv)[i].sa.s + genalloc_s(ss_resolve_t,gasv)[i].name ; newargv[m++] = 0 ; @@ -84,26 +84,28 @@ static pid_t send(genalloc *gasv, char const *livetree, char const *signal,char int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) { - // be sure that the global var are set correctly - DEADLINE = 0 ; + if (info->timeout) DEADLINE = info->timeout ; - unsigned int up, down, reload ; + unsigned int up, down, reload, ret ; - int wstat ; + int wstat, writein ; pid_t pid ; char *signal = 0 ; char *mainsv = "Master" ; - genalloc gasv = GENALLOC_ZERO ; //stralist + genalloc resdeps = GENALLOC_ZERO ; //ss_resolve_t + genalloc toreload = GENALLOC_ZERO ;//ss_resolve_t stralloc tmp = STRALLOC_ZERO ; - ss_resolve_t res = RESOLVE_ZERO ; stralloc src = STRALLOC_ZERO ; + s6_svstatus_t status = S6_SVSTATUS_ZERO ; - up = down = reload = 0 ; + up = down = reload = ret = 0 ; + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; + - if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; //PROG = "66-dbctl" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -125,26 +127,67 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe } if (!up && !down && !reload){ strerr_warnw1x("signal must be set") ; exitusage(usage_dbctl) ; } + + if (down) signal = "-d" ; + else signal = "-u" ; + + if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to live") ; + if (argc < 1) { - if (!stra_add(&gasv,mainsv)) strerr_diefu1sys(111,"add: Master as service to handle") ; + unsigned int i = 0 ; + genalloc tmp = GENALLOC_ZERO ; + ss_resolve_t res = RESOLVE_ZERO ; + if (!ss_resolve_check(info,mainsv,SS_RESOLVE_LIVE)) strerr_dief1sys(111,"inner bundle doesn't exit -- please make a bug report") ; + if (!ss_resolve_read(&res,src.s,mainsv)) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + if (res.ndeps) + { + if (!clean_val(&tmp,res.sa.s + res.deps)) strerr_dief1sys(111,"retrieve dependencies of inner bundle") ; + for (;i < genalloc_len(stralist,&tmp) ; i++) + { + ss_resolve_t dres = RESOLVE_ZERO ; + char *name = gaistr(&tmp,i) ; + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2sys(110,"unknow service: ",name) ; + if (!ss_resolve_read(&dres,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; + if (!genalloc_append(ss_resolve_t,&resdeps,&dres)) strerr_diefu1sys(111,"append genalloc") ; + if (reload) if (!genalloc_append(ss_resolve_t,&toreload,&dres)) strerr_diefu1sys(111,"append genalloc") ; + } + } + else + { + VERBO1 strerr_warni1x("nothing to do") ; + ss_resolve_free(&res) ; + genalloc_deepfree(stralist,&tmp,stra_free) ; + goto freed ; + } + ss_resolve_free(&res) ; + genalloc_deepfree(stralist,&tmp,stra_free) ; } else { - for(;*argv;argv++) { + ss_resolve_t res = RESOLVE_ZERO ; char const *name = *argv ; - res.sa.len = 0 ; - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2sys(110,"unknow service: ",name) ; - if (!ss_resolve_read(&res,src.s,name)) strerr_diefu3sys(111,"read resolve file of: ",src.s,name) ; + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2sys(110,"unknow service: ",name) ; + if (!ss_resolve_read(&res,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; if (res.type == CLASSIC) strerr_dief2x(111,name," has type classic") ; - if (!stra_add(&gasv,name)) strerr_diefu3sys(111,"add: ",name," as service to handle") ; + + if (up) + { + if (!ss_resolve_add_deps(&resdeps,&res,info)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; + } + else + { + if (!ss_resolve_add_rdeps(&resdeps,&res,info)) strerr_diefu2sys(111,"resolve recursive dependencies of: ",name) ; + } + if (reload) + { + if (!ss_resolve_add_rdeps(&toreload,&res,info)) strerr_diefu2sys(111,"resolve recursive dependencies of: ",name) ; + } } - } - if (info->timeout) DEADLINE = info->timeout ; - + } if (!db_ok(info->livetree.s,info->treename.s)) strerr_dief5sys(111,"db: ",info->livetree.s,"/",info->treename.s," is not running") ; @@ -155,69 +198,78 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe if (reload) { - pid = send(&gasv,tmp.s,"-d",envp) ; + pid = send(&toreload,tmp.s,"-d",envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) strerr_diefu1sys(111,"wait for s6-rc") ; - if (wstat) strerr_diefu3x(111,"bring",down ? " down " : " up ","services list") ; + if (wstat) strerr_diefu2x(111,down ? " stop " : " start ","services list") ; } - - if (down) signal = "-d" ; - else signal = "-u" ; - - pid = send(&gasv,tmp.s,signal,envp) ; + + pid = send(&resdeps,tmp.s,signal,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) strerr_diefu1sys(111,"wait for s6-rc") ; - if (wstat) strerr_diefu3x(111,"bring",down ? " down " : " up ","services list") ; - - /** we are forced to do this ugly check cause of the design - * of s6-rc(generally s6-svc) which is launch and forgot. So - * s6-rc will not warn us if the daemon fail when we don't use - * readiness which is rarely used on DESKTOP configuration due of - * the bad design of the majority of daemon. - * The result of the check is not guaranted due of the rapidity of the code. - * between the end of the s6-rc process and the check of the daemon status, - * the real value of the status can be not written yet,so we can hit - * this window.*/ + if (wstat) strerr_diefu2x(111,down ? " start " : " stop ","services list") ; - for (unsigned int i = 0; i < genalloc_len(stralist,&gasv) ; i++) - { - res.sa.len = 0 ; - char *name = gaistr(&gasv,i) ; + genalloc_reverse(ss_resolve_t,&resdeps) ; + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&resdeps) ; i++) + { + int nret = 0 ; + ss_resolve_t_ref pres = &genalloc_s(ss_resolve_t,&resdeps)[i] ; + char *name = pres->sa.s + pres->name ; + /** do not touch the Master resolve file*/ if (obstr_equal(name,SS_MASTER + 1)) continue ; - - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2sys(111,"unknow service: ",name) ; - if (!ss_resolve_read(&res,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; /** only check longrun service */ - if (res.type == LONGRUN) + if (pres->type == LONGRUN) { - if (!s6_svstatus_read(res.sa.s + res.runat,&status)) + if (!s6_svstatus_read(pres->sa.s + pres->runat,&status)) { - strerr_diefu4sys(111,"read status of: ",res.sa.s + res.runat," -- race condition, try 66-info -S ",res.sa.s + res.name) ; + strerr_diefu4sys(111,"read status of: ",pres->sa.s + pres->runat," -- race condition, try 66-info -S ",pres->sa.s + pres->name) ; } - if (down) + else if (down) { if (WEXITSTATUS(status.wstat) && WIFEXITED(status.wstat) && status.pid) - strerr_diefu2x(111,"stop: ",name) ; + { + VERBO1 strerr_warnwu2x("stop: ",name) ; + ss_resolve_setflag(pres,SS_FLAGS_PID,(uint32_t)status.pid) ; + nret = 1 ; + } + else ss_resolve_setflag(pres,SS_FLAGS_PID,SS_FLAGS_FALSE) ; } - else if (up) + else { if (WEXITSTATUS(status.wstat) && WIFEXITED(status.wstat)) - strerr_diefu2x(111,"start: ",name) ; + { + VERBO1 strerr_warnwu2x("start: ",name) ; + nret = 1 ; + ss_resolve_setflag(pres,SS_FLAGS_PID,SS_FLAGS_FALSE) ; + } + else ss_resolve_setflag(pres,SS_FLAGS_PID,(uint32_t)status.pid) ; } } - VERBO1 strerr_warni3x(name,down ? " stopped " : " started ", "successfully") ; + if (nret) ret = 111 ; + ss_resolve_setflag(pres,SS_FLAGS_RUN,SS_FLAGS_TRUE) ; + ss_resolve_setflag(pres,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(pres,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + ss_resolve_setflag(pres,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(pres,src.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + ret = 111 ; + } + if (!nret) VERBO1 strerr_warni3x(reload ? "Reloaded" : up ? "Started" : "Stopped"," successfully: ",name) ; } - ss_resolve_free(&res) ; + freed: stralloc_free(&tmp) ; stralloc_free(&src) ; - genalloc_deepfree(stralist,&gasv,stra_free) ; + genalloc_deepfree(ss_resolve_t,&resdeps,ss_resolve_free) ; + genalloc_free(ss_resolve_t,&toreload) ; - return 0 ; + return ret ; } diff --git a/src/lib66/ssexec_disable.c b/src/lib66/ssexec_disable.c index c1997e036837a995bd22b32d9f85b30810df990e..d411733f31307fa6cccf885b1e0554757166cf62 100644 --- a/src/lib66/ssexec_disable.c +++ b/src/lib66/ssexec_disable.c @@ -50,162 +50,70 @@ static void cleanup(char const *dst) rm_rf(dst) ; errno = e ; } -int svc_remove(genalloc *tostop,ss_resolve_t *res, char const *src) -{ - char *name = res->sa.s + res->name ; - size_t namelen = strlen(name) ; - size_t srclen = strlen(src) ; - - char dst[srclen + SS_SVC_LEN + 1 + namelen + 1] ; - memcpy(dst,src,srclen) ; - memcpy(dst + srclen, SS_SVC, SS_SVC_LEN) ; - dst[srclen + SS_SVC_LEN] = '/' ; - memcpy(dst + srclen + SS_SVC_LEN + 1, name, namelen) ; - dst[srclen + SS_SVC_LEN + 1 + namelen] = 0 ; - - VERBO1 strerr_warni3x("Removing: ",name," directory service") ; - if (rm_rf(dst) < 0) - { - VERBO1 strerr_warnwu2sys("remove: ", dst) ; - return 0 ; - } - /** modify the resolve file for 66-stop*/ - res->disen = 0 ; - res->reload = 0 ; - res->init = 0 ; - res->unsupervise = 1 ; - VERBO2 strerr_warni2x("Write resolve file of: ",name) ; - if (!ss_resolve_write(res,src,name)) - { - VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; - return 0 ; - } - /** if a logger is associated modify the resolve for it */ - if (res->logger) - { - VERBO2 strerr_warni2x("Write logger resolve file of: ",name) ; - if (!ss_resolve_setlognwrite(res,src)) - { - VERBO1 strerr_warnwu2sys("write logger resolve file of: ",name) ; - return 0 ; - } - if (!stra_add(tostop,res->sa.s + res->logger)) retstralloc(0,"main") ; - } - - return 1 ; -} -int rc_remove(genalloc *toremove, ss_resolve_t *res, char const *src) +int svc_remove(genalloc *tostop,ss_resolve_t *res, char const *src,ssexec_t *info) { - int r ; - char *name = res->sa.s + res->name ; + unsigned int i = 0 ; + genalloc rdeps = GENALLOC_ZERO ; + stralloc dst = STRALLOC_ZERO ; size_t newlen ; - - stralloc sa = STRALLOC_ZERO ; - - ss_resolve_t dres = RESOLVE_ZERO ; - - graph_t g = GRAPH_ZERO ; - stralloc sagraph = STRALLOC_ZERO ; - genalloc tokeep = GENALLOC_ZERO ; - /** build dependencies graph*/ - r = graph_type_src(&tokeep,src,1) ; - if (r <= 0) + char *name = res->sa.s + res->name ; + if (!stralloc_cats(&dst,src)) goto err ; + if (res->type == CLASSIC) { - VERBO1 strerr_warnwu2x("resolve source of graph for tree: ",src) ; - goto err ; - } - if (!graph_build(&g,&sagraph,&tokeep,src)) - { - VERBO1 strerr_warnwu1x("make dependencies graph") ; - goto err ; + if (!stralloc_cats(&dst,SS_SVC)) goto err ; } + else if (!stralloc_cats(&dst,SS_DB SS_SRC)) retstralloc(0,"remove_sv") ; + if (!stralloc_cats(&dst,"/")) goto err ; + newlen = dst.len ; - r = graph_rdepends(toremove,&g,name,src) ; - if (!r) + if (!ss_resolve_add_rdeps(&rdeps,res,info)) { - VERBO1 strerr_warnwu2x("find services depending for: ",name) ; + VERBO1 strerr_warnwu2sys("resolve recursive dependencies of: ",name) ; goto err ; } - if(r == 2) VERBO2 strerr_warnt2x("any services depends of: ",name) ; - - if (!stra_cmp(toremove,name)) + if (!ss_resolve_add_logger(&rdeps,info)) { - if (!stra_add(toremove,name)) - { - VERBO1 strerr_warnwu3x("add: ",name," as dependency to remove") ; - goto err ; - } + VERBO1 strerr_warnwu1sys("resolve logger") ; + goto err ; } - if (!stralloc_cats(&sa,src)) retstralloc(0,"remove_sv") ; - if (!stralloc_cats(&sa,SS_DB SS_SRC)) retstralloc(0,"remove_sv") ; - if (!stralloc_cats(&sa, "/")) retstralloc(0,"remove_sv") ; - newlen = sa.len ; - genalloc_reverse(stralist,toremove) ; - for (unsigned int i = 0; i < genalloc_len(stralist,toremove); i++) + for (;i < genalloc_len(ss_resolve_t,&rdeps) ; i++) { - ss_resolve_init(&dres) ; - char *dname = gaistr(toremove,i) ; - sa.len = newlen ; - if (!stralloc_cats(&sa,dname)) retstralloc(0,"remove_sv") ; - if (!stralloc_0(&sa)) retstralloc(0,"remove_sv") ; - VERBO1 strerr_warni3x("Removing: ",dname," directory service") ; - if (rm_rf(sa.s) < 0) - { - VERBO1 strerr_warnwu2sys("remove: ", sa.s) ; - goto err ; - } - - if (!ss_resolve_read(&dres,src,dname)) + ss_resolve_t_ref pres = &genalloc_s(ss_resolve_t,&rdeps)[i] ; + char *string = pres->sa.s ; + char *name = string + pres->name ; + dst.len = newlen ; + if (!stralloc_cats(&dst,name)) goto err ; + if (!stralloc_0(&dst)) goto err ; + + VERBO2 strerr_warni2x("delete directory service of: ",name) ; + if (rm_rf(dst.s) < 0) { - VERBO1 strerr_warnwu2sys("read resolve file of: ",dname) ; + VERBO1 strerr_warnwu2sys("delete directory service: ",dst.s) ; goto err ; } - dres.disen = 0 ; - dres.reload = 0 ; - dres.init = 0 ; - dres.unsupervise = 1 ; - VERBO2 strerr_warni2x("Write resolve file of: ",dname) ; - if (!ss_resolve_write(&dres,src,dname)) + /** modify the resolve file for 66-stop*/ + ss_resolve_setflag(pres,SS_FLAGS_DISEN,SS_FLAGS_FALSE) ; + ss_resolve_setflag(pres,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(pres,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + ss_resolve_setflag(pres,SS_FLAGS_UNSUPERVISE,SS_FLAGS_TRUE) ; + + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(pres,src,name,SS_SIMPLE)) { - VERBO1 strerr_warnwu2sys("write resolve file of: ",dname) ; + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; goto err ; } - if (dres.logger) - { - sa.len = newlen ; - if (!stralloc_cats(&sa,dres.sa.s + dres.logger)) retstralloc(0,"remove_sv") ; - if (!stralloc_0(&sa)) retstralloc(0,"remove_sv") ; - VERBO1 strerr_warni3x("Removing: ",dres.sa.s + dres.logger," directory service") ; - if (rm_rf(sa.s) < 0) - { - VERBO1 strerr_warnwu2sys("remove: ", sa.s) ; - goto err ; - } - VERBO2 strerr_warni2x("Write logger resolve file of: ",dname) ; - if (!ss_resolve_setlognwrite(&dres,src)) - { - VERBO1 strerr_warnwu2sys("write logger resolve file of: ",dname) ; - goto err ; - } - } - + if (!ss_resolve_cmp(tostop,name)) + if (!genalloc_append(ss_resolve_t,tostop,pres)) goto err ; } - - graph_free(&g) ; - stralloc_free(&sagraph) ; - genalloc_deepfree(stralist,&tokeep,stra_free) ; - stralloc_free(&sa) ; - ss_resolve_free(&dres) ; + + stralloc_free(&dst) ; return 1 ; err: - graph_free(&g) ; - stralloc_free(&sagraph) ; - genalloc_deepfree(stralist,&tokeep,stra_free) ; - stralloc_free(&sa) ; - ss_resolve_free(&dres) ; + stralloc_free(&dst) ; return 0 ; } @@ -216,9 +124,7 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse stralloc workdir = STRALLOC_ZERO ; - genalloc tostop = GENALLOC_ZERO ;//stralist - - ss_resolve_t res = RESOLVE_ZERO ; + genalloc tostop = GENALLOC_ZERO ;//ss_resolve_t graph_t g = GRAPH_ZERO ; stralloc sagraph = STRALLOC_ZERO ; @@ -248,70 +154,47 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse if (!tree_copy(&workdir,info->tree.s,info->treename.s)) strerr_diefu1sys(111,"create tmp working directory") ; + for(;*argv;argv++) { - - for(;*argv;argv++) + ss_resolve_t res = RESOLVE_ZERO ; + char const *name = *argv ; + logname = 0 ; + if (obstr_equal(name,SS_MASTER + 1)) { - char const *name = *argv ; - logname = 0 ; - if (obstr_equal(name,SS_MASTER + 1)) - { - cleanup(workdir.s) ; - strerr_dief1x(110,"nice try peon") ; - } - ss_resolve_init(&res) ; - logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if (logname > 0) - { - cleanup(workdir.s) ; - strerr_dief1x(110,"logger detected - disabling is not allowed") ; - } - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) - { - cleanup(workdir.s) ; - strerr_dief2x(110,name," is not enabled") ; - } - if (!ss_resolve_read(&res,workdir.s,name)) - { cleanup(workdir.s) ; - strerr_diefu2sys(111,"read resolve file of: ",name) ; - } - - if (!res.disen) - { - strerr_warni2x(name,": is already disabled") ; - continue ; - } - - if (res.type == CLASSIC) - { - if (!svc_remove(&tostop,&res,workdir.s)) - { - cleanup(workdir.s) ; - strerr_diefu3sys(111,"remove",name," directory service") ; - } - if (!stra_add(&tostop,name)) - { - cleanup(workdir.s) ; - retstralloc(111,"main") ; - } - nclassic++ ; - } - else if (res.type >= BUNDLE) - { - if (!stra_cmp(&tostop,name)) - { - if (!rc_remove(&tostop,&res,workdir.s)) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"disable: ",name) ; - } - } - nlongrun++ ; - } + strerr_dief1x(110,"nice try peon") ; } + ss_resolve_init(&res) ; + logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; + if (logname > 0) + { + cleanup(workdir.s) ; + strerr_dief1x(110,"logger detected - disabling is not allowed") ; + } + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) + { + cleanup(workdir.s) ; + strerr_dief2x(110,name," is not enabled") ; + } + if (!ss_resolve_read(&res,workdir.s,name)) + { + cleanup(workdir.s) ; + strerr_diefu2sys(111,"read resolve file of: ",name) ; + } + + if (!res.disen) + { + VERBO1 strerr_warni2x(name,": is already disabled") ; + continue ; + } + if (!svc_remove(&tostop,&res,workdir.s,info)) + { + cleanup(workdir.s) ; + strerr_diefu3sys(111,"remove",name," directory service") ; + } + if (res.type == CLASSIC) nclassic++ ; + else nlongrun++ ; } - ss_resolve_free(&res) ; if (nclassic) { @@ -325,7 +208,6 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse if (nlongrun) { - r = graph_type_src(&tokeep,workdir.s,1) ; if (!r) { @@ -360,7 +242,7 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse } } genalloc_reverse(stralist,&master) ; - if (!db_write_master(info,&master,workdir.s)) + if (!db_write_master(info,&master,workdir.s,SS_SIMPLE)) { cleanup(workdir.s) ; strerr_diefu2x(111,"update bundle: ", SS_MASTER) ; @@ -388,8 +270,7 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse } cleanup(workdir.s) ; - workdir.len = 0 ; - + stralloc_free(&workdir) ; /** graph allocation */ graph_free(&g) ; @@ -397,35 +278,32 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse genalloc_deepfree(stralist,&master,stra_free) ; genalloc_deepfree(stralist,&tokeep,stra_free) ; - if (stop && genalloc_len(stralist,&tostop)) + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&tostop); i++) + VERBO1 strerr_warni2x("Disabled successfully: ",genalloc_s(ss_resolve_t,&tostop)[i].sa.s + genalloc_s(ss_resolve_t,&tostop)[i].name) ; + + if (stop && genalloc_len(ss_resolve_t,&tostop)) { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostop) ; i++) - { - char *name = gaistr(&tostop,i) ; - int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if (logname > 0) - if (!stra_remove(&tostop,name)) strerr_diefu1sys(111,"logger from the list to stop") ; - } - int nargc = 3 + genalloc_len(stralist,&tostop) ; + + int nargc = 3 + genalloc_len(ss_resolve_t,&tostop) ; char const *newargv[nargc] ; unsigned int m = 0 ; newargv[m++] = "fake_name" ; newargv[m++] = "-u" ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostop); i++) - newargv[m++] = gaistr(&tostop,i) ; + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&tostop); i++) + newargv[m++] = genalloc_s(ss_resolve_t,&tostop)[i].sa.s + genalloc_s(ss_resolve_t,&tostop)[i].name ; newargv[m++] = 0 ; if (ssexec_stop(nargc,newargv,envp,info)) { - genalloc_deepfree(stralist,&tostop,stra_free) ; + genalloc_deepfree(ss_resolve_t,&tostop,ss_resolve_free) ; return 111 ; } } - genalloc_deepfree(stralist,&tostop,stra_free) ; + genalloc_deepfree(ss_resolve_t,&tostop,ss_resolve_free) ; return 0 ; } diff --git a/src/lib66/ssexec_enable.c b/src/lib66/ssexec_enable.c index c1a98c47962af874fcd93faab3f898c0daf3a1d1..f6e3e17c2a3b8c7871af974365e436abd5b826a2 100644 --- a/src/lib66/ssexec_enable.c +++ b/src/lib66/ssexec_enable.c @@ -51,10 +51,13 @@ static unsigned int FORCE = 0 ; static void cleanup(char const *dst) { int e = errno ; - //rm_rf(dst) ; + rm_rf(dst) ; errno = e ; } - +static void check_identifier(char const *name) +{ + if (!memcmp(name,"Master",6)) strerr_dief3x(111,"service: ",name,": starts with reserved prefix") ; +} static int start_parser(char const *src,char const *svname,char const *tree, unsigned int *nbsv) { stralloc sasv = STRALLOC_ZERO ; @@ -124,27 +127,30 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex if (argc < 1) exitusage(usage_enable) ; - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to source") ; for(;*argv;argv++) { - ss_resolve_t_ref pres = &res ; - if (ss_resolve_check(info,*argv,SS_RESOLVE_SRC)) + check_identifier(*argv) ; + if (ss_resolve_check(info,*argv,SS_RESOLVE_LIVE)) { - if (!ss_resolve_read(pres,sares.s,*argv)) strerr_diefu2sys(111,"read resolve file of: ",*argv) ; + if (!ss_resolve_read(&res,sares.s,*argv)) strerr_diefu2sys(111,"read resolve file of: ",*argv) ; if (res.disen && !FORCE) { - VERBO1 strerr_warnw3x("ignoring: ",*argv," service: already enabled") ; - ss_resolve_free(pres) ; + VERBO1 strerr_warnw3x("Ignoring: ",*argv," service: already enabled") ; continue ; } } unsigned int found = 0 ; if (!ss_resolve_src(&gasrc,&sasrc,*argv,src,&found)) { - src = SS_SERVICE_PACKDIR ; + src = SS_SERVICE_SYSDIR ; if (!ss_resolve_src(&gasrc,&sasrc,*argv,src,&found)) - strerr_dief2sys(110,"unknow service: ",*argv) ; + { + src = SS_SERVICE_PACKDIR ; + if (!ss_resolve_src(&gasrc,&sasrc,*argv,src,&found)) + strerr_dief2sys(110,"unknow service: ",*argv) ; + } } } @@ -154,55 +160,40 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex for (unsigned int i = 0 ; i < genalloc_len(diuint32,&gasrc) ; i++) start_parser(sasrc.s + genalloc_s(diuint32,&gasrc)[i].right,sasrc.s + genalloc_s(diuint32,&gasrc)[i].left,info->tree.s,&nbsv) ; - + + if (!tree_copy(&workdir,info->tree.s,info->treename.s)) strerr_diefu1sys(111,"create tmp working directory") ; + + for (unsigned int i = 0; i < genalloc_len(sv_alltype,&gasv); i++) { + sv_alltype_ref sv = &genalloc_s(sv_alltype,&gasv)[i] ; + char *name = keep.s + sv->cname.name ; + r = write_services(info,sv, workdir.s,FORCE) ; + if (!r) + { + cleanup(workdir.s) ; + strerr_diefu2x(111,"write service: ",name) ; + } + if (r > 1) continue ; //service already added - if (!tree_copy(&workdir,info->tree.s,info->treename.s)) strerr_diefu1sys(111,"create tmp working directory") ; - - for (unsigned int i = 0; i < genalloc_len(sv_alltype,&gasv); i++) + VERBO2 strerr_warni2x("write resolve file of: ",name) ; + if (!ss_resolve_setnwrite(sv,info,workdir.s)) { - ss_resolve_t res = RESOLVE_ZERO ; - ss_resolve_init(&res) ; - sv_alltype_ref sv = &genalloc_s(sv_alltype,&gasv)[i] ; - r = write_services(sv, workdir.s,FORCE) ; - if (!r) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"write service: ",keep.s+sv->cname.name) ; - } - if (r > 1) continue ; //service already added - - if (sv->cname.itype > CLASSIC) - { - if (!stra_add(&tostart,keep.s + sv->cname.name)) - { - cleanup(workdir.s) ; - retstralloc(111,"main") ; - } - nlongrun++ ; - } - else if (sv->cname.itype == CLASSIC) - { - if (!stra_add(&tostart,keep.s + sv->cname.name)) - { - cleanup(workdir.s) ; - retstralloc(111,"main") ; - } - nclassic++ ; - } - VERBO2 strerr_warni2x("write resolve file of: ",keep.s + sv->cname.name) ; - if (!ss_resolve_setnwrite(&res,sv,info,workdir.s)) + cleanup(workdir.s) ; + strerr_diefu2x(111,"write revolve file for: ",name) ; + } + VERBO2 strerr_warni2x("Service written successfully: ", name) ; + if (!stra_cmp(&tostart,name)) + { + if (sv->cname.itype == CLASSIC) nclassic++ ; + else nlongrun++ ; + if (!stra_add(&tostart,name)) { cleanup(workdir.s) ; - strerr_diefu2x(111,"write revolve file for: ",keep.s + sv->cname.name) ; + retstralloc(111,"main") ; } - VERBO1 strerr_warni2x("Service written successfully: ", keep.s + sv->cname.name) ; - ss_resolve_free(&res) ; } - } - if (nclassic) { if (!svc_switch_to(info,SS_SWBACK)) @@ -244,7 +235,7 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex } } genalloc_reverse(stralist,&master) ; - if (!db_write_master(info,&master,workdir.s)) + if (!db_write_master(info,&master,workdir.s,SS_SIMPLE)) { cleanup(workdir.s) ; strerr_diefu2sys(111,"update bundle: ", SS_MASTER + 1) ; @@ -271,7 +262,7 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex } cleanup(workdir.s) ; - + freed: /** parser allocation*/ freed_parser() ; @@ -285,7 +276,10 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex genalloc_deepfree(stralist,&master,stra_free) ; stralloc_free(&sagraph) ; genalloc_deepfree(stralist,&tokeep,stra_free) ; - + + for (unsigned int i = 0 ; i < genalloc_len(stralist,&tostart); i++) + VERBO1 strerr_warni2x("Enabled successfully: ", gaistr(&tostart,i)) ; + if (start && genalloc_len(stralist,&tostart)) { int nargc = 2 + genalloc_len(stralist,&tostart) ; @@ -304,7 +298,6 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex genalloc_deepfree(stralist,&tostart,stra_free) ; return 111 ; } - } genalloc_deepfree(stralist,&tostart,stra_free) ; diff --git a/src/lib66/ssexec_init.c b/src/lib66/ssexec_init.c index d3a1c42b1ad19ae4b2f1981b9810ac7c8e31ddd6..77598970428c9fd859c3e06d7f2c1391910348a1 100644 --- a/src/lib66/ssexec_init.c +++ b/src/lib66/ssexec_init.c @@ -17,10 +17,12 @@ #include <stdlib.h> #include <oblibs/obgetopt.h> +#include <oblibs/string.h> #include <oblibs/error2.h> #include <oblibs/directory.h> #include <oblibs/types.h>//scan_mode #include <oblibs/stralist.h> +#include <oblibs/files.h> #include <skalibs/buffer.h> #include <skalibs/types.h> @@ -28,10 +30,6 @@ #include <skalibs/djbunix.h> #include <skalibs/direntry.h> -#include <s6/config.h> -#include <s6-rc/config.h> -#include <s6/s6-supervise.h> - #include <66/utils.h> #include <66/enum.h> #include <66/constants.h> @@ -41,6 +39,7 @@ #include <66/svc.h> #include <66/resolve.h> #include <66/ssexec.h> +#include <66/rc.h> #include <stdio.h> @@ -48,12 +47,11 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec { int r, db, classic, earlier ; - int wstat ; - pid_t pid ; - genalloc gasvc = GENALLOC_ZERO ; //stralist type - genalloc gares = GENALLOC_ZERO ; //ss_resolve_t type + stralloc ressrc = STRALLOC_ZERO ; + stralloc resdst = STRALLOC_ZERO ; + stralloc src = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; classic = db = earlier = 0 ; @@ -91,9 +89,33 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec svdirlen = info->tree.len + SS_SVDIRS_LEN ; memcpy(svdir + svdirlen, SS_SVC ,SS_SVC_LEN) ; svdir[svdirlen + SS_SVC_LEN] = 0 ; - - stralloc src = STRALLOC_ZERO ; + + /** resolve live dir*/ if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + + if (!stralloc_copy(&ressrc,&src)) retstralloc(111,"main") ; + ressrc.len--; + if (!stralloc_cats(&ressrc,SS_RESOLVE)) retstralloc(111,"main") ; + if (!stralloc_0(&ressrc)) retstralloc(111,"main") ; + + if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to source") ; + r = scan_mode(src.s,S_IFDIR) ; + if (r < 0) strerr_dief2x(111,src.s," conflicting format") ; + if (!r) + { + VERBO2 strerr_warni3x("create directory: ",src.s,SS_RESOLVE) ; + r = dir_create_under(src.s,SS_RESOLVE+1,0700) ; + if (!r) strerr_diefu3sys(111,"create directory: ",src.s,SS_RESOLVE) ; + } + if (!stralloc_copy(&resdst,&src)) retstralloc(111,"main") ; + resdst.len--; + if (!stralloc_cats(&resdst,SS_RESOLVE)) retstralloc(111,"main") ; + if (!stralloc_0(&resdst)) retstralloc(111,"main") ; + + if (!hiercopy(ressrc.s,resdst.s)) strerr_diefu4sys(111,"copy resolve file of: ",ressrc.s," to ",resdst.s) ; + + stralloc_free(&ressrc) ; + stralloc_free(&resdst) ; /** svc already initiated */ if (classic) { @@ -105,18 +127,18 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec VERBO1 strerr_warni3x("svc service of tree: ",info->treename.s," already initiated") ; goto follow ; } + for (i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) { char *name = gaistr(&gasvc,i) ; ss_resolve_t tmp = RESOLVE_ZERO ; - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2sys(110,"unknow service: ",name) ; + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2sys(110,"unknow service: ",name) ; if (!ss_resolve_read(&tmp,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (!genalloc_append(ss_resolve_t,&gares,&tmp)) strerr_diefu3x(111,"add: ",name," on genalloc") ; - + if (!ss_resolve_add_deps(&gares,&tmp,info)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; } - if (!ss_resolve_addlogger(info,&gares)) strerr_diefu1sys(111,"add logger to list") ; - + /** reverse to start first the logger */ + genalloc_reverse(ss_resolve_t,&gares) ; if (!earlier) { if (!svc_init(info,svdir,&gares)) strerr_diefu2x(111,"initiate service of tree: ",info->treename.s) ; @@ -135,6 +157,7 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec memcpy(tocopy + dirlen + 1, name, namelen) ; tocopy[dirlen + 1 + namelen] = 0 ; if (!hiercopy(tocopy,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) strerr_diefu4sys(111,"to copy: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ; + if (!file_create_empty(string + genalloc_s(ss_resolve_t,&gares)[i].runat,"earlier",0644)) strerr_diefu3sys(111,"mark ",string + genalloc_s(ss_resolve_t,&gares)[i].name," as earlier service") ; } } } @@ -144,6 +167,7 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec stralloc_free(&src) ; ss_resolve_free(&res) ; genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; + genalloc_deepfree(stralist,&gasvc,stra_free) ; /** db already initiated? */ if (db) @@ -159,49 +183,30 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec }else goto end ; { - char ltree[info->livetree.len + 1 + info->treename.len + 1] ; - memcpy(ltree,info->livetree.s,info->livetree.len) ; - ltree[info->livetree.len] = '/' ; - memcpy(ltree + info->livetree.len + 1, info->treename.s, info->treename.len) ; - ltree[info->livetree.len + 1 + info->treename.len] = 0 ; - - memcpy(svdir + svdirlen,SS_DB,SS_DB_LEN) ; - memcpy(svdir + svdirlen + SS_DB_LEN, "/", 1) ; - memcpy(svdir + svdirlen + SS_DB_LEN + 1, info->treename.s,info->treename.len) ; - svdir[svdirlen + SS_DB_LEN + 1 + info->treename.len] = 0 ; + if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_SRC)) + VERBO1 strerr_diefu1x(111,"set revolve pointer to source") ; - char prefix[info->treename.len + 1 + 1] ; - memcpy(prefix,info->treename.s,info->treename.len) ; - memcpy(prefix + info->treename.len, "-",1) ; - prefix[info->treename.len + 1] = 0 ; + if (!ss_resolve_check(info,SS_MASTER +1,SS_RESOLVE_SRC)) strerr_diefu1x(111,"find inner bundle -- please make a bug report") ; + if (!ss_resolve_read(&res,src.s,SS_MASTER + 1)) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + if (!clean_val(&gasvc,res.sa.s + res.deps)) strerr_diefu1sys(111,"clean dependencies of inner bundle") ; + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++) { - char const *newargv[10] ; - unsigned int m = 0 ; - - newargv[m++] = S6RC_BINPREFIX "s6-rc-init" ; - newargv[m++] = "-l" ; - newargv[m++] = ltree ; - newargv[m++] = "-c" ; - newargv[m++] = svdir ; - newargv[m++] = "-p" ; - newargv[m++] = prefix ; - newargv[m++] = "--" ; - newargv[m++] = info->scandir.s ; - newargv[m++] = 0 ; - - VERBO2 strerr_warni3x("initiate db ",svdir," ...") ; - - pid = child_spawn0(newargv[0],newargv,envp) ; - if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu2sys(111,"wait for ",newargv[0]) ; - - if (wstat) - strerr_diefu2x(111,"init db: ",svdir) ; + char *name = gaistr(&gasvc,i) ; + ss_resolve_t tmp = RESOLVE_ZERO ; + if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2sys(110,"unknow service: ",name) ; + if (!ss_resolve_read(&tmp,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; + if (!genalloc_append(ss_resolve_t,&gares,&tmp)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + if (!ss_resolve_add_deps(&gares,&tmp,info)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; } + + if (!rc_init(info,&gares,envp)) strerr_diefu2sys(111,"initiate db of tree: ",info->treename.s) ; + + genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; + genalloc_deepfree(stralist,&gasvc,stra_free) ; + ss_resolve_free(&res) ; + stralloc_free(&src) ; } end: - - genalloc_deepfree(stralist,&gasvc,stra_free) ; return 0 ; } diff --git a/src/lib66/ssexec_start.c b/src/lib66/ssexec_start.c index 9dd9fce8430303c13e283608c32373767866d180..219b14f2942e59593276edbbaa9871780129033e 100644 --- a/src/lib66/ssexec_start.c +++ b/src/lib66/ssexec_start.c @@ -61,85 +61,14 @@ static stralloc sares = STRALLOC_ZERO ; static genalloc nclassic = GENALLOC_ZERO ; //resolve_t type static genalloc nrc = GENALLOC_ZERO ; //resolve_t type -int write_start_resolve(ss_resolve_t *res,ssexec_t *info) -{ - s6_svstatus_t status = S6_SVSTATUS_ZERO ; - - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - { - strerr_warnwu1sys("set revolve pointer to source") ; - return 0 ; - } - char const *string = res->sa.s ; - char const *name = string + res->name ; - res->reload = 0 ; - res->init = 0 ; - res->run = 1 ; - res->unsupervise = 0 ; - if (res->type == CLASSIC || res->type == LONGRUN) - { - if (!s6_svstatus_read(string + res->runat,&status)) - { - VERBO1 strerr_warnwu2sys("read status of: ",name) ; - return 0 ; - } - res->pid = status.pid ; - } - VERBO2 strerr_warni2x("Write resolve file of: ",name) ; - if (!ss_resolve_write(res,sares.s,name)) - { - VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; - return 0 ; - } - if (res->logger) - { - VERBO2 strerr_warni2x("Write logger resolve file of: ",name) ; - if (!ss_resolve_setlognwrite(res,sares.s)) - { - VERBO1 strerr_warnwu2sys("write logger resolve file of: ",name) ; - return 0 ; - } - } - - return 1 ; -} -int svc_shutnremove(ssexec_t *info, genalloc *ga, char const *sig,char const *const *envp) -{ - if (!svc_send(info,ga,sig,envp)) - { - VERBO1 strerr_warnwu1x("shutdown list of services") ; - return 0 ; - } - - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) - { - char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; - VERBO2 strerr_warni2x("Delete: ", string + genalloc_s(ss_resolve_t,ga)[i].runat) ; - if (rm_rf(string + genalloc_s(ss_resolve_t,ga)[i].runat) < 0) - { - VERBO1 strerr_warnwu2sys("delete: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; - return 0 ; - } - } - - return 1 ; -} - int svc_start(ssexec_t *info,genalloc *ga,char const *const *envp) { - - /** reverse to start first the logger */ - genalloc_reverse(ss_resolve_t,ga) ; if (!svc_send(info,ga,SIG,envp)) { - VERBO1 strerr_warnwu1x("bring up services") ; + VERBO1 strerr_warnwu1x("start services") ; return 0 ; } - - for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) - if (!write_start_resolve(&genalloc_s(ss_resolve_t,ga)[i],info)) return 0 ; - - + return 1 ; } @@ -175,11 +104,7 @@ int svc_sanitize(ssexec_t *info,genalloc *ga, char const *const *envp) if (genalloc_len(ss_resolve_t,&toreload)) { - if (!svc_shutnremove(info,&toreload,"-D",envp)) - { - VERBO1 strerr_warnwu1x("down list of service") ; - goto err ; - } + if (!svc_unsupervise(info,&toreload,"-D",envp)) goto err ; genalloc_cat(ss_resolve_t,&toinit,&toreload) ; } if (!ss_resolve_pointo(&sares,info,CLASSIC,SS_RESOLVE_SRC)) @@ -189,8 +114,6 @@ int svc_sanitize(ssexec_t *info,genalloc *ga, char const *const *envp) } if (genalloc_len(ss_resolve_t,&toinit)) { - /** reverse to start first the logger */ - genalloc_reverse(ss_resolve_t,&toinit) ; if (!svc_init(info,sares.s,&toinit)) { VERBO1 strerr_warnwu1x("iniatiate svc service list") ; @@ -222,7 +145,7 @@ int rc_sanitize(ssexec_t *info,genalloc *ga, char const *const *envp) db[info->livetree.len + 1 + info->treename.len] = 0 ; if (!db_ok(info->livetree.s,info->treename.s)) - if (!rc_init(info,envp)) return 0 ; + if (!rc_init(info,ga,envp)) return 0 ; for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) @@ -258,13 +181,13 @@ int rc_sanitize(ssexec_t *info,genalloc *ga, char const *const *envp) if (!db_switch_to(info,envp,SS_SWSRC)) { - VERBO1 strerr_warnwu3x("switch ",info->treename.s," to backup") ; + VERBO1 strerr_warnwu3x("switch ",info->treename.s," to source") ; goto err ; } if (!rc_send(info,&toreload,"-d",envp)) { - VERBO1 strerr_warnwu1x("bring down services") ; + VERBO1 strerr_warnwu1x("stop services") ; goto err ; } } @@ -288,35 +211,31 @@ int rc_start(ssexec_t *info,genalloc *ga,char const *const *envp) if (!db_switch_to(info,envp,SS_SWSRC)) strerr_diefu3x(111,"switch: ",info->treename.s," to source") ; } - /** reverse to start first the logger */ - genalloc_reverse(ss_resolve_t,ga) ; + if (RELOAD == 1) s = "-r" ; else s = "-u" ; if (!rc_send(info,ga,s,envp)) { - VERBO1 strerr_warnwu1x("bring up services") ; + VERBO1 strerr_warnwu1x("start services") ; return 0 ; } - - - for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) - if (!write_start_resolve(&genalloc_s(ss_resolve_t,ga)[i],info)) return 0 ; - + return 1 ; } int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) { - // be sure that the global var are set correctly RELOAD = 0 ; - DEADLINE = 0 ; SIG = "-U" ; sares.len = 0 ; - ss_resolve_t_ref pres ; - + if (info->timeout) DEADLINE = info->timeout ; + int cl, rc, logname ; + genalloc gagen = GENALLOC_ZERO ; //ss_resolve_t + ss_resolve_t_ref pres ; + cl = rc = logname = 0 ; { @@ -340,83 +259,106 @@ int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexe if (argc < 1) exitusage(usage_start) ; - if (info->timeout) DEADLINE = info->timeout ; - if ((scandir_ok(info->scandir.s)) !=1 ) strerr_dief3sys(111,"scandir: ", info->scandir.s," is not running") ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to source") ; + + for (;*argv;argv++) { - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + char const *name = *argv ; + ss_resolve_t res = RESOLVE_ZERO ; + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2x(110,name," is not enabled") ; + else if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; + if (!genalloc_append(ss_resolve_t,&gagen,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + if (!ss_resolve_add_deps(&gagen,&res,info)) strerr_diefu2sys(111,"resolve recursive dependencies of: ",name) ; + } - for(;*argv;argv++) + stralloc_free(&sares) ; + + for(unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gagen) ; i++) + { + pres = &genalloc_s(ss_resolve_t,&gagen)[i] ; + char const *string = pres->sa.s ; + char const *name = string + pres->name ; + logname = 0 ; + size_t earlen = strlen(string + pres->runat) ; + char earlier[earlen + 8 + 1] ; + memcpy(earlier,string + pres->runat,earlen) ; + memcpy(earlier + earlen,"/earlier",8) ; + earlier[earlen + 8] = 0 ; + if (!access(earlier, F_OK)) + { + pres->disen = 1 ; + pres->run = 1 ; + unlink_void(earlier) ; + } + if (obstr_equal(name,SS_MASTER + 1)) goto run ; + /** always check if the daemon is present or not into the scandir + * it can be stopped from different manner (crash,66-scandir signal,..) + * without changing the corresponding resolve file */ + if (pres->type == LONGRUN || pres->type == CLASSIC) { - char const *name = *argv ; - logname = 0 ; - - ss_resolve_t res = RESOLVE_ZERO ; - pres = &res ; - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2x(111,name,": is not enabled") ; - if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (!res.disen && res.run) + if (!s6_svc_ok(string + pres->runat)) { - VERBO1 strerr_warnw3x("service: ",name," was disabled, you can only stop it") ; - continue ; + pres->init = 1 ; + pres->run = 0 ; } - else if (!res.disen) strerr_dief2x(111,name,": is not enabled") ; - - logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if ((RELOAD > 1) && (logname > 0)) strerr_dief1x(111,"-R signal is not allowed to a logger") ; - if (RELOAD > 1) res.reload = 1 ; - /** always check if the daemon is present or not into the scandir - * it can be stopped from different manner (crash,66-scandir signal,..) - * without changing the corresponding resolve file */ - if (!s6_svc_ok(res.sa.s + res.runat)) res.init = 1 ; - else res.init = 0 ; - - if (res.init) res.reload = 0 ; - - if (res.type == CLASSIC) + else { - if (!genalloc_append(ss_resolve_t,&nclassic,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; - if (!ss_resolve_setlognwrite(&res,sares.s)) strerr_diefu2sys(111,"set logger of: ",name) ; - if (!ss_resolve_addlogger(info,&nclassic)) strerr_diefu2sys(111,"add logger of: ",name) ; - cl++ ; - } - else - { - if (!genalloc_append(ss_resolve_t,&nrc,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; - if (!ss_resolve_setlognwrite(&res,sares.s)) strerr_diefu2sys(111,"set logger of: ",name) ; - if (!ss_resolve_addlogger(info,&nrc)) strerr_diefu2sys(111,"add logger of: ",name) ; - rc++; + pres->init = 0 ; + pres->run = 1 ; } } - stralloc_free(&sares) ; + if (!pres->disen && pres->run){ VERBO1 strerr_dief3x(111,"service: ",name," was disabled, you can only stop it") ; } + else if (!pres->disen) strerr_dief2x(111,name,": is not enabled") ; + + logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; + if (RELOAD > 1) + { + if (logname > 0 && (!ss_resolve_cmp(&gagen,string + pres->logassoc))) strerr_dief1x(111,"-R signal is not allowed to a logger") ; + } + if (RELOAD > 1) pres->reload = 1 ; + + if (pres->init) pres->reload = 0 ; + + run: + if (pres->type == CLASSIC) + { + if (!genalloc_append(ss_resolve_t,&nclassic,pres)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + cl++ ; + } + else + { + if (!genalloc_append(ss_resolve_t,&nrc,pres)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + rc++; + } } - if (!cl && !rc) ss_resolve_free(pres) ; + if (cl) { - VERBO2 strerr_warni1x("sanitize classic services ...") ; + VERBO2 strerr_warni1x("sanitize classic services list...") ; if(!svc_sanitize(info,&nclassic,envp)) - strerr_diefu1x(111,"sanitize classic services") ; - VERBO1 strerr_warni1x("start classic services ...") ; + strerr_diefu1x(111,"sanitize classic services list") ; + VERBO2 strerr_warni1x("start classic services list ...") ; if(!svc_start(info,&nclassic,envp)) - strerr_diefu1x(111,"start classic services") ; - VERBO2 strerr_warni3x("switch classic service of: ",info->treename.s," to source") ; + strerr_diefu1x(111,"start classic services list") ; + VERBO2 strerr_warni3x("switch classic service list of: ",info->treename.s," to source") ; if (!svc_switch_to(info,SS_SWSRC)) - strerr_diefu3x(111,"switch classic service of: ",info->treename.s," to source") ; + strerr_diefu3x(111,"switch classic service list of: ",info->treename.s," to source") ; genalloc_deepfree(ss_resolve_t,&nclassic,ss_resolve_free) ; } if (rc) { - VERBO2 strerr_warni1x("sanitize atomic services ...") ; + VERBO2 strerr_warni1x("sanitize atomic services list...") ; if (!rc_sanitize(info,&nrc,envp)) - strerr_diefu1x(111,"sanitize atomic services") ; - VERBO1 strerr_warni1x("start atomic services ...") ; + strerr_diefu1x(111,"sanitize atomic services list") ; + VERBO2 strerr_warni1x("start atomic services list ...") ; if (!rc_start(info,&nrc,envp)) - strerr_diefu1x(111,"update atomic services") ; - VERBO2 strerr_warni3x("switch atomic services of: ",info->treename.s," to source") ; + strerr_diefu1x(111,"start atomic services list ") ; + VERBO2 strerr_warni3x("switch atomic services list of: ",info->treename.s," to source") ; if (!db_switch_to(info,envp,SS_SWSRC)) - strerr_diefu5x(111,"switch",info->livetree.s,"/",info->treename.s," to source") ; + strerr_diefu3x(111,"switch atomic services list of: ",info->treename.s," to source") ; genalloc_deepfree(ss_resolve_t,&nrc,ss_resolve_free) ; } diff --git a/src/lib66/ssexec_stop.c b/src/lib66/ssexec_stop.c index e3ec4a5f7f1e2a9fee108cbb62d1d664db761d9a..f2cb5ba86420884c5ebbadc2dc9710ccc56c0202 100644 --- a/src/lib66/ssexec_stop.c +++ b/src/lib66/ssexec_stop.c @@ -58,42 +58,9 @@ static stralloc sares = STRALLOC_ZERO ; static genalloc nclassic = GENALLOC_ZERO ;//ss_resolve_t static genalloc nrc = GENALLOC_ZERO ;//ss_resolve_t -int write_stop_resolve(ss_resolve_t *res,ssexec_t *info) -{ - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - { - strerr_warnwu1sys("set revolve pointer to source") ; - return 0 ; - } - char const *string = res->sa.s ; - char const *name = string + res->name ; - res->reload = 0 ; - res->run = 1 ; - res->unsupervise = 0 ; - res->pid = 0 ; - VERBO2 strerr_warni2x("Write resolve file of: ",name) ; - if (!ss_resolve_write(res,sares.s,name)) - { - VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; - return 0 ; - } - if (res->logger) - { - VERBO2 strerr_warni2x("Write logger resolve file of: ",name) ; - if (!ss_resolve_setlognwrite(res,sares.s)) - { - VERBO1 strerr_warnwu2sys("write logger resolve file of: ",name) ; - return 0 ; - } - } - - return 1 ; -} - int svc_down(ssexec_t *info,genalloc *ga,char const *const *envp) { genalloc tounsup = GENALLOC_ZERO ; //stralist - ss_resolve_t_ref pres ; for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) @@ -113,45 +80,15 @@ int svc_down(ssexec_t *info,genalloc *ga,char const *const *envp) if (genalloc_len(ss_resolve_t,&tounsup)) { UNSUP = 1 ; - if (!svc_shutnremove(info,&tounsup,SIG,envp)) return 0 ; - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - { - strerr_warnwu1sys("set revolve pointer to source") ; - return 0 ; - } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&tounsup) ; i++) - { - char const *string = genalloc_s(ss_resolve_t,&tounsup)[i].sa.s ; - char const *name = string + genalloc_s(ss_resolve_t,&tounsup)[i].name ; - // do not remove the resolve file if the daemon was not disabled - if (genalloc_s(ss_resolve_t,&tounsup)[i].disen) - { - genalloc_s(ss_resolve_t,&tounsup)[i].init = 1 ; - if (!write_stop_resolve(&genalloc_s(ss_resolve_t,&tounsup)[i],info)) goto err ; - continue ; - } - int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if (logname > 0) continue ; - VERBO2 strerr_warni2x("Removing resolve file of: ",name) ; - if (!ss_resolve_rmfile(&genalloc_s(ss_resolve_t,&tounsup)[i],sares.s,name)) - { - VERBO1 strerr_warnwu2sys("remove resolve file of: ",name) ; - goto err ; - } - } + if (!svc_unsupervise(info,&tounsup,SIG,envp)) return 0 ; } else { if (!svc_send(info,ga,SIG,envp)) { - VERBO1 strerr_warnwu1x("bring down services") ; + VERBO1 strerr_warnwu1x("stop services") ; goto err ; } - for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) - { - genalloc_s(ss_resolve_t,ga)[i].init = 0 ; - if (!write_stop_resolve(&genalloc_s(ss_resolve_t,ga)[i],info)) goto err ; - } } genalloc_free(ss_resolve_t,&tounsup) ; @@ -161,13 +98,77 @@ int svc_down(ssexec_t *info,genalloc *ga,char const *const *envp) return 0 ; } +int rc_unsupervise(ssexec_t *info, genalloc *ga,char const *sig,char const *const *envp) +{ + int writein ; + + ss_resolve_t_ref pres ; + stralloc sares = STRALLOC_ZERO ; + + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; + + if (!rc_send(info,ga,sig,envp)) + { + VERBO1 strerr_warnwu1x("stop services") ; + goto err ; + } + if (!db_switch_to(info,envp,SS_SWSRC)) + { + VERBO1 strerr_warnwu3x("switch ",info->treename.s," to source") ; + goto err ; + } + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { + VERBO1 strerr_warnwu1sys("set revolve pointer to live") ; + return 0 ; + } + + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + { + pres = &genalloc_s(ss_resolve_t,ga)[i] ; + char const *string = pres->sa.s ; + char const *name = string + pres->name ; + // do not remove the resolve file if the daemon was not disabled + if (pres->disen) + { + ss_resolve_setflag(pres,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; + ss_resolve_setflag(pres,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(pres,sares.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + goto err ; + } + VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + continue ; + } + VERBO2 strerr_warni2x("Delete resolve file of: ",name) ; + if (!ss_resolve_rmfile(pres,sares.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("delete resolve file of: ",name) ; + goto err ; + } + VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + } + + return 1 ; + err: + stralloc_free(&sares) ; + return 0 ; +} int rc_down(ssexec_t *info,genalloc *ga,char const *const *envp) { genalloc tounsup = GENALLOC_ZERO ; //stralist - ss_resolve_t_ref pres ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { + VERBO1 strerr_warnwu1sys("set revolve pointer to source") ; + return 0 ; + } + for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) { pres = &genalloc_s(ss_resolve_t,ga)[i] ; @@ -184,41 +185,11 @@ int rc_down(ssexec_t *info,genalloc *ga,char const *const *envp) if (genalloc_len(ss_resolve_t,&tounsup)) { UNSUP = 1 ; - if (!rc_send(info,&tounsup,"-d",envp)) - { - VERBO1 strerr_warnwu1x("bring down services") ; - goto err ; - } - if (!db_switch_to(info,envp,SS_SWSRC)) + if (!rc_unsupervise(info,&tounsup,"-d",envp)) { - VERBO1 strerr_warnwu3x("switch ",info->treename.s," to backup") ; + VERBO1 strerr_warnwu1x("stop services") ; goto err ; } - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - { - strerr_warnwu1sys("set revolve pointer to source") ; - return 0 ; - } - for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&tounsup) ; i++) - { - char const *string = genalloc_s(ss_resolve_t,&tounsup)[i].sa.s ; - char const *name = string + genalloc_s(ss_resolve_t,&tounsup)[i].name ; - // not really necessary because unsup is ignored if the daemon was not disabled - if (genalloc_s(ss_resolve_t,&tounsup)[i].disen) - { - genalloc_s(ss_resolve_t,&tounsup)[i].init = 1 ; - if (!write_stop_resolve(&genalloc_s(ss_resolve_t,&tounsup)[i],info)) goto err ; - continue ; - } - int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if (logname > 0) continue ; - VERBO2 strerr_warni2x("Removing resolve file of: ",name) ; - if (!ss_resolve_rmfile(&genalloc_s(ss_resolve_t,&tounsup)[i],sares.s,name)) - { - VERBO1 strerr_warnwu2sys("remove resolve file of: ",name) ; - goto err ; - } - } } else { @@ -227,15 +198,9 @@ int rc_down(ssexec_t *info,genalloc *ga,char const *const *envp) VERBO1 strerr_warnwu1x("bring down services") ; goto err ; } - - for (unsigned int i = 0; i < genalloc_len(ss_resolve_t,ga) ; i++) - { - genalloc_s(ss_resolve_t,ga)[i].init = 0 ; - if (!write_stop_resolve(&genalloc_s(ss_resolve_t,ga)[i],info)) goto err ; - } } - genalloc_free(ss_resolve_t,&tounsup) ; + if (!UNSUP) genalloc_free(ss_resolve_t,&tounsup) ; return 1 ; err: genalloc_free(ss_resolve_t,&tounsup) ; @@ -245,15 +210,16 @@ int rc_down(ssexec_t *info,genalloc *ga,char const *const *envp) int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) { // be sure that the global var are set correctly - DEADLINE = 0 ; UNSUP = 0 ; SIG = "-D" ; sares.len = 0 ; + if (info->timeout) DEADLINE = info->timeout ; + int cl, rc, sigopt, mainunsup ; - + genalloc gagen = GENALLOC_ZERO ; //ss_resolve_t ss_resolve_t_ref pres ; - + cl = rc = sigopt = mainunsup = 0 ; { @@ -278,74 +244,83 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec if (argc < 1) exitusage(usage_stop) ; - if (info->timeout) DEADLINE = info->timeout ; - if ((scandir_ok(info->scandir.s)) !=1 ) strerr_dief3sys(111,"scandir: ", info->scandir.s," is not running") ; { - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to source") ; - for(;*argv;argv++) + for (;*argv;argv++) { char const *name = *argv ; - ss_resolve_t res = RESOLVE_ZERO ; - pres = &res ; - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2x(110,name," is not enabled") ; + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2x(110,name," is not enabled") ; else if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - + if (!genalloc_append(ss_resolve_t,&gagen,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; + if (!ss_resolve_add_rdeps(&gagen,&res,info)) strerr_diefu2sys(111,"resolve recursive dependencies of: ",name) ; + } + + stralloc_free(&sares) ; + + for(unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gagen) ; i++) + { + pres = &genalloc_s(ss_resolve_t,&gagen)[i] ; + char const *string = pres->sa.s ; + char const *name = string + pres->name ; + size_t earlen = strlen(string + pres->runat) ; + char earlier[earlen + 8 +1] ; + memcpy(earlier,string + pres->runat,earlen) ; + memcpy(earlier + earlen,"/earlier",8) ; + earlier[earlen + 8] = 0 ; + if (!access(earlier, F_OK)) + { + pres->run = 1 ; + unlink_void(earlier) ; + } int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; if (obstr_equal(name,SS_MASTER + 1)) goto run ; /** special case, enabling->starting->stopping->disabling * make an orphan service. * check if it's the case and force to stop it*/ - if (!res.run) strerr_dief2x(110,name," : is not running, try 66-start before") ; + if (!pres->run && pres->disen) strerr_dief2x(110,name," : is not running, try 66-start before") ; + if (!pres->unsupervise && !pres->disen) strerr_dief2x(110,name," : is not enabled") ; + /** always check if the daemon is present or not into the scandir * it can be stopped from different manner (crash,66-scandir signal,..) * without changing the corresponding resolve file */ - if (!s6_svc_ok(res.sa.s + res.runat)) strerr_dief2x(110,name," : is not running") ; + if (pres->type == LONGRUN || pres->type == CLASSIC) + { + if (!s6_svc_ok(string + pres->runat)) strerr_dief2x(110,name," : is not running") ; + } + /** logger cannot be unsupervised alone */ if (logname > 0) { - if (UNSUP) - { - strerr_warnw1x("logger detected - ignoring unsupervise request") ; - } - res.unsupervise = 0 ; + if (UNSUP && (!ss_resolve_cmp(&gagen,string + pres->logassoc))) strerr_dief1x(111,"logger detected - unsupervise request is not allowed") ; } - - if (UNSUP && res.type >= BUNDLE && !res.unsupervise) + if (UNSUP) pres->unsupervise = 1 ; + if (UNSUP && pres->type >= BUNDLE && !pres->unsupervise) { - strerr_warnw2x(get_keybyid(res.type)," detected - ignoring unsupervise request") ; - res.unsupervise = 0 ; - //UNSUP = 0 ; + VERBO1 strerr_warnw2x(get_keybyid(pres->type)," detected - ignoring unsupervise request") ; + pres->unsupervise = 0 ; } - - if (UNSUP) res.unsupervise = 1 ; - - run: - if (res.type == CLASSIC) + run: + if (pres->type == CLASSIC) { - if (!genalloc_append(ss_resolve_t,&nclassic,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; - if (!ss_resolve_setlognwrite(&res,sares.s)) strerr_diefu2sys(111,"set logger of: ",name) ; - if (!ss_resolve_addlogger(info,&nclassic)) strerr_diefu2sys(111,"add logger of: ",name) ; + if (!genalloc_append(ss_resolve_t,&nclassic,pres)) strerr_diefu3x(111,"add: ",name," on genalloc") ; cl++ ; } else { - if (!genalloc_append(ss_resolve_t,&nrc,&res)) strerr_diefu3x(111,"add: ",name," on genalloc") ; - if (!ss_resolve_setlognwrite(&res,sares.s)) strerr_diefu2sys(111,"set logger of: ",name) ; - if (!ss_resolve_addlogger(info,&nrc)) strerr_diefu2sys(111,"add logger of: ",name) ; + if (!genalloc_append(ss_resolve_t,&nrc,pres)) strerr_diefu3x(111,"add: ",name," on genalloc") ; rc++; } } - stralloc_free(&sares) ; } - if (!cl && !rc) ss_resolve_free(pres) ; + /** rc work */ if (rc) { - VERBO1 strerr_warni1x("stop atomic services ...") ; + VERBO2 strerr_warni1x("stop atomic services ...") ; if (!rc_down(info,&nrc,envp)) strerr_diefu1x(111,"update atomic services") ; VERBO2 strerr_warni3x("switch atomic services of: ",info->treename.s," to source") ; @@ -358,7 +333,7 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec /** svc work */ if (cl) { - VERBO1 strerr_warni1x("stop classic services ...") ; + VERBO2 strerr_warni1x("stop classic services ...") ; if (!svc_down(info,&nclassic,envp)) strerr_diefu1x(111,"update classic services") ; VERBO2 strerr_warni3x("switch classic services of: ",info->treename.s," to source") ; @@ -374,6 +349,6 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec if (scandir_send_signal(info->scandir.s,"an") <= 0) strerr_diefu2sys(111,"send signal to scandir: ", info->scandir.s) ; } - + return 0 ; } diff --git a/src/lib66/ssexec_svctl.c b/src/lib66/ssexec_svctl.c index ae709c6e40ea26d43a32e70178de3f8b4445b671..decd8a18108c5907840c9489404514952da90890 100644 --- a/src/lib66/ssexec_svctl.c +++ b/src/lib66/ssexec_svctl.c @@ -83,6 +83,8 @@ int handle_signal_svc(ss_resolve_sig_t *sv_signal) VERBO3 strerr_warnwu2sys("read status of: ",sv) ; return 0 ; } + sv_signal->pid = status.pid ; + if (WIFSIGNALED(status.wstat) && !WEXITSTATUS(status.wstat) && (WTERMSIG(status.wstat) == 15 )) return 1 ; if (!WIFSIGNALED(status.wstat) && !WEXITSTATUS(status.wstat)) return 1 ; else return 0 ; @@ -158,48 +160,49 @@ static const uint8_t chtenum[128] = * @Return 2 on fail * @Return 3 for PERMANENT failure */ -int handle_case(char c, ss_resolve_sig_t *sv_signal) +int handle_case(stralloc *sa, ss_resolve_sig_t *sv_signal) { int p, h, err ; - unsigned int state ; + unsigned int state, i = 0 ; state = sv_signal->sig ; err = 2 ; - p = chtenum[(unsigned char)c] ; - - unsigned char action = actions[state][p] ; - - switch (action) + for (;i < sa->len ; i++) { - case GOTIT: - h = handle_signal_svc(sv_signal) ; - - if (!h) - { + p = chtenum[(unsigned char)sa->s[i]] ; + + unsigned char action = actions[state][p] ; + + + switch (action) + { + case GOTIT: + h = handle_signal_svc(sv_signal) ; + if (!h) + { + err = 1 ; + break ; + } + err = 0 ; + return err ; + case WAIT: err = 1 ; break ; - } - err = 0 ; - break ; - case WAIT: - err = 1 ; - break ; - case DEAD: - err = 2 ; - break ; - case DONE: - err = 0 ; - break ; - case PERM: - err = 3 ; - break ; - case UKNOW: - default: - VERBO3 strerr_warnw1x("invalid state, make a bug report"); - err = 2 ; - break ; + case DEAD: + err = 2 ; + return err ; + case DONE: + err = 0 ; + return err ; + case PERM: + err = 3 ; + return err ; + default: + VERBO3 strerr_warnw1x("invalid state, make a bug report"); + err = 2 ; + return err ; + } } - return err ; } @@ -228,15 +231,18 @@ static void announce(ss_resolve_sig_t *sv_signal) int r = sv_signal->state ; char *sv = sv_signal->res.sa.s + sv_signal->res.runat ; - if (r == 3) { VERBO1 strerr_warnw3x(sv," report permanent failure to bring ",(sv_signal->sig > 1) ? "down" : "up") ; } - else if (r == 2) { VERBO1 strerr_warnwu3x("bring ", (sv_signal->sig > 3) ? "down " : "up ", sv) ; } - else if (r == 1) { VERBO1 strerr_warni4x(sv," is ",(sv_signal->sig > 3) ? "down" : "up"," but not notified by the daemon itself") ; } - else if (!r) { VERBO1 strerr_warni4x(sv,": ",(sv_signal->sig > 3) ? "stopped" : "started"," successfully") ; } + if (r == 3) { VERBO2 strerr_warnw3x(sv," report permanent failure -- unable to ",(sv_signal->sig > 1) ? "stop" : "start") ; } + else if (r == 2) { VERBO2 strerr_warnwu2x((sv_signal->sig > 3) ? "stop " : "start ", sv) ; } + else if (r == 1) { VERBO2 strerr_warni4x(sv," is ",(sv_signal->sig > 3) ? "down" : "up"," but not notified by the daemon itself") ; } + else if (!r) { VERBO2 strerr_warni4x(sv,": ",(sv_signal->sig > 3) ? "stopped" : "started"," successfully") ; } } int svc_listen(genalloc *gasv, ftrigr_t *fifo,int spfd,ss_resolve_sig_t *svc) { int r ; + + stralloc sa = STRALLOC_ZERO ; + iopause_fd x[2] = { { .fd = ftrigr_fd(fifo), .events = IOPAUSE_READ } , { .fd = spfd, .events = IOPAUSE_READ, .revents = 0 } } ; tain_t t ; @@ -247,21 +253,19 @@ int svc_listen(genalloc *gasv, ftrigr_t *fifo,int spfd,ss_resolve_sig_t *svc) for(;;) { - char receive ; - r = ftrigr_check(fifo,svc->ids, &receive) ; + r = ftrigr_checksa(fifo,svc->ids, &sa) ; if (r < 0) { VERBO3 strerr_warnwu1sys("ftrigr_check") ; return 0 ; } if (r) { - svc->state = handle_case(receive, svc) ; - if (svc->state < 0) return 0 ; - if (!svc->state){ announce(svc) ; break ; } - else if (svc->state > 2){ announce(svc) ; break ; } + svc->state = handle_case(&sa,svc) ; + if (!svc->state){ announce(svc) ; goto end ; } + else if (svc->state >= 2){ announce(svc) ; goto end ; } } if (!(svc->ndeath)) { VERBO2 strerr_warnw2x("number of try exceeded for: ",svc->res.sa.s + svc->res.runat) ; announce(svc) ; - break ; + goto end ; } r = iopause_g(x, 2, &t) ; @@ -277,8 +281,9 @@ int svc_listen(genalloc *gasv, ftrigr_t *fifo,int spfd,ss_resolve_sig_t *svc) svc->ndeath--; } } - - return 1 ; + end: + stralloc_free(&sa) ; + return svc->state ; } int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) @@ -289,18 +294,22 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe DEATHSV = 10 ; tain_t ttmain ; - int e, isup ; + int e, isup, ret,writein ; unsigned int death, tsv ; int SIGNAL = -1 ; genalloc gakeep = GENALLOC_ZERO ; //type ss_resolve_sig + genalloc resdeps = GENALLOC_ZERO ; //ss_resolve_t char *sig = 0 ; ftrigr_t fifo = FTRIGR_ZERO ; s6_svstatus_t status = S6_SVSTATUS_ZERO ; - tsv = death = 0 ; + tsv = death = ret = 0 ; + + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; //PROG = "66-svctl" ; { @@ -316,10 +325,10 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe case 'n' : if (!uint0_scan(l.arg, &death)) exitusage(usage_svctl) ; break ; case 'u' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGUP ; sig ="u" ; break ; case 'U' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGRUP ; sig = "uwU" ; break ; - case 'd' : if (SIGNAL > 0) ; SIGNAL = SIGDOWN ; sig = "d" ; break ; - case 'D' : if (SIGNAL > 0) ; SIGNAL = SIGRDOWN ; sig = "dwD" ; break ; case 'r' : if (SIGNAL > 0) ; SIGNAL = SIGR ; sig = "r" ; break ; case 'R' : if (SIGNAL > 0) ; SIGNAL = SIGRR ; sig = "rwR" ; break ; + case 'd' : if (SIGNAL > 0) ; SIGNAL = SIGDOWN ; sig = "d" ; break ; + case 'D' : if (SIGNAL > 0) ; SIGNAL = SIGRDOWN ; sig = "dwD" ; break ; case 'X' : if (SIGNAL > 0) ; SIGNAL = SIGX ; sig = "xd" ; break ; case 'K' : if (SIGNAL > 0) ; SIGNAL = SIGRDOWN ; sig = "kd" ; break ; @@ -332,37 +341,49 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe if (argc < 1 || (SIGNAL < 0)) exitusage(usage_svctl) ; if (info->timeout) tsv = info->timeout ; - - + if ((scandir_ok(info->scandir.s)) !=1 ) strerr_dief3sys(111,"scandir: ", info->scandir.s," is not running") ; stralloc src = STRALLOC_ZERO ; - if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + if (!ss_resolve_pointo(&src,info,SS_NOTYPE,SS_RESOLVE_LIVE)) strerr_diefu1sys(111,"set revolve pointer to source") ; + for(;*argv;argv++) { - ss_resolve_sig_t sv_signal = RESOLVE_SIG_ZERO ; + ss_resolve_t gres = RESOLVE_ZERO ; char const *name = *argv ; - if (!ss_resolve_check(info,name,SS_RESOLVE_SRC)) strerr_dief2sys(110,"unknow service: ",name) ; - if (!ss_resolve_read(&sv_signal.res,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (sv_signal.res.type >= BUNDLE) strerr_dief3x(111,name," has type ",get_keybyid(sv_signal.res.type)) ; + + if (!ss_resolve_check(info,name,SS_RESOLVE_LIVE)) strerr_dief2sys(111,"unknow service: ",name) ; + if (!ss_resolve_read(&gres,src.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; + if (gres.type >= BUNDLE) strerr_dief3x(111,name," has type ",get_keybyid(gres.type)) ; + + if (SIGNAL <= SIGRR) + { + if (!ss_resolve_add_deps(&resdeps,&gres,info)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; + } + else if (!ss_resolve_add_rdeps(&resdeps,&gres,info)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; + } + genalloc_reverse(ss_resolve_t,&resdeps) ; + for(unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&resdeps) ; i++) + { + ss_resolve_sig_t sv_signal = RESOLVE_SIG_ZERO ; + sv_signal.res = genalloc_s(ss_resolve_t,&resdeps)[i] ; char *string = sv_signal.res.sa.s ; char *svok = string + sv_signal.res.runat ; size_t svoklen = strlen(svok) ; char file[svoklen + 16 + 1] ; memcpy(file,svok,svoklen) ; - if (!s6_svstatus_read(svok,&status)) strerr_diefu2sys(111,"read status of: ",svok) ; isup = status.pid && !status.flagfinishing ; if (isup && (SIGNAL <= SIGRUP)) { - VERBO1 strerr_warni2x(svok,": already up") ; + VERBO1 strerr_warni2x("Already up: ",string + sv_signal.res.name) ; ss_resolve_free(&sv_signal.res) ; continue ; } else if (!isup && (SIGNAL >= SIGDOWN)) { - VERBO1 strerr_warni2x(svok,": already down") ; + VERBO1 strerr_warni2x("Already down: ",string + sv_signal.res.name) ; ss_resolve_free(&sv_signal.res) ; continue ; } @@ -479,11 +500,38 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111,"ignore SIGPIPE") ; if (!svc_init_pipe(&fifo,&gakeep)) strerr_diefu1x(111,"init pipe") ; - + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_sig_t,&gakeep) ; i++) { + int nret = 0 ; ss_resolve_sig_t *sv = &genalloc_s(ss_resolve_sig_t,&gakeep)[i] ; - if (!svc_listen(&gakeep,&fifo,spfd,sv)) strerr_diefu1x(111,"listen pipe") ; + char *name = sv->res.sa.s + sv->res.name ; + nret = svc_listen(&gakeep,&fifo,spfd,sv) ; + if (nret > 1) ret = 111 ; + if (sv->sig <= 3) + { + if (nret <= 1) + ss_resolve_setflag(&sv->res,SS_FLAGS_PID,(uint32_t)sv->pid) ; + else ss_resolve_setflag(&sv->res,SS_FLAGS_PID,SS_FLAGS_FALSE) ; + } + else + { + if (nret <=1) + ss_resolve_setflag(&sv->res,SS_FLAGS_PID,SS_FLAGS_FALSE) ; + /** wtf, the system can kill a process?? should never happen */ + else ss_resolve_setflag(&sv->res,SS_FLAGS_PID,(uint32_t)sv->pid) ; + } + ss_resolve_setflag(&sv->res,SS_FLAGS_RUN,SS_FLAGS_TRUE) ; + ss_resolve_setflag(&sv->res,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&sv->res,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + ss_resolve_setflag(&sv->res,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(&sv->res,src.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + ret = 111 ; + } + if (!nret) VERBO1 strerr_warni3x((sv->sig > 3) ? "Stopped" : "Started"," successfully: ",name) ; ss_resolve_free(&sv->res) ; } @@ -495,8 +543,8 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe ss_resolve_sig_t *sv = &genalloc_s(ss_resolve_sig_t,&gakeep)[i] ; if (!ftrigr_unsubscribe_g(&fifo, sv->ids, &ttmain)) { - VERBO3 strerr_warnwu1sys("unsubscribe to fifo of") ; - return 0 ; + VERBO3 strerr_warnwu2sys("unsubscribe to fifo of: ",sv->res.sa.s + sv->res.name) ; + ret = 111 ; } } @@ -508,7 +556,7 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe genalloc_deepfree(ss_resolve_sig_t,&gakeep,ss_resolve_free) ; - return 0 ; + return (ret > 1) ? 111 : 0 ; } diff --git a/src/lib66/svc_init.c b/src/lib66/svc_init.c index dbd7d059ea42b445f20bfed23d33551d7719add9..e844c9bc37fd33ffb9b63dcaaec830492266f454 100644 --- a/src/lib66/svc_init.c +++ b/src/lib66/svc_init.c @@ -42,21 +42,24 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) { - int r,logname ; + int logname, writein ; gid_t gid = getgid() ; uint16_t id ; ftrigr_t fifo = FTRIGR_ZERO ; genalloc gadown = GENALLOC_ZERO ; genalloc ids = GENALLOC_ZERO ; // uint16_t - + stralloc sares = STRALLOC_ZERO ; + tain_t deadline ; tain_now_g() ; tain_addsec(&deadline,&STAMP,2) ; - //VERBO3 strerr_warnt1x("iniate fifo") ; - if (!ftrigr_startf(&fifo, &deadline, &STAMP)) - return 0 ; + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; + + if (!ftrigr_startf(&fifo, &deadline, &STAMP)) + return 0 ; for (unsigned int i=0 ; i < genalloc_len(ss_resolve_t,ga); i++) { @@ -150,18 +153,12 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) if (!genalloc_append(uint16_t, &ids, &id)) goto err ; } VERBO3 strerr_warnt2x("reload scandir: ",info->scandir.s) ; - r = s6_svc_writectl(info->scandir.s, S6_SVSCAN_CTLDIR, "an", 2) ; - if (r < 0) + if (scandir_send_signal(info->scandir.s,"an") <= 0) { - VERBO3 strerr_warnw3sys("something is wrong with the ",info->scandir.s, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; + VERBO3 strerr_warnwu2sys("reload scandir: ",info->scandir.s) ; goto err ; } - if (!r) - { - VERBO3 strerr_warnw3x("scandir: ",info->scandir.s, " is not running, make a bug report") ; - goto err ; - } - + VERBO3 strerr_warnt1x("waiting for events on fifo") ; if (ftrigr_wait_and_g(&fifo, genalloc_s(uint16_t, &ids), genalloc_len(uint16_t, &ids), &deadline) < 0) goto err ; @@ -171,7 +168,25 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) VERBO3 strerr_warnt2x("Delete down file at: ",gaistr(&gadown,i)) ; if (unlink(gaistr(&gadown,i)) < 0 && errno != ENOENT) return 0 ; } - + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { + VERBO3 strerr_warnwu1x("set revolve pointer to live") ; + goto err ; + } + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + { + char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; + char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; + ss_resolve_setflag(&genalloc_s(ss_resolve_t,ga)[i],SS_FLAGS_INIT,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(&genalloc_s(ss_resolve_t,ga)[i],sares.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + goto err ; + } + VERBO1 strerr_warni2x("Initiated successfully: ",name) ; + } + ftrigr_end(&fifo) ; genalloc_deepfree(stralist,&gadown,stra_free) ; genalloc_free(uint16_t, &ids) ; diff --git a/src/lib66/svc_switch_to.c b/src/lib66/svc_switch_to.c index aa30ed5c4c4ce719d1b84ee2a62c1b92e16d4dd7..806ff4f309eee9f785be74c1452b921e2914efe9 100644 --- a/src/lib66/svc_switch_to.c +++ b/src/lib66/svc_switch_to.c @@ -54,25 +54,26 @@ int svc_switch_to(ssexec_t *info,unsigned int where) VERBO3 strerr_warnwu2sys("make a backup of svc service for: ",info->treename.s) ; return 0 ; } - VERBO3 strerr_warnt3x("switch svc service for tree: ",info->treename.s," to backup") ; + VERBO3 strerr_warnt3x("switch svc symlink of tree: ",info->treename.s," to backup") ; memcpy(cmd + cmdlen," -s1",4) ; cmd[cmdlen + 4] = 0 ; r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch svc service for: ",info->treename.s," to backup") ; + VERBO3 strerr_warnwu3sys("switch svc symlink of tree: ",info->treename.s," to backup") ; } } else if (r > 0 && !where) { - VERBO3 strerr_warnt3x("switch svc service for tree: ",info->treename.s," to source") ; + VERBO3 strerr_warnt3x("switch svc symlink of tree: ",info->treename.s," to source") ; memcpy(cmd + cmdlen," -s0",4) ; cmd[cmdlen + 4] = 0 ; r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch svc service for: ",info->treename.s," to source") ; + VERBO3 strerr_warnwu3sys("switch svc symlink of tree: ",info->treename.s," to source") ; } + VERBO3 strerr_warnt2x("make a backup of svc service for: ",info->treename.s) ; if (!backup_make_new(info,CLASSIC)) { diff --git a/src/lib66/svc_unsupervise.c b/src/lib66/svc_unsupervise.c new file mode 100644 index 0000000000000000000000000000000000000000..99bf823ffde7dcc69477c50c78e836a9f908abde --- /dev/null +++ b/src/lib66/svc_unsupervise.c @@ -0,0 +1,93 @@ +/* + * svc_unsupervise.c + * + * Copyright (c) 2018-2019 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <66/svc.h> + +#include <string.h> +#include <unistd.h>//access + +#include <oblibs/error2.h> + +#include <skalibs/genalloc.h> +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> + +#include <66/utils.h> +#include <66/resolve.h> +#include <66/ssexec.h> + +int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const *envp) +{ + int writein ; + + ss_resolve_t_ref pres ; + stralloc sares = STRALLOC_ZERO ; + + if (!access(info->tree.s,W_OK)) writein = SS_DOUBLE ; + else writein = SS_SIMPLE ; + + if (!svc_send(info,ga,sig,envp)) + { + VERBO1 strerr_warnwu1x("stop services") ; + goto err ; + } + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + { + char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; + VERBO2 strerr_warni2x("delete directory service: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; + if (rm_rf(string + genalloc_s(ss_resolve_t,ga)[i].runat) < 0) + { + VERBO1 strerr_warnwu2sys("delete: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; + goto err ; + } + } + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { + strerr_warnwu1sys("set revolve pointer to live") ; + goto err ; + } + for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) + { + pres = &genalloc_s(ss_resolve_t,ga)[i] ; + char const *string = pres->sa.s ; + char const *name = string + pres->name ; + // do not remove the resolve file if the daemon was not disabled + if (pres->disen) + { + ss_resolve_setflag(pres,SS_FLAGS_INIT,SS_FLAGS_TRUE) ; + ss_resolve_setflag(pres,SS_FLAGS_RUN,SS_FLAGS_FALSE) ; + VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + if (!ss_resolve_write(pres,sares.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + goto err ; + } + VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + continue ; + } + VERBO2 strerr_warni2x("Delete resolve file of: ",name) ; + if (!ss_resolve_rmfile(pres,sares.s,name,writein)) + { + VERBO1 strerr_warnwu2sys("delete resolve file of: ",name) ; + goto err ; + } + VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + } + stralloc_free(&sares) ; + return 1 ; + err: + stralloc_free(&sares) ; + return 0 ; +} + diff --git a/src/lib66/tree_copy_tmp.c b/src/lib66/tree_copy_tmp.c index 41fbeb038cde9e35d808791828806f79eef68d58..f84f6fc1b5f1f1eb90f0e9e552417874cc6d884c 100644 --- a/src/lib66/tree_copy_tmp.c +++ b/src/lib66/tree_copy_tmp.c @@ -18,6 +18,8 @@ #include <oblibs/string.h> #include <oblibs/error2.h> +#include <oblibs/directory.h> +#include <oblibs/types.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -35,10 +37,12 @@ void err(unsigned int *e, unsigned int msg,char const *resolve,char const *swap, break ; case 1: strerr_warnwu1x("set revolve pointer to backup") ; break ; - case 2: strerr_warnwu4sys("to copy tree: ",resolve," to ", swap) ; + case 2: strerr_warnwu4sys("copy : ",svdir," to ", resolve) ; break ; case 3: strerr_warnwu2sys("remove directory: ", svdir) ; break ; + case 4: strerr_warnwu1x("set revolve pointer to live") ; + break ; default: break ; } *e = 0 ; @@ -49,7 +53,9 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) stralloc saresolve = STRALLOC_ZERO ; stralloc swap = STRALLOC_ZERO ; unsigned int e = 1 ; + int r ; size_t svdirlen ; + size_t newlen ; char svdir[info->tree.len + SS_SVDIRS_LEN + SS_RESOLVE_LEN + 1] ; memcpy(svdir,info->tree.s,info->tree.len) ; @@ -58,6 +64,12 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) memcpy(svdir + svdirlen,SS_SVC, SS_SVC_LEN) ; svdir[svdirlen + SS_SVC_LEN] = 0 ; + size_t workdirlen = strlen(workdir) ; + char resolve[workdirlen + SS_RESOLVE_LEN + 1] ; + memcpy(resolve,workdir,workdirlen) ; + memcpy(resolve + workdirlen, SS_RESOLVE,SS_RESOLVE_LEN) ; + resolve[workdirlen + SS_RESOLVE_LEN] = 0 ; + /** svc */ if (rm_rf(svdir) < 0) { @@ -135,7 +147,8 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) err(&e,3,saresolve.s,swap.s,svdir) ; goto err ; } - + + svdir[svdirlen] = 0 ; if (!hiercopy(workdir,svdir)) @@ -155,10 +168,66 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) err(&e,2,saresolve.s,swap.s,svdir) ; goto err ; } - err(&e,3,saresolve.s,swap.s,svdir) ; + err(&e,2,saresolve.s,swap.s,svdir) ; + goto err ; + } + + /** resolve in live */ + if (!ss_resolve_pointo(&saresolve,info,SS_NOTYPE,SS_RESOLVE_LIVE)) + { + err(&e,0,saresolve.s,swap.s,resolve) ; + goto err ; + } + newlen = saresolve.len ; + saresolve.len--; + if (!stralloc_cats(&saresolve,SS_RESOLVE)) goto err ; + if (!stralloc_0(&saresolve)) goto err ; + + r = scan_mode(saresolve.s,S_IFDIR) ; + if (r < 0) strerr_dief2x(111,resolve," conflicting format") ; + if (!r) + { + saresolve.len = newlen ; + if (!stralloc_0(&saresolve)) goto err ; + VERBO2 strerr_warni3x("create directory: ",saresolve.s,SS_RESOLVE+1) ; + r = dir_create_under(saresolve.s,SS_RESOLVE+1,0700) ; + if (!r) strerr_diefu3sys(111,"create directory: ",saresolve.s,SS_RESOLVE+1) ; + } + saresolve.len = newlen ; + if (!stralloc_cats(&saresolve,SS_RESOLVE)) goto err ; + if (!stralloc_0(&saresolve)) goto err ; + + if (!ss_resolve_pointo(&swap,info,SS_NOTYPE,SS_RESOLVE_BACK)) + { + err(&e,1,saresolve.s,swap.s,resolve) ; + goto err ; + } + swap.len--; + if (!stralloc_cats(&swap,SS_RESOLVE)) goto err ; + if (!stralloc_0(&swap)) goto err ; + + if (rm_rf(saresolve.s) < 0) + { + if (!hiercopy(swap.s,saresolve.s)) + { + err(&e,2,saresolve.s,swap.s,resolve) ; + goto err ; + } + err(&e,2,saresolve.s,swap.s,resolve) ; goto err ; } + if (!hiercopy(resolve,saresolve.s)) + { + + if (!hiercopy(swap.s,saresolve.s)) + { + err(&e,2,saresolve.s,swap.s,resolve) ; + goto err ; + } + err(&e,2,saresolve.s,swap.s,resolve) ; + goto err ; + } err: stralloc_free(&saresolve) ; stralloc_free(&swap) ;