From 301a9e82dc808636377f1b129fd28321b6474025 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Thu, 12 Dec 2019 16:46:21 +1100 Subject: [PATCH] pass to new log_? function familly --- src/66/66-all.c | 121 ++++--- src/66/66-boot.c | 32 +- src/66/66-dbctl.c | 4 +- src/66/66-disable.c | 4 +- src/66/66-enable.c | 4 +- src/66/66-env.c | 4 +- src/66/66-hpr.c | 25 +- src/66/66-info.c | 14 +- src/66/66-init.c | 4 +- src/66/66-inservice.c | 140 ++++---- src/66/66-intree.c | 112 +++---- src/66/66-parser.c | 72 ++-- src/66/66-scanctl.c | 36 +- src/66/66-scandir.c | 119 ++++--- src/66/66-shutdown.c | 53 +-- src/66/66-shutdownd.c | 76 +++-- src/66/66-start.c | 4 +- src/66/66-stop.c | 4 +- src/66/66-svctl.c | 4 +- src/66/66-tree.c | 248 +++++++------- src/66/deps-exe/66-hpr | 1 + src/66/deps-exe/66-shutdown | 1 + src/extra-tools/66-echo.c | 9 +- src/extra-tools/66-umountall.c | 13 +- src/extra-tools/deps-exe/66-echo | 1 + src/extra-tools/deps-exe/66-umountall | 2 +- src/include/66/info.h | 6 +- src/include/66/utils.h | 8 +- src/lib66/backup_cmd_switcher.c | 44 +-- src/lib66/backup_make_new.c | 49 +-- src/lib66/backup_realpath_sym.c | 4 +- src/lib66/db_compile.c | 20 +- src/lib66/db_find_compiled_state.c | 15 +- src/lib66/db_switch_to.c | 36 +- src/lib66/db_update.c | 14 +- src/lib66/deps-lib/66 | 1 - src/lib66/hpr_wall.c | 1 - src/lib66/instance.c | 6 +- src/lib66/parser.c | 19 +- src/lib66/parser_enabled.c | 36 +- src/lib66/parser_utils.c | 180 ++++------ src/lib66/parser_write.c | 466 +++++++++----------------- src/lib66/rc_init.c | 44 +-- src/lib66/rc_manage.c | 12 +- src/lib66/rc_unsupervise.c | 20 +- src/lib66/resolve.c | 72 ++-- src/lib66/resolve_graph.c | 5 +- src/lib66/scandir_send_signal.c | 13 +- src/lib66/set_livedir.c | 10 +- src/lib66/set_livescan.c | 8 +- src/lib66/set_livestate.c | 10 +- src/lib66/set_livetree.c | 8 +- src/lib66/set_ownerhome.c | 8 +- src/lib66/set_ownersysdir.c | 14 +- src/lib66/ss_info_utils.c | 37 +- src/lib66/ss_utils.c | 17 - src/lib66/ssexec_dbctl.c | 90 ++--- src/lib66/ssexec_disable.c | 111 +++--- src/lib66/ssexec_enable.c | 106 +++--- src/lib66/ssexec_env.c | 24 +- src/lib66/ssexec_init.c | 52 +-- src/lib66/ssexec_main.c | 44 +-- src/lib66/ssexec_start.c | 98 +++--- src/lib66/ssexec_stop.c | 68 ++-- src/lib66/ssexec_svctl.c | 139 ++++---- src/lib66/svc_init.c | 48 +-- src/lib66/svc_init_pipe.c | 22 +- src/lib66/svc_switch_to.c | 31 +- src/lib66/svc_unsupervise.c | 20 +- src/lib66/tree_cmd_state.c | 22 +- src/lib66/tree_copy.c | 1 - src/lib66/tree_copy_tmp.c | 20 +- src/lib66/tree_find_current.c | 4 +- src/lib66/tree_get_permissions.c | 1 - src/lib66/tree_sethome.c | 10 +- src/lib66/tree_switch_current.c | 2 +- 76 files changed, 1400 insertions(+), 1803 deletions(-) delete mode 100644 src/lib66/ss_utils.c diff --git a/src/66/66-all.c b/src/66/66-all.c index 2e864372..c00936a1 100644 --- a/src/66/66-all.c +++ b/src/66/66-all.c @@ -18,7 +18,7 @@ #include <fcntl.h> #include <stdio.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/obgetopt.h> #include <oblibs/types.h> #include <oblibs/string.h> @@ -34,7 +34,6 @@ #include <66/utils.h> #include <66/tree.h> -unsigned int VERBOSITY = 1 ; static unsigned int DEADLINE = 0 ; unsigned int trc = 0 ; #define USAGE "66-all [ -h ] [ -v verbosity ] [ -f ] [ -T timeout ] [ -l live ] [ -t tree ] up/down" @@ -54,7 +53,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } int doit(char const *tree,char const *treename,char const *live, unsigned int what,uid_t owner, char const *const *envp) @@ -80,7 +79,7 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh src[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + treenamelen] = 0 ; if (!sastr_dir_get(&dirlist,src,"init",S_IFREG)) - strerr_diefu2sys(111,"get init file from directory: ",src) ; + log_dieusys(LOG_EXIT_SYS,"get init file from directory: ",src) ; if (dirlist.len) { @@ -115,12 +114,12 @@ int doit(char const *tree,char const *treename,char const *live, unsigned int wh pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) { - VERBO3 strerr_warnwu2sys("wait for ",newargv[0]) ; + log_warnusys("wait for ",newargv[0]) ; goto err ; } if (wstat) goto err ; } - else VERBO1 strerr_warni3x("Empty tree: ",treename," -- nothing to do") ; + else log_info("Empty tree: ",treename," -- nothing to do") ; stralloc_free(&dirlist) ; return 1 ; @@ -141,8 +140,8 @@ static void redir_fd(void) dup2 (fd,2) ; fd_close(fd) ; - if (setsid() < 0) strerr_diefu1sys(111,"setsid") ; - if ((chdir("/")) < 0) strerr_diefu1sys(111,"chdir") ; + if (setsid() < 0) log_dieusys(LOG_EXIT_SYS,"setsid") ; + if ((chdir("/")) < 0) log_dieusys(LOG_EXIT_SYS,"chdir") ; ioctl(0,TIOCSCTTY,1) ; umask(022) ; @@ -175,82 +174,82 @@ int main(int argc, char const *const *argv,char const *const *envp) { int opt = getopt_args(argc,argv, ">hv:l:T:t:f", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; - if (!stralloc_0(&live)) retstralloc(111,"main") ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'l' : if (!stralloc_cats(&live,l.arg)) log_die_nomem("stralloc") ; + if (!stralloc_0(&live)) log_die_nomem("stralloc") ; break ; - case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) exitusage(USAGE) ; break ; + case 'T' : if (!uint0_scan(l.arg, &DEADLINE)) log_usage(USAGE) ; break ; case 't' : treename = l.arg ; break ; case 'f' : shut = 1 ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc != 1) exitusage(USAGE) ; + if (argc != 1) log_usage(USAGE) ; if (*argv[0] == 'u') what = 1 ; else if (*argv[0] == 'd') what = 0 ; - else exitusage(USAGE) ; + else log_usage(USAGE) ; owner = MYUID ; - if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; + if (!set_ownersysdir(&base,owner)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ; r = set_livedir(&live) ; - if (!r) retstralloc(111,"main") ; - if (r < 0 ) strerr_dief3x(111,"live: ",live.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if (r < 0 ) log_die(LOG_EXIT_SYS,"live: ",live.s," must be an absolute path") ; - if (!stralloc_copy(&scandir,&live)) retstralloc(111,"main") ; + if (!stralloc_copy(&scandir,&live))log_die_nomem("stralloc") ; r = set_livescan(&scandir,owner) ; - if (!r) retstralloc(111,"main") ; - if (r < 0 ) strerr_dief3x(111,"scandir: ",scandir.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if (r < 0 ) log_die(LOG_EXIT_SYS,"scandir: ",scandir.s," must be an absolute path") ; - if ((scandir_ok(scandir.s)) <= 0) strerr_dief3sys(111,"scandir: ", scandir.s," is not running") ; + if ((scandir_ok(scandir.s)) <= 0) log_die(LOG_EXIT_SYS,"scandir: ", scandir.s," is not running") ; - if (!stralloc_copy(&livetree,&live)) retstralloc(111,"main") ; + if (!stralloc_copy(&livetree,&live)) log_die_nomem("stralloc") ; r = set_livetree(&livetree,owner) ; - if (!r) retstralloc(111,"main") ; - if (r < 0 ) strerr_dief3x(111,"livetree: ",livetree.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if (r < 0 ) log_die(LOG_EXIT_SYS,"livetree: ",livetree.s," must be an absolute path") ; - char state[base.len + SS_SYSTEM_LEN + SS_STATE_LEN + 1] ; - memcpy(state,base.s,base.len) ; - memcpy(state + base.len,SS_SYSTEM,SS_SYSTEM_LEN) ; - memcpy(state + base.len + SS_SYSTEM_LEN, SS_STATE ,SS_STATE_LEN) ; + char ste[base.len + SS_SYSTEM_LEN + SS_STATE_LEN + 1] ; + memcpy(ste,base.s,base.len) ; + memcpy(ste + base.len,SS_SYSTEM,SS_SYSTEM_LEN) ; + memcpy(ste + base.len + SS_SYSTEM_LEN, SS_STATE ,SS_STATE_LEN) ; statelen = base.len + SS_SYSTEM_LEN + SS_STATE_LEN ; - state[statelen] = 0 ; + ste[statelen] = 0 ; - r = scan_mode(state,S_IFREG) ; - if (r < 0) strerr_dief2x(111,"conflict format for: ",state) ; - if (!r) strerr_diefu2sys(111,"find: ",state) ; + r = scan_mode(ste,S_IFREG) ; + if (r < 0) log_die(LOG_EXIT_SYS,"conflict format for: ",ste) ; + if (!r) log_dieusys(LOG_EXIT_SYS,"find: ",ste) ; /** only one tree?*/ if (treename) { - if (!stralloc_cats(&contents,treename)) strerr_diefu3x(111,"add: ", treename," as tree to start") ; - if (!stralloc_0(&contents)) retstralloc(111,"main") ; + if (!stralloc_cats(&contents,treename))log_dieu(LOG_EXIT_SYS,"add: ", treename," as tree to start") ; + if (!stralloc_0(&contents)) log_die_nomem("stralloc") ; } else { - statesize = file_get_size(state) ; + statesize = file_get_size(ste) ; - r = openreadfileclose(state,&contents,statesize) ; - if(!r) strerr_diefu2sys(111,"open: ", state) ; + r = openreadfileclose(ste,&contents,statesize) ; + if(!r) log_dieusys(LOG_EXIT_SYS,"open: ", ste) ; /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(&contents,"\n")) retstralloc(111,"main") ; - if (!stralloc_0(&contents)) retstralloc(111,"main") ; + if (!stralloc_cats(&contents,"\n")) log_die_nomem("stralloc") ; + if (!stralloc_0(&contents)) log_die_nomem("stralloc") ; if (!sastr_clean_element(&contents)) { - strerr_warni1x("nothing to do") ; + log_info("nothing to do") ; goto end ; } @@ -263,14 +262,14 @@ int main(int argc, char const *const *argv,char const *const *envp) dpid = fork() ; - if (dpid < 0) strerr_diefu1sys(111,"fork") ; + if (dpid < 0) log_dieusys(LOG_EXIT_SYS,"fork") ; else if (dpid > 0) { if (waitpid_nointr(dpid,&wstat, 0) < 0) - strerr_diefu1sys(111,"wait for child") ; + log_dieusys(LOG_EXIT_SYS,"wait for child") ; if (wstat) - strerr_dief1x(111,"child fail") ; + log_die(LOG_EXIT_SYS,"child fail") ; goto end ; @@ -284,34 +283,34 @@ int main(int argc, char const *const *argv,char const *const *envp) char *treename = contents.s + pos ; - if(!stralloc_cats(&tree,treename)) retstralloc(111,"main") ; - if(!stralloc_0(&tree)) retstralloc(111,"main") ; + if(!stralloc_cats(&tree,treename)) log_die_nomem("stralloc") ; + if(!stralloc_0(&tree)) log_die_nomem("stralloc") ; r = tree_sethome(&tree,base.s,owner) ; - if (r < 0 || !r) strerr_diefu2sys(111,"find tree: ", tree.s) ; + if (r < 0 || !r) log_dieusys(LOG_EXIT_SYS,"find tree: ", tree.s) ; if (!tree_get_permissions(tree.s,owner)) - strerr_dief2x(110,"You're not allowed to use the tree: ",tree.s) ; + log_die(LOG_EXIT_USER,"You're not allowed to use the tree: ",tree.s) ; /* we need to make an ugly check here, a tree might be empty. * 66-init will not complain about this but doit function will do. * So, we need to scan the tree before trying to start any service from it. * This check is a temporary one because the tree dependencies feature * will come on a near future and it will change this default behavior */ size_t newlen = tree.len ; - if (!stralloc_cats(&tree,SS_SVDIRS SS_SVC)) retstralloc(111,"main") ; - if (!stralloc_0(&tree)) retstralloc(111,"main") ; + if (!stralloc_cats(&tree,SS_SVDIRS SS_SVC)) log_die_nomem("stralloc") ; + if (!stralloc_0(&tree)) log_die_nomem("stralloc") ; - if (!sastr_dir_get(&ugly,tree.s,"",S_IFDIR)) strerr_diefu2x(111,"get classic services from: ",tree.s) ; + if (!sastr_dir_get(&ugly,tree.s,"",S_IFDIR)) log_dieu(LOG_EXIT_SYS,"get classic services from: ",tree.s) ; if (!ugly.len) { tree.len = newlen ; ugly.len = 0 ; - if (!stralloc_cats(&tree,SS_SVDIRS SS_DB SS_SRC)) retstralloc(111,"main") ; - if (!stralloc_0(&tree)) retstralloc(111,"main") ; - if (!sastr_dir_get(&ugly,tree.s,SS_MASTER+1,S_IFDIR)) strerr_diefu2sys(111,"get rc services from: ",tree.s) ; + if (!stralloc_cats(&tree,SS_SVDIRS SS_DB SS_SRC)) log_die_nomem("stralloc") ; + if (!stralloc_0(&tree)) log_die_nomem("stralloc") ; + if (!sastr_dir_get(&ugly,tree.s,SS_MASTER+1,S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get rc services from: ",tree.s) ; if (!ugly.len) { - strerr_warni3x("empty tree: ",treename," -- nothing to do") ; + log_info("empty tree: ",treename," -- nothing to do") ; goto end ; } } @@ -334,18 +333,18 @@ int main(int argc, char const *const *argv,char const *const *envp) pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu2sys(111,"wait for ",newargv[0]) ; + log_dieusys(LOG_EXIT_SYS,"wait for ",newargv[0]) ; if (wstat) - strerr_diefu2x(111,"initiate services of tree: ",treename) ; + log_dieu(LOG_EXIT_SYS,"initiate services of tree: ",treename) ; - VERBO3 strerr_warnt2x("reload scandir: ",scandir.s) ; + log_trace("reload scandir: ",scandir.s) ; if (scandir_send_signal(scandir.s,"an") <= 0) - strerr_diefu2sys(111,"reload scandir: ",scandir.s) ; + log_dieusys(LOG_EXIT_SYS,"reload scandir: ",scandir.s) ; } - if (!doit(tree.s,treename,live.s,what,owner,envp)) strerr_diefu3x(111,(what) ? "start" : "stop" , " services of tree: ",treename) ; + if (!doit(tree.s,treename,live.s,what,owner,envp)) log_dieu(LOG_EXIT_SYS,(what) ? "start" : "stop" , " services of tree: ",treename) ; } end: if (shut) diff --git a/src/66/66-boot.c b/src/66/66-boot.c index dbef3f05..aa19c272 100644 --- a/src/66/66-boot.c +++ b/src/66/66-boot.c @@ -21,7 +21,7 @@ #include <sys/mount.h> #include <sys/reboot.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/files.h> #include <oblibs/string.h> #include <oblibs/obgetopt.h> @@ -36,7 +36,6 @@ #include <66/config.h> #include <66/constants.h> -unsigned int VERBOSITY = 1 ; static mode_t mask = SS_BOOT_UMASK ; static unsigned int rescan = SS_BOOT_RESCAN ; static char const *skel = SS_SKEL_DIR ; @@ -66,16 +65,16 @@ static void sulogin(char const *msg,char const *arg) pid_t pid ; int wstat ; fd_close(0) ; - if (dup2(fdin,0) == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ; + if (dup2(fdin,0) == -1) log_dieu(LOG_EXIT_SYS,"duplicate stdin -- you are on your own") ; fd_close(fdin) ; - if (*msg) strerr_warnwu2x(msg,arg) ; + if (*msg) log_warnu(msg,arg) ; pid = child_spawn0(newarg[0],newarg,genv) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu1sys(111,"wait for sulogin -- you are on your own") ; + log_dieusys(LOG_EXIT_SYS,"wait for sulogin -- you are on your own") ; fdin=dup(0) ; - if (fdin == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ; + if (fdin == -1) log_dieu(LOG_EXIT_SYS,"duplicate stdin -- you are on your own") ; fd_close(0) ; - if (open("/dev/null",O_WRONLY)) strerr_diefu1x(111,"open /dev/null -- you are on your own") ; + if (open("/dev/null",O_WRONLY)) log_dieu(LOG_EXIT_SYS,"open /dev/null -- you are on your own") ; } static inline void info_help (void) @@ -123,7 +122,7 @@ static void parse_conf(void) /** value may be empty, in this case we use the default one */ if (!sastr_clean_element(&val)) { - strerr_warnwu3x("get value of: ",*p," -- keeps the default") ; + log_warnu("get value of: ",*p," -- keeps the default") ; continue ; } if (!sastr_rebuild_in_oneline(&val)) sulogin("rebuild line of value: ",val.s) ; @@ -255,7 +254,7 @@ int main(int argc, char const *const *argv,char const *const *envp) case 'd' : slashdev = l.arg ; break ; case 'b' : banner = l.arg ; break ; case 'l' : log_user = l.arg ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; @@ -263,7 +262,7 @@ int main(int argc, char const *const *argv,char const *const *envp) if (geteuid()) { errno = EPERM ; - strerr_dief1sys(100, "nice try, peon") ; + log_diesys(LOG_EXIT_USER, "nice try, peon") ; } fdin=dup(0) ; parse_conf() ; @@ -286,7 +285,7 @@ int main(int argc, char const *const *argv,char const *const *envp) if (slashdev) { - strerr_warni2x("Mount: ",slashdev) ; + log_info("Mount: ",slashdev) ; fd_close(1) ; fd_close(2) ; if (mount("dev", slashdev, "devtmpfs", MS_NOSUID | MS_NOEXEC, "") == -1) @@ -307,10 +306,10 @@ int main(int argc, char const *const *argv,char const *const *envp) { if (r && tmpfs) { - strerr_warni2x("Umount: ",fs) ; + log_info("Umount: ",fs) ; if (umount(fs) == -1) sulogin ("umount: ",fs ) ; } - strerr_warni2x("Mount: ",fs) ; + log_info("Mount: ",fs) ; if (mount("tmpfs", fs, "tmpfs", MS_NODEV | MS_NOSUID, "mode=0755") == -1) sulogin("mount: ",fs) ; } @@ -319,13 +318,13 @@ int main(int argc, char const *const *argv,char const *const *envp) /** create scandir */ { char const *t[] = { "-b", "-c", "-s", skel, "-L", log_user } ; - strerr_warni2x("Create live scandir at: ",live) ; + log_info("Create live scandir at: ",live) ; make_cmdline(SS_EXTBINPREFIX "66-scandir",t,6,"create live scandir at: ",live,envp) ; } /** initiate earlier service */ { char const *t[] = { "-t",tree,"classic" } ; - strerr_warni2x("Initiate earlier service of tree: ",tree) ; + log_info("Initiate earlier service of tree: ",tree) ; make_cmdline(SS_EXTBINPREFIX "66-init",t,3,"initiate earlier service of tree: ",tree,envp) ; } @@ -335,13 +334,14 @@ int main(int argc, char const *const *argv,char const *const *envp) } { - strerr_warni3x("Starts boot logger at: ",live,"/log/0") ; + log_info("Starts boot logger at: ",live,"/log/0") ; int fdr = open_read(fifo) ; if (fdr == -1) sulogin("open fifo: ",fifo) ; fd_close(1) ; if (open(fifo, O_WRONLY) != 1) sulogin("open fifo: ",fifo) ; fd_close(fdr) ; } + /** fork and starts scandir */ { static char const *newargv[7] ; diff --git a/src/66/66-dbctl.c b/src/66/66-dbctl.c index bef35c1a..615e41ae 100644 --- a/src/66/66-dbctl.c +++ b/src/66/66-dbctl.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-dbctl" ; diff --git a/src/66/66-disable.c b/src/66/66-disable.c index c0145de3..224d5c87 100644 --- a/src/66/66-disable.c +++ b/src/66/66-disable.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-disable" ; diff --git a/src/66/66-enable.c b/src/66/66-enable.c index 3e593e78..d66d5028 100644 --- a/src/66/66-enable.c +++ b/src/66/66-enable.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-enable" ; diff --git a/src/66/66-env.c b/src/66/66-env.c index 54dc6235..afd3c710 100644 --- a/src/66/66-env.c +++ b/src/66/66-env.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-env" ; diff --git a/src/66/66-hpr.c b/src/66/66-hpr.c index 5924dc2b..24a20acc 100644 --- a/src/66/66-hpr.c +++ b/src/66/66-hpr.c @@ -24,7 +24,8 @@ #include <utmpx.h> #include <sys/reboot.h> -#include <skalibs/strerr2.h> +#include <oblibs/log.h> + #include <skalibs/sgetopt.h> #include <skalibs/sig.h> #include <skalibs/tai.h> @@ -69,7 +70,7 @@ static inline void info_help (void) " -W: do not send a wall message\n" ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } int main (int argc, char const *const *argv) { @@ -97,31 +98,31 @@ int main (int argc, char const *const *argv) case 'w' : dowtmp = 2 ; break ; case 'W' : dowall = 0 ; break ; case 'b' : banner = l.arg ; break ; - default : strerr_dieusage(100,USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!banner) banner = HPR_WALL_BANNER ; - if (live && live[0] != '/') strerr_dief3x(110,"live: ",live," must be an absolute path") ; + if (live && live[0] != '/') log_die(LOG_EXIT_USER,"live: ",live," must be an absolute path") ; else live = SS_LIVE ; if (!what) - strerr_dief1x(110, "one of the -h, -p or -r options must be given") ; + log_die(LOG_EXIT_USER, "one of the -h, -p or -r options must be given") ; if (geteuid()) { errno = EPERM ; - strerr_dief1sys(110, "nice try, peon") ; + log_diesys(LOG_EXIT_USER, "nice try, peon") ; } if (force) { sync() ; reboot(what == 3 ? RB_AUTOBOOT : what == 2 ? RB_POWER_OFF : RB_HALT_SYSTEM) ; - strerr_diefu1sys(111, "reboot()") ; + log_dieusys(LOG_EXIT_SYS, "reboot()") ; } - if (!tain_now_g()) strerr_warnw1sys("get current time") ; + if (!tain_now_g()) log_warnsys("get current time") ; if (dowtmp) { struct utmpx utx = @@ -136,7 +137,7 @@ int main (int argc, char const *const *argv) if (gethostname(utx.ut_host, UT_HOSTSIZE) < 0) { utx.ut_host[0] = 0 ; - strerr_warnwu1sys("gethostname") ; + log_warnusys("gethostname") ; } else utx.ut_host[UT_HOSTSIZE - 1] = 0 ; @@ -145,13 +146,13 @@ int main (int argc, char const *const *argv) { struct timeval tv ; if (!timeval_from_tain(&tv, &STAMP)) - strerr_warnwu1sys("timeval_from_tain") ; + log_warnusys("timeval_from_tain") ; utx.ut_tv.tv_sec = tv.tv_sec ; utx.ut_tv.tv_usec = tv.tv_usec ; } #else if (!timeval_from_tain(&utx.ut_tv, &STAMP)) - strerr_warnwu1sys("timeval_from_tain") ; + log_warnusys("timeval_from_tain") ; #endif updwtmpx(_PATH_WTMP, &utx) ; @@ -165,7 +166,7 @@ int main (int argc, char const *const *argv) memcpy(tlive + livelen,INITCTL,INITCTL_LEN) ; tlive[livelen + INITCTL_LEN] = 0 ; if (!hpr_shutdown(tlive,what, &tain_zero, 0)) - strerr_diefu1sys(111, "notify 66-shutdownd") ; + log_dieusys(LOG_EXIT_SYS, "notify 66-shutdownd") ; } return 0 ; } diff --git a/src/66/66-info.c b/src/66/66-info.c index f2f1736f..069715ec 100644 --- a/src/66/66-info.c +++ b/src/66/66-info.c @@ -13,7 +13,7 @@ */ #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/buffer.h> @@ -26,7 +26,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } int main(int argc, char const *const *argv, char const *const *envp) @@ -43,23 +43,23 @@ int main(int argc, char const *const *argv, char const *const *envp) { int opt = getopt_args(2,argv, ">hTS", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; case 'T' : what = 0 ; break ; case 'S' : what = 1 ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } } - if (what == -1) exitusage(USAGE) ; + if (what == -1) log_usage(USAGE) ; if (!what) { - strerr_warnw1x("66-info is deprecated -- use 66-intree instead") ; + log_info("66-info is deprecated -- use 66-intree instead") ; } else if (what) { - strerr_warnw1x("66-info is deprecated -- use 66-inservice instead") ; + log_info("66-info is deprecated -- use 66-inservice instead") ; } return 0 ; diff --git a/src/66/66-init.c b/src/66/66-init.c index ec45d6ba..5cc172f3 100644 --- a/src/66/66-init.c +++ b/src/66/66-init.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-init" ; diff --git a/src/66/66-inservice.c b/src/66/66-inservice.c index f3f3026f..f228bc34 100644 --- a/src/66/66-inservice.c +++ b/src/66/66-inservice.c @@ -21,14 +21,13 @@ //#include <stdio.h> #include <oblibs/sastr.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/obgetopt.h> #include <oblibs/types.h> #include <oblibs/string.h> #include <oblibs/files.h> #include <oblibs/directory.h> -#include <skalibs/strerr2.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/lolstdio.h> @@ -46,7 +45,6 @@ #include <s6/s6-supervise.h> -unsigned int VERBOSITY = 1 ; static unsigned int REVERSE = 0 ; unsigned int MAXDEPTH = 1 ; static unsigned int GRAPH = 0 ; @@ -138,7 +136,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } char *print_nlog(char *str, int n) @@ -177,10 +175,10 @@ char *print_nlog(char *str, int n) static void info_display_string(char const *str) { if (!bprintf(buffer_1," %s",str)) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_name(char const *field, ss_resolve_t *res) @@ -207,8 +205,8 @@ static void info_get_status(ss_resolve_t *res) r = s6_svc_ok(res->sa.s + res->runat) ; if (r != 1) { - if (!bprintf(buffer_1,"%s%s%s",info_color->warning,"not running\n",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s",log_color->warning,"not running\n",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; return ; } char const *newargv[3] ; @@ -220,15 +218,15 @@ static void info_get_status(ss_resolve_t *res) pid = child_spawn0(newargv[0],newargv,ENVP) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu2sys(111,"wait for ",newargv[0]) ; + log_dieusys(LOG_EXIT_SYS,"wait for ",newargv[0]) ; if (wstat) - strerr_diefu2x(111,"status for service: ",res->sa.s + res->name) ; + log_dieu(LOG_EXIT_SYS,"status for service: ",res->sa.s + res->name) ; } else { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning,"nothing to display",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning,"nothing to display",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } } @@ -237,11 +235,11 @@ static void info_display_status(char const *field,ss_resolve_t *res) info_display_field_name(field) ; - if (!bprintf(buffer_1," %s%s%s%s",res->disen ? info_color->valid : info_color->error,res->disen ? "enabled" : "disabled",info_color->off,", ")) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1," %s%s%s%s",res->disen ? log_color->valid : log_color->error,res->disen ? "enabled" : "disabled",log_color->off,", ")) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; info_get_status(res) ; @@ -284,21 +282,21 @@ static void info_display_deps(char const *field, ss_resolve_t *res) if (GRAPH) { if (!bprintf(buffer_1," %s\n","/")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!info_graph_init(res,src.s,REVERSE, padding, STYLE)) - strerr_dief2x(111,"display graph of: ",res->sa.s + res->name) ; + log_dieu(LOG_EXIT_SYS,"display graph of: ",res->sa.s + res->name) ; goto freed ; } else { if (!bprintf(buffer_1,"%s"," ")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!sastr_clean_string(&salist,res->sa.s + res->deps)) - strerr_diefu1x(111,"build dependencies list") ; + log_dieu(LOG_EXIT_SYS,"build dependencies list") ; if (REVERSE) if (!sastr_reverse(&salist)) - strerr_diefu1x(111,"reverse dependencies list") ; + log_dieu(LOG_EXIT_SYS,"reverse dependencies list") ; info_display_list(field,&salist) ; goto freed ; } @@ -306,14 +304,14 @@ static void info_display_deps(char const *field, ss_resolve_t *res) if (GRAPH) { if (!bprintf(buffer_1," %s\n","/")) - strerr_diefu1sys(111,"write to stdout") ; - if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", STYLE->last, info_color->warning," no dependencies",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; + if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", STYLE->last, log_color->warning," no dependencies",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } else { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," no dependencies",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," no dependencies",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } freed: @@ -329,8 +327,8 @@ static void info_display_start(char const *field,ss_resolve_t *res) } else { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," nothing to display",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," nothing to display",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } } @@ -343,8 +341,8 @@ static void info_display_stop(char const *field,ss_resolve_t *res) } else { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," nothing to display",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," nothing to display",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } } @@ -368,8 +366,8 @@ static void info_display_envat(char const *field,ss_resolve_t *res) } empty: - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," environment was not set",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," environment was not set",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_envfile(char const *field,ss_resolve_t *res) @@ -380,14 +378,14 @@ static void info_display_envfile(char const *field,ss_resolve_t *res) stralloc sa = STRALLOC_ZERO ; char *name = res->sa.s + res->name ; char *src = res->sa.s + res->srconf ; - if (!file_readputsa(&sa,src,name)) strerr_diefu1sys(111,"read environment file") ; + if (!file_readputsa(&sa,src,name)) log_dieusys(LOG_EXIT_SYS,"read environment file") ; info_display_nline(field,sa.s) ; stralloc_free(&sa) ; return ; } empty: - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," environment was not set",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," environment was not set",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_logname(char const *field,ss_resolve_t *res) @@ -405,8 +403,8 @@ static void info_display_logname(char const *field,ss_resolve_t *res) return ; empty: - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," logger doesn't exist",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," logger doesn't exist",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_logdst(char const *field,ss_resolve_t *res) @@ -424,8 +422,8 @@ static void info_display_logdst(char const *field,ss_resolve_t *res) return ; empty: - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," logger doesn't exist",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," logger doesn't exist",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_logfile(char const *field,ss_resolve_t *res) @@ -446,18 +444,18 @@ static void info_display_logfile(char const *field,ss_resolve_t *res) scan[dstlen + 8] = 0 ; int r = scan_mode(scan,S_IFREG) ; - if (r < 0) { errno = EEXIST ; strerr_dief2sys(111,"conflicting format of: ",scan) ; } + if (r < 0) { errno = EEXIST ; log_diesys(LOG_EXIT_SYS,"conflicting format of: ",scan) ; } if (!r) { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->error," unable to find the log file",info_color->off)) + if (!bprintf(buffer_1,"%s%s%s\n",log_color->error," unable to find the log file",log_color->off)) goto err ; } else { - if (!file_readputsa(&log,res->sa.s + res->dstlog,"current")) strerr_diefu2sys(111,"read log file of: ",res->sa.s + res->name) ; + if (!file_readputsa(&log,res->sa.s + res->dstlog,"current")) log_dieusys(LOG_EXIT_SYS,"read log file of: ",res->sa.s + res->name) ; if (log.len < 10) { - if (!bprintf(buffer_1,"%s%s%s",info_color->warning," log file is empty \n",info_color->off)) goto err ; + if (!bprintf(buffer_1,"%s%s%s",log_color->warning," log file is empty \n",log_color->off)) goto err ; } else { @@ -473,11 +471,11 @@ static void info_display_logfile(char const *field,ss_resolve_t *res) return ; empty: - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," logger doesn't exist",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," logger doesn't exist",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; return ; err: - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_all(ss_resolve_t *res,int *what) @@ -497,7 +495,7 @@ static void info_parse_options(char const *str,int *what) size_t pos = 0 ; stralloc sa = STRALLOC_ZERO ; - if (!sastr_clean_string_wdelim(&sa,str,DELIM)) strerr_diefu1x(111,"parse options") ; + if (!sastr_clean_string_wdelim(&sa,str,DELIM)) log_dieu(LOG_EXIT_SYS,"parse options") ; unsigned int n = sastr_len(&sa), nopts = 0 , old ; checkopts(n) ; info_opts_map_t const *t ; @@ -512,7 +510,7 @@ static void info_parse_options(char const *str,int *what) if (obstr_equal(o,t->str)) what[nopts++] = t->id ; } - if (old == nopts) strerr_dief2x(111,"invalid option: ",o) ; + if (old == nopts) log_die(LOG_EXIT_SYS,"invalid option: ",o) ; } stralloc_free(&sa) ; @@ -531,7 +529,7 @@ int main(int argc, char const *const *argv, char const *const *envp) ss_resolve_t res = RESOLVE_ZERO ; stralloc satree = STRALLOC_ZERO ; - info_color = &no_color ; + log_color = &log_color_disable ; char const *svname = 0 ; char const *tname = 0 ; @@ -567,25 +565,25 @@ int main(int argc, char const *const *argv, char const *const *envp) { int opt = getopt_args(argc,argv, ">hv:co:grd:t:p:", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'c' : info_color = !isatty(1) ? &no_color : &use_color ; break ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'c' : log_color = !isatty(1) ? &log_color_disable : &log_color_enable ; break ; case 'o' : legacy = 0 ; info_parse_options(l.arg,what) ; break ; case 'g' : GRAPH = 1 ; break ; case 'r' : REVERSE = 1 ; break ; - case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) exitusage(USAGE) ; break ; + case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) log_usage(USAGE) ; break ; case 't' : tname = l.arg ; break ; - case 'p' : if (!uint0_scan(l.arg, &nlog)) exitusage(USAGE) ; break ; - default : exitusage(USAGE) ; + case 'p' : if (!uint0_scan(l.arg, &nlog)) log_usage(USAGE) ; break ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (!argc) exitusage(USAGE) ; + if (!argc) log_usage(USAGE) ; svname = *argv ; if (legacy) @@ -609,28 +607,28 @@ int main(int argc, char const *const *argv, char const *const *envp) STYLE = &graph_utf8; } - if (!set_ownersysdir(&src,owner)) strerr_diefu1sys(111, "set owner directory") ; + if (!set_ownersysdir(&src,owner)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ; if (!stralloc_cats(&src,SS_SYSTEM) || - !stralloc_0(&src)) exitstralloc("main") ; + !stralloc_0(&src)) log_die_nomem("stralloc") ; src.len-- ; if (!scan_mode(src.s,S_IFDIR)) { - strerr_warni1x("no tree exist yet") ; + log_info("no tree exist yet") ; goto freed ; } - if (!stralloc_cats(&src,"/")) exitstralloc("main") ; + if (!stralloc_cats(&src,"/")) log_die_nomem("stralloc") ; newlen = src.len ; if (!tname) { stralloc tmp = STRALLOC_ZERO ; if (!stralloc_0(&src) || - !stralloc_copy(&tmp,&src)) exitstralloc("main") ; + !stralloc_copy(&tmp,&src)) log_die_nomem("stralloc") ; if (!sastr_dir_get(&satree, src.s,SS_BACKUP+1, S_IFDIR)) - strerr_diefu2x(111,"get tree from directory: ",src.s) ; + log_dieu(LOG_EXIT_SYS,"get tree from directory: ",src.s) ; if (satree.len) { @@ -641,21 +639,21 @@ int main(int argc, char const *const *argv, char const *const *envp) if (!stralloc_cats(&tmp,name) || !stralloc_cats(&tmp,SS_SVDIRS) || - !stralloc_0(&tmp)) exitstralloc("main"); + !stralloc_0(&tmp)) log_die_nomem("stralloc") ; if (ss_resolve_check(tmp.s,svname)) { if (!found) - if (!stralloc_copy(&src,&tmp)) exitstralloc("main") ; + if (!stralloc_copy(&src,&tmp)) log_die_nomem("stralloc") ; found++ ; } } } else { - if (!bprintf(buffer_1,"%s%s%s\n",info_color->warning," nothing to display",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning," nothing to display",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") < 0) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } stralloc_free(&tmp) ; } @@ -663,27 +661,27 @@ int main(int argc, char const *const *argv, char const *const *envp) { if (!stralloc_cats(&src,tname) || !stralloc_cats(&src,SS_SVDIRS) || - !stralloc_0(&src)) exitstralloc("main") ; + !stralloc_0(&src)) log_die_nomem("stralloc") ; if (ss_resolve_check(src.s,svname)) found++; } if (!found) { - strerr_dief2x(111,"unknown service: ",svname) ; + log_die(LOG_EXIT_SYS,"unknown service: ",svname) ; } else if (found > 1) { - strerr_dief2x(111,svname," is set on different tree -- please use -t options") ; + log_die(LOG_EXIT_SYS,svname," is set on different tree -- please use -t options") ; } if (!ss_resolve_read(&res,src.s,svname)) - strerr_diefu2sys(111,"read resolve file of: ",svname) ; + log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",svname) ; info_display_all(&res,what) ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; freed: diff --git a/src/66/66-intree.c b/src/66/66-intree.c index 2b8dec2c..b49851e3 100644 --- a/src/66/66-intree.c +++ b/src/66/66-intree.c @@ -20,12 +20,11 @@ #include <unistd.h>//access #include <oblibs/sastr.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/obgetopt.h> #include <oblibs/types.h> #include <oblibs/string.h> -#include <skalibs/strerr2.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/lolstdio.h> @@ -39,7 +38,6 @@ #include <66/enum.h> #include <66/resolve.h> -unsigned int VERBOSITY = 1 ; static unsigned int REVERSE = 0 ; unsigned int MAXDEPTH = 1 ; static unsigned int GRAPH = 0 ; @@ -70,7 +68,7 @@ info_opts_map_t const opts_tree_table[] = } ; #define MAXOPTS 6 -#define checkopts(n) if (n >= MAXOPTS) strerr_dief1x(100, "too many options") +#define checkopts(n) if (n >= MAXOPTS) log_die(100, "too many options") #define DELIM ',' #define USAGE "66-intree [ -h ] [ -v verbosity ] [ -l live ] [ -c ] [ -o name,init,enabled,... ] [ -g ] [ -d depth ] [ -r ] tree" @@ -101,7 +99,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } static int info_cmpnsort(stralloc *sa) @@ -142,17 +140,17 @@ static void info_display_name(char const *field, char const *treename) { info_display_field_name(field) ; if (!bprintf(buffer_1," %s",treename)) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_display_init(char const *field,char const *treename) { unsigned int init = 0 ; int r = set_livedir(&live) ; - if (!r) exitstralloc("display_init") ; - if (r == -1) strerr_dief3x(111,"live: ",live.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if (r == -1) log_die(LOG_EXIT_SYS,"live: ",live.s," must be an absolute path") ; if (!stralloc_cats(&live,SS_STATE + 1) || !stralloc_cats(&live,"/") || @@ -160,15 +158,15 @@ static void info_display_init(char const *field,char const *treename) !stralloc_cats(&live,"/") || !stralloc_cats(&live,treename) || !stralloc_cats(&live,"/init") || - !stralloc_0(&live)) exitstralloc("display_init") ; + !stralloc_0(&live)) log_die_nomem("stralloc") ; if (!access(live.s, F_OK)) init = 1 ; info_display_field_name(field) ; - if (!bprintf(buffer_1," %s%s%s",init ? info_color->valid : info_color->warning, init ? "yes":"no",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1," %s%s%s",init ? log_color->valid : log_color->warning, init ? "yes":"no",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } @@ -180,15 +178,15 @@ static void info_display_current(char const *field,char const *treename) if (tree_find_current(&sacurr,base.s,OWNER)) { char name[sacurr.len] ; - if (!basename(name,sacurr.s)) strerr_diefu2x(111,"basename of: ",sacurr.s) ; + if (!basename(name,sacurr.s)) log_dieu(LOG_EXIT_SYS,"basename of: ",sacurr.s) ; current = obstr_equal(treename,name) ; } info_display_field_name(field) ; - if (!bprintf(buffer_1," %s%s%s", current ? info_color->blink : info_color->warning, current ? "yes":"no",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1," %s%s%s", current ? log_color->blink : log_color->warning, current ? "yes":"no",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; stralloc_free(&sacurr) ; } @@ -197,11 +195,11 @@ static void info_display_enabled(char const *field,char const *treename) { int enabled = tree_cmd_state(VERBOSITY,"-s",treename) ; info_display_field_name(field) ; - if (!bprintf(buffer_1," %s%s%s",enabled == 1 ? info_color->valid : info_color->warning, enabled == 1 ? "yes":"no",info_color->off)) - strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1," %s%s%s",enabled == 1 ? log_color->valid : log_color->warning, enabled == 1 ? "yes":"no",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } static void info_get_graph_src(ss_resolve_graph_t *graph,char const *src,unsigned int reverse) @@ -216,15 +214,15 @@ static void info_get_graph_src(ss_resolve_graph_t *graph,char const *src,unsigne solve[srclen + SS_RESOLVE_LEN] = 0 ; if (!sastr_dir_get(&sa,solve,"",S_IFREG)) - strerr_diefu2sys(111,"get source service file at: ",solve) ; + log_dieusys(LOG_EXIT_SYS,"get source service file at: ",solve) ; for (pos = 0 ;pos < sa.len; pos += strlen(sa.s + pos) + 1) { char *name = sa.s + pos ; if (!ss_resolve_read(&res,src,name)) - strerr_diefu2x(111,"read resolve file of: ",name) ; + log_dieu(LOG_EXIT_SYS,"read resolve file of: ",name) ; if (!ss_resolve_graph_build(graph,&res,src,reverse)) - strerr_diefu2x(111,"build the graph from: ",src) ; + log_dieu(LOG_EXIT_SYS,"build the graph from: ",src) ; } stralloc_free(&sa) ; @@ -256,36 +254,36 @@ static void info_display_contents(char const *field, char const *treename) if (!genalloc_len(ss_resolve_t,&graph.name)) goto empty ; r = ss_resolve_graph_publish(&graph,0) ; - if (r < 0) strerr_dief2x(110,"cyclic graph detected at tree: ", treename) ; - else if (!r) strerr_diefu2sys(111,"publish service graph of tree: ",treename) ; + if (r < 0) log_die(LOG_EXIT_USER,"cyclic graph detected at tree: ", treename) ; + else if (!r) log_dieusys(LOG_EXIT_SYS,"publish service graph of tree: ",treename) ; for (size_t i = 0 ; i < genalloc_len(ss_resolve_t,&graph.sorted) ; i++) { char *string = genalloc_s(ss_resolve_t,&graph.sorted)[i].sa.s ; char *name = string + genalloc_s(ss_resolve_t,&graph.sorted)[i].name ; - if (!stralloc_catb(&salist,name,strlen(name)+1)) exitstralloc("display_contains") ; + if (!stralloc_catb(&salist,name,strlen(name)+1)) log_die_nomem("stralloc") ; } if (GRAPH) { if (!bprintf(buffer_1," %s\n","/")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; size_t el = sastr_len(&salist) ; - if (!sastr_rebuild_in_oneline(&salist)) strerr_diefu1x(111,"rebuild dependencies list") ; + if (!sastr_rebuild_in_oneline(&salist)) log_dieu(LOG_EXIT_SYS,"rebuild dependencies list") ; ss_resolve_init(&res) ; res.ndeps = el ; res.deps = ss_resolve_add_string(&res,salist.s) ; if (!info_graph_init(&res,tmp,REVERSE, padding, STYLE)) - strerr_dief2x(111,"display graph of: ",treename) ; + log_die(LOG_EXIT_SYS,"display graph of: ",treename) ; goto freed ; } else { if (!bprintf(buffer_1,"%s"," ")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (REVERSE) if (!sastr_reverse(&salist)) - strerr_diefu1x(111,"reverse dependencies list") ; + log_dieusys(LOG_EXIT_SYS,"reverse dependencies list") ; info_display_list(field,&salist) ; goto freed ; } @@ -293,17 +291,17 @@ static void info_display_contents(char const *field, char const *treename) if (GRAPH) { if (!bprintf(buffer_1," %s\n","/")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!bprintf(buffer_1,"%*s%s%s",padding,"",STYLE->last," empty tree")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } else { if (!bprintf(buffer_1,"%s"," empty tree")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; freed: ss_resolve_free(&res) ; ss_resolve_graph_free(&graph) ; @@ -327,7 +325,7 @@ static void info_parse_options(char const *str,int *what) size_t pos = 0 ; stralloc sa = STRALLOC_ZERO ; - if (!sastr_clean_string_wdelim(&sa,str,DELIM)) strerr_diefu1x(111,"parse options") ; + if (!sastr_clean_string_wdelim(&sa,str,DELIM)) log_dieu(LOG_EXIT_SYS,"parse options") ; unsigned int n = sastr_len(&sa), nopts = 0 , old ; checkopts(n) ; info_opts_map_t const *t ; @@ -345,7 +343,7 @@ static void info_parse_options(char const *str,int *what) else*/ what[nopts++] = t->id ; } } - if (old == nopts) strerr_dief2x(111,"invalid option: ",o) ; + if (old == nopts) log_die(LOG_EXIT_SYS,"invalid option: ",o) ; } stralloc_free(&sa) ; @@ -358,7 +356,7 @@ int main(int argc, char const *const *argv, char const *const *envp) size_t pos, newlen, livelen ; int what[MAXOPTS] = { 0 } ; - info_color = &no_color ; + log_color = &log_color_disable ; char const *treename = 0 ; @@ -384,20 +382,20 @@ int main(int argc, char const *const *argv, char const *const *envp) { int opt = getopt_args(argc,argv, ">hv:co:grd:l:", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'c' : info_color = !isatty(1) ? &no_color : &use_color ; break ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'c' : log_color = !isatty(1) ? &log_color_disable : &log_color_enable ; break ; case 'o' : legacy = 0 ; info_parse_options(l.arg,what) ; break ; case 'g' : GRAPH = 1 ; break ; case 'r' : REVERSE = 1 ; break ; - case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) exitusage(USAGE) ; break ; - case 'l' : if (!stralloc_cats(&live,l.arg)) exitusage(USAGE) ; - if (!stralloc_0(&live)) exitusage(USAGE) ; + case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) log_usage(USAGE) ; break ; + case 'l' : if (!stralloc_cats(&live,l.arg)) log_usage(USAGE) ; + if (!stralloc_0(&live)) log_usage(USAGE) ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; @@ -426,19 +424,19 @@ int main(int argc, char const *const *argv, char const *const *envp) STYLE = &graph_utf8; } - if (!set_ownersysdir(&base,OWNER)) strerr_diefu1sys(111, "set owner directory") ; + if (!set_ownersysdir(&base,OWNER)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ; if (!stralloc_copy(&src,&base) || !stralloc_cats(&src,SS_SYSTEM) || - !stralloc_0(&src)) exitstralloc("main") ; + !stralloc_0(&src)) log_die_nomem("stralloc") ; src.len-- ; if (!scan_mode(src.s,S_IFDIR)) { - strerr_warni1x("no tree exist yet") ; + log_info("no tree exist yet") ; goto freed ; } - if (!stralloc_cats(&src,"/")) exitstralloc("main") ; + if (!stralloc_cats(&src,"/")) log_die_nomem("stralloc") ; newlen = src.len ; livelen = live.len ; @@ -447,18 +445,18 @@ int main(int argc, char const *const *argv, char const *const *envp) { if (!stralloc_cats(&src,treename) || - !stralloc_0(&src)) exitstralloc("main") ; - if (!scan_mode(src.s,S_IFDIR)) strerr_diefu2sys(111,"find tree: ", src.s) ; + !stralloc_0(&src)) log_die_nomem("stralloc") ; + if (!scan_mode(src.s,S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"find tree: ", src.s) ; src.len = newlen ; info_display_all(treename,what) ; } else { - if (!stralloc_0(&src)) exitstralloc("main") ; - if (!sastr_dir_get(&satree, src.s,SS_BACKUP + 1, S_IFDIR)) strerr_diefu2sys(111,"get list of tree at: ",src.s) ; + if (!stralloc_0(&src)) log_die_nomem("stralloc") ; + if (!sastr_dir_get(&satree, src.s,SS_BACKUP + 1, S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get list of tree at: ",src.s) ; if (satree.len) { - if (!info_cmpnsort(&satree)) strerr_diefu1x(111,"sort list of tree") ; + if (!info_cmpnsort(&satree)) log_dieu(LOG_EXIT_SYS,"sort list of tree") ; for(pos = 0 ; pos < satree.len ; pos += strlen(satree.s + pos) +1 ) { src.len = newlen ; @@ -466,18 +464,18 @@ int main(int argc, char const *const *argv, char const *const *envp) char *name = satree.s + pos ; info_display_all(name,what) ; if (buffer_puts(buffer_1,"\n") == -1) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } } else { - strerr_warni1x("no tree exist yet") ; + log_info("no tree exist yet") ; goto freed ; } } if (buffer_putsflush(buffer_1,"\n") == -1) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; freed: diff --git a/src/66/66-parser.c b/src/66/66-parser.c index 4bf607de..1b491289 100644 --- a/src/66/66-parser.c +++ b/src/66/66-parser.c @@ -18,7 +18,7 @@ #include <errno.h> #include <stdint.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/files.h> #include <oblibs/obgetopt.h> #include <oblibs/types.h> @@ -49,7 +49,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } static void check_dir(char const *dir,uint8_t force,int main) @@ -57,16 +57,16 @@ static void check_dir(char const *dir,uint8_t force,int main) int r ; r = scan_mode(dir,S_IFDIR) ; - if (r < 0){ errno = ENOTDIR ; strerr_dief2sys(111,"conflicting format of: ",dir) ; } + if (r < 0){ errno = ENOTDIR ; log_diesys(LOG_EXIT_SYS,"conflicting format of: ",dir) ; } if (r && force && main) { - if ((rm_rf(dir) < 0) || !r ) strerr_diefu2sys(111,"sanitize directory: ",dir) ; + if ((rm_rf(dir) < 0) || !r ) log_dieusys(LOG_EXIT_SYS,"sanitize directory: ",dir) ; r = 0 ; } - else if (r && !force && main) strerr_dief3x(111,"destination: ",dir," already exist") ; + else if (r && !force && main) log_die(LOG_EXIT_SYS,"destination: ",dir," already exist") ; if (!r) - if (!dir_create_parent(dir, 0755)) strerr_diefu2sys(111,"create: ",dir) ; + if (!dir_create_parent(dir, 0755)) log_dieusys(LOG_EXIT_SYS,"create: ",dir) ; } int main(int argc, char const *const *argv,char const *const *envp) @@ -91,27 +91,27 @@ int main(int argc, char const *const *argv,char const *const *envp) { int opt = getopt_args(argc,argv, ">hv:fcC", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'f' : force = 1 ; break ; - case 'c' : if (conf) exitusage(USAGE) ; conf = 1 ; break ; - case 'C' : if (conf) exitusage(USAGE) ; conf = 2 ; break ; - default : exitusage(USAGE) ; + case 'h' : info_help(); return 0 ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'f' : force = 1 ; break ; + case 'c' : if (conf) log_usage(USAGE) ; conf = 1 ; break ; + case 'C' : if (conf) log_usage(USAGE) ; conf = 2 ; break ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 2) exitusage(USAGE) ; + if (argc < 2) log_usage(USAGE) ; sv = argv[0] ; dir = argv[1] ; - if (dir[0] != '/') strerr_dief3x(110, "directory: ",dir," must be an absolute path") ; - if (sv[0] != '/') strerr_dief3x(110, "service: ",sv," must be an absolute path") ; - if (!basename(name,sv)) strerr_diefu1x(111,"set name"); + if (dir[0] != '/') log_die(LOG_EXIT_USER, "directory: ",dir," must be an absolute path") ; + if (sv[0] != '/') log_die(LOG_EXIT_USER, "service: ",sv," must be an absolute path") ; + if (!basename(name,sv)) log_dieu(LOG_EXIT_SYS,"set name"); size_t svlen = strlen(sv) ; size_t namelen = strlen(name) ; char tmp[svlen + 1 + namelen + 1] ; @@ -124,66 +124,66 @@ int main(int argc, char const *const *argv,char const *const *envp) tmp[svlen + 1 + namelen] = 0 ; sv = tmp ; } - if (!dirname(srcdir,sv)) strerr_diefu1x(111,"set directory name") ; + if (!dirname(srcdir,sv)) log_dieu(LOG_EXIT_SYS,"set directory name") ; check_dir(dir,force,0) ; if (!stralloc_cats(&insta,name) || - !stralloc_0(&insta)) retstralloc(111,"main") ; + !stralloc_0(&insta)) log_die_nomem("stralloc") ; r = instance_check(insta.s) ; - if (!r) strerr_dief2x(111,"invalid instance name: ",insta.s) ; + if (!r) log_die(LOG_EXIT_SYS,"invalid instance name: ",insta.s) ; if (r > 0) { if (!instance_create(&src,insta.s,SS_INSTANCE,srcdir,r)) - strerr_diefu2x(111,"create instance service: ",name) ; + log_dieu(LOG_EXIT_SYS,"create instance service: ",name) ; memcpy(name,insta.s,insta.len) ; name[insta.len] = 0 ; } - else if (!read_svfile(&src,name,srcdir)) strerr_dief2sys(111,"open: ",sv) ; + else if (!read_svfile(&src,name,srcdir)) log_dieusys(LOG_EXIT_SYS,"open: ",sv) ; - VERBO1 strerr_warni2x("Parsing service file: ", sv) ; - if (!parser(&service,&src,sv)) strerr_diefu2x(111,"parse service file: ",sv) ; + log_info("Parsing service file: ", sv) ; + if (!parser(&service,&src,sv)) log_dieu(LOG_EXIT_SYS,"parse service file: ",sv) ; if (!stralloc_cats(&dst,dir) || !stralloc_cats(&dst,"/") || !stralloc_cats(&dst,name) || - !stralloc_0(&dst)) retstralloc(111,"main") ; + !stralloc_0(&dst)) log_die_nomem("stralloc") ; check_dir(dst.s,force,1) ; - VERBO1 strerr_warni4x("Write service file: ", name," at: ",dst.s) ; + log_info("Write service file: ", name," at: ",dst.s) ; type = service.cname.itype ; srcdirlen = strlen(srcdir) ; service.src = keep.len ; - if (!stralloc_catb(&keep,srcdir,srcdirlen + 1)) retstralloc(111,"main") ; + if (!stralloc_catb(&keep,srcdir,srcdirlen + 1)) log_die_nomem("stralloc") ; /* save and prepare environment file */ if (service.opts[2]) { stralloc conf = STRALLOC_ZERO ; - if (!stralloc_catb(&conf,dst.s,dst.len-1)) retstralloc(111,"main") ; - if (!stralloc_cats(&conf,"/env/")) retstralloc(111,"main") ; - if (!stralloc_0(&conf)) retstralloc(111,"main") ; + if (!stralloc_catb(&conf,dst.s,dst.len-1) || + !stralloc_cats(&conf,"/env/") || + !stralloc_0(&conf)) log_die_nomem("stralloc") ; if (!scan_mode(conf.s,S_IFDIR)) { - if (!dir_create_parent(conf.s,0755)) strerr_diefu2sys(111,"environment directory: ",conf.s) ; + if (!dir_create_parent(conf.s,0755)) log_dieusys(LOG_EXIT_SYS,"environment directory: ",conf.s) ; } service.srconf = keep.len ; - if (!stralloc_catb(&keep,conf.s,conf.len + 1)) retstralloc(111,"main") ; + if (!stralloc_catb(&keep,conf.s,conf.len + 1)) log_die_nomem("stralloc") ; stralloc_free(&conf) ; } switch(type) { case CLASSIC: if (!write_classic(&service, dst.s, force, conf)) - strerr_diefu2x(111,"write: ",name) ; + log_dieu(LOG_EXIT_SYS,"write: ",name) ; break ; case LONGRUN: if (!write_longrun(&service, dst.s, force, conf)) - strerr_diefu2x(111,"write: ",name) ; + log_dieu(LOG_EXIT_SYS,"write: ",name) ; break ; case ONESHOT: if (!write_oneshot(&service, dst.s, conf)) - strerr_diefu2x(111,"write: ",name) ; + log_dieu(LOG_EXIT_SYS,"write: ",name) ; break ; case BUNDLE: if (!write_bundle(&service, dst.s)) - strerr_diefu2x(111,"write: ",name) ; + log_dieu(LOG_EXIT_SYS,"write: ",name) ; break ; default: break ; } diff --git a/src/66/66-scanctl.c b/src/66/66-scanctl.c index 6299ad78..6fb1292b 100644 --- a/src/66/66-scanctl.c +++ b/src/66/66-scanctl.c @@ -13,7 +13,7 @@ */ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/obgetopt.h> #include <skalibs/buffer.h> @@ -26,8 +26,6 @@ #define USAGE "66-scanctl [ -h ] [ -v verbosity ] [ -l live ] [ -o owner ] signal" -unsigned int VERBOSITY = 1 ; - static inline void info_help (void) { static char const *help = @@ -41,7 +39,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } static inline unsigned int lookup (char const *const *table, char const *signal) { @@ -103,7 +101,7 @@ int send_signal(char const *scandir, char const *signal) memcpy(csig,signal,siglen) ; csig[siglen] = 0 ; } - VERBO1 strerr_warni5x("Sending -",csig," signal to scandir: ",scandir," ...") ; + log_info("Sending -",csig," signal to scandir: ",scandir,"...") ; return scandir_send_signal(scandir,csig) ; } @@ -122,35 +120,35 @@ int main(int argc, char const *const *argv) { int opt = getopt_args(argc,argv, ">hv:l:o:", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'l' : if (!stralloc_cats(&scandir,l.arg)) retstralloc(111,"main") ; - if (!stralloc_0(&scandir)) retstralloc(111,"main") ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'l' : if (!stralloc_cats(&scandir,l.arg)) log_die_nomem("stralloc") ; + if (!stralloc_0(&scandir)) log_die_nomem("stralloc") ; break ; case 'o' : - if (MYUID) strerr_dief1x(110, "only root can use -o options") ; - else if (!youruid(&owner,l.arg)) strerr_diefu2sys(111,"get uid of: ",l.arg) ; + if (MYUID) log_die(LOG_EXIT_USER, "only root can use -o options") ; + else if (!youruid(&owner,l.arg)) log_dieusys(LOG_EXIT_SYS,"get uid of: ",l.arg) ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(USAGE) ; + if (argc < 1) log_usage(USAGE) ; signal = argv[0] ; r = set_livedir(&scandir) ; - if (r < 0) strerr_dief3x(110,"live: ",scandir.s," must be an absolute path") ; - if (!r) strerr_diefu1sys(111,"set live directory") ; + if (r < 0) log_die(LOG_EXIT_USER,"live: ",scandir.s," must be an absolute path") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set live directory") ; r = set_livescan(&scandir,owner) ; - if (r < 0) strerr_dief3x(110,"scandir: ", scandir.s, " must be an absolute path") ; - if (!r) strerr_diefu1sys(111,"set scandir directory") ; + if (r < 0) log_die(LOG_EXIT_USER,"scandir: ", scandir.s, " must be an absolute path") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set scandir directory") ; r = scandir_ok(scandir.s) ; - if (!r) strerr_dief3sys(111,"scandir: ",scandir.s," is not running") ; - else if (r < 0) strerr_diefu2sys(111, "check: ", scandir.s) ; + if (!r)log_diesys(LOG_EXIT_SYS,"scandir: ",scandir.s," is not running") ; + else if (r < 0) log_dieusys(LOG_EXIT_SYS, "check: ", scandir.s) ; if (send_signal(scandir.s,signal) <= 0) goto err ; diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index 05243175..667a0716 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -21,7 +21,7 @@ //#include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/directory.h> #include <oblibs/types.h> #include <oblibs/files.h> @@ -65,7 +65,6 @@ static char TMPENV[MAXENV+1] ; static char const *skel = SS_SKEL_DIR ; static char const *log_user = SS_LOGGER_RUNNER ; static unsigned int BOOT = 0 ; -unsigned int VERBOSITY = 1 ; unsigned int NOTIF = 0 ; #define USAGE "66-scandir [ -h ] [ -v verbosity ] [ -b ] [ -l live ] [ -d notif ] [ -t rescan ] [ -L log_user ] [ -s skel ] [ -e environment ] [ -c | u | r ] owner" @@ -91,17 +90,17 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } void scandir_up(char const *scandir, unsigned int timeout, char const *const *envp) { int r ; r = scandir_ok(scandir) ; - if (r < 0) strerr_diefu2sys(111, "check: ", scandir) ; + if (r < 0) log_dieusys(LOG_EXIT_SYS, "check: ", scandir) ; if (r) { - VERBO2 strerr_warni3x("scandir: ",scandir," already running") ; + log_trace("scandir: ",scandir," already running") ; return ; } @@ -131,42 +130,42 @@ void scandir_up(char const *scandir, unsigned int timeout, char const *const *en static void inline auto_chown(char const *str) { - VERBO3 strerr_warnt6x("chown directory: ",str," to: ",OWNERSTR,":",GIDSTR) ; + log_trace("chown directory: ",str," to: ",OWNERSTR,":",GIDSTR) ; if (chown(str,OWNER,GIDOWNER) < 0) - strerr_diefu2sys(111,"chown: ",str) ; + log_dieusys(LOG_EXIT_SYS,"chown: ",str) ; } static void inline auto_dir(char const *str,mode_t mode) { - VERBO3 strerr_warnt2x("create directory: ",str) ; + log_trace("create directory: ",str) ; if (!dir_create(str,mode)) - strerr_diefu2sys(111,"create directory: ",str) ; + log_dieusys(LOG_EXIT_SYS,"create directory: ",str) ; } static void inline auto_chmod(char const *str,mode_t mode) { //VERBO3 strerr_warnt2x("chmod: ",str) ; if (chmod(str,mode) < 0) - strerr_diefu2sys(111,"chmod: ",str) ; + log_dieusys(LOG_EXIT_SYS,"chmod: ",str) ; } static void inline auto_file(char const *dst,char const *file,char const *contents,size_t conlen) { - VERBO3 strerr_warnt4x("write file: ",dst,"/",file) ; + log_trace("write file: ",dst,"/",file) ; if (!file_write_unsafe(dst,file,contents,conlen)) - strerr_diefu4sys(111,"write file: ",dst,"/",file) ; + log_dieusys(LOG_EXIT_SYS,"write file: ",dst,"/",file) ; } static void inline auto_stralloc(stralloc *sa,char const *str) { - if (!stralloc_cats(sa,str)) strerr_diefu1sys(111,"append stralloc") ; + if (!stralloc_cats(sa,str)) log_dieusys(LOG_EXIT_SYS,"append stralloc") ; } static void inline auto_check(char const *str,mode_t check,mode_t type,mode_t perm,int what) { int r ; r = scan_mode(str,check) ; - if (r < 0) { errno = EEXIST ; strerr_dief2sys(111,"conflicting format of: ",str) ; } + if (r < 0) { errno = EEXIST ; log_diesys(LOG_EXIT_SYS,"conflicting format of: ",str) ; } if (!r) { auto_dir(str,type) ; @@ -179,12 +178,12 @@ static void inline auto_fifo(char const *str) { int r ; r = scan_mode(str,S_IFIFO) ; - if (r < 0) { errno = EEXIST ; strerr_dief2sys(111,"conflicting format of: ",str) ; } + if (r < 0) { errno = EEXIST ; log_diesys(LOG_EXIT_SYS,"conflicting format of: ",str) ; } if (!r) { - VERBO3 strerr_warnt2x("create fifo: ",str) ; + log_trace("create fifo: ",str) ; if (mkfifo(str, 0600) < 0) - strerr_diefu2sys(111,"create fifo: ",str) ; + log_dieusys(LOG_EXIT_SYS,"create fifo: ",str) ; } } static void inline auto_rm(char const *str) @@ -193,14 +192,14 @@ static void inline auto_rm(char const *str) r = scan_mode(str,S_IFDIR) ; if (r > 0) { - VERBO1 strerr_warni3x("removing ",str," ...") ; - if (rm_rf(str) < 0) strerr_diefu2sys(111,"remove: ",str) ; + log_info("removing: ",str,"...") ; + if (rm_rf(str) < 0) log_dieusys(LOG_EXIT_SYS,"remove: ",str) ; } } static void inline log_perm(char const *str,uid_t *uid,gid_t *gid) { - if (!youruid(uid,str)) strerr_diefu2sys(111,"set uid of: ",str) ; - if (!yourgid(gid,*uid)) strerr_diefu2sys(111,"set gid of: ",str) ; + if (!youruid(uid,str)) log_dieusys(LOG_EXIT_SYS,"set uid of: ",str) ; + if (!yourgid(gid,*uid)) log_dieusys(LOG_EXIT_SYS,"set gid of: ",str) ; } static void inline auto_addlive(stralloc *sa,char const *live, char const *str) @@ -269,12 +268,12 @@ void write_bootlog(char const *live, char const *scandir) path[livelen + 3] = '/' ; memcpy(path + livelen + 4,OWNERSTR,ownerlen) ; path[livelen + 4 + ownerlen] = 0 ; - VERBO3 strerr_warnt2x("create directory: ",path) ; + log_trace("create directory: ",path) ; r = dir_create_parent(path,02750) ; - if (!r) strerr_diefu2sys(111,"create: ",path) ; + if (!r) log_dieusys(LOG_EXIT_SYS,"create: ",path) ; log_perm(log_user,&uid,&gid) ; if (chown(path,uid,gid) < 0) - strerr_diefu2sys(111,"chown: ",path) ; + log_dieusys(LOG_EXIT_SYS,"chown: ",path) ; auto_chmod(path,02755) ; /** make run file */ @@ -428,7 +427,7 @@ void create_scandir(char const *live, char const *scandir) "/crash", "/finish", "/SIGHUP", "/SIGINT", "/SIGQUIT", "/SIGTERM", "/SIGUSR1", "/SIGUSR2" } ; - VERBO2 strerr_warni1x("write control file... ") ; + log_trace("write control file... ") ; for (int i = 0 ; i < 8; i++) write_control(scandir,live,file[i],i) ; @@ -491,77 +490,77 @@ int main(int argc, char const *const *argv, char const *const *envp) { int opt = getopt_args(argc,argv, ">hv:bl:d:t:s:e:cruL:", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; case 'b' : BOOT = 1 ; break ; - case 'l' : if(!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; - if(!stralloc_0(&live)) retstralloc(111,"main") ; + case 'l' : if(!stralloc_cats(&live,l.arg)) log_die_nomem("stralloc") ; + if(!stralloc_0(&live)) log_die_nomem("stralloc") ; break ; - case 'd' : if (!uint0_scan(l.arg, &NOTIF)) exitusage(USAGE) ; - if (NOTIF < 3) strerr_dief1x(110, "notification fd must be 3 or more") ; - if (fcntl(NOTIF, F_GETFD) < 0) strerr_dief1sys(110, "invalid notification fd") ; + case 'd' : if (!uint0_scan(l.arg, &NOTIF)) log_usage(USAGE) ; + if (NOTIF < 3) log_die(LOG_EXIT_USER, "notification fd must be 3 or more") ; + if (fcntl(NOTIF, F_GETFD) < 0) log_diesys(LOG_EXIT_USER, "invalid notification fd") ; break ; case 't' : if (!uint0_scan(l.arg, &rescan)) break ; case 's' : skel = l.arg ; break ; - case 'e' : if(!stralloc_cats(&envdir,l.arg)) retstralloc(111,"main") ; - if(!stralloc_0(&envdir)) retstralloc(111,"main") ; + case 'e' : if(!stralloc_cats(&envdir,l.arg)) log_die_nomem("stralloc") ; + if(!stralloc_0(&envdir)) log_die_nomem("stralloc") ; break ; - case 'c' : create = 1 ; if (remove) exitusage(USAGE) ; break ; - case 'r' : remove = 1 ; if (create) exitusage(USAGE) ; break ; - case 'u' : up = 1 ; if (remove) exitusage(USAGE) ; break ; + case 'c' : create = 1 ; if (remove) log_usage(USAGE) ; break ; + case 'r' : remove = 1 ; if (create) log_usage(USAGE) ; break ; + case 'u' : up = 1 ; if (remove) log_usage(USAGE) ; break ; case 'L' : log_user = l.arg ; break ; - default : exitusage(USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) OWNER = MYUID ; - else if (!youruid(&OWNER,argv[0])) strerr_diefu2sys(111,"set uid of: ",argv[0]) ; + else if (!youruid(&OWNER,argv[0])) log_dieusys(LOG_EXIT_SYS,"set uid of: ",argv[0]) ; if (BOOT && NOTIF) NOTIF = 0 ; - if (BOOT && OWNER) strerr_dief1x(110,"-b options can be set only with root") ; + if (BOOT && OWNER) log_die(LOG_EXIT_USER,"-b options can be set only with root") ; OWNERSTR[uid_fmt(OWNERSTR,OWNER)] = 0 ; - if (!yourgid(&GIDOWNER,OWNER)) strerr_diefu2sys(111,"set gid of: ",OWNERSTR) ; + if (!yourgid(&GIDOWNER,OWNER)) log_dieusys(LOG_EXIT_SYS,"set gid of: ",OWNERSTR) ; GIDSTR[gid_fmt(GIDSTR,GIDOWNER)] = 0 ; /** live -> /run/66/ */ r = set_livedir(&live) ; - if (r < 0) strerr_dief3x(110,"live: ",live.s," must be an absolute path") ; - if (!r) strerr_diefu1sys(111,"set live directory") ; + if (r < 0) log_die(LOG_EXIT_USER,"live: ",live.s," must be an absolute path") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set live directory") ; - if (!stralloc_copy(&scandir,&live)) retstralloc(111,"main") ; + if (!stralloc_copy(&scandir,&live)) log_die_nomem("stralloc") ; /** scandir -> /run/66/scandir/ */ r = set_livescan(&scandir,OWNER) ; - if (r < 0) strerr_dief3x(110,"scandir: ", scandir.s, " must be an absolute path") ; - if (!r) strerr_diefu1sys(111,"set scandir directory") ; + if (r < 0) log_die(LOG_EXIT_USER,"scandir: ", scandir.s, " must be an absolute path") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set scandir directory") ; if (BOOT && skel[0] != '/') - strerr_dief3x(110, "rc.shutdown: ",skel," must be an absolute path") ; + log_die(LOG_EXIT_USER, "rc.shutdown: ",skel," must be an absolute path") ; if (envdir.len) { if (envdir.s[0] != '/') - strerr_dief3x(110,"environment: ",envdir.s," must be an absolute path") ; + log_die(LOG_EXIT_USER,"environment: ",envdir.s," must be an absolute path") ; - if (!environ_get_envfile_n_merge(envdir.s,envp,newenv,TMPENV)) strerr_diefu2x(111,"build environment with: ",envdir.s) ; + if (!environ_get_envfile_n_merge(envdir.s,envp,newenv,TMPENV)) log_dieusys(LOG_EXIT_SYS,"build environment with: ",envdir.s) ; genv = newenv ; } else genv = envp ; r = scan_mode(scandir.s, S_IFDIR) ; - if (r < 0) strerr_dief3x(111,"scandir: ",scandir.s," exist with unkown mode") ; - if (!r && !create && !remove) strerr_dief3x(110,"scandir: ",scandir.s," doesn't exist") ; + if (r < 0) log_die(LOG_EXIT_SYS,"scandir: ",scandir.s," exist with unkown mode") ; + if (!r && !create && !remove) log_die(LOG_EXIT_USER,"scandir: ",scandir.s," doesn't exist") ; if (!r && create) { - VERBO2 strerr_warni3x("sanitize ",live.s," ...") ; + log_trace("sanitize ",live.s," ...") ; sanitize_live(live.s) ; - VERBO2 strerr_warni3x("create scandir ",scandir.s," ...") ; + log_trace("create scandir ",scandir.s," ...") ; create_scandir(live.s, scandir.s) ; } /**swap to char [] to be able to freed stralloc*/ @@ -570,25 +569,25 @@ int main(int argc, char const *const *argv, char const *const *envp) ownerscan[scandir.len] = 0 ; if (r && create) { - VERBO1 strerr_warni3x("scandir: ",scandir.s," already exist, keep it") ; + log_info("scandir: ",scandir.s," already exist, keep it") ; goto end ; } r = scandir_ok(scandir.s) ; - if (r < 0) strerr_diefu2sys(111, "check: ", scandir.s) ; - if (r && remove) strerr_diefu3x(110,"remove: ",scandir.s,": is running") ; + if (r < 0) log_dieusys(LOG_EXIT_SYS, "check: ", scandir.s) ; + if (r && remove) log_dieu(LOG_EXIT_USER,"remove: ",scandir.s,": is running") ; if (remove) { auto_rm(scandir.s) ; /** /run/66/tree/uid */ - if (!stralloc_copy(&scandir,&live)) retstralloc(111,"main") ; + if (!stralloc_copy(&scandir,&live)) log_die_nomem("stralloc") ; r = set_livetree(&scandir,OWNER) ; - if (!r) strerr_diefu1sys(111,"set livetree directory") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set livetree directory") ; auto_rm(scandir.s) ; - if (!stralloc_copy(&scandir,&live)) retstralloc(111,"main") ; + if (!stralloc_copy(&scandir,&live)) log_die_nomem("stralloc") ; /** run/66/state/uid */ r = set_livestate(&scandir,OWNER) ; - if (!r) strerr_diefu1sys(111,"set livestate directory") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set livestate directory") ; auto_rm(scandir.s) ; } end: diff --git a/src/66/66-shutdown.c b/src/66/66-shutdown.c index fd0b14da..8eac2b30 100644 --- a/src/66/66-shutdown.c +++ b/src/66/66-shutdown.c @@ -25,10 +25,11 @@ #include <time.h> #include <utmpx.h> +#include <oblibs/log.h> + #include <skalibs/uint32.h> #include <skalibs/types.h> #include <skalibs/allreadwrite.h> -#include <skalibs/strerr2.h> #include <skalibs/sgetopt.h> #include <skalibs/sig.h> #include <skalibs/tai.h> @@ -43,7 +44,7 @@ #define UT_NAMESIZE 32 #endif -#define USAGE "66-shutdown [ -H ] [ -l live ] [ -h | -p | -r | -k ] [ -f | -F ] [ -a ] [ -t sec ] time [ message ] or 66-shutdown -c [ message ]" +#define USAGE "66-shutdown [ -H ] [ -v verbosity ] [ -l live ] [ -h | -p | -r | -k ] [ -f | -F ] [ -a ] [ -t sec ] time [ message ] or 66-shutdown -c [ message ]" #define AC_FILE SS_SKEL_DIR "shutdown.allow" #define AC_BUFSIZE 4096 @@ -57,7 +58,8 @@ static inline void info_help (void) "66-shutdown <options> time [message] or 66-shutdown -c [ message ]\n" "\n" "options :\n" -" -H: print this help\n" +" -H: print this help\n" +" -v: increase/decrease verbosity\n" " -l: live directory\n" " -h: halt the system\n" " -p: poweroff the system\n" @@ -70,7 +72,7 @@ static inline void info_help (void) " -c: cancel planned shutdown\n" ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } /* shutdown 01:23: date/time format parsing */ @@ -91,23 +93,23 @@ static inline void parse_hourmin (tain_t *when, char const *s) unsigned int hour, minute ; size_t len = uint_scan(s, &hour) ; if (!len || len > 2 || s[len] != ':' || hour > 23) - strerr_dief1x(110, "invalid time format") ; + log_die(LOG_EXIT_USER, "invalid time format") ; s += len+1 ; len = uint0_scan(s, &minute) ; if (!len || len != 2 || minute > 59) - strerr_dief1x(110, "invalid time format") ; + log_die(LOG_EXIT_USER, "invalid time format") ; if (!localtm_from_tai(&tmthen, tain_secp(&STAMP), 1)) - strerr_diefu1sys(111, "break down current time into struct tm") ; + log_dieusys(LOG_EXIT_SYS, "break down current time into struct tm") ; tmthen.tm_hour = hour ; tmthen.tm_min = minute ; tmthen.tm_sec = 0 ; if (!tai_from_localtm(&taithen, &tmthen)) - strerr_diefu1sys(111, "assemble broken-down time into tain_t") ; + log_dieusys(LOG_EXIT_SYS, "assemble broken-down time into tain_t") ; if (tai_less(&taithen, tain_secp(&STAMP))) { add_one_day(&tmthen) ; if (!tai_from_localtm(&taithen, &tmthen)) - strerr_diefu1sys(111, "assemble broken-down time into tain_t") ; + log_dieusys(LOG_EXIT_SYS, "assemble broken-down time into tain_t") ; } when->sec = taithen ; when->nano = 0 ; @@ -116,7 +118,7 @@ static inline void parse_hourmin (tain_t *when, char const *s) static void parse_mins (tain_t *when, char const *s) { unsigned int mins ; - if (!uint0_scan(s, &mins)) strerr_dieusage(100,USAGE) ; + if (!uint0_scan(s, &mins)) log_usage(USAGE) ; tain_addsec_g(when, mins * 60) ; } @@ -165,7 +167,7 @@ static inline unsigned int parse_authorized_users (char *buf, char const **users { char fmt[UINT32_FMT] ; fmt[uint32_fmt(fmt, AC_MAX)] = 0 ; - strerr_warnw4x(AC_FILE, " lists more than ", fmt, " authorized users - ignoring the extra ones") ; + log_warn(AC_FILE, " lists more than ", fmt, " authorized users - ignoring the extra ones") ; break ; } buf[pos] = 0 ; @@ -205,23 +207,23 @@ static inline void access_control (void) if (fd == -1) { if (errno == ENOENT) return ; - strerr_diefu2sys(111, "open ", AC_FILE) ; + log_dieusys(LOG_EXIT_SYS, "open ", AC_FILE) ; } if (fstat(fd, &st) == -1) - strerr_diefu2sys(111, "stat ", AC_FILE) ; + log_dieusys(LOG_EXIT_SYS, "stat ", AC_FILE) ; if (st.st_size >= AC_BUFSIZE) { char fmt[UINT32_FMT] ; fmt[uint32_fmt(fmt, AC_BUFSIZE - 1)] = 0 ; - strerr_dief4x(1, AC_FILE, " is too big: it needs to be ", fmt, " bytes or less") ; + log_die(LOG_EXIT_ONE, AC_FILE, " is too big: it needs to be ", fmt, " bytes or less") ; } if (allread(fd, buf, st.st_size) < st.st_size) - strerr_diefu2sys(111, "read ", AC_FILE) ; + log_dieusys(LOG_EXIT_SYS, "read ", AC_FILE) ; fd_close(fd) ; buf[st.st_size] = 0 ; n = parse_authorized_users(buf, users, AC_MAX) ; if (!n || !match_users_with_utmp(users, n)) - strerr_dief1x(1, "no authorized users logged in") ; + log_die(LOG_EXIT_ONE, "no authorized users logged in") ; } @@ -240,11 +242,12 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "l:hprkafFct:", &l) ; + int opt = subgetopt_r(argc, argv, "v:Hl:hprkafFct:", &l) ; if (opt == -1) break ; switch (opt) { case 'H' : info_help() ; return 0 ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; case 'l' : live = l.arg ; break ; case 'h' : what = 1 ; break ; case 'p' : what = 2 ; break ; @@ -254,13 +257,13 @@ int main (int argc, char const *const *argv) case 'f' : /* talk to the hand */ break ; case 'F' : /* no, the other hand */ break ; case 'c' : docancel = 1 ; break ; - case 't' : if (!uint0_scan(l.arg, &gracetime)) strerr_dieusage(100,USAGE) ; break ; - default : strerr_dieusage(100,USAGE) ; + case 't' : if (!uint0_scan(l.arg, &gracetime)) log_usage(USAGE) ; break ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (live && live[0] != '/') strerr_dief3x(110,"live: ",live," must be an absolute path") ; + if (live && live[0] != '/') log_die(LOG_EXIT_USER,"live: ",live," must be an absolute path") ; else live = SS_LIVE ; size_t livelen = strlen(live) ; char tlive[livelen + INITCTL_LEN + 1] ; @@ -270,17 +273,17 @@ int main (int argc, char const *const *argv) if (geteuid()) { errno = EPERM ; - strerr_diefu1sys(111, "shutdown") ; + log_dieusys(LOG_EXIT_SYS, "shutdown") ; } if (doactl) access_control() ; - if (!tain_now_g()) strerr_warnw1sys("get current time") ; + if (!tain_now_g()) log_warnsys("get current time") ; if (docancel) { if (argv[0]) hpr_wall(argv[0]) ; if (!hpr_cancel(tlive)) goto err ; return 0 ; } - if (!argc) strerr_dieusage(100,USAGE) ; + if (!argc) log_usage(USAGE) ; parse_time(&when, argv[0]) ; tain_sub(&when, &when, &STAMP) ; if (argv[1]) @@ -297,11 +300,11 @@ int main (int argc, char const *const *argv) if (gracetime > 300) { gracetime = 300 ; - strerr_warnw1x("delay between SIGTERM and SIGKILL is capped to 300 seconds") ; + log_warn("delay between SIGTERM and SIGKILL is capped to 300 seconds") ; } if (!hpr_shutdown(tlive,what, &when, gracetime * 1000)) goto err ; } return 0 ; err: - strerr_diefu2sys(111, "write to ", tlive) ; + log_dieusys(LOG_EXIT_SYS, "write to ", tlive) ; } diff --git a/src/66/66-shutdownd.c b/src/66/66-shutdownd.c index 45892430..42b45442 100644 --- a/src/66/66-shutdownd.c +++ b/src/66/66-shutdownd.c @@ -28,6 +28,7 @@ #include <oblibs/environ.h> #include <oblibs/files.h> +#include <oblibs/log.h> #include <skalibs/posixplz.h> #include <skalibs/uint32.h> @@ -35,7 +36,6 @@ #include <skalibs/allreadwrite.h> #include <skalibs/bytestr.h> #include <skalibs/buffer.h> -#include <skalibs/strerr2.h> #include <skalibs/sgetopt.h> #include <skalibs/sig.h> #include <skalibs/tai.h> @@ -75,7 +75,7 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } struct at_s @@ -119,8 +119,8 @@ static void parse_conf(char const *confile,char *rcshut,char const *key) stralloc src = STRALLOC_ZERO ; size_t filesize = file_get_size(confile) ; r = openreadfileclose(confile,&src,filesize) ; - if(!r) strerr_diefu2sys(111,"open configuration file: ",confile) ; - if (!stralloc_0(&src)) strerr_diefu1sys(111,"append stralloc configuration file") ; + if(!r) log_dieusys(LOG_EXIT_SYS,"open configuration file: ",confile) ; + if (!stralloc_0(&src)) log_dieusys(LOG_EXIT_SYS,"append stralloc configuration file") ; if (environ_get_val_of_key(&src,key)) { @@ -144,19 +144,19 @@ static inline void run_rcshut (char const *const *envp) { int wstat ; char fmt[UINT_FMT] ; - if (wait_pid(pid, &wstat) == -1) strerr_diefu1sys(111, "waitpid") ; + if (wait_pid(pid, &wstat) == -1) log_dieusys(LOG_EXIT_SYS, "waitpid") ; if (WIFSIGNALED(wstat)) { fmt[uint_fmt(fmt, WTERMSIG(wstat))] = 0 ; - strerr_warnw3x(rcshut, " was killed by signal ", fmt) ; + log_warn(rcshut, " was killed by signal ", fmt) ; } else if (WEXITSTATUS(wstat)) { fmt[uint_fmt(fmt, WEXITSTATUS(wstat))] = 0 ; - strerr_warnw3x(rcshut, " exited ", fmt) ; + log_warn(rcshut, " exited ", fmt) ; } } - else strerr_warnwu2sys("spawn ", rcshut) ; + else log_warnusys("spawn ", rcshut) ; } static inline void prepare_shutdown (buffer *b, tain_t *deadline, unsigned int *grace_time) @@ -164,8 +164,8 @@ static inline void prepare_shutdown (buffer *b, tain_t *deadline, unsigned int * uint32_t u ; char pack[TAIN_PACK + 4] ; ssize_t r = sanitize_read(buffer_get(b, pack, TAIN_PACK + 4)) ; - if (r == -1) strerr_diefu1sys(111, "read from pipe") ; - if (r < TAIN_PACK + 4) strerr_dief1x(101, "bad shutdown protocol") ; + if (r == -1) log_dieusys(LOG_EXIT_SYS, "read from pipe") ; + if (r < TAIN_PACK + 4) log_dieusys(101, "bad shutdown protocol") ; tain_unpack(pack, deadline) ; tain_add_g(deadline,deadline) ; uint32_unpack_big(pack + TAIN_PACK, &u) ; @@ -178,7 +178,7 @@ static inline void handle_fifo (buffer *b, char *what, tain_t *deadline, unsigne { char c ; ssize_t r = sanitize_read(buffer_get(b, &c, 1)) ; - if (r == -1) strerr_diefu1sys(111, "read from pipe") ; + if (r == -1) log_dieusys(LOG_EXIT_SYS, "read from pipe") ; else if (!r) break ; switch (c) { @@ -196,7 +196,7 @@ static inline void handle_fifo (buffer *b, char *what, tain_t *deadline, unsigne default : { char s[2] = { c, 0 } ; - strerr_warnw2x("unknown command: ", s) ; + log_warn("unknown command: ", s) ; } break ; } @@ -215,7 +215,7 @@ static inline void prepare_stage4 (char what) parse_conf(confile,shutfinal,"RCSHUTDOWNFINAL") ; unlink_void(STAGE4_FILE ".new") ; fd = open_excl(STAGE4_FILE ".new") ; - if (fd == -1) strerr_diefu3sys(111, "open ", STAGE4_FILE ".new", " for writing") ; + if (fd == -1) log_dieusys(LOG_EXIT_SYS, "open ", STAGE4_FILE ".new", " for writing") ; buffer_init(&b, &buffer_write, fd, buf, 512) ; if (buffer_puts(&b, @@ -227,11 +227,11 @@ static inline void prepare_stage4 (char what) || buffer_puts(&b," }\n" SS_BINPREFIX "66-hpr -f -") < 0 || buffer_put(&b, &what, 1) < 0 - || buffer_putsflush(&b, "\n") < 0) strerr_diefu2sys(111, "write to ", STAGE4_FILE ".new") ; - if (fchmod(fd, S_IRWXU) == -1) strerr_diefu2sys(111, "fchmod ", STAGE4_FILE ".new") ; + || buffer_putsflush(&b, "\n") < 0) log_dieusys(LOG_EXIT_SYS, "write to ", STAGE4_FILE ".new") ; + if (fchmod(fd, S_IRWXU) == -1) log_dieusys(LOG_EXIT_SYS, "fchmod ", STAGE4_FILE ".new") ; fd_close(fd) ; if (rename(STAGE4_FILE ".new", STAGE4_FILE) == -1) - strerr_diefu4sys(111, "rename ", STAGE4_FILE ".new", " to ", STAGE4_FILE) ; + log_dieusys(LOG_EXIT_SYS, "rename ", STAGE4_FILE ".new", " to ", STAGE4_FILE) ; } static inline void unsupervise_tree (void) @@ -251,9 +251,9 @@ static inline void unsupervise_tree (void) newlen = livelen + SS_SCANDIR_LEN + 4 ; DIR *dir = opendir(tmp) ; int fdd ; - if (!dir) strerr_diefu2sys(111, "opendir: ",tmp) ; + if (!dir)log_dieusys(LOG_EXIT_SYS, "opendir: ",tmp) ; fdd = dirfd(dir) ; - if (fdd == -1) strerr_diefu2sys(111, "dir_fd: ",tmp) ; + if (fdd == -1) log_dieusys(LOG_EXIT_SYS, "dir_fd: ",tmp) ; for (;;) { char const *const *p = except ; @@ -273,7 +273,7 @@ static inline void unsupervise_tree (void) memcpy(fn + newlen + DOTPREFIXLEN + dlen, DOTSUFFIX, DOTSUFFIXLEN + 1) ; if (mkrenametemp(fdd, d->d_name, fn + newlen) == -1) { - strerr_warnwu5sys("rename ",tmp, d->d_name, " to something based on ", fn) ; + log_warnusys("rename ",tmp, d->d_name, " to something based on ", fn) ; unlinkat(fdd, d->d_name, 0) ; /* if it still fails, too bad, it will restart in stage 4 and race */ } @@ -281,7 +281,7 @@ static inline void unsupervise_tree (void) } } dir_close(dir) ; - if (errno) strerr_diefu2sys(111, "readdir: ",tmp) ; + if (errno) log_dieusys(LOG_EXIT_SYS, "readdir: ",tmp) ; } int main (int argc, char const *const *argv, char const *const *envp) @@ -305,14 +305,14 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'h' : info_help(); return 0 ; case 'l' : live = l.arg ; break ; case 's' : conf = l.arg ; break ; - case 'g' : if (!uint0_scan(l.arg, &grace_time)) strerr_dieusage(100,USAGE) ; break ; - default : strerr_dieusage(100,USAGE) ; + case 'g' : if (!uint0_scan(l.arg, &grace_time)) log_usage(USAGE) ; break ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (conf[0] != '/') strerr_dief3x(110, "skeleton: ",conf," must be an absolute path") ; - if (live && live[0] != '/') strerr_dief3x(110,"live: ",live," must be an absolute path") ; + if (conf[0] != '/') log_dieusys(LOG_EXIT_USER, "skeleton: ",conf," must be an absolute path") ; + if (live && live[0] != '/') log_die(LOG_EXIT_USER,"live: ",live," must be an absolute path") ; else live = SS_LIVE ; if (grace_time > 300000) grace_time = 300000 ; @@ -320,17 +320,17 @@ int main (int argc, char const *const *argv, char const *const *envp) { char const *stage4_argv[2] = { "./" STAGE4_FILE, 0 } ; execve(stage4_argv[0], (char **)stage4_argv, (char *const *)envp) ; - if (errno != ENOENT) strerr_warnwu2sys("exec ", stage4_argv[0]) ; + if (errno != ENOENT) log_warnusys("exec ", stage4_argv[0]) ; } fdr = open_read(SHUTDOWND_FIFO) ; if (fdr == -1 || coe(fdr) == -1) - strerr_diefu3sys(111, "open ", SHUTDOWND_FIFO, " for reading") ; + log_dieusys(LOG_EXIT_SYS, "open ", SHUTDOWND_FIFO, " for reading") ; fdw = open_write(SHUTDOWND_FIFO) ; if (fdw == -1 || coe(fdw) == -1) - strerr_diefu3sys(111, "open ", SHUTDOWND_FIFO, " for writing") ; + log_dieusys(LOG_EXIT_SYS, "open ", SHUTDOWND_FIFO, " for writing") ; if (sig_ignore(SIGPIPE) == -1) - strerr_diefu1sys(111, "sig_ignore SIGPIPE") ; + log_dieusys(LOG_EXIT_SYS, "sig_ignore SIGPIPE") ; buffer_init(&b, &buffer_read, fdr, buf, 64) ; tain_now_set_stopwatch_g() ; tain_add_g(&deadline, &tain_infinite_relative) ; @@ -339,7 +339,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { iopause_fd x = { .fd = fdr, .events = IOPAUSE_READ } ; int r = iopause_g(&x, 1, &deadline) ; - if (r == -1) strerr_diefu1sys(111, "iopause") ; + if (r == -1) log_dieusys(LOG_EXIT_SYS, "iopause") ; if (!r) { run_rcshut(envp) ; @@ -356,17 +356,18 @@ int main (int argc, char const *const *argv, char const *const *envp) fd_close(fdr) ; fd_close(1) ; if (open("/dev/console", O_WRONLY) != 1) - strerr_diefu1sys(111, "open /dev/console for writing") ; - if (fd_copy(2, 1) == -1) strerr_warnwu1sys("fd_copy") ; - + log_dieusys(LOG_EXIT_SYS, "open /dev/console for writing") ; + if (fd_copy(2, 1) == -1) log_warnusys("fd_copy") ; /* The end is coming! */ - prepare_stage4(what) ; unsupervise_tree() ; sync() ; - if (sig_ignore(SIGTERM) == -1) strerr_warnwu1sys("sig_ignore SIGTERM") ; - strerr_warni1x("sending all processes the TERM signal...") ; + + if (sig_ignore(SIGTERM) == -1) log_warnusys("sig_ignore SIGTERM") ; + + log_info("sending all processes the TERM signal...") ; + kill(-1, SIGTERM) ; kill(-1, SIGCONT) ; tain_from_millisecs(&deadline, grace_time) ; @@ -374,8 +375,11 @@ int main (int argc, char const *const *argv, char const *const *envp) tain_add_g(&deadline, &deadline) ; deepsleepuntil_g(&deadline) ; sync() ; - strerr_warni1x("sending all processes the KILL signal...") ; + + log_info("sending all processes the KILL signal...") ; + kill(-1, SIGKILL) ; + return 0 ; } diff --git a/src/66/66-start.c b/src/66/66-start.c index 6d86c07d..9cdb7c7c 100644 --- a/src/66/66-start.c +++ b/src/66/66-start.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-start" ; diff --git a/src/66/66-stop.c b/src/66/66-stop.c index 672958e6..a8b54450 100644 --- a/src/66/66-stop.c +++ b/src/66/66-stop.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-stop" ; diff --git a/src/66/66-svctl.c b/src/66/66-svctl.c index b4b63ab4..994a7970 100644 --- a/src/66/66-svctl.c +++ b/src/66/66-svctl.c @@ -12,12 +12,10 @@ * except according to the terms contained in the LICENSE file./ */ -#include <skalibs/strerr2.h> +#include <oblibs/log.h> #include <66/ssexec.h> -unsigned int VERBOSITY = 1 ; - int main(int argc, char const *const *argv,char const *const *envp) { PROG = "66-svctl" ; diff --git a/src/66/66-tree.c b/src/66/66-tree.c index ef3834b6..9211b369 100644 --- a/src/66/66-tree.c +++ b/src/66/66-tree.c @@ -19,7 +19,7 @@ //#include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <oblibs/directory.h> #include <oblibs/files.h> @@ -45,7 +45,6 @@ #define USAGE "66-tree [ -h ] [ -v verbosity ] [ -l ] [ -n|R ] [ -a|d ] [ -c ] [ -E|D ] [ -U ] [ -C clone ] tree" -unsigned int VERBOSITY = 1 ; static stralloc reslive = STRALLOC_ZERO ; static char const *cleantree = 0 ; @@ -70,35 +69,36 @@ static inline void info_help (void) ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(111,"write to stdout") ; } -static void cleanup(char const *tree){ - VERBO3 strerr_warnt3x("removing ",tree," ...") ; - rm_rf(tree) ; +static void cleanup(void) +{ + if (cleantree) + { + log_trace("removing ",cleantree,"...") ; + rm_rf(cleantree) ; + } } -static void auto_string(char *string,char const *str,size_t baselen) +static void auto_string(char *strings,char const *str,size_t baselen) { size_t slen = strlen(str) ; - memcpy(string + baselen,str,slen) ; - string[baselen+slen] = 0 ; + memcpy(strings + baselen,str,slen) ; + strings[baselen+slen] = 0 ; } static void auto_dir(char const *dst,mode_t mode) { - VERBO3 strerr_warnt2x("create directory: ",dst) ; + log_trace("create directory: ",dst) ; if (!dir_create_parent(dst,mode)) - { - if (cleantree) cleanup(cleantree) ; - strerr_diefu2sys(111,"create directory: ",dst) ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"create directory: ",dst) ; } -static void auto_create(char *string,char const *str,size_t baselen,mode_t mode) +static void auto_create(char *strings,char const *str,size_t baselen,mode_t mode) { - auto_string(string,str,baselen) ; - auto_dir(string,mode) ; + auto_string(strings,str,baselen) ; + auto_dir(strings,mode) ; } static void auto_check(char *dst,char const *str,size_t baselen,mode_t mode) @@ -114,12 +114,12 @@ static void auto_check_one(char *dst,mode_t mode) static void inline auto_stralloc(stralloc *sa,char const *str) { - if (!stralloc_cats(sa,str)) strerr_diefu1sys(111,"append stralloc") ; + if (!stralloc_cats(sa,str)) log_die_nomem("stralloc") ; } static void inline auto_stralloc0(stralloc *sa) { - if (!stralloc_0(sa)) strerr_diefu1sys(111,"append stralloc") ; + if (!stralloc_0(sa)) log_die_nomem("stralloc") ; sa->len-- ; } @@ -154,7 +154,7 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t own size_t extralen ; stralloc extra = STRALLOC_ZERO ; if (!set_ownerhome(&extra,owner)) - strerr_diefu1sys(111,"set home directory") ; + log_dieusys(LOG_EXIT_SYS,"set home directory") ; extralen = extra.len ; auto_stralloc_0(&extra,SS_LOGGER_USERDIR) ; @@ -176,15 +176,15 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t own { auto_string(dst,SS_SYSTEM,baselen) ; if(!file_create_empty(dst,SS_STATE + 1,0644)) - strerr_diefu3sys(111,"create ",dst,SS_STATE) ; + log_dieusys(LOG_EXIT_SYS,"create ",dst,SS_STATE) ; } auto_string(dst,"/",baselen + SS_SYSTEM_LEN) ; auto_string(dst,tree,baselen + SS_SYSTEM_LEN + 1) ; r = scan_mode(dst,S_IFDIR) ; - if (r == -1) strerr_dief2x(111,"invalid directory: ",dst) ; + if (r == -1) log_die(LOG_EXIT_SYS,"invalid directory: ",dst) ; /** we have one, keep it*/ - if (!stralloc_cats(dstree,dst)) retstralloc(0,"sanitize_tree") ; - if (!stralloc_0(dstree)) retstralloc(0,"sanitize_tree") ; + if (!stralloc_cats(dstree,dst)) log_die_nomem("stralloc") ; + if (!stralloc_0(dstree)) log_die_nomem("stralloc") ; if (!r) return 0 ; @@ -219,12 +219,11 @@ void create_tree(char const *tree,char const *treename) auto_create(dst,SS_SVC,newlen,0755) ; auto_create(dst,SS_RESOLVE,newlen,0755) ; dst[newlen] = 0 ; - VERBO3 strerr_warnt1x("write resolve file of inner bundle") ; + log_trace("write resolve file of inner bundle") ; if (!ss_resolve_write(&res,dst,SS_MASTER+1)) { ss_resolve_free(&res) ; - cleanup(cleantree) ; - strerr_diefu1sys(111,"write resolve file of inner bundle") ; + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"write resolve file of inner bundle") ; } ss_resolve_free(&res) ; @@ -237,21 +236,15 @@ void create_tree(char const *tree,char const *treename) auto_string(dstsym,dst,0) ; auto_string(dstsym,SS_SVC,newlen) ; - VERBO3 strerr_warnt4x("point symlink: ",sym," to ",dstsym) ; + log_trace("point symlink: ",sym," to ",dstsym) ; if (symlink(dstsym,sym) < 0) - { - cleanup(cleantree) ; - strerr_diefu2sys(111,"symlink: ", sym) ; - } - + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"symlink: ", sym) ; + auto_string(sym,SS_SYM_DB,newlen + 1) ; auto_string(dstsym,SS_DB,newlen) ; - VERBO3 strerr_warnt4x("point symlink: ",sym," to ",dstsym) ; + log_trace("point symlink: ",sym," to ",dstsym) ; if (symlink(dstsym,sym) < 0) - { - cleanup(cleantree) ; - strerr_diefu2sys(111,"symlink: ", sym) ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"symlink: ", sym) ; auto_string(dst,SS_DB,newlen) ; newlen = newlen + SS_DB_LEN ; @@ -261,20 +254,15 @@ void create_tree(char const *tree,char const *treename) auto_create(dst,SS_MASTER,newlen,0755) ; auto_string(dst,SS_MASTER,newlen) ; newlen = newlen + SS_MASTER_LEN ; - VERBO3 strerr_warnt3x("create file: ",dst,"/contents") ; + log_trace("create file: ",dst,"/contents") ; if (!file_create_empty(dst,"contents",0644)) - { - cleanup(cleantree) ; - strerr_diefu3sys(111,"create ",dst,"/contents") ; - } - + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"create: ",dst,"/contents") ; + auto_string(dst,"/type",newlen) ; - VERBO3 strerr_warnt2x("create file: ",dst) ; + log_trace("create file:",dst) ; if(!openwritenclose_unsafe(dst,"bundle\n",7)) - { - cleanup(cleantree) ; - strerr_diefu2sys(111,"write ",dst) ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"write: ",dst) ; + } @@ -297,12 +285,9 @@ void create_backupdir(char const *base, char const *treename) r = scan_mode(treetmp,S_IFDIR) ; if (r || (r == -1)) { - VERBO3 strerr_warnt2x("remove existing backup: ",treetmp) ; + log_trace("remove existing backup: ",treetmp) ; if (rm_rf(treetmp) < 0) - { - cleanup(cleantree) ; - strerr_diefu2sys(111,"remove: ",treetmp) ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"remove: ",treetmp) ; } if (!r) auto_dir(treetmp,0755) ; } @@ -330,13 +315,13 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) { uint32_pack(pack,uids[i+1]) ; pack[uint_fmt(pack,uids[i+1])] = 0 ; - VERBO3 strerr_warnt4x("create file : ",pack," at ",tmp) ; + log_trace("create file: ",pack," at ",tmp) ; if(!file_create_empty(tmp,pack,0644) && errno != EEXIST) { - VERBO3 strerr_warnwu4sys("create file : ",pack," at ",tmp) ; + log_warnusys("create file: ",pack," at ",tmp) ; return 0 ; } - VERBO3 strerr_warnt4x("user: ",pack," is allowed for tree: ",tree) ; + log_trace("user: ",pack," is allowed for tree: ",tree) ; } return 1 ; } @@ -352,11 +337,11 @@ int set_rules(char const *tree,uid_t *uids, size_t uidn,unsigned int what) memcpy(tmp + treelen + SS_RULES_LEN,"/",1) ; memcpy(tmp + treelen + SS_RULES_LEN + 1,pack,uint_fmt(pack,uids[i+1])) ; tmp[treelen + SS_RULES_LEN + 1 + uint_fmt(pack,uids[i + 1])] = 0 ; - VERBO3 strerr_warnt2x("unlink: ",tmp) ; + log_trace("unlink: ",tmp) ; r = unlink(tmp) ; if (r == -1) return 0 ; } - VERBO3 strerr_warnt4x("user: ",pack," is denied for tree: ",tree) ; + log_trace("user: ",pack," is denied for tree: ",tree) ; } return 1 ; } @@ -381,15 +366,15 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid auto_stralloc(&scandir,live->s) ; r = set_livescan(&scandir,owner) ; - if (!r) strerr_diefu1sys(111,"set livescan directory") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set livescan directory") ; auto_stralloc(&livestate,live->s) ; r = set_livestate(&livestate,owner) ; - if (!r) strerr_diefu1sys(111,"set livestate directory") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set livestate directory") ; auto_stralloc(&livetree,live->s) ; r = set_livetree(&livetree,owner) ; - if (!r) strerr_diefu1sys(111,"set livetree directory") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"set livetree directory") ; auto_stralloc(&livetree,"/") ; newlen = livetree.len ; auto_stralloc0(&livetree) ; @@ -399,11 +384,11 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid auto_stralloc0(&livestate) ; /** works begin */ if (scan_mode(livestate.s,S_IFDIR)) - if (!sastr_dir_get(&list,livestate.s,SS_LIVETREE_INIT,S_IFREG)) strerr_diefu2x(111,"get service list at: ",livestate.s) ; + if (!sastr_dir_get(&list,livestate.s,SS_LIVETREE_INIT,S_IFREG)) log_dieusys(LOG_EXIT_SYS,"get service list at: ",livestate.s) ; if (!list.len) { - VERBO1 strerr_warni2x("Not supervised: ",livestate.s) ; + log_warn("Not supervised: ",livestate.s) ; return ; } @@ -431,10 +416,10 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - VERBO3 strerr_warnwu2sys("wait for ",newargv[0]) ; + log_dieusys(LOG_EXIT_SYS,"wait for: ",newargv[0]) ; /** we don't want to die here, we try we can do to stop correctly * service list, in any case we want to unsupervise */ - if (wstat) VERBO3 strerr_warnwu1sys("stop services") ; + if (wstat) log_dieusys(LOG_EXIT_SYS,"stop services") ; } if (db_find_compiled_state(livetree.s,treename) >=0) @@ -444,7 +429,7 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid auto_stralloc(&livetree,treename) ; auto_stralloc(&livetree,SS_SVDIRS) ; auto_stralloc0(&livetree) ; - if (!sastr_dir_get(&list,livetree.s,"",S_IFDIR)) strerr_diefu2x(111,"get service list at: ",livetree.s) ; + if (!sastr_dir_get(&list,livetree.s,"",S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get service list at: ",livetree.s) ; livetree.len = newlen ; auto_stralloc(&livetree,treename) ; auto_stralloc0(&livetree) ; @@ -454,10 +439,10 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid s6rc_servicedir_unsupervise(livetree.s,prefix,list.s + i,0) ; r = sarealpath(&realsym,livetree.s) ; - if (r < 0 ) strerr_diefu2sys(111,"find realpath of: ",livetree.s) ; + if (r < 0 ) log_dieusys(LOG_EXIT_SYS,"find realpath of: ",livetree.s) ; auto_stralloc0(&realsym) ; - if (rm_rf(realsym.s) < 0) strerr_diefu2sys(111,"remove ", realsym.s) ; - if (rm_rf(livetree.s) < 0) strerr_diefu2sys(111,"remove ", livetree.s) ; + if (rm_rf(realsym.s) < 0) log_dieusys(LOG_EXIT_SYS,"remove: ", realsym.s) ; + if (rm_rf(livetree.s) < 0) log_dieusys(LOG_EXIT_SYS,"remove: ", livetree.s) ; livetree.len = newlen ; auto_stralloc(&livetree,treename) ; auto_stralloc0(&livetree) ; @@ -465,12 +450,12 @@ void tree_unsupervise(stralloc *live, char const *tree, char const *treename,uid unlink_void(livetree.s) ; } - if (scandir_send_signal(scandir.s,"an") <= 0) strerr_diefu2sys(111,"reload scandir: ",scandir.s) ; + if (scandir_send_signal(scandir.s,"an") <= 0) log_dieusys(LOG_EXIT_SYS,"reload scandir: ",scandir.s) ; /** remove /run/66/state/uid/treename directory */ - VERBO2 strerr_warni3x("delete ",livestate.s," ..." ) ; - if (rm_rf(livestate.s) < 0) strerr_diefu2sys(111,"delete ",livestate.s) ; + log_trace("delete: ",livestate.s,"..." ) ; + if (rm_rf(livestate.s) < 0) log_dieusys(LOG_EXIT_SYS,"delete ",livestate.s) ; - VERBO1 strerr_warni2x("Unsupervised successfully tree: ",treename) ; + log_info("Unsupervised successfully tree: ",treename) ; stralloc_free(&scandir) ; stralloc_free(&livestate) ; @@ -509,137 +494,132 @@ int main(int argc, char const *const *argv,char const *const *envp) int opt = getopt_args(argc,argv, "hv:l:na:d:cEDRC:U", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_dieusys(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(USAGE) ; break ; - case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; - if (!stralloc_0(&live)) retstralloc(111,"main") ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(USAGE) ; break ; + case 'l' : if (!stralloc_cats(&live,l.arg)) log_die_nomem("stralloc") ; + if (!stralloc_0(&live)) log_die_nomem("stralloc") ; break ; case 'n' : create = 1 ; break ; - case 'a' : if (!scan_uidlist_wdelim(l.arg,auids,',')) exitusage(USAGE) ; + case 'a' : if (!scan_uidlist_wdelim(l.arg,auids,',')) log_usage(USAGE) ; auidn = auids[0] ; allow = 1 ; break ; - case 'd' : if (!scan_uidlist_wdelim(l.arg,duids,',')) exitusage(USAGE) ; + case 'd' : if (!scan_uidlist_wdelim(l.arg,duids,',')) log_usage(USAGE) ; duidn = duids[0] ; deny = 1 ; break ; 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 'C' : if (!stralloc_cats(&clone,l.arg)) retstralloc(111,"main") ; - if (!stralloc_0(&clone)) retstralloc(111,"main") ; + case 'E' : enable = 1 ; if (disable) log_usage(USAGE) ; break ; + case 'D' : disable = 1 ; if (enable) log_usage (USAGE) ; break ; + case 'R' : remove = 1 ; if (create) log_usage(USAGE) ; break ; + case 'C' : if (!stralloc_cats(&clone,l.arg)) log_die_nomem("stralloc") ; + if (!stralloc_0(&clone)) log_die_nomem("stralloc") ; snap = 1 ; break ; - case 'U' : unsupervise = 1 ; if (create) exitusage(USAGE) ; break ; - default : exitusage(USAGE) ; + case 'U' : unsupervise = 1 ; if (create)log_usage(USAGE) ; break ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc != 1) exitusage(USAGE) ; + if (argc != 1) log_usage(USAGE) ; tree = argv[0] ; owner = MYUID ; - if (!set_ownersysdir(&base, owner)) strerr_diefu1sys(111, "set owner directory") ; + if (!set_ownersysdir(&base, owner)) log_dieusys(LOG_EXIT_SYS,"set owner directory") ; r = set_livedir(&live) ; - if (!r) exitstralloc("main:livedir") ; - if(r < 0) strerr_dief3x(111,"livedir: ",live.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if(r < 0) log_dieu(LOG_EXIT_SYS,"livedir: ",live.s," must be an absolute path") ; - VERBO2 strerr_warni3x("sanitize ",tree," ..." ) ; + log_trace("sanitize ",tree,"..." ) ; r = sanitize_tree(&dstree,base.s,tree,owner) ; if(!r && create) { /** set cleanup */ cleantree = dstree.s ; - VERBO2 strerr_warni3x("creating ",dstree.s," ..." ) ; + log_trace("creating: ",dstree.s,"..." ) ; create_tree(dstree.s,tree) ; - VERBO2 strerr_warni3x("creating backup directory for ", tree," ...") ; + log_trace("creating backup directory for: ", tree,"...") ; create_backupdir(base.s,tree) ; /** unset cleanup */ cleantree = 0 ; - VERBO2 strerr_warni3x("set permissions rules for ",dstree.s," ..." ) ; + log_trace("set permissions rules for: ",dstree.s,"..." ) ; if (!set_rules(dstree.s,auids,auidn,1))//1 allow - { - cleanup(dstree.s) ; - strerr_diefu1x(111,"set permissions access") ; - } - + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"set permissions access") ; + size_t dblen = dstree.len - 1 ; char newdb[dblen + SS_SVDIRS_LEN + 1] ; auto_string(newdb,dstree.s,0) ; auto_string(newdb,SS_SVDIRS,dblen) ; - VERBO2 strerr_warni5x("compile ",newdb,"/db/",tree," ..." ) ; + log_trace("compile: ",newdb,"/db/",tree,"..." ) ; if (!db_compile(newdb,dstree.s,tree,envp)) - { - cleanup(dstree.s) ; - strerr_diefu4x(111,"compile ",newdb,"/db/",tree) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"compile ",newdb,"/db/",tree) ; + r = 1 ; create = 0 ; - VERBO1 strerr_warni2x("Created successfully tree: ",tree) ; + log_info("Created successfully tree: ",tree) ; } - if ((!r && !create) || (!r && enable)) strerr_diefu2x(111,"find tree: ",dstree.s) ; - if (r && create) strerr_diefu3x(110,"create ",dstree.s,": already exist") ; + if ((!r && !create) || (!r && enable)) log_dieusys(LOG_EXIT_SYS,"find tree: ",dstree.s) ; + if (r && create) log_dieu(LOG_EXIT_USER,"create: ",dstree.s,": already exist") ; if (enable) { - VERBO2 strerr_warni3x("enable ",dstree.s," ..." ) ; + log_trace("enable: ",dstree.s,"..." ) ; r = tree_cmd_state(VERBOSITY,"-a",tree) ; - if (!r) strerr_diefu6x(111,"add: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + if (!r) log_dieusys(LOG_EXIT_SYS,"add: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; else if (r == 1) { - VERBO1 strerr_warni2x("Enabled successfully tree: ",tree) ; + log_info("Enabled successfully tree: ",tree) ; } - else VERBO1 strerr_warni2x("Already enabled tree: ",tree) ; + else log_info("Already enabled tree: ",tree) ; } if (disable) { - VERBO2 strerr_warni3x("disable ",dstree.s," ..." ) ; + log_trace("disable: ",dstree.s,"..." ) ; r = tree_cmd_state(VERBOSITY,"-d",tree) ; - if (!r) strerr_diefu6x(111,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + if (!r) log_dieusys(LOG_EXIT_SYS,"remove: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; else if (r == 1) { - VERBO1 strerr_warni2x("Disabled successfully tree: ",tree) ; + log_info("Disabled successfully tree: ",tree) ; } - else VERBO1 strerr_warni2x("Already disabled tree: ",tree) ; + else log_info("Already disabled tree: ",tree) ; } if (auidn) { - VERBO2 strerr_warni3x("set allowed user for tree: ",dstree.s," ..." ) ; - if (!set_rules(dstree.s,auids,auidn,1)) strerr_diefu1x(111,"set permissions access") ; + log_trace("set allowed user for tree: ",dstree.s,"..." ) ; + if (!set_rules(dstree.s,auids,auidn,1)) log_dieu(LOG_EXIT_SYS,"set permissions access") ; } if (duidn) { - VERBO2 strerr_warni3x("set denied user for tree: ",dstree.s," ..." ) ; - if (!set_rules(dstree.s,duids,duidn,0)) strerr_diefu1x(111,"set permissions access") ; + log_trace("set denied user for tree: ",dstree.s,"..." ) ; + if (!set_rules(dstree.s,duids,duidn,0)) log_dieu(LOG_EXIT_SYS,"set permissions access") ; } if(current) { - 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") ; + log_trace("make: ",dstree.s," as default ..." ) ; + if (!tree_switch_current(base.s,tree)) log_dieusys(LOG_EXIT_SYS,"set: ",dstree.s," as default") ; + log_info("Set successfully: ",tree," as default") ; } if (unsupervise) tree_unsupervise(&live,dstree.s,tree,owner,envp) ; if (remove) { - VERBO2 strerr_warni3x("delete ",dstree.s," ..." ) ; - if (rm_rf(dstree.s) < 0) strerr_diefu2sys(111,"delete ", dstree.s) ; + log_trace("delete: ",dstree.s,"..." ) ; + if (rm_rf(dstree.s) < 0) log_dieusys(LOG_EXIT_SYS,"delete: ", dstree.s) ; size_t treelen = strlen(tree) ; size_t baselen = base.len ; @@ -653,14 +633,14 @@ 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("delete backup of tree ",treetmp," ...") ; - if (rm_rf(treetmp) < 0) strerr_diefu2sys(111,"delete: ",treetmp) ; + log_trace("delete backup of tree: ",treetmp,"...") ; + if (rm_rf(treetmp) < 0) log_dieusys(LOG_EXIT_SYS,"delete: ",treetmp) ; } - VERBO2 strerr_warni6x("disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + log_trace("disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; if (!tree_cmd_state(VERBOSITY,"-d",tree)) - strerr_diefu6x(111,"disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; + log_dieu(LOG_EXIT_SYS,"disable: ",dstree.s," at: ",base.s,SS_SYSTEM,SS_STATE) ; - VERBO1 strerr_warni2x("Deleted successfully: ",tree) ; + log_info("Deleted successfully: ",tree) ; } if (snap) @@ -673,10 +653,10 @@ int main(int argc, char const *const *argv,char const *const *envp) auto_stralloc_0(&dstree,clone.s) ; r = scan_mode(dstree.s,S_IFDIR) ; - 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) ; + if ((r < 0) || r) log_die(LOG_EXIT_SYS,dstree.s,": already exist") ; + log_trace("clone: ",dstree.s," as ",tmp,"..." ) ; + if (!hiercopy(tmp,dstree.s)) log_dieusys(LOG_EXIT_SYS,"copy: ",dstree.s," at: ",clone.s) ; + log_info("Cloned successfully: ",tree," to ",clone.s) ; } stralloc_free(&reslive) ; stralloc_free(&base) ; diff --git a/src/66/deps-exe/66-hpr b/src/66/deps-exe/66-hpr index d720e509..ccd6e590 100644 --- a/src/66/deps-exe/66-hpr +++ b/src/66/deps-exe/66-hpr @@ -1,5 +1,6 @@ ${LIB66} ${LIBUTMPS} +-loblibs -lskarnet ${SYSCLOCK_LIB} ${SOCKET_LIB} diff --git a/src/66/deps-exe/66-shutdown b/src/66/deps-exe/66-shutdown index aa3691e7..2e83e857 100644 --- a/src/66/deps-exe/66-shutdown +++ b/src/66/deps-exe/66-shutdown @@ -1,5 +1,6 @@ ${LIB66} ${LIBUTMPS} +-loblibs -lskarnet ${SYSCLOCK_LIB} ${SOCKET_LIB} diff --git a/src/extra-tools/66-echo.c b/src/extra-tools/66-echo.c index bc3d8966..d9c3b242 100644 --- a/src/extra-tools/66-echo.c +++ b/src/extra-tools/66-echo.c @@ -16,9 +16,10 @@ * All credits goes to Laurent Bercot <ska-remove-this-if-you-are-not-a-bot@skarnet.org> * */ +#include <oblibs/log.h> + #include <skalibs/sgetopt.h> #include <skalibs/buffer.h> -#include <skalibs/strerr2.h> #define USAGE "66-echo [ -h ] [ -n ] [ -s sep ] args..." @@ -33,7 +34,7 @@ static inline void info_help (void) " -s: use as character separator\n" ; if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } int main (int argc, char const *const *argv) @@ -52,7 +53,7 @@ int main (int argc, char const *const *argv) case 'h': info_help() ; return 0 ; case 'n': donl = 0 ; break ; case 's': sep = *l.arg ; break ; - default : strerr_dieusage(100, USAGE) ; + default : log_usage(USAGE) ; } } argc -= l.ind ; argv += l.ind ; @@ -65,5 +66,5 @@ int main (int argc, char const *const *argv) if (!buffer_flush(buffer_1small)) goto err ; return 0 ; err: - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } diff --git a/src/extra-tools/66-umountall.c b/src/extra-tools/66-umountall.c index 2b9321b0..f58ca6a3 100644 --- a/src/extra-tools/66-umountall.c +++ b/src/extra-tools/66-umountall.c @@ -22,7 +22,8 @@ #include <mntent.h> #include <sys/mount.h> -#include <skalibs/strerr2.h> +#include <oblibs/log.h> + #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> @@ -44,7 +45,7 @@ int main (int argc, char const *const *argv) PROG = "s6-linux-init-umountall" ; fp = setmntent("/proc/mounts", "r") ; - if (!fp) strerr_diefu1sys(111, "open /proc/mounts") ; + if (!fp) log_dieusys(LOG_EXIT_SYS, "open /proc/mounts") ; for (;;) { @@ -63,12 +64,12 @@ int main (int argc, char const *const *argv) } if (i < EXCLUDEN && got[i] == 1) continue ; if (line >= MAXLINES) - strerr_dief1x(100, "too many mount points") ; + log_die(100, "too many mount points") ; mountpoints[line++] = sa.len ; if (!stralloc_cats(&sa, p->mnt_dir) || !stralloc_0(&sa)) - strerr_diefu1sys(111, "add mount point to list") ; + log_dieusys(LOG_EXIT_SYS, "add mount point to list") ; } - if (errno) strerr_diefu1sys(111, "read /proc/mounts") ; + if (errno) log_dieusys(LOG_EXIT_SYS, "read /proc/mounts") ; endmntent(fp) ; while (line--) @@ -76,7 +77,7 @@ int main (int argc, char const *const *argv) if (umount(sa.s + mountpoints[line]) == -1) { e++ ; - strerr_warnwu2sys("umount ", sa.s + mountpoints[line]) ; + log_warnusys("umount ", sa.s + mountpoints[line]) ; } } stralloc_free(&sa) ; diff --git a/src/extra-tools/deps-exe/66-echo b/src/extra-tools/deps-exe/66-echo index 9db13a13..aa08a149 100644 --- a/src/extra-tools/deps-exe/66-echo +++ b/src/extra-tools/deps-exe/66-echo @@ -1,2 +1,3 @@ +-loblibs -lskarnet diff --git a/src/extra-tools/deps-exe/66-umountall b/src/extra-tools/deps-exe/66-umountall index 9db13a13..d24233ce 100644 --- a/src/extra-tools/deps-exe/66-umountall +++ b/src/extra-tools/deps-exe/66-umountall @@ -1,2 +1,2 @@ +-loblibs -lskarnet - diff --git a/src/include/66/info.h b/src/include/66/info.h index 26a548a0..d4368f33 100644 --- a/src/include/66/info.h +++ b/src/include/66/info.h @@ -15,7 +15,7 @@ #include <wchar.h> #include <oblibs/string.h> -#include <oblibs/display.h> +#include <oblibs/log.h> #include <66/enum.h> #include <66/resolve.h> @@ -26,10 +26,6 @@ #define INFO_FIELD_MAXLEN 30 -set_color_t *info_color ; -extern set_color_t use_color ; -extern set_color_t no_color ; - typedef struct depth_s depth_t ; struct depth_s { diff --git a/src/include/66/utils.h b/src/include/66/utils.h index 75737380..946656a1 100644 --- a/src/include/66/utils.h +++ b/src/include/66/utils.h @@ -18,18 +18,14 @@ #include <sys/types.h> #include <unistd.h> //getuid +#include <oblibs/log.h> + #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <66/ssexec.h> #include <66/resolve.h> -extern unsigned int VERBOSITY ; - -#define VERBO1 if(VERBOSITY >= 1) -#define VERBO2 if(VERBOSITY >= 2) -#define VERBO3 if(VERBOSITY >= 3) - #define MYUID getuid() #define YOURUID(passto,owner) youruid(passto,owner) #define MYGID getgid() diff --git a/src/lib66/backup_cmd_switcher.c b/src/lib66/backup_cmd_switcher.c index a918cd5d..5cc5bb8e 100644 --- a/src/lib66/backup_cmd_switcher.c +++ b/src/lib66/backup_cmd_switcher.c @@ -17,7 +17,7 @@ #include <sys/stat.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/sastr.h> @@ -55,7 +55,7 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) { int opt = getopt_args(argc,argv, "v:t:s:b", &l) ; if (opt == -1) break ; - if (opt == -2){ strerr_warnw1x("options must be set first") ; return -1 ; } + if (opt == -2) log_warn_return(LOG_EXIT_LESSONE,"options must be set first") ; switch (opt) { case 'v' : if (!uint0_scan(l.arg, &verbosity)) return -1 ; break ; @@ -72,10 +72,8 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) if ((!change && !back) || !type) return -1 ; if (type < CLASSIC || type > ONESHOT) - { - VERBO3 strerr_warnw1x("unknown type for backup_switcher") ; - return -1 ; - } + log_warn_return(LOG_EXIT_LESSONE,"unknown type for backup_switcher") ; + tree = *argv ; size_t treelen = strlen(tree) ; @@ -107,18 +105,14 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) { if(lstat(sym,&st) < 0) return -1 ; if(!(S_ISLNK(st.st_mode))) - { - VERBO3 strerr_warnwu2x("find symlink: ",sym) ; - return -1 ; - } + log_warn_return(LOG_EXIT_LESSONE,"find symlink: ",sym) ; + stralloc symreal = STRALLOC_ZERO ; r = sarealpath(&symreal,sym) ; if (r < 0) - { - VERBO3 strerr_warnwu2sys("retrieve real path from: ",sym) ; - return -1 ; - } + log_warnusys_return(LOG_EXIT_LESSONE,"retrieve real path from: ",sym) ; + char *b = NULL ; b = memmem(symreal.s,symreal.len,SS_BACKUP,SS_BACKUP_LEN) ; @@ -174,27 +168,17 @@ int backup_switcher(int argc, char const *const *argv,ssexec_t *info) if (what >= 0) { if (unlink(sym) < 0) - { - VERBO3 strerr_warnwu2sys("remove symlink: ", sym) ; - return -1 ; - } + log_warnusys_return(LOG_EXIT_LESSONE,"remove symlink: ", sym) ; } if (what) { - if (symlink(dstback,sym) < 0) - { - VERBO3 strerr_warnwu2sys("symlink: ", dstback) ; - return -1 ; - } + log_warnusys_return(LOG_EXIT_LESSONE,"symlink: ", dstback) ; } if (!what) { if (symlink(dstsrc,sym) < 0) - { - VERBO3 strerr_warnwu2sys("symlink: ", psrc) ; - return -1 ; - } + log_warnusys_return(LOG_EXIT_LESSONE,"symlink: ", psrc) ; } } @@ -208,10 +192,8 @@ int backup_cmd_switcher(unsigned int verbosity,char const *cmd,ssexec_t *info) stralloc opts = STRALLOC_ZERO ; if (!sastr_clean_string(&opts,cmd)) - { - VERBO3 strerr_warnwu2x("clean: ",cmd) ; - return -1 ; - } + log_warnu_return(LOG_EXIT_LESSONE,"clean: ",cmd) ; + int newopts = 5 + sastr_len(&opts) ; char const *newargv[newopts] ; unsigned int m = 0 ; diff --git a/src/lib66/backup_make_new.c b/src/lib66/backup_make_new.c index 3346d6b5..a5cf5bfe 100644 --- a/src/lib66/backup_make_new.c +++ b/src/lib66/backup_make_new.c @@ -17,7 +17,8 @@ #include <sys/stat.h> #include <stdlib.h> -#include <oblibs/error2.h> + +#include <oblibs/log.h> #include <oblibs/types.h> #include <oblibs/directory.h> @@ -72,29 +73,21 @@ int backup_make_new(ssexec_t *info, unsigned int type) r = scan_mode(back,S_IFDIR) ; if (r || (r < 0)) { - VERBO3 strerr_warnt2x("rm directory: ", back) ; + log_trace("rm directory: ", back) ; if (rm_rf(back) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",back) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"remove: ",back) ; + r = 0 ; } if (!r) { - VERBO3 strerr_warnt2x("create directory: ", back) ; + log_trace("create directory: ", back) ; if (!dir_create(back,0755)) - { - VERBO3 strerr_warnwu2sys("create directory: ",back) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create directory: ",back) ; } - VERBO3 strerr_warnt4x("copy: ",src," to: ", back) ; + log_trace("copy: ",src," to: ", back) ; if (!hiercopy(src, back)) - { - VERBO3 strerr_warnwu4sys("copy: ",src," to ",back) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"copy: ",src," to ",back) ; memcpy(src + newsrc,SS_RESOLVE,SS_RESOLVE_LEN) ; src[newsrc + SS_RESOLVE_LEN] = 0 ; @@ -105,29 +98,21 @@ int backup_make_new(ssexec_t *info, unsigned int type) r = scan_mode(back,S_IFDIR) ; if (r || (r < 0)) { - VERBO3 strerr_warnt2x("rm directory: ", back) ; + log_trace("rm directory: ", back) ; if (rm_rf(back) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",back) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"remove: ",back) ; + r = 0 ; } if (!r) { - VERBO3 strerr_warnt2x("create directory: ", back) ; + log_trace("create directory: ", back) ; if (!dir_create(back,0755)) - { - VERBO3 strerr_warnwu2sys("create directory: ",back) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create directory: ",back) ; } - VERBO3 strerr_warnt4x("copy: ",src," to: ", back) ; + log_trace("copy: ",src," to: ", back) ; if (!hiercopy(src, back)) - { - VERBO3 strerr_warnwu4sys("copy: ",src," to ",back) ; - return 0 ; - } - + log_warnusys_return(LOG_EXIT_ZERO,"copy: ",src," to ",back) ; + return 1 ; } diff --git a/src/lib66/backup_realpath_sym.c b/src/lib66/backup_realpath_sym.c index 8761c188..e08537d5 100644 --- a/src/lib66/backup_realpath_sym.c +++ b/src/lib66/backup_realpath_sym.c @@ -17,7 +17,7 @@ #include <sys/types.h> #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <skalibs/stralloc.h> @@ -57,7 +57,7 @@ int backup_realpath_sym(stralloc *sa, ssexec_t *info,unsigned int type) sa->len = 0 ; r = sarealpath(sa,sym) ; if (r == -1 ) return 0 ; - if (!stralloc_0(sa)) retstralloc(0,"backup_realpath_sym") ; + if (!stralloc_0(sa)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; return 1 ; } diff --git a/src/lib66/db_compile.c b/src/lib66/db_compile.c index 2f64cde6..9ea1554d 100644 --- a/src/lib66/db_compile.c +++ b/src/lib66/db_compile.c @@ -21,7 +21,7 @@ #include <sys/types.h> #include <oblibs/string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <skalibs/types.h> @@ -53,10 +53,7 @@ int db_compile(char const *workdir, char const *tree, char const *treename, char if (r) { if (rm_rf(dest) < 0) - { - VERBO3 strerr_warnwu2sys("remove ", dest) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"remove: ", dest) ; } char const *newargv[7] ; @@ -74,15 +71,10 @@ int db_compile(char const *workdir, char const *tree, char const *treename, char pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - { - VERBO3 strerr_warnwu2sys("wait for ",newargv[0]) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"wait for: ",newargv[0]) ; + if (wstat) - { - VERBO3 strerr_warnwu2x("compile: ",dest) ; - return 0 ; - } - + log_warnusys_return(LOG_EXIT_ZERO,"compile: ",dest) ; + return 1 ; } diff --git a/src/lib66/db_find_compiled_state.c b/src/lib66/db_find_compiled_state.c index 3c33b87f..fb4b0212 100644 --- a/src/lib66/db_find_compiled_state.c +++ b/src/lib66/db_find_compiled_state.c @@ -16,7 +16,7 @@ #include <sys/stat.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -43,18 +43,15 @@ int db_find_compiled_state(char const *livetree, char const *treename) if(lstat(current,&st) < 0) return -1 ; if(!(S_ISLNK(st.st_mode))) - { - VERBO3 strerr_warnwu2x("find symlink: ",current) ; - return -1 ; - } - + log_warnu_return(LOG_EXIT_LESSONE,"find symlink: ",current) ; + stralloc symreal = STRALLOC_ZERO ; r = sarealpath(&symreal,current) ; - if (r < 0 ) + if (r < 0 ) { - VERBO3 strerr_warnwu2x("find real path: ",current) ; - return -1 ; + stralloc_free(&symreal) ; + log_warnu_return(LOG_EXIT_LESSONE,"find real path: ",current) ; } char *b = NULL ; b = memmem(symreal.s,symreal.len,SS_BACKUP,SS_BACKUP_LEN) ; diff --git a/src/lib66/db_switch_to.c b/src/lib66/db_switch_to.c index 40d9b52f..441003b9 100644 --- a/src/lib66/db_switch_to.c +++ b/src/lib66/db_switch_to.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> @@ -49,43 +49,43 @@ 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 realpath of symlink for db of tree: ",info->treename.s) ; + log_warnusys("find realpath of symlink for db of tree: ",info->treename.s) ; goto err ; } // point to origin if (!r && where) { - VERBO3 strerr_warnt2x("make a backup of db service for: ",info->treename.s) ; + log_trace("make a backup of db service for: ",info->treename.s) ; if (!backup_make_new(info,LONGRUN)) { - VERBO3 strerr_warnwu2sys("make a backup of db service for: ",info->treename.s) ; + log_warnusys("make a backup of db service for: ",info->treename.s) ; goto err ; } - VERBO3 strerr_warnt3x("switch db symlink of tree: ",info->treename.s," to backup") ; + log_trace("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 symlink of tree: ",info->treename.s," to backup") ; + log_warnusys("switch db symlink of tree: ",info->treename.s," to backup") ; goto err ; } if (db_ok(info->livetree.s, info->treename.s)) { if (!backup_realpath_sym(&db,info,LONGRUN)) { - VERBO3 strerr_warnwu2sys("find path of db: ",db.s) ; + log_warnusys("find path of db: ",db.s) ; } - VERBO3 strerr_warnt4x("update ",info->livetree.s," to ",db.s) ; + log_trace("update ",info->livetree.s," to ",db.s) ; if (!db_update(db.s, info,envp)) { - VERBO3 strerr_warnt2x("rollback db service: ", info->treename.s) ; + log_trace("rollback db service: ", info->treename.s) ; memcpy(cmd + cmdlen," -s0",4) ; cmd[cmdlen + 4] = 0 ; r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) { - VERBO3 strerr_warnwu3sys("switch db symlink of tree: ",info->treename.s," to source") ; + log_warnusys("switch db symlink of tree: ",info->treename.s," to source") ; goto err ; } } @@ -93,13 +93,13 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) } else if (r > 0 && !where) { - VERBO3 strerr_warnt3x("switch db symlink of tree: ",info->treename.s," to source") ; + log_trace("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 symlink of tree: ",info->treename.s," to source") ; + log_warnusys("switch db symlink of tree: ",info->treename.s," to source") ; goto err ; } @@ -107,27 +107,27 @@ int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) { if (!backup_realpath_sym(&db,info,LONGRUN)) { - VERBO3 strerr_warnwu2sys("find path of db: ",db.s) ; + log_warnusys("find path of db: ",db.s) ; goto err ; } - VERBO3 strerr_warnt4x("update ",info->livetree.s," to ",db.s) ; + log_trace("update ",info->livetree.s," to ",db.s) ; if (!db_update(db.s, info,envp)) { - VERBO3 strerr_warnt2x("rollback db: ", info->treename.s) ; + log_trace("rollback db: ", info->treename.s) ; 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") ; + log_warnusys("switch db service for: ",info->treename.s," to backup") ; goto err ; } } } - VERBO3 strerr_warnt2x("make a backup of db service for: ",info->treename.s) ; + log_trace("make a backup of db service for: ",info->treename.s) ; if (!backup_make_new(info,LONGRUN)) { - VERBO3 strerr_warnwu2sys("make a backup of db service for: ",info->treename.s) ; + log_warnusys("make a backup of db service for: ",info->treename.s) ; goto err ; } } diff --git a/src/lib66/db_update.c b/src/lib66/db_update.c index 174a502f..875f31e6 100644 --- a/src/lib66/db_update.c +++ b/src/lib66/db_update.c @@ -19,7 +19,7 @@ #include <sys/types.h> #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> @@ -63,14 +63,10 @@ int db_update(char const *newdb, ssexec_t *info,char const *const *envp) pid = child_spawn0(newargv[0],newargv,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - { - strerr_warnwu2sys("wait for ",newargv[0]) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"wait for ",newargv[0]) ; + if (wstat) - { - VERBO3 strerr_warnwu4x("update: ",newlive," to ",db) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"update: ",newlive," to ",db) ; + return 1 ; } diff --git a/src/lib66/deps-lib/66 b/src/lib66/deps-lib/66 index dd739253..bbea3507 100644 --- a/src/lib66/deps-lib/66 +++ b/src/lib66/deps-lib/66 @@ -32,7 +32,6 @@ set_livetree.o set_ownerhome.o set_ownersysdir.o ss_info_utils.o -ss_utils.o ssexec_dbctl.o ssexec_enable.o ssexec_env.o diff --git a/src/lib66/hpr_wall.c b/src/lib66/hpr_wall.c index 8fce8ebf..0a1f8475 100644 --- a/src/lib66/hpr_wall.c +++ b/src/lib66/hpr_wall.c @@ -21,7 +21,6 @@ #include <skalibs/posixishard.h> #include <skalibs/allreadwrite.h> -#include <skalibs/strerr2.h> #include <skalibs/djbunix.h> #include <66/hpr.h> diff --git a/src/lib66/instance.c b/src/lib66/instance.c index bc07ad2f..d8367c99 100644 --- a/src/lib66/instance.c +++ b/src/lib66/instance.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/files.h> #include <oblibs/string.h> #include <oblibs/directory.h> @@ -75,11 +75,11 @@ int instance_create(stralloc *sasv,char const *svname, char const *regex, char c copy = svname + tlen ; if (!file_readputsa(&tmp,src,template)) { - VERBO3 strerr_warnwu3sys("open: ",src,template) ; + log_warnusys("open: ",src,template) ; goto err ; } if (!sastr_replace_all(&tmp,regex,copy)){ - VERBO3 strerr_warnwu3x("replace instance character at: ",src,template) ; + log_warnusys("replace instance character at: ",src,template) ; goto err ; } if (!stralloc_copy(sasv,&tmp)) goto err ; diff --git a/src/lib66/parser.c b/src/lib66/parser.c index a510fbbe..7b1fc676 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -17,7 +17,7 @@ #include <stdint.h> //#include <stdio.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/files.h> #include <oblibs/obgetopt.h> @@ -26,7 +26,6 @@ #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> -#include <skalibs/strerr2.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> #include <66/enum.h> @@ -44,27 +43,27 @@ int parser(sv_alltype *service,stralloc *src,char const *svname) r = section_get_range(&sasection,src) ; if (r <= 0){ - strerr_warnwu2x("parse section of service file: ",svname) ; + log_warnu("parse section of service file: ",svname) ; goto err ; } if (!sasection.idx[MAIN]) { - VERBO1 strerr_warnw2x("missing section [main] in service file: ", svname) ; + log_warn("missing section [main] in service file: ", svname) ; goto err ; } if (!key_get_range(&ganocheck,&sasection,&svtype)) goto err ; if (svtype < 0) { - VERBO1 strerr_warnw4x("invalid value for key: ",get_keybyid(TYPE)," in service file: ",svname) ; + log_warn("invalid value for key: ",get_keybyid(TYPE)," in service file: ",svname) ; goto err ; } if (svtype != BUNDLE && !sasection.idx[START]) { - VERBO1 strerr_warnw2x("missing section [start] in service file: ", svname) ; + log_warn("missing section [start] in service file: ", svname) ; goto err ; } if (!genalloc_len(keynocheck,&ganocheck)){ - VERBO1 strerr_warnw2x("empty service file: ",svname) ; + log_warn("empty service file: ",svname) ; goto err ; } for (i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) @@ -74,7 +73,7 @@ int parser(sv_alltype *service,stralloc *src,char const *svname) { if (!get_mandatory(&ganocheck,idsec,j)) { - VERBO1 strerr_warnw2x("mandatory key is missing in service file: ",svname) ; + log_warn("mandatory key is missing in service file: ",svname) ; goto err ; } } @@ -83,7 +82,7 @@ int parser(sv_alltype *service,stralloc *src,char const *svname) { if (!nocheck_toservice(&(genalloc_s(keynocheck,&ganocheck)[i]),svtype,service)) { - VERBO1 strerr_warnwu2x("keep information of service file: ",svname) ; + log_warnu("keep information of service file: ",svname) ; goto err ; } } @@ -91,7 +90,7 @@ int parser(sv_alltype *service,stralloc *src,char const *svname) { if (!add_pipe(service, &deps)) { - VERBO1 strerr_warnwu2x("add pipe: ", keep.s+service->cname.name) ; + log_warnu("add pipe: ", keep.s+service->cname.name) ; goto err ; } } diff --git a/src/lib66/parser_enabled.c b/src/lib66/parser_enabled.c index 4866a54a..306c47bc 100644 --- a/src/lib66/parser_enabled.c +++ b/src/lib66/parser_enabled.c @@ -20,7 +20,7 @@ #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/directory.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/sastr.h> #include <skalibs/stralloc.h> @@ -37,21 +37,21 @@ int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force int ret = 1 ; if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) { - VERBO3 strerr_warnwu1sys("set revolve pointer to source") ; + log_warnusys("set revolve pointer to source") ; goto err ; } if (ss_resolve_check(sares.s,svname)) { if (!ss_resolve_read(&res,sares.s,svname)) { - VERBO3 strerr_warnwu2sys("read resolve file of: ",svname) ; + log_warnusys("read resolve file of: ",svname) ; goto err ; } if (res.disen) { (*exist) = 1 ; if (!force) { - VERBO1 strerr_warnw3x("Ignoring: ",svname," service: already enabled") ; + log_info("Ignoring: ",svname," service: already enabled") ; ret = 2 ; goto freed ; } @@ -105,18 +105,18 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo newsv.len = 0 ; if (sv_before->cname.itype != BUNDLE) { - VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+id) ; - }else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+id," as service") ; + log_trace("Service : ",sv, " depends on : ",deps.s+id) ; + }else log_trace("Bundle : ",sv, " contents : ",deps.s+id," as service") ; dname = deps.s + id ; if (!ss_resolve_src_path(&newsv,dname,info)) { - VERBO3 strerr_warnwu2x("resolve source path of: ",dname) ; + log_warnu("resolve source path of: ",dname) ; goto err ; } if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist)) goto err ; } } - else VERBO3 strerr_warni2x(sv,": haven't dependencies") ; + else log_trace(sv,": haven't dependencies") ; stralloc_free(&newsv) ; return 1 ; err: @@ -145,20 +145,16 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un insta = instance_check(svname) ; if (!insta) - { - VERBO3 strerr_warnw2x("invalid instance name: ",svname) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO, "invalid instance name: ",svname) ; + if (insta > 0) { if (!instance_create(sasv,svname,SS_INSTANCE,svsrc,insta)) - { - VERBO3 strerr_warnwu2x("create instance service: ",svname) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"create instance service: ",svname) ; + /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(sasv,"\n")) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(sasv)) retstralloc(0,"parse_service_before") ; + if (!stralloc_cats(sasv,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(sasv)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; }else if (!read_svfile(sasv,svname,svsrc)) return 0 ; memcpy(svpath,svsrc,svsrclen) ; @@ -167,7 +163,7 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un if (sastr_cmp(parsed_list,svpath) >= 0) { - VERBO2 strerr_warni2x(sv,": already added") ; + log_trace(sv,": already added") ; sasv->len = 0 ; sv_alltype_free(&sv_before) ; goto freed ; @@ -188,7 +184,7 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un if (!instance_splitname(&sainsta,svname,insta,0)) goto err ; if (sastr_find(&name,sainsta.s) == -1) { - strerr_warnw2x("invalid instantiated service name: ", keep.s + sv_before.cname.name) ; + log_warn("invalid instantiated service name: ", keep.s + sv_before.cname.name) ; goto err ; } stralloc_free(&sainsta) ; diff --git a/src/lib66/parser_utils.c b/src/lib66/parser_utils.c index 2b6cd8fd..23a03baa 100644 --- a/src/lib66/parser_utils.c +++ b/src/lib66/parser_utils.c @@ -26,7 +26,7 @@ #include <oblibs/bytes.h> #include <oblibs/string.h> #include <oblibs/files.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <oblibs/mill.h> #include <oblibs/environ.h> @@ -228,7 +228,7 @@ int key_get_range(genalloc *ga, section_t *sasection,int *svtype) nocheck.mandatory = OPTS ; section_setsa(i,&psasection,sasection) ; if (!stralloc_cats(&nocheck.val,psasection->s+1)) goto err ;//+1 remove the first '\n' - if (!environ_get_clean_env(&nocheck.val)) { VERBO3 strerr_warnwu2x("parse section: ",get_keybyid(i)) ; goto err ; } + if (!environ_get_clean_env(&nocheck.val)) { log_warnu("parse section: ",get_keybyid(i)) ; goto err ; } if (!stralloc_cats(&nocheck.val,"\n") || !stralloc_0(&nocheck.val)) goto err ; nocheck.val.len-- ; @@ -269,7 +269,7 @@ int key_get_range(genalloc *ga, section_t *sasection,int *svtype) case QUOTE: if (!sastr_get_double_quote(&nocheck.val)) { - VERBO3 parse_err(6,&nocheck) ; + parse_err(6,&nocheck) ; goto err ; } if (!stralloc_0(&nocheck.val)) goto err ; @@ -277,12 +277,12 @@ int key_get_range(genalloc *ga, section_t *sasection,int *svtype) case BRACKET: if (!parse_bracket(&nocheck.val,&pos)) { - VERBO3 parse_err(6,&nocheck) ; + parse_err(6,&nocheck) ; goto err ; } if (nocheck.val.len == 1) { - VERBO3 parse_err(9,&nocheck) ; + parse_err(9,&nocheck) ; goto err ; } break ; @@ -291,12 +291,12 @@ int key_get_range(genalloc *ga, section_t *sasection,int *svtype) case SLASH: if (!parse_line(&nocheck.val,&pos)) { - VERBO3 parse_err(7,&nocheck) ; + parse_err(7,&nocheck) ; goto err ; } if (nocheck.val.len == 1) { - VERBO3 parse_err(9,&nocheck) ; + parse_err(9,&nocheck) ; goto err ; } if (!i && !j) (*svtype) = get_enumbyid(nocheck.val.s,key_enum_el) ; @@ -310,7 +310,7 @@ int key_get_range(genalloc *ga, section_t *sasection,int *svtype) } if (!found && r >=0) { - VERBO3 strerr_warnw4x("unknown key: ",sakey.s," : in section: ",get_keybyid(sasection->idx[i])) ; + log_warn("unknown key: ",sakey.s," : in section: ",get_keybyid(sasection->idx[i])) ; keynocheck_free(&nocheck) ; goto err ; } @@ -355,10 +355,8 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) } } if ((!count) && (countidsec)) - { - VERBO3 strerr_warnw4x("mandatory key: ",list[idsec].list[idkey].name," not found on section: ",get_keybyid(idsec)) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"mandatory key: ",list[idsec].list[idkey].name," not found on section: ",get_keybyid(idsec)) ; + break ; case CUSTOM: for (unsigned int j = 0;j < genalloc_len(keynocheck,nocheck);j++) @@ -383,10 +381,7 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) if ((!count) && (countidsec) && bkey>=0) { if (obstr_equal(genalloc_s(keynocheck,nocheck)[bkey].val.s,get_keybyid(CUSTOM))) - { - VERBO3 strerr_warnw5x("custom build asked on section: ",get_keybyid(idsec)," -- key: ",list[idsec].list[idkey].name," must be set") ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"custom build asked on section: ",get_keybyid(idsec)," -- key: ",list[idsec].list[idkey].name," must be set") ; } break ; case BUNDLE: @@ -409,10 +404,7 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) if ((!count) && (countidsec) && bkey>=0) { if (obstr_equal(genalloc_s(keynocheck,nocheck)[bkey].val.s,get_keybyid(BUNDLE))) - { - VERBO3 strerr_warnw1x("bundle type detected -- key @contents must be set") ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"bundle type detected -- key @contents must be set") ; } break ; /** only pass through here to check if flags env was asked @@ -435,16 +427,11 @@ int get_mandatory(genalloc *nocheck,int idsec,int idkey) if (bkey >= 0) { if (!sastr_clean_string(&sa,genalloc_s(keynocheck,nocheck)[bkey].val.s)) - { - VERBO3 strerr_warnwu2x("clean value of: ",sa.s) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"clean value of: ",sa.s) ; + r = sastr_cmp(&sa,get_keybyid(ENVIR)) ; if ((r >= 0) && (!count)) - { - VERBO3 strerr_warnw1x("options env was asked -- section environment must be set") ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"options env was asked -- section environment must be set") ; } break ; default: break ; @@ -528,10 +515,8 @@ int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service) break ; case SKIP: break ; - default: - VERBO3 strerr_warnw1x("unknown action") ; - return 0 ; - } + default: log_warn_return(LOG_EXIT_ZERO,"unknown action") ; + } } return 1 ; @@ -554,11 +539,11 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) break ; case NAME: service->cname.name = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common:NAME") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; case DESCRIPTION: service->cname.description = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common:DESCRIPTION") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; case OPTIONS: if (!get_clean_val(nocheck)) return 0 ; @@ -596,10 +581,7 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) if (!owner) { if (sastr_find(&nocheck->val,"root") == -1) - { - VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"use service: ",keep.s+service->cname.name," -- permission denied") ; } /** special case, we don't know which user want to use * the service, we need a general name to allow all user @@ -610,7 +592,7 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) if (pos == (size_t)p) continue ; if (!scan_uidlist(chval + pos,(uid_t *)service->user)) { - VERBO3 parse_err(0,nocheck) ; + parse_err(0,nocheck) ; return 0 ; } } @@ -622,10 +604,7 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) if (service->user[i] == owner) e = 1 ; if (!e) - { - VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"use service: ",keep.s+service->cname.name," -- permission denied") ; } } break ; @@ -638,36 +617,32 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) char *name = chval + pos ; size_t namelen = strlen(chval + pos) ; service->hiercopy[idx+1] = keep.len ; - if (!stralloc_catb(&keep,name,namelen + 1)) retstralloc(0,"parse_common:HIERCOPY") ; + if (!stralloc_catb(&keep,name,namelen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; service->hiercopy[0] = ++idx ; } } break ; case DEPENDS: if ((service->cname.itype == CLASSIC) || (service->cname.itype == BUNDLE)) - { - VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; + if (!get_clean_val(nocheck)) return 0 ; service->cname.idga = deps.len ; for (;pos < *chlen; pos += strlen(chval + pos)+1) { - if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common:DEPENDS") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; service->cname.nga++ ; } break ; case CONTENTS: if (service->cname.itype != BUNDLE) - { - VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; + if (!get_clean_val(nocheck)) return 0 ; service->cname.idga = deps.len ; for (;pos < *chlen; pos += strlen(chval + pos) + 1) { - if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common:CONTENTS") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; service->cname.nga++ ; } break ; @@ -685,27 +660,21 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) break ; case ENVAL: if (!environ_clean_nline(&nocheck->val)) - { - VERBO3 strerr_warnwu2x("clean environment value: ",chval) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"clean environment value: ",chval) ; + if (!stralloc_cats(&nocheck->val,"\n")) return 0 ; if (!stralloc_copy(&service->saenv,&nocheck->val)) - { - VERBO3 strerr_warnwu2x("store environment value: ",chval) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"store environment value: ",chval) ; break ; case SIGNAL: if (!sig0_scan(chval,&service->signal)) { - VERBO3 parse_err(3,nocheck) ; + parse_err(3,nocheck) ; return 0 ; } break ; - default: - VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; - return 0 ; + default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_keybyid(nocheck->idkey)) ; + } return 1 ; @@ -727,24 +696,22 @@ int keep_runfinish(sv_exec *exec,keynocheck *nocheck) case RUNAS: if (!check_valid_runas(nocheck)) return 0 ; exec->runas = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:RUNAS") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; case SHEBANG: if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck) ; + parse_err(4,nocheck) ; return 0 ; } exec->shebang = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:SHEBANG") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; case EXEC: exec->exec = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_runfinish:EXEC") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; - default: - VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; - return 0 ; + default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_keybyid(nocheck->idkey)) ; } return 1 ; } @@ -767,7 +734,7 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) log->idga = deps.len ; for (;pos < *chlen; pos += strlen(chval + pos) + 1) { - if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_logger:DEPENDS") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; log->nga++ ; } break ; @@ -784,11 +751,11 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) case DESTINATION: if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck) ; + parse_err(4,nocheck) ; return 0 ; } log->destination = keep.len ; - if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_logger:DESTINATION") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; break ; case BACKUP: if (!get_uint(nocheck,&log->backup)) return 0 ; @@ -801,9 +768,7 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) if (!r) return 0 ; log->timestamp = r ; break ; - default: - VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; - return 0 ; + default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_keybyid(nocheck->idkey)) ; } return 1 ; } @@ -823,24 +788,19 @@ int read_svfile(stralloc *sasv,char const *name,char const *src) memcpy(svtmp + srclen + 1, name, namelen) ; svtmp[srclen + 1 + namelen] = 0 ; - VERBO3 strerr_warni4x("Read service file of : ",name," from: ",src) ; + log_trace("Read service file of : ",name," from: ",src) ; size_t filesize=file_get_size(svtmp) ; if (!filesize) - { - VERBO3 strerr_warnw2x(svtmp," is empty") ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,svtmp," is empty") ; r = openreadfileclose(svtmp,sasv,filesize) ; if(!r) - { - VERBO3 strerr_warnwu2sys("open ", svtmp) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"open ", svtmp) ; + /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(sasv,"\n")) retstralloc(0,"read_svfile") ; - if (!stralloc_0(sasv)) retstralloc(0,"read_svfile") ; + if (!stralloc_cats(sasv,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(sasv)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; return 1 ; } @@ -852,11 +812,11 @@ int add_pipe(sv_alltype *sv, stralloc *sa) stralloc tmp = STRALLOC_ZERO ; sv->pipeline = sa->len ; - if (!stralloc_cats(&tmp,SS_PIPE_NAME)) retstralloc(0,"add_pipe") ; - if (!stralloc_cats(&tmp,prodname)) retstralloc(0,"add_pipe") ; - if (!stralloc_0(&tmp)) retstralloc(0,"add_pipe") ; + if (!stralloc_cats(&tmp,SS_PIPE_NAME)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&tmp,prodname)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(&tmp)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; - if (!stralloc_catb(sa,tmp.s,tmp.len+1)) retstralloc(0,"add_pipe") ; + if (!stralloc_catb(sa,tmp.s,tmp.len+1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; stralloc_free(&tmp) ; @@ -984,7 +944,7 @@ int get_clean_val(keynocheck *ch) { if (!sastr_clean_element(&ch->val)) { - VERBO3 parse_err(8,ch) ; + parse_err(8,ch) ; return 0 ; } return 1 ; @@ -995,7 +955,7 @@ int get_enum(char const *string, keynocheck *ch) int r = get_enumbyid(string,key_enum_el) ; if (r == -1) { - VERBO3 parse_err(0,ch) ; + parse_err(0,ch) ; return 0 ; } return r ; @@ -1010,7 +970,7 @@ int get_timeout(keynocheck *ch,uint32_t *ui) else if (ch->idkey == T_DOWN) time = 3 ; if (scan_timeout(ch->val.s,ui,time) == -1) { - VERBO3 parse_err(3,ch) ; + parse_err(3,ch) ; return 0 ; } return 1 ; @@ -1020,7 +980,7 @@ int get_uint(keynocheck *ch,uint32_t *ui) { if (!uint32_scan(ch->val.s,ui)) { - VERBO3 parse_err(3,ch) ; + parse_err(3,ch) ; return 0 ; } return 1 ; @@ -1032,7 +992,7 @@ int check_valid_runas(keynocheck *ch) struct passwd *pw = getpwnam(ch->val.s); if (pw == NULL && errno) { - VERBO3 parse_err(0,ch) ; + parse_err(0,ch) ; return 0 ; } return 1 ; @@ -1045,37 +1005,37 @@ void parse_err(int ierr,keynocheck *check) switch(ierr) { case 0: - strerr_warnw4x("invalid value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warn("invalid value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 1: - strerr_warnw4x("multiple definition of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warn("multiple definition of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 2: - strerr_warnw4x("same value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warn("same value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 3: - strerr_warnw4x("key: ",get_keybyid(idkey),": must be an integrer value in section: ",get_keybyid(idsec)) ; + log_warn("key: ",get_keybyid(idkey),": must be an integrer value in section: ",get_keybyid(idsec)) ; break ; case 4: - strerr_warnw4x("key: ",get_keybyid(idkey),": must be an absolute path in section: ",get_keybyid(idsec)) ; + log_warn("key: ",get_keybyid(idkey),": must be an absolute path in section: ",get_keybyid(idsec)) ; break ; case 5: - strerr_warnw4x("key: ",get_keybyid(idkey),": must be set in section: ",get_keybyid(idsec)) ; + log_warn("key: ",get_keybyid(idkey),": must be set in section: ",get_keybyid(idsec)) ; break ; case 6: - strerr_warnw4x("invalid format of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warn("invalid format of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 7: - strerr_warnwu4x("parse key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warnu("parse key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 8: - strerr_warnwu4x("clean value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warnu("clean value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 9: - strerr_warnw4x("empty value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + log_warn("empty value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; default: - strerr_warnw1x("unknown parse_err number") ; + log_warn("unknown parse_err number") ; break ; } } diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 5a4227bc..152e343d 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -22,11 +22,10 @@ #include <oblibs/string.h> #include <oblibs/files.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <oblibs/directory.h> -#include <skalibs/strerr2.h> #include <skalibs/types.h> #include <skalibs/bytestr.h> #include <skalibs/djbunix.h> @@ -60,8 +59,8 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t f ss_resolve_t res = RESOLVE_ZERO ; if (ss_resolve_check(workdir,name)) { - if (!ss_resolve_read(&res,workdir,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (res.type != type && res.disen) strerr_dief6x(111,"Detection of incompatible type format for: ",name," -- current: ",get_keybyid(type)," previous: ",get_keybyid(res.type)) ; + if (!ss_resolve_read(&res,workdir,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (res.type != type && res.disen) log_dieusys(LOG_EXIT_SYS,"Detection of incompatible type format for: ",name," -- current: ",get_keybyid(type)," previous: ",get_keybyid(res.type)) ; } ss_resolve_free(&res) ; } @@ -92,68 +91,47 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t f r = scan_mode(wname,S_IFDIR) ; if (r < 0) - { - VERBO3 strerr_warnw2x("unvalide source: ",wname) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"unvalide source: ",wname) ; + if ((r && force) || !r) { if (rm_rf(wname) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",wname) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"remove: ",wname) ; r = dir_create(wname, 0755) ; if (!r) - { - VERBO3 strerr_warnwu2sys("create ",wname) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create ",wname) ; } else if (r && !force) { - VERBO1 strerr_warnw3x("Ignoring: ",name," service: already enabled") ; + log_info("Ignoring: ",name," service: already enabled") ; return 2 ; } - VERBO2 strerr_warnt3x("Write service ", name," ...") ; + log_trace("Write service ", name," ...") ; switch(type) { case CLASSIC: if (!write_classic(sv, wname, force, conf)) - { - VERBO3 strerr_warnwu2x("write: ",wname) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",wname) ; + break ; case LONGRUN: if (!write_longrun(sv, wname, force, conf)) - { - VERBO3 strerr_warnwu2x("write: ",wname) ; - return 0 ; - } - + log_warnu_return(LOG_EXIT_ZERO,"write: ",wname) ; + break ; case ONESHOT: if (!write_oneshot(sv, wname, conf)) - { - VERBO3 strerr_warnwu2x("write: ",wname) ; - return 0 ; - } - + log_warnu_return(LOG_EXIT_ZERO,"write: ",wname) ; + break ; case BUNDLE: if (!write_bundle(sv, wname)) - { - VERBO3 strerr_warnwu2x("write: ",wname) ; - return 0 ; - } - + log_warnu_return(LOG_EXIT_ZERO,"write: ",wname) ; + break ; - default: - VERBO3 strerr_warni2x("unkown type: ", get_keybyid(sv->cname.itype)) ; - return 0 ; + default: log_warn_return(LOG_EXIT_ZERO,"unkown type: ", get_keybyid(sv->cname.itype)) ; } return 1 ; @@ -163,36 +141,25 @@ int write_classic(sv_alltype *sv, char const *dst, uint8_t force,uint8_t conf) { /**notification,timeout, ...*/ if (!write_common(sv, dst, conf)) - { - VERBO3 strerr_warnwu1x("write common files") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write common files") ; + /** run file*/ if (!write_exec(sv, &sv->type.classic_longrun.run,"run",dst,0755)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/run") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/run") ; + /** finish file*/ if (sv->type.classic_longrun.finish.exec) { if (!write_exec(sv, &sv->type.classic_longrun.finish,"finish",dst,0755)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/finish") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/finish") ; } /**logger */ if (sv->opts[0]) { if (!write_logger(sv, &sv->type.classic_longrun.log,"log",dst,0755, force)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/log") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/log") ; } - return 1 ; } @@ -207,25 +174,18 @@ int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) /**notification,timeout ...*/ if (!write_common(sv, dst,conf)) - { - VERBO3 strerr_warnwu1x("write common files") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write common files") ; + /**run file*/ if (!write_exec(sv, &sv->type.classic_longrun.run,"run",dst,0644)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/run") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/run") ; + /**finish file*/ if (sv->type.classic_longrun.finish.exec) { if (!write_exec(sv, &sv->type.classic_longrun.finish,"finish",dst,0644)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/finish") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/finish") ; } /**logger*/ @@ -241,25 +201,15 @@ int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) dstlog[r] = 0 ; if (!write_logger(sv, &sv->type.classic_longrun.log,logname,dstlog,0644,force)) - { - VERBO3 strerr_warnwu4x("write: ",dstlog,"/",logname) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dstlog,"/",logname) ; + if (!write_consprod(sv,name,logname,dst,dstlog)) - { - VERBO3 strerr_warnwu1x("write consumer/producer files") ; - return 0 ; - } - + log_warnu_return(LOG_EXIT_ZERO,"write consumer/producer files") ; } /** dependencies */ if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies")) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ; - return 0 ; - } - - + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/dependencies") ; + return 1 ; } @@ -267,31 +217,21 @@ int write_oneshot(sv_alltype *sv,char const *dst,uint8_t conf) { if (!write_common(sv, dst,conf)) - { - VERBO3 strerr_warnwu1x("write common files") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write common files") ; + /** up file*/ if (!write_exec(sv, &sv->type.oneshot.up,"up",dst,0644)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/up") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/up") ; + /** down file*/ if (sv->type.oneshot.down.exec) { if (!write_exec(sv, &sv->type.oneshot.down,"down",dst,0644)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/down") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/down") ; } if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies")) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/dependencies") ; return 1 ; } @@ -300,16 +240,11 @@ int write_bundle(sv_alltype *sv, char const *dst) { /** type file*/ if (!file_write_unsafe(dst,"type","bundle",6)) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/type") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/type") ; + /** contents file*/ if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "contents")) - { - VERBO3 strerr_warnwu3x("write: ",dst,"/contents") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",dst,"/contents") ; return 1 ; } @@ -337,39 +272,30 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d stralloc exec = STRALLOC_ZERO ; stralloc destlog = STRALLOC_ZERO ; - if(!stralloc_cats(&ddst,dst)) retstralloc(0,"write_logger") ; - if(!stralloc_cats(&ddst,"/")) retstralloc(0,"write_logger") ; - if(!stralloc_cats(&ddst,name)) retstralloc(0,"write_logger") ; - if(!stralloc_0(&ddst)) retstralloc(0,"write_logger") ; + if(!stralloc_cats(&ddst,dst) || + !stralloc_cats(&ddst,"/") || + !stralloc_cats(&ddst,name) || + !stralloc_0(&ddst)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; r = scan_mode(ddst.s,S_IFDIR) ; if (r && force) { if (rm_rf(ddst.s) < 0) - { - VERBO3 strerr_warnwu2sys("remove: ",ddst.s) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"remove: ",ddst.s) ; + r = dir_create(ddst.s, 0755) ; if (!r) - { - VERBO3 strerr_warnwu3sys("create ",ddst.s," directory") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create ",ddst.s," directory") ; } else if (r) { - VERBO3 strerr_warnw3x("ignoring ",name,": already enabled") ; - return 0 ; + log_warnu_return(LOG_EXIT_ZERO,"ignoring ",name,": already enabled") ; } else { r = dir_create(ddst.s, 0755) ; if (!r) - { - VERBO3 strerr_warnwu3sys("create ",ddst.s," directory") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create ",ddst.s," directory") ; } userhome = get_userhome(MYUID) ; @@ -393,19 +319,13 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d if (log->nga) { if (!write_dependencies(log->nga,log->idga,ddst.s,"dependencies")) - { - VERBO3 strerr_warnwu3x("write: ",ddst.s,"/dependencies") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",ddst.s,"/dependencies") ; } if (sv->cname.itype > CLASSIC) { if (!file_write_unsafe(ddst.s,"type","longrun",7)) - { - VERBO3 strerr_warnwu3sys("write: ",ddst.s,"/type") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write: ",ddst.s,"/type") ; } /**logger section may not be set @@ -417,38 +337,38 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d { case AUTO: /** uid */ - if (!stralloc_cats(&shebang, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n")) retstralloc(0,"write_logger") ; - if (!stralloc_0(&shebang)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&shebang, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n") || + !stralloc_0(&shebang)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; if ((!MYUID)) { - if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&ui,logrunner)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ") || + !stralloc_cats(&ui,logrunner)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_cats(&ui,"\n")) retstralloc(0,"write_logger") ; - if (!stralloc_0(&ui)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&ui,"\n") || + !stralloc_0(&ui)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /** destination */ if (!log->destination) { if(MYUID > 0) { - if (!stralloc_cats(&destlog,userhome)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&destlog,"/")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&destlog,SS_LOGGER_USERDIR)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&destlog,svname)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&destlog,userhome) || + !stralloc_cats(&destlog,"/") || + !stralloc_cats(&destlog,SS_LOGGER_USERDIR) || + !stralloc_cats(&destlog,svname)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } else { - if (!stralloc_cats(&destlog,SS_LOGGER_SYSDIR)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&destlog,svname)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&destlog,SS_LOGGER_SYSDIR) || + !stralloc_cats(&destlog,svname)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } } else { - if (!stralloc_cats(&destlog,keep.s+log->destination)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&destlog,keep.s+log->destination)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_0(&destlog)) retstralloc(0,"write_logger") ; - + if (!stralloc_0(&destlog)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (log->timestamp == ISO) timestamp = "T" ; else if (log->timestamp == NONE) timestamp = "" ; @@ -468,87 +388,64 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d else pmax = "1000000" ; - if (!stralloc_cats(&exec,shebang.s)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,EXECLINE_BINPREFIX "fdmove -c 2 1\n")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,ui.s)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,S6_BINPREFIX "s6-log -d3 " "n")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,pback)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec," ")) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&exec,shebang.s) || + !stralloc_cats(&exec,EXECLINE_BINPREFIX "fdmove -c 2 1\n") || + !stralloc_cats(&exec,ui.s) || + !stralloc_cats(&exec,S6_BINPREFIX "s6-log -d3 " "n") || + !stralloc_cats(&exec,pback) || + !stralloc_cats(&exec," ")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; if (log->timestamp < NONE) { - if (!stralloc_cats(&exec,timestamp)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec," ")) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&exec,timestamp) || + !stralloc_cats(&exec," ")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_cats(&exec,"s")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,pmax)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec," ")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,destlog.s)) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&exec,"\n")) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&exec,"s") || + !stralloc_cats(&exec,pmax) || + !stralloc_cats(&exec," ") || + !stralloc_cats(&exec,destlog.s) || + !stralloc_cats(&exec,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /**write it*/ if (!file_write_unsafe(ddst.s,"run",exec.s,exec.len)) - { - VERBO3 strerr_warnwu3sys("write: ",ddst.s,"/run") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write: ",ddst.s,"/run") ; + /** notification fd */ if (!file_write_unsafe(ddst.s,SS_NOTIFICATION,"3\n",2)) - { - VERBO3 strerr_warnwu3sys("write: ",ddst.s,"/" SS_NOTIFICATION) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write: ",ddst.s,"/" SS_NOTIFICATION) ; + if (sv->cname.itype == CLASSIC) { ddst.len-- ; - if (!stralloc_cats(&ddst,"/run")) retstralloc(0,"write_logger") ; - if (!stralloc_0(&ddst)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&ddst,"/run") || + !stralloc_0(&ddst)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; if (chmod(ddst.s, mode) < 0) - { - VERBO3 strerr_warnwu2sys("chmod ", ddst.s) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"chmod ", ddst.s) ; } break; case CUSTOM: if (!write_exec(sv, &log->run,"run",ddst.s,mode)) - { - VERBO3 strerr_warnwu3x("write: ",ddst.s,"/run") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",ddst.s,"/run") ; break; - default: - VERBO3 strerr_warnw2x("unknown build value: ",get_keybyid(logbuild)) ; - return 0 ; - + default: log_warn_return(LOG_EXIT_ZERO,"unknown build value: ",get_keybyid(logbuild)) ; } r = scan_mode(destlog.s,S_IFDIR) ; if (r == -1) - { - VERBO3 strerr_warnw3x("log directory: ", destlog.s,": already exist with a different mode") ; - return 0 ; - } - { - if (!dir_create_parent(destlog.s,0755)) - { - VERBO3 strerr_warnwu2sys("create log directory: ",destlog.s) ; - return 0 ; - } - } + log_warn_return(LOG_EXIT_ZERO,"log directory: ", destlog.s,": already exist with a different mode") ; + + + if (!dir_create_parent(destlog.s,0755)) + log_warnusys_return(LOG_EXIT_ZERO,"create log directory: ",destlog.s) ; + if ((!MYUID)) { if (!youruid(&log_uid,logrunner) || !yourgid(&log_gid,log_uid)) - { - VERBO3 strerr_warnwu2sys("get uid and gid of: ",logrunner) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"get uid and gid of: ",logrunner) ; + if (chown(destlog.s,log_uid,log_gid) == -1) - { - VERBO3 strerr_warnwu2sys("chown: ",destlog.s) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"chown: ",destlog.s) ; } stralloc_free(&shebang) ; @@ -580,16 +477,12 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char /**producer-for*/ if (!file_write_unsafe(consfile,get_keybyid(CONSUMER),prodname,strlen(prodname))) - { - VERBO3 strerr_warnwu3x("write: ",consfile,get_keybyid(CONSUMER)) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",consfile,get_keybyid(CONSUMER)) ; + /**consumer-for*/ if (!file_write_unsafe(prodfile,get_keybyid(PRODUCER),consname,strlen(consname))) - { - VERBO3 strerr_warnwu3x("write: ",prodfile,get_keybyid(PRODUCER)) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",prodfile,get_keybyid(PRODUCER)) ; + /**pipeline**/ if (sv->opts[1]) { @@ -604,10 +497,7 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char memcpy(pipename,deps.s+sv->pipeline,len) ; pipename[len] = 0 ; if (!file_write_unsafe(pipefile,PIPELINE_NAME,pipename,len)) - { - VERBO3 strerr_warnwu3x("write: ",pipefile,PIPELINE_NAME) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write: ",pipefile,PIPELINE_NAME) ; } return 1 ; @@ -626,29 +516,20 @@ int write_common(sv_alltype *sv, char const *dst,uint8_t conf) if (sv->flags[0]) { if (!file_create_empty(dst,"down",0644)) - { - VERBO3 strerr_warnwu1sys("create down file") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create down file") ; } /**nosetsid file*/ if (sv->flags[1]) { if (!file_create_empty(dst,"nosetsid",0644)) - { - VERBO3 strerr_warnwu1sys("create nosetsid file") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"create nosetsid file") ; } /**notification-fd*/ if (sv->notification) { if (!write_uint(dst,"notification-fd", sv->notification)) - { - VERBO3 strerr_warnwu1x("write notification file") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write notification file") ; } /**timeout family*/ for (uint32_t i = 0; i < 4;i++) @@ -666,10 +547,7 @@ int write_common(sv_alltype *sv, char const *dst,uint8_t conf) time = "timeout-down" ; if (!write_uint(dst, time, sv->timeout[i][0])) - { - VERBO3 strerr_warnwu2x("write file: ",time) ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write file: ",time) ; } } @@ -677,28 +555,19 @@ int write_common(sv_alltype *sv, char const *dst,uint8_t conf) if (sv->cname.itype > CLASSIC) { if (!file_write_unsafe(dst,"type",get_keybyid(sv->cname.itype),strlen(get_keybyid(sv->cname.itype)))) - { - VERBO3 strerr_warnwu1sys("write type file") ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write type file") ; } /** max-death-tally */ if (sv->death) { if (!write_uint(dst, "max-death-tally", sv->death)) - { - VERBO3 strerr_warnwu1x("write max-death-tally file") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write max-death-tally file") ; } /**down-signal*/ if (sv->signal) { if (!write_uint(dst,"down-signal", sv->signal)) - { - VERBO3 strerr_warnwu1x("write down-signal file") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write down-signal file") ; } /** environment */ if (sv->opts[2]) @@ -716,21 +585,16 @@ int write_common(sv_alltype *sv, char const *dst,uint8_t conf) { copy[dlen] = 0 ; if (!write_env(name,&sv->saenv,copy)) - { - VERBO3 strerr_warnwu1x("write environment") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"write environment") ; } else if (conf == 1) { stralloc salist = STRALLOC_ZERO ; //merge config from upstream to sysadmin - if (!file_readputsa(&salist,dst,name)) strerr_diefu3sys(111,"read: ",dst,name) ; + if (!file_readputsa(&salist,dst,name)) log_warnusys_return(LOG_EXIT_ZERO,"read: ",dst,name) ; if (!env_merge_conf(dst,name,&salist,&sv->saenv,conf)) - { - VERBO3 strerr_warnwu1x("merge environment file") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"merge environment file") ; + stralloc_free(&salist) ; } } @@ -756,14 +620,11 @@ int write_common(sv_alltype *sv, char const *dst,uint8_t conf) if (r <= 0) { r = scan_mode(tmp,S_IFREG) ; - if (!r) { VERBO3 strerr_warnwu2sys("find: ",tmp) ; return 0 ; } - if (r < 0) { errno = ENOTSUP ; VERBO3 strerr_warnw2sys("invalid format of: ",tmp) ; return 0 ; } + if (!r) log_warnusys_return(LOG_EXIT_ZERO,"find: ",tmp) ; + if (r < 0) { errno = ENOTSUP ; log_warnsys_return(LOG_EXIT_ZERO,"invalid format of: ",tmp) ; } } if (!hiercopy(tmp,dtmp)) - { - VERBO3 strerr_warnwu4sys("copy: ",tmp," to: ",dtmp) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"copy: ",tmp," to: ",dtmp) ; } } return 1 ; @@ -792,67 +653,64 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,mo /** uid */ if ((!owner && exec->runas)) { - if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&ui,keep.s + exec->runas)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&ui,"\n")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&ui,S6_BINPREFIX "s6-setuidgid ") || + !stralloc_cats(&ui,keep.s + exec->runas) || + !stralloc_cats(&ui,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } /** environment */ if (sv->opts[2] && (exec->build == AUTO)) { - if (!stralloc_cats(&env,SS_BINPREFIX "execl-envfile ")) retstralloc(0,"write_exec") ; - //if (!env_resolve_conf(&env,owner)) - //{ VERBO3 strerr_warnwu1sys("get path of service configuration file") ; return 0 ; } - if (!stralloc_cats(&env,keep.s + sv->srconf)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,name)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&env,"\n")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&env,SS_BINPREFIX "execl-envfile ") || + !stralloc_cats(&env,keep.s + sv->srconf) || + !stralloc_cats(&env,name) || + !stralloc_cats(&env,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } /** shebang */ if (type != ONESHOT) { - if (!stralloc_cats(&shebang, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&shebang, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } break ; case CUSTOM: if (type != ONESHOT) { - if (!stralloc_cats(&shebang, "#!")) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&shebang, keep.s+exec->shebang)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&shebang,"\n")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&shebang, "#!") || + !stralloc_cats(&shebang, keep.s+exec->shebang) || + !stralloc_cats(&shebang,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } else { - if (!stralloc_cats(&shebang, keep.s+exec->shebang)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&shebang," \"")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&shebang, keep.s+exec->shebang) || + !stralloc_cats(&shebang," \"")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } break ; - default: - VERBO3 strerr_warnw3x("unknown ", get_keybyid(exec->build)," build type") ; + default: log_warn(LOG_EXIT_ZERO,"unknown ", get_keybyid(exec->build)," build type") ; break ; } /** close uid */ - if (!stralloc_0(&ui)) retstralloc(0,"write_exec") ; + if (!stralloc_0(&ui)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /** close env*/ - if (!stralloc_0(&env)) retstralloc(0,"write_exec") ; + if (!stralloc_0(&env)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /** close shebang */ - if (!stralloc_0(&shebang)) retstralloc(0,"write_exec") ; + if (!stralloc_0(&shebang)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /** close command */ - if (!stralloc_cats(&runuser, keep.s+exec->exec)) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&runuser, keep.s+exec->exec)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; if ((type == ONESHOT) && (exec->build == CUSTOM)) { - if (!stralloc_cats(&runuser," \"")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&runuser," \"")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_cats(&runuser,"\n")) retstralloc(0,"write_exec") ; - if (!stralloc_0(&runuser)) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&runuser,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(&runuser)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; /** build the file*/ - if (!stralloc_cats(&execute,shebang.s)) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&execute,shebang.s)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; if (exec->build == AUTO) { - if (!stralloc_cats(&execute,EXECLINE_BINPREFIX "fdmove -c 2 1\n")) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&execute,EXECLINE_BINPREFIX "fdmove -c 2 1\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_cats(&execute,env.s)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&execute,ui.s)) retstralloc(0,"write_exec") ; - if (!stralloc_cats(&execute,runuser.s)) retstralloc(0,"write_exec") ; + if (!stralloc_cats(&execute,env.s) || + !stralloc_cats(&execute,ui.s) || + !stralloc_cats(&execute,runuser.s)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; memcpy(write,dst,dstlen) ; write[dstlen] = '/' ; @@ -860,16 +718,10 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,mo write[dstlen + 1 + filelen] = 0 ; if (!file_write_unsafe(dst,file,execute.s,execute.len)) - { - VERBO3 strerr_warnwu4sys("write: ",dst,"/",file) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write: ",dst,"/",file) ; if (chmod(write, mode) < 0) - { - VERBO3 strerr_warnwu2sys("chmod ", write) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"chmod ", write) ; stralloc_free(&home) ; stralloc_free(&shebang) ; @@ -888,14 +740,14 @@ int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char c for (;nid; id += strlen(deps.s + id) + 1, nid--) { if (!stralloc_cats(&contents,deps.s + id) || - !stralloc_cats(&contents,"\n")) retstralloc(0,"write_dependencies") ; + !stralloc_cats(&contents,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } if (contents.len) { if (!file_write_unsafe(dst,filename,contents.s,contents.len)) { - VERBO3 strerr_warnwu3sys("create file: ",dst,filename) ; + log_warnusys("create file: ",dst,filename) ; goto err ; } } @@ -912,10 +764,7 @@ int write_uint(char const *dst, char const *name, uint32_t ui) char number[UINT32_FMT] ; if (!file_write_unsafe(dst,name,number,uint32_fmt(number,ui))) - { - VERBO3 strerr_warnwu4sys("write: ",dst,"/",name) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"write: ",dst,"/",name) ; return 1 ; } @@ -926,21 +775,14 @@ int write_env(char const *name, stralloc *sa,char const *dst) r = scan_mode(dst,S_IFDIR) ; if (r < 0) - { - VERBO3 strerr_warnw2sys(" invalid environment directory: ",dst) ; - return 0 ; - } + log_warnsys_return(LOG_EXIT_ZERO," invalid environment directory: ",dst) ; else if (!r) { - VERBO3 strerr_warnw2sys(dst," service environment directory doesn't exist") ; - return 0 ; + log_warnsys_return(LOG_EXIT_ZERO,dst," service environment directory doesn't exist") ; } if (!file_write_unsafe(dst,name,sa->s,sa->len)) - { - VERBO3 strerr_warnwu4sys("create file: ",dst,"/",name) ; - return 0 ; - } - + log_warnusys_return(LOG_EXIT_ZERO,"create file: ",dst,"/",name) ; + return 1 ; } diff --git a/src/lib66/rc_init.c b/src/lib66/rc_init.c index 6f6c3b2e..5067fb9a 100644 --- a/src/lib66/rc_init.c +++ b/src/lib66/rc_init.c @@ -18,7 +18,7 @@ #include <stdlib.h> #include <sys/types.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/directory.h> @@ -59,31 +59,31 @@ int rc_init(ssexec_t *info, char const *const *envp) unsigned int m = 0 ; gid_t gidowner ; - if (!yourgid(&gidowner,info->owner)){ VERBO1 strerr_warnwu1sys("set gid") ; goto err ; } + if (!yourgid(&gidowner,info->owner)){ log_warnusys("set gid") ; goto err ; } r = scan_mode(info->livetree.s,S_IFDIR) ; - if (r < 0){ VERBO1 strerr_warnw2x(info->livetree.s," conflicted format") ; goto err ; } + if (r < 0){ log_warn(info->livetree.s," conflicted format") ; goto err ; } if (!r) { - VERBO2 strerr_warni2x("create directory: ",info->livetree.s) ; + log_trace("create directory: ",info->livetree.s) ; r = dir_create(info->livetree.s,0700) ; - if (!r){ VERBO1 strerr_warnwu2sys("create directory: ",info->livetree.s) ; goto err ; } - VERBO2 strerr_warni2x("chown directory: ",info->livetree.s) ; - if (chown(info->livetree.s,info->owner,gidowner) < 0){ VERBO1 strerr_warnwu2sys("chown directory: ",info->livetree.s) ; goto err ; } + if (!r){ log_warnusys("create directory: ",info->livetree.s) ; goto err ; } + log_trace("chown directory: ",info->livetree.s) ; + if (chown(info->livetree.s,info->owner,gidowner) < 0){ log_warnusys("chown directory: ",info->livetree.s) ; goto err ; } } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - { VERBO1 strerr_warnwu1x("set revolve pointer to source") ; goto err ; } + { log_warnu("set revolve pointer to source") ; goto err ; } - if (!ss_resolve_check(sares.s,SS_MASTER +1)) { VERBO1 strerr_warnwu1x("find inner bundle -- please make a bug report") ; goto err ; } - if (!ss_resolve_read(&res,sares.s,SS_MASTER + 1)) { VERBO1 strerr_warnwu1sys("read resolve file of inner bundle") ; goto err ; } + if (!ss_resolve_check(sares.s,SS_MASTER +1)) { log_warnu("find inner bundle -- please make a bug report") ; goto err ; } + if (!ss_resolve_read(&res,sares.s,SS_MASTER + 1)) { log_warnusys("read resolve file of inner bundle") ; goto err ; } if (!res.ndeps) { - VERBO1 strerr_warni2x("Initialization aborted -- no atomic services into tree: ",info->treename.s) ; + log_info("Initialization aborted -- no atomic services into tree: ",info->treename.s) ; empty = 1 ; goto end ; } - if (!ss_resolve_create_live(info)) { VERBO1 strerr_warnwu1sys("create live state") ; goto err ; } + if (!ss_resolve_create_live(info)) { log_warnusys("create live state") ; goto err ; } memcpy(svdir,info->tree.s,info->tree.len) ; memcpy(svdir + info->tree.len ,SS_SVDIRS ,SS_SVDIRS_LEN) ; @@ -116,23 +116,23 @@ int rc_init(ssexec_t *info, char const *const *envp) newargv[m++] = info->scandir.s ; newargv[m++] = 0 ; - VERBO3 strerr_warni3x("initiate db of tree: ",info->treename.s," ...") ; + log_trace("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 ; } + { log_warnusys("wait for ",newargv[0]) ; goto err ; } - if (wstat) { VERBO1 strerr_warnwu2x("init db of tree: ",info->treename.s) ; goto err ; } + if (wstat) { log_warnu("init db of tree: ",info->treename.s) ; goto err ; } - if (!sastr_clean_string(&sasvc,res.sa.s + res.deps)) { VERBO1 strerr_warnwu1sys("clean dependencies of inner bundle") ; goto err ; } + if (!sastr_clean_string(&sasvc,res.sa.s + res.deps)) { log_warnusys("clean dependencies of inner bundle") ; goto err ; } for (; pos < sasvc.len ; pos += strlen(sasvc.s + pos) +1) { char *name = sasvc.s + pos ; ss_resolve_t tmp = RESOLVE_ZERO ; - if (!ss_resolve_check(sares.s,name)){ VERBO1 strerr_warnw2sys("unknown service: ",name) ; goto err ; } - if (!ss_resolve_read(&tmp,sares.s,name)) { VERBO1 strerr_warnwu2sys("read resolve file of: ",name) ; goto err ; } - if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) { VERBO1 strerr_warnwu2sys("resolve dependencies of: ",name) ; goto err ; } + if (!ss_resolve_check(sares.s,name)){ log_warnsys("unknown service: ",name) ; goto err ; } + if (!ss_resolve_read(&tmp,sares.s,name)) { log_warnusys("read resolve file of: ",name) ; goto err ; } + if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) { log_warnusys("resolve dependencies of: ",name) ; goto err ; } ss_resolve_free(&tmp) ; } @@ -142,13 +142,13 @@ int rc_init(ssexec_t *info, char const *const *envp) char const *name = string + genalloc_s(ss_resolve_t,&gares)[pos].name ; char const *state = string + genalloc_s(ss_resolve_t,&gares)[pos].state ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } - VERBO1 strerr_warni2x("Initialized successfully: ",name) ; + log_info("Initialized successfully: ",name) ; } end: diff --git a/src/lib66/rc_manage.c b/src/lib66/rc_manage.c index 318f05fd..4331e94b 100644 --- a/src/lib66/rc_manage.c +++ b/src/lib66/rc_manage.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/tai.h> #include <skalibs/genalloc.h> @@ -60,7 +60,7 @@ int rc_manage(ssexec_t *info,genalloc *ga) if (!ss_resolve_pointo(&sares,info,LONGRUN,SS_RESOLVE_SRC)) { - strerr_warnwu1sys("set revolve pointer to source") ; + log_warnusys("set revolve pointer to source") ; goto err ; } sares.len--; @@ -92,7 +92,7 @@ int rc_manage(ssexec_t *info,genalloc *ga) r = s6rc_servicedir_manage_g(live, prefix, &deadline) ; if (!r) { - VERBO1 strerr_warnwu3sys("supervise service directories in ", live, "/servicedirs") ; + log_warnusys("supervise service directories in ", live, "/servicedirs") ; goto err ; } } @@ -101,13 +101,13 @@ int rc_manage(ssexec_t *info,genalloc *ga) char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; char const *state = string + genalloc_s(ss_resolve_t,ga)[i].state ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } - VERBO1 strerr_warni2x("Initialized successfully: ",name) ; + log_info("Initialized successfully: ",name) ; } stralloc_free(&sares) ; diff --git a/src/lib66/rc_unsupervise.c b/src/lib66/rc_unsupervise.c index a5128469..0c15a054 100644 --- a/src/lib66/rc_unsupervise.c +++ b/src/lib66/rc_unsupervise.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/genalloc.h> #include <skalibs/stralloc.h> @@ -51,13 +51,13 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const if (!db_switch_to(info,envp,SS_SWSRC)) { - VERBO1 strerr_warnwu3x("switch ",info->treename.s," to source") ; + log_warnu("switch ",info->treename.s," to source") ; goto err ; } if (!rc_send(info,ga,sig,envp)) { - VERBO1 strerr_warnwu1x("stop services") ; + log_warnu("stop services") ; goto err ; } @@ -65,13 +65,13 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const { char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; - VERBO2 strerr_warni2x("delete directory service: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; + log_trace("delete directory service: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; s6rc_servicedir_unsupervise(live,prefix,name,0) ; if (rm_rf(string + genalloc_s(ss_resolve_t,ga)[i].runat) < 0) goto err ; } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) { - strerr_warnwu1sys("set revolve pointer to source") ; + log_warnusys("set revolve pointer to source") ; goto err ; } for (i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) @@ -83,9 +83,9 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const // remove the resolve/state file if the service is disabled if (!pres->disen) { - VERBO2 strerr_warni2x("Delete resolve file of: ",name) ; + log_trace("Delete resolve file of: ",name) ; ss_resolve_rmfile(sares.s,name) ; - VERBO2 strerr_warni2x("Delete state file of: ",name) ; + log_trace("Delete state file of: ",name) ; ss_state_rmfile(state,name) ; } else @@ -95,14 +95,14 @@ int rc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *const // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_FALSE) ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } } - VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + log_info("Unsupervised successfully: ",name) ; } stralloc_free(&sares) ; return 1 ; diff --git a/src/lib66/resolve.c b/src/lib66/resolve.c index a8a98e1c..35603ac3 100644 --- a/src/lib66/resolve.c +++ b/src/lib66/resolve.c @@ -20,7 +20,7 @@ //#include <stdio.h> #include <oblibs/types.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/directory.h> #include <oblibs/files.h> #include <oblibs/string.h> @@ -122,28 +122,28 @@ int ss_resolve_src_path(stralloc *sasrc,char const *sv, ssexec_t *info) if (!info->owner) src = SS_SERVICE_ADMDIR ; else { - if (!set_ownerhome(&home,info->owner)){ VERBO3 strerr_warnwu1sys("set home directory") ; goto err ; } - if (!stralloc_cats(&home,SS_SERVICE_USERDIR)) retstralloc(0,"ss_resolve_src_path") ; - if (!stralloc_0(&home)) retstralloc(0,"ss_resolve_src_path") ; + if (!set_ownerhome(&home,info->owner)){ log_warnusys("set home directory") ; goto err ; } + if (!stralloc_cats(&home,SS_SERVICE_USERDIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(&home)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; home.len-- ; src = home.s ; } r = ss_resolve_src(sasrc,sv,src,&found) ; - if (r < 0){ VERBO3 strerr_warnwu2sys("parse source directory: ",src) ; goto err ; } + if (r < 0){ log_warnusys("parse source directory: ",src) ; goto err ; } if (!r) { found = 0 ; src = SS_SERVICE_ADMDIR ; r = ss_resolve_src(sasrc,sv,src,&found) ; - if (r < 0) { VERBO3 strerr_warnwu2sys("parse source directory: ",src) ; goto err ; } + if (r < 0) { log_warnusys("parse source directory: ",src) ; goto err ; } if (!r) { found = 0 ; src = SS_SERVICE_SYSDIR ; r = ss_resolve_src(sasrc,sv,src,&found) ; - if (r < 0) { VERBO3 strerr_warnwu2sys("parse source directory: ",src) ; goto err ; } - if (!r) { VERBO3 strerr_warnw2x("unknown service: ",sv) ; goto err ; } + if (r < 0) { log_warnusys("parse source directory: ",src) ; goto err ; } + if (!r) { log_warn("unknown service: ",sv) ; goto err ; } } } stralloc_free(&home) ; @@ -179,7 +179,7 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found DIR *dir = opendir(src) ; if (!dir) { - VERBO3 strerr_warnwu2sys("open : ", src) ; + log_warnusys("open : ", src) ; goto errstra ; } fdsrc = dir_fd(dir) ; @@ -196,7 +196,7 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found if (stat_at(fdsrc, d->d_name, &st) < 0) { - VERBO3 strerr_warnwu3sys("stat ", src, d->d_name) ; + log_warnusys("stat ", src, d->d_name) ; goto errdir ; } @@ -226,7 +226,7 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found *found = 1 ; if (stat_at(fdsrc, d->d_name, &st) < 0) { - VERBO3 strerr_warnwu3sys("stat ", src, d->d_name) ; + log_warnusys("stat ", src, d->d_name) ; goto errdir ; } @@ -242,7 +242,7 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found else r = sastr_dir_get(&satmp,subdir.s,"",S_IFREG) ; if (!r) { - VERBO3 strerr_warnwu2sys("get services from directory: ",subdir.s) ; + log_warnusys("get services from directory: ",subdir.s) ; goto errdir ; } i = 0, len = satmp.len ; @@ -342,11 +342,11 @@ uint32_t ss_resolve_add_string(ss_resolve_t *res, char const *data) uint32_t baselen = res->sa.len ; if (!data) { - if (!stralloc_catb(&res->sa,"",1)) strerr_diefu1sys(111,"stralloc:resolve_add_string") ; + if (!stralloc_catb(&res->sa,"",1)) log_dieusys(LOG_EXIT_SYS,"stralloc:resolve_add_string") ; return baselen ; } size_t datalen = strlen(data) ; - if (!stralloc_catb(&res->sa,data,datalen + 1)) strerr_diefu1sys(111,"stralloc:resolve_add_string") ; + if (!stralloc_catb(&res->sa,data,datalen + 1)) log_dieusys(LOG_EXIT_SYS,"stralloc:resolve_add_string") ; return baselen ; } @@ -547,17 +547,17 @@ int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst,ssexec_t *info) if (ss_state_check(string + sv->state,string + sv->logger)) { - if (!ss_state_read(&sta,string + sv->state,string + sv->logger)) { VERBO1 strerr_warnwu2sys("read state file of: ",string + sv->logger) ; goto err ; } + if (!ss_state_read(&sta,string + sv->state,string + sv->logger)) { log_warnusys("read state file of: ",string + sv->logger) ; goto err ; } if (!sta.init) ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_TRUE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; - if (!ss_state_write(&sta,string + sv->state,string + sv->logger)){ VERBO1 strerr_warnwu2sys("write state file of: ",string + sv->logger) ; goto err ; } + if (!ss_state_write(&sta,string + sv->state,string + sv->logger)){ log_warnusys("write state file of: ",string + sv->logger) ; goto err ; } } if (!ss_resolve_write(&res,dst,res.sa.s + res.name)) { - VERBO1 strerr_warnwu5sys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; + log_warnusys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; goto err ; } ss_resolve_free(&res) ; @@ -639,12 +639,12 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) if (ss_state_check(state,name)) { - if (!ss_state_read(&sta,state,name)) { VERBO1 strerr_warnwu2sys("read state file of: ",name) ; goto err ; } + if (!ss_state_read(&sta,state,name)) { log_warnusys("read state file of: ",name) ; goto err ; } if (!sta.init) ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_TRUE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; - if (!ss_state_write(&sta,res.sa.s + res.state,name)){ VERBO1 strerr_warnwu2sys("write state file of: ",name) ; goto err ; } + if (!ss_state_write(&sta,res.sa.s + res.state,name)){ log_warnusys("write state file of: ",name) ; goto err ; } } @@ -654,10 +654,10 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) for (;nid; id += strlen(deps.s + id) + 1, nid--) { if (!stralloc_catb(&final,deps.s + id,strlen(deps.s + id)) || - !stralloc_catb(&final," ",1)) retstralloc(0,"write_dependencies") ; + !stralloc_catb(&final," ",1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } final.len-- ; - if (!stralloc_0(&final)){ VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_0(&final)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; res.deps = ss_resolve_add_string(&res,final.s) ; } @@ -678,9 +678,9 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) 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)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&final,res.sa.s + res.logger)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_0(&final)){ VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_catb(&final," ",1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&final,res.sa.s + res.logger)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(&final)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; res.deps = ss_resolve_add_string(&res,final.s) ; if (res.type == CLASSIC) res.ndeps = 1 ; else if (res.type == LONGRUN) res.ndeps += 1 ; @@ -689,22 +689,22 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) { if(info->owner > 0) { - if (!stralloc_cats(&destlog,get_userhome(info->owner))) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&destlog,"/")) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&destlog,SS_LOGGER_USERDIR)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&destlog,name)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_cats(&destlog,get_userhome(info->owner))) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&destlog,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&destlog,SS_LOGGER_USERDIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&destlog,name)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } else { - if (!stralloc_cats(&destlog,SS_LOGGER_SYSDIR)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } - if (!stralloc_cats(&destlog,name)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_cats(&destlog,SS_LOGGER_SYSDIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(&destlog,name)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } } else { - if (!stralloc_cats(&destlog,keep.s+services->type.classic_longrun.log.destination)) { warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_cats(&destlog,keep.s+services->type.classic_longrun.log.destination)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } - if (!stralloc_0(&destlog)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } + if (!stralloc_0(&destlog)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; res.dstlog = ss_resolve_add_string(&res,destlog.s) ; @@ -713,7 +713,7 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) /** may on workdir so a copy with made to source, write it SIMPLE */ if (!ss_resolve_write(&res,dst,res.sa.s + res.name)) { - VERBO1 strerr_warnwu5sys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; + log_warnusys("write resolve file: ",dst,SS_RESOLVE,"/",res.sa.s + res.name) ; goto err ; } @@ -983,10 +983,10 @@ int ss_resolve_create_live(ssexec_t *info) memcpy(sym + sares.len, SS_SVDIRS, SS_SVDIRS_LEN) ; sym[sares.len + SS_SVDIRS_LEN] = 0 ; - VERBO3 strerr_warnt4x("point symlink: ",sym," to ",ressrc.s) ; + log_trace("point symlink: ",sym," to ",ressrc.s) ; if (symlink(ressrc.s,sym) < 0) { - VERBO3 strerr_warnwu2sys("symlink: ", sym) ; + log_warnusys("symlink: ", sym) ; goto err ; } } @@ -1092,7 +1092,7 @@ int ss_resolve_write_master(ssexec_t *info,ss_resolve_graph_t *graph,char const r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ; if (!r) { - VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ; + log_warnusys("write: ",dst,"contents") ; goto err ; } diff --git a/src/lib66/resolve_graph.c b/src/lib66/resolve_graph.c index 07902f09..2b965b1b 100644 --- a/src/lib66/resolve_graph.c +++ b/src/lib66/resolve_graph.c @@ -19,7 +19,7 @@ #include <oblibs/string.h> #include <oblibs/directory.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/sastr.h> #include <skalibs/genalloc.h> @@ -85,8 +85,7 @@ int ss_resolve_graph_sort(ss_resolve_graph_t *graph) int data = genalloc_s(uint32_t,&genalloc_s(ss_resolve_graph_ndeps_t,&graph->cp)[ename].ndeps)[edeps] ; char *name = genalloc_s(ss_resolve_t,&graph->name)[ename].sa.s + genalloc_s(ss_resolve_t,&graph->name)[ename].name ; char *deps = genalloc_s(ss_resolve_t,&graph->name)[data].sa.s + genalloc_s(ss_resolve_t,&graph->name)[data].name ; - VERBO3 strerr_warnw4x("resolution of : ",name,": encountered a cycle involving service: ",deps) ; - return -1 ; + log_warn_return(LOG_EXIT_LESSONE,"resolution of : ",name,": encountered a cycle involving service: ",deps) ; } } diff --git a/src/lib66/scandir_send_signal.c b/src/lib66/scandir_send_signal.c index cad238ea..b4e6fbd8 100644 --- a/src/lib66/scandir_send_signal.c +++ b/src/lib66/scandir_send_signal.c @@ -16,7 +16,7 @@ #include <stddef.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <s6/s6-supervise.h> @@ -34,18 +34,15 @@ int scandir_send_signal(char const *scandir,char const *signal) datalen++ ; } if (datalen >= DATASIZE) - { - VERBO3 strerr_warnw2x("too many command to send to: ",scandir) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"too many command to send to: ",scandir) ; switch (s6_svc_writectl(scandir, S6_SVSCAN_CTLDIR, data, datalen)) { - case -1: VERBO3 strerr_warnwu2sys("control: ", scandir) ; + case -1: log_warnusys("control: ", scandir) ; return 0 ; - case -2: VERBO3 strerr_warnw3sys("something is wrong with the ", scandir, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; + case -2: log_warnsys("something is wrong with the ", scandir, "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; return 0 ; - case 0: VERBO3 strerr_warnwu3x("control: ", scandir, ": supervisor not listening") ; + case 0: log_warnu("control: ", scandir, ": supervisor not listening") ; return 0 ; } diff --git a/src/lib66/set_livedir.c b/src/lib66/set_livedir.c index 5901194c..a17500c9 100644 --- a/src/lib66/set_livedir.c +++ b/src/lib66/set_livedir.c @@ -14,7 +14,7 @@ #include <66/utils.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> @@ -29,14 +29,14 @@ int set_livedir(stralloc *live) if (live->s[live->len - 2] != '/') { live->len-- ; - if (!stralloc_cats(live,"/")) retstralloc(0,"set_livedir") ; - if (!stralloc_0(live)) retstralloc(0,"set_livedir") ; + if (!stralloc_cats(live,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(live)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } } else { - if (!stralloc_cats(live,SS_LIVE)) retstralloc(0,"set_livedir") ; - if (!stralloc_0(live)) retstralloc(0,"set_livedir") ; + if (!stralloc_cats(live,SS_LIVE)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(live)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } live->len--; return 1 ; diff --git a/src/lib66/set_livescan.c b/src/lib66/set_livescan.c index 9d30f1e5..6fdfc3df 100644 --- a/src/lib66/set_livescan.c +++ b/src/lib66/set_livescan.c @@ -16,7 +16,7 @@ #include <stddef.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> @@ -35,9 +35,9 @@ int set_livescan(stralloc *scandir,uid_t owner) size_t ownerlen = uid_fmt(ownerpack,owner) ; ownerpack[ownerlen] = 0 ; - if (!stralloc_cats(scandir,SS_SCANDIR "/")) retstralloc(0,"set_livescan") ; - if (!stralloc_cats(scandir,ownerpack)) retstralloc(0,"set_livescan") ; - if (!stralloc_0(scandir)) retstralloc(0,"set_livescan") ; + if (!stralloc_cats(scandir,SS_SCANDIR "/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(scandir,ownerpack)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(scandir)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; scandir->len--; return 1 ; } diff --git a/src/lib66/set_livestate.c b/src/lib66/set_livestate.c index a8409b1c..27304a76 100644 --- a/src/lib66/set_livestate.c +++ b/src/lib66/set_livestate.c @@ -16,7 +16,7 @@ #include <stddef.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> @@ -35,10 +35,10 @@ int set_livestate(stralloc *livestate,uid_t owner) size_t ownerlen = uid_fmt(ownerpack,owner) ; ownerpack[ownerlen] = 0 ; - if (!stralloc_cats(livestate,SS_STATE + 1)) retstralloc(0,"set_livestate") ; - if (!stralloc_cats(livestate,"/")) retstralloc(0,"set_livestate") ; - if (!stralloc_cats(livestate,ownerpack)) retstralloc(0,"set_livestate") ; - if (!stralloc_0(livestate)) retstralloc(0,"set_livestate") ; + if (!stralloc_cats(livestate,SS_STATE + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(livestate,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(livestate,ownerpack)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(livestate)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; livestate->len--; return 1 ; } diff --git a/src/lib66/set_livetree.c b/src/lib66/set_livetree.c index e0bb8bd9..8903efbd 100644 --- a/src/lib66/set_livetree.c +++ b/src/lib66/set_livetree.c @@ -16,7 +16,7 @@ #include <stddef.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> @@ -35,9 +35,9 @@ int set_livetree(stralloc *livetree,uid_t owner) size_t ownerlen = uid_fmt(ownerpack,owner) ; ownerpack[ownerlen] = 0 ; - if (!stralloc_cats(livetree,SS_TREE "/")) retstralloc(0,"set_livetree") ; - if (!stralloc_cats(livetree,ownerpack)) retstralloc(0,"set_livetree") ; - if (!stralloc_0(livetree)) retstralloc(0,"set_livetree") ; + if (!stralloc_cats(livetree,SS_TREE "/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(livetree,ownerpack)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(livetree)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; livetree->len--; return 1 ; } diff --git a/src/lib66/set_ownerhome.c b/src/lib66/set_ownerhome.c index 39b8555f..b39e1b3a 100644 --- a/src/lib66/set_ownerhome.c +++ b/src/lib66/set_ownerhome.c @@ -18,7 +18,7 @@ #include <pwd.h> #include <errno.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> @@ -39,9 +39,9 @@ int set_ownerhome(stralloc *base,uid_t owner) errno = e ; if (!user_home) return 0 ; - if (!stralloc_cats(base,user_home)) retstralloc(0,"set_ownerhome") ; - if (!stralloc_cats(base,"/")) retstralloc(0,"set_ownerhome") ; - if (!stralloc_0(base)) retstralloc(0,"set_ownerhome") ; + if (!stralloc_cats(base,user_home)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(base,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; base->len--; return 1 ; } diff --git a/src/lib66/set_ownersysdir.c b/src/lib66/set_ownersysdir.c index 1647d9d8..5a7f2af0 100644 --- a/src/lib66/set_ownersysdir.c +++ b/src/lib66/set_ownersysdir.c @@ -18,7 +18,7 @@ #include <pwd.h> #include <errno.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> @@ -40,15 +40,15 @@ int set_ownersysdir(stralloc *base, uid_t owner) if (user_home == NULL) return 0 ; if(owner > 0){ - if (!stralloc_cats(base,user_home)) retstralloc(0,"set_ownersysdir") ; - if (!stralloc_cats(base,"/")) retstralloc(0,"set_ownersysdir") ; - if (!stralloc_cats(base,SS_USER_DIR)) retstralloc(0,"set_ownersysdir") ; - if (!stralloc_0(base)) retstralloc(0,"set_ownersysdir") ; + if (!stralloc_cats(base,user_home)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(base,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_cats(base,SS_USER_DIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } else { - if (!stralloc_cats(base,SS_SYSTEM_DIR)) retstralloc(0,"set_ownersysdir") ; - if (!stralloc_0(base)) retstralloc(0,"set_ownersysdir") ; + if (!stralloc_cats(base,SS_SYSTEM_DIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; + if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; } base->len--; return 1 ; diff --git a/src/lib66/ss_info_utils.c b/src/lib66/ss_info_utils.c index fc459259..6c56a195 100644 --- a/src/lib66/ss_info_utils.c +++ b/src/lib66/ss_info_utils.c @@ -21,9 +21,8 @@ #include <string.h> #include <sys/types.h> //ssize_t -#include <oblibs/display.h> #include <oblibs/sastr.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/buffer.h> #include <skalibs/lolstdio.h> @@ -46,24 +45,6 @@ ss_resolve_graph_style graph_default = { 2 } ; -set_color_t use_color = { - BWHITE, //info - BGREEN, // valid - BYELLOW, //warning - BL_BBLUE, // blink - BRED, //error - NOCOLOR //reset -} ; - -set_color_t no_color = { - "", - "", - "", - "", - "", - "" -} ; - int info_getcols_fd(int fd) { int width = -1; @@ -142,7 +123,7 @@ size_t info_display_field_name(char const *field) if(field) { len = info_length_from_wchar(field) + 1 ; - if (!bprintf(buffer_1,"%s%s%s", info_color->info, field, info_color->off)) strerr_diefu1sys(111,"write to stdout") ; + if (!bprintf(buffer_1,"%s%s%s", log_color->info, field, log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } return len ; } @@ -180,7 +161,7 @@ void info_display_list(char const *field, stralloc *list) return ; err: - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } void info_display_nline(char const *field,char const *str) @@ -189,22 +170,22 @@ void info_display_nline(char const *field,char const *str) stralloc tmp = STRALLOC_ZERO ; stralloc cp = STRALLOC_ZERO ; if (!stralloc_cats(&tmp,str) || - !stralloc_0(&tmp)) exitstralloc("info_display_nline") ; - if (!sastr_split_string_in_nline(&tmp)) strerr_diefu1x(111,"split string in nline") ; + !stralloc_0(&tmp)) log_die_nomem("stralloc") ; + if (!sastr_split_string_in_nline(&tmp)) log_dieu(LOG_EXIT_SYS,"split string in nline") ; for (;pos < tmp.len ; pos += strlen(tmp.s + pos) + 1) { cp.len = 0 ; if (!stralloc_cats(&cp,tmp.s + pos) || - !stralloc_0(&cp)) exitstralloc("info_display_nline") ; + !stralloc_0(&cp)) log_die_nomem("stralloc") ; if (!pos) { if (!bprintf(buffer_1,"%s"," ")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } else { if (!bprintf(buffer_1,"%*s",padding,"")) - strerr_diefu1sys(111,"write to stdout") ; + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } info_display_list(field,&cp) ; } @@ -237,7 +218,7 @@ void info_graph_display(ss_resolve_t *res, depth_t *depth, int last, int padding depth = depth->next ; } - if (!bprintf(buffer_1,"%*s%*s%s(%s%i%s,%s%s%s,%s) %s",level == 1 ? padding : 0,"", style->indent * (depth->level - level), "", tip, status.pid ? info_color->valid : info_color->off,status.pid ? status.pid : 0,info_color->off, res->disen ? info_color->off : info_color->error, res->disen ? "Enabled" : "Disabled",info_color->off,get_keybyid(res->type), name)) return ; + if (!bprintf(buffer_1,"%*s%*s%s(%s%i%s,%s%s%s,%s) %s",level == 1 ? padding : 0,"", style->indent * (depth->level - level), "", tip, status.pid ? log_color->valid : log_color->off,status.pid ? status.pid : 0,log_color->off, res->disen ? log_color->off : log_color->error, res->disen ? "Enabled" : "Disabled",log_color->off,get_keybyid(res->type), name)) return ; if (buffer_putsflush(buffer_1,"\n") < 0) return ; } diff --git a/src/lib66/ss_utils.c b/src/lib66/ss_utils.c deleted file mode 100644 index b35adecd..00000000 --- a/src/lib66/ss_utils.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * ss_utils.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/utils.h> - -unsigned int VERBOSITY = 1 ; diff --git a/src/lib66/ssexec_dbctl.c b/src/lib66/ssexec_dbctl.c index 250e6ee2..87e045f6 100644 --- a/src/lib66/ssexec_dbctl.c +++ b/src/lib66/ssexec_dbctl.c @@ -17,7 +17,7 @@ //#include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <skalibs/tai.h> @@ -52,24 +52,24 @@ static void rebuild_list(ss_resolve_graph_t *graph,ssexec_t *info, int what) char *name = string + genalloc_s(ss_resolve_t,&graph->sorted)[i].name ; char *runat = string + genalloc_s(ss_resolve_t,&graph->sorted)[i].runat ; char *state = string + genalloc_s(ss_resolve_t,&graph->sorted)[i].state ; - if (!ss_state_check(state,name)) strerr_dief2x(111,"unitialized service: ",name) ; - if (!ss_state_read(&sta,state,name)) strerr_diefu2sys(111,"read state of: ",name) ; - if (sta.init) strerr_dief2x(111,"unitialized service: ",name) ; + if (!ss_state_check(state,name)) log_die(LOG_EXIT_SYS,"unitialized service: ",name) ; + if (!ss_state_read(&sta,state,name)) log_dieusys(LOG_EXIT_SYS,"read state of: ",name) ; + if (sta.init) log_die(LOG_EXIT_SYS,"unitialized service: ",name) ; int type = genalloc_s(ss_resolve_t,&graph->sorted)[i].type ; if (type == LONGRUN && genalloc_s(ss_resolve_t,&graph->sorted)[i].disen) { - if (!s6_svstatus_read(runat,&status)) strerr_diefu2sys(111,"read status of: ",runat) ; + if (!s6_svstatus_read(runat,&status)) log_dieusys(LOG_EXIT_SYS,"read status of: ",runat) ; isup = status.pid && !status.flagfinishing ; if (isup && !what) { - VERBO1 strerr_warni2x("Already up: ",name) ; + log_info("Already up: ",name) ; continue ; } else if (!isup && what) { - VERBO1 strerr_warni2x("Already down: ",name) ; + log_info("Already down: ",name) ; continue ; } } @@ -77,12 +77,12 @@ static void rebuild_list(ss_resolve_graph_t *graph,ssexec_t *info, int what) { if (!sta.state && what) { - VERBO1 strerr_warni2x("Already down: ",name) ; + log_info("Already down: ",name) ; continue ; } if (sta.state && !what) { - VERBO1 strerr_warni2x("Already up: ",name) ; + log_info("Already up: ",name) ; continue ; } } @@ -115,7 +115,7 @@ static int check_status(genalloc *gares,ssexec_t *info,int signal) /** only check longrun service */ if (pres->type == LONGRUN) { - if (!s6_svstatus_read(pres->sa.s + pres->runat,&status)) strerr_diefu2sys(111,"read status of: ",pres->sa.s + pres->runat) ; + if (!s6_svstatus_read(pres->sa.s + pres->runat,&status)) log_dieusys(LOG_EXIT_SYS,"read status of: ",pres->sa.s + pres->runat) ; else if (up) { if ((!WEXITSTATUS(status.wstat) && !WIFSIGNALED(status.wstat)) || (WIFSIGNALED(status.wstat) && !WEXITSTATUS(status.wstat) && (WTERMSIG(status.wstat) == 15 ))) @@ -125,7 +125,7 @@ static int check_status(genalloc *gares,ssexec_t *info,int signal) } else { - VERBO1 strerr_warnwu2x("start: ",name) ; + log_warnu("start: ",name) ; nret = 1 ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; @@ -140,7 +140,7 @@ static int check_status(genalloc *gares,ssexec_t *info,int signal) } else { - VERBO1 strerr_warnwu2x("stop: ",name) ; + log_warnu("stop: ",name) ; ss_state_setflag(&sta,SS_FLAGS_PID,status.pid) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_TRUE) ; nret = 1 ; @@ -156,13 +156,13 @@ static int check_status(genalloc *gares,ssexec_t *info,int signal) if (up) ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_TRUE) ; else ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; } - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; ret = 111 ; } - if (!nret) VERBO1 strerr_warni3x(reload ? "Reloaded" : up ? "Started" : "Stopped"," successfully: ",name) ; + if (!nret) log_info(reload ? "Reloaded" : up ? "Started" : "Stopped"," successfully: ",name) ; } return ret ; @@ -232,19 +232,19 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe { int opt = getopt_args(argc,argv, "udr", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - case 'u' : up = 1 ; if (down || reload) exitusage(usage_dbctl) ; break ; - case 'd' : down = 1 ; if (up || reload) exitusage(usage_dbctl) ; break ; - case 'r' : reload = 1 ; if (down || up) exitusage(usage_dbctl) ; break ; - default : exitusage(usage_dbctl) ; + case 'u' : up = 1 ; if (down || reload) log_usage(usage_dbctl) ; break ; + case 'd' : down = 1 ; if (up || reload) log_usage(usage_dbctl) ; break ; + case 'r' : reload = 1 ; if (down || up) log_usage(usage_dbctl) ; break ; + default : log_usage(usage_dbctl) ; } } argc -= l.ind ; argv += l.ind ; } - if (!up && !down && !reload){ strerr_warnw1x("signal must be set") ; exitusage(usage_dbctl) ; } + if (!up && !down && !reload){ log_warn("signal must be set") ; log_usage(usage_dbctl) ; } if (down) { @@ -252,20 +252,20 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe } else signal = "-u" ; - 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_SRC)) log_dieusys(LOG_EXIT_SYS,"set revolve pointer to source") ; if (argc < 1) { - if (!ss_resolve_check(sares.s,mainsv)) strerr_dief1sys(111,"inner bundle doesn't exit -- please make a bug report") ; - if (!ss_resolve_read(&res,sares.s,mainsv)) strerr_diefu1sys(111,"read resolve file of inner bundle") ; + if (!ss_resolve_check(sares.s,mainsv)) log_diesys(LOG_EXIT_SYS,"inner bundle doesn't exit -- please make a bug report") ; + if (!ss_resolve_read(&res,sares.s,mainsv)) log_dieusys(LOG_EXIT_SYS,"read resolve file of inner bundle") ; if (res.ndeps) { - if (!ss_resolve_append(&gares,&res)) strerr_diefu1sys(111,"append services selection with inner bundle") ; + if (!ss_resolve_append(&gares,&res)) log_dieusys(LOG_EXIT_SYS,"append services selection with inner bundle") ; } else { - VERBO1 strerr_warni1x("nothing to do") ; + log_info("nothing to do") ; ss_resolve_free(&res) ; goto freed ; } @@ -276,40 +276,40 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe for(;*argv;argv++) { char const *name = *argv ; - if (!ss_resolve_check(sares.s,name)) strerr_dief2sys(111,"unknown service: ",name) ; - if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (res.type == CLASSIC) strerr_dief2x(111,name," has type classic") ; - if (!ss_resolve_append(&gares,&res)) strerr_diefu2sys(111,"append services selection with: ", name) ; + if (!ss_resolve_check(sares.s,name)) log_diesys(LOG_EXIT_SYS,"unknown service: ",name) ; + if (!ss_resolve_read(&res,sares.s,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (res.type == CLASSIC) log_die(LOG_EXIT_SYS,name," has type classic") ; + if (!ss_resolve_append(&gares,&res)) log_dieusys(LOG_EXIT_SYS,"append services selection with: ", name) ; } } if (!db_ok(info->livetree.s,info->treename.s)) - strerr_dief5sys(111,"db: ",info->livetree.s,"/",info->treename.s," is not running") ; + log_diesys(LOG_EXIT_SYS,"db: ",info->livetree.s,"/",info->treename.s," is not running") ; - if (!stralloc_cats(&tmp,info->livetree.s)) retstralloc(111,"main") ; - if (!stralloc_cats(&tmp,"/")) retstralloc(111,"main") ; - if (!stralloc_cats(&tmp,info->treename.s)) retstralloc(111,"main") ; - if (!stralloc_0(&tmp)) retstralloc(111,"main") ; + if (!stralloc_cats(&tmp,info->livetree.s)) log_die_nomem("stralloc") ; + if (!stralloc_cats(&tmp,"/")) log_die_nomem("stralloc") ; + if (!stralloc_cats(&tmp,info->treename.s)) log_die_nomem("stralloc") ; + if (!stralloc_0(&tmp)) log_die_nomem("stralloc") ; if (reload) { reverse = 1 ; for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) { - if (!ss_resolve_graph_build(&graph,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) strerr_diefu1sys(111,"build services graph") ; + if (!ss_resolve_graph_build(&graph,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) log_dieusys(LOG_EXIT_SYS,"build services graph") ; } r = ss_resolve_graph_publish(&graph,reverse) ; - if (r < 0) strerr_dief1x(111,"cyclic dependencies detected") ; - if (!r) strerr_diefu1sys(111,"publish service graph") ; + if (r < 0) log_die(LOG_EXIT_SYS,"cyclic dependencies detected") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"publish service graph") ; rebuild_list(&graph,info,reverse) ; pid = send(&graph.sorted,tmp.s,"-d",envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu1sys(111,"wait for s6-rc") ; + log_dieusys(LOG_EXIT_SYS,"wait for s6-rc") ; - if (wstat) strerr_diefu1x(111," stop services selection") ; + if (wstat) log_dieu(LOG_EXIT_SYS," stop services selection") ; ret = check_status(&graph.sorted,info,2) ; if (ret) goto freed ; @@ -327,20 +327,20 @@ int ssexec_dbctl(int argc, char const *const *argv,char const *const *envp,ssexe ireverse = 1 ; if (reload) ireverse = 1 ; - if (!ss_resolve_graph_build(&graph,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,ireverse)) strerr_diefu1sys(111,"build services graph") ; + if (!ss_resolve_graph_build(&graph,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,ireverse)) log_dieusys(LOG_EXIT_SYS,"build services graph") ; } r = ss_resolve_graph_publish(&graph,reverse) ; - if (r < 0) strerr_dief1x(111,"cyclic dependencies detected") ; - if (!r) strerr_diefu1sys(111,"publish service graph") ; + if (r < 0) log_die(LOG_EXIT_SYS,"cyclic dependencies detected") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"publish service graph") ; rebuild_list(&graph,info,reverse) ; pid = send(&graph.sorted,tmp.s,signal,envp) ; if (waitpid_nointr(pid,&wstat, 0) < 0) - strerr_diefu1sys(111,"wait for s6-rc") ; + log_dieusys(LOG_EXIT_SYS,"wait for s6-rc") ; - if (wstat) strerr_diefu2x(111,down ? "stop" : "start"," services selection") ; + if (wstat) log_dieu(LOG_EXIT_SYS,down ? "stop" : "start"," services selection") ; ret = check_status(&graph.sorted,info,down ? 2 : 1) ; diff --git a/src/lib66/ssexec_disable.c b/src/lib66/ssexec_disable.c index 6284d4a7..bc5fce66 100644 --- a/src/lib66/ssexec_disable.c +++ b/src/lib66/ssexec_disable.c @@ -17,7 +17,7 @@ //#include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <skalibs/stralloc.h> @@ -32,10 +32,12 @@ #include <66/state.h> #include <66/utils.h> -static void cleanup(char const *dst) +static stralloc workdir = STRALLOC_ZERO ; + +static void cleanup(void) { int e = errno ; - rm_rf(dst) ; + rm_rf(workdir.s) ; errno = e ; } @@ -51,7 +53,7 @@ int svc_remove(genalloc *tostop,ss_resolve_t *res, char const *src,ssexec_t *inf char *name = res->sa.s + res->name ; if (!ss_resolve_copy(&cp,res)) { - VERBO1 strerr_warnwu1sys("copy resolve file") ; + log_warnusys("copy resolve file") ; goto err ; } if (!stralloc_cats(&dst,src)) goto err ; @@ -65,14 +67,14 @@ int svc_remove(genalloc *tostop,ss_resolve_t *res, char const *src,ssexec_t *inf if (!ss_resolve_add_rdeps(&rdeps,&cp,src)) { - VERBO1 strerr_warnwu2sys("resolve recursive dependencies of: ",name) ; + log_warnusys("resolve recursive dependencies of: ",name) ; goto err ; } ss_resolve_free(&cp) ; if (!ss_resolve_add_logger(&rdeps,src)) { - VERBO1 strerr_warnwu1sys("resolve logger") ; + log_warnusys("resolve logger") ; goto err ; } @@ -86,35 +88,35 @@ int svc_remove(genalloc *tostop,ss_resolve_t *res, char const *src,ssexec_t *inf if (!stralloc_cats(&dst,name)) goto err ; if (!stralloc_0(&dst)) goto err ; - VERBO2 strerr_warni2x("delete source service file of: ",name) ; + log_trace("delete source service file of: ",name) ; if (rm_rf(dst.s) < 0) { - VERBO1 strerr_warnwu2sys("delete source service file: ",dst.s) ; + log_warnusys("delete source service file: ",dst.s) ; goto err ; } /** service was not initialized */ if (!ss_state_check(state,name)) { - VERBO2 strerr_warni2x("Delete resolve file of: ",name) ; + log_trace("Delete resolve file of: ",name) ; ss_resolve_rmfile(src,name) ; } else { /** modify the resolve file for 66-stop*/ pres->disen = 0 ; - VERBO2 strerr_warni2x("Write resolve file of: ",name) ; + log_trace("Write resolve file of: ",name) ; if (!ss_resolve_write(pres,src,name)) { - VERBO1 strerr_warnwu2sys("write resolve file of: ",name) ; + log_warnusys("write resolve file of: ",name) ; goto err ; } ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_TRUE) ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } } @@ -138,7 +140,7 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse int r, logname ; unsigned int nlongrun, nclassic, stop ; - stralloc workdir = STRALLOC_ZERO ; + genalloc tostop = GENALLOC_ZERO ;//ss_resolve_t genalloc gares = GENALLOC_ZERO ; //ss_resolve_t ss_resolve_t res = RESOLVE_ZERO ; @@ -153,26 +155,26 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse { int opt = getopt_args(argc,argv, ">S", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'S' : stop = 1 ; break ; - default : exitusage(usage_disable) ; + default : log_usage(usage_disable) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(usage_disable) ; + if (argc < 1) log_usage(usage_disable) ; - if (!tree_copy(&workdir,info->tree.s,info->treename.s)) strerr_diefu1sys(111,"create tmp working directory") ; + if (!tree_copy(&workdir,info->tree.s,info->treename.s)) log_dieusys(LOG_EXIT_SYS,"create tmp working directory") ; for (;*argv;argv++) { char const *name = *argv ; - if (!ss_resolve_check(workdir.s,name)) { 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 (!ss_resolve_append(&gares,&res)) { cleanup(workdir.s) ; strerr_diefu2sys(111,"append services selection with: ",name) ; } + if (!ss_resolve_check(workdir.s,name)) log_die_nclean(LOG_EXIT_USER,&cleanup,name," is not enabled") ; + if (!ss_resolve_read(&res,workdir.s,name)) log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"read resolve file of: ",name) ; + if (!ss_resolve_append(&gares,&res)) log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"append services selection with: ",name) ; } for(unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) @@ -182,27 +184,21 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse char *name = string + pres->name ; logname = 0 ; if (obstr_equal(name,SS_MASTER + 1)) - { - cleanup(workdir.s) ; - strerr_dief1x(110,"nice try peon") ; - } + log_die_nclean(LOG_EXIT_USER,&cleanup,"nice try peon") ; + logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; if (logname > 0 && (!ss_resolve_cmp(&gares,string + pres->logassoc))) - { - cleanup(workdir.s) ; - strerr_dief1x(110,"logger detected - disabling is not allowed") ; - } + log_die_nclean(LOG_EXIT_USER,&cleanup,"logger detected - disabling is not allowed") ; + if (!pres->disen) { - VERBO1 strerr_warni2x(name,": is already disabled") ; + log_info(name,": is already disabled") ; ss_resolve_free(&res) ; continue ; } if (!svc_remove(&tostop,pres,workdir.s,info)) - { - cleanup(workdir.s) ; - strerr_diefu3sys(111,"remove",name," directory service") ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"remove",name," directory service") ; + if (res.type == CLASSIC) nclassic++ ; else nlongrun++ ; @@ -211,11 +207,7 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse if (nclassic) { if (!svc_switch_to(info,SS_SWBACK)) - { - cleanup(workdir.s) ; - strerr_diefu1sys(111,"switch classic service to backup") ; - } - + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"switch classic service to backup") ; } if (nlongrun) @@ -223,51 +215,38 @@ int ssexec_disable(int argc, char const *const *argv,char const *const *envp,sse ss_resolve_graph_t graph = RESOLVE_GRAPH_ZERO ; r = ss_resolve_graph_src(&graph,workdir.s,0,1) ; if (!r) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"resolve source of graph for tree: ",info->treename.s) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"resolve source of graph for tree: ",info->treename.s) ; + r= ss_resolve_graph_publish(&graph,0) ; if (r <= 0) { - cleanup(workdir.s) ; - if (r < 0) strerr_dief1x(110,"cyclic graph detected") ; - strerr_diefu1sys(111,"publish service graph") ; + cleanup() ; + if (r < 0) log_die(LOG_EXIT_USER,"cyclic graph detected") ; + log_dieusys(LOG_EXIT_SYS,"publish service graph") ; } if (!ss_resolve_write_master(info,&graph,workdir.s,1)) - { - cleanup(workdir.s) ; - strerr_diefu1sys(111,"update inner bundle") ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"update inner bundle") ; + ss_resolve_graph_free(&graph) ; if (!db_compile(workdir.s,info->tree.s, info->treename.s,envp)) - { - cleanup(workdir.s) ; - strerr_diefu4x(111,"compile ",workdir.s,"/",info->treename.s) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"compile ",workdir.s,"/",info->treename.s) ; + /** this is an important part, we call s6-rc-update here */ if (!db_switch_to(info,envp,SS_SWBACK)) - { - cleanup(workdir.s) ; - strerr_diefu3x(111,"switch ",info->treename.s," to backup") ; - } - + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"switch ",info->treename.s," to backup") ; } if (!tree_copy_tmp(workdir.s,info)) - { - cleanup(workdir.s) ; - strerr_diefu4x(111,"copy: ",workdir.s," to: ", info->tree.s) ; - } - - cleanup(workdir.s) ; + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"copy: ",workdir.s," to: ", info->tree.s) ; + + cleanup() ; stralloc_free(&workdir) ; ss_resolve_free(&res) ; genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ; 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) ; + log_info("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)) { diff --git a/src/lib66/ssexec_enable.c b/src/lib66/ssexec_enable.c index 56ec9ec9..5ac0862f 100644 --- a/src/lib66/ssexec_enable.c +++ b/src/lib66/ssexec_enable.c @@ -18,7 +18,7 @@ //#include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/sastr.h> @@ -35,22 +35,23 @@ #include <66/resolve.h> #include <66/ssexec.h> +static stralloc workdir = STRALLOC_ZERO ; /** force == 1, only rewrite the service * force == 2, rewrite the service and it dependencies*/ static uint8_t FORCE = 0 ; /** rewrite configuration file */ static uint8_t CONF = 0 ; -static void cleanup(char const *dst) +static void cleanup(void) { int e = errno ; - rm_rf(dst) ; + rm_rf(workdir.s) ; errno = e ; } static void check_identifier(char const *name) { - if (!memcmp(name,SS_MASTER+1,6)) strerr_dief3x(111,"service: ",name,": starts with reserved prefix") ; + if (!memcmp(name,SS_MASTER+1,6)) log_die(LOG_EXIT_USER,"service: ",name,": starts with reserved prefix") ; } static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) @@ -68,12 +69,12 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) char *name = list->s+i ; size_t namelen = strlen(name) ; char svname[namelen + 1] ; - if (!basename(svname,name)) strerr_diefu2sys(111,"get basename of: ", svname) ; + if (!basename(svname,name)) log_dieusys(LOG_EXIT_SYS,"get basename of: ", svname) ; r = parse_service_check_enabled(info,svname,FORCE,&exist) ; - if (!r) strerr_diefu2x(111,"check enabled service: ",svname) ; + if (!r) log_dieu(LOG_EXIT_SYS,"check enabled service: ",svname) ; if (r == 2) continue ; if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,&exist)) - strerr_diefu3x(111,"parse service file: ",svname,": or its dependencies") ; + log_dieu(LOG_EXIT_SYS,"parse service file: ",svname,": or its dependencies") ; } stralloc_free(&sasv) ; stralloc_free(&tmp) ; @@ -88,9 +89,8 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex int r ; size_t pos = 0 ; unsigned int nbsv, nlongrun, nclassic, start ; - - stralloc home = STRALLOC_ZERO ; - stralloc workdir = STRALLOC_ZERO ; + + //stralloc home = STRALLOC_ZERO ; stralloc sasrc = STRALLOC_ZERO ; stralloc tostart = STRALLOC_ZERO ; @@ -103,33 +103,33 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex { int opt = getopt_args(argc,argv, ">cCfFS", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - case 'f' : if (FORCE) exitusage(usage_enable) ; + case 'f' : if (FORCE) log_usage(usage_enable) ; FORCE = 1 ; break ; - case 'F' : if (FORCE) exitusage(usage_enable) ; + case 'F' : if (FORCE) log_usage(usage_enable) ; FORCE = 2 ; break ; - case 'c' : if (CONF) exitusage(usage_enable) ; CONF = 1 ; break ; - case 'C' : if (CONF) exitusage(usage_enable) ; CONF = 2 ; break ; + case 'c' : if (CONF) log_usage(usage_enable) ; CONF = 1 ; break ; + case 'C' : if (CONF) log_usage(usage_enable) ; CONF = 2 ; break ; case 'S' : start = 1 ; break ; - default : exitusage(usage_enable) ; + default : log_usage(usage_enable) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(usage_enable) ; - + if (argc < 1) log_usage(usage_enable) ; + for(;*argv;argv++) { check_identifier(*argv) ; - if (!ss_resolve_src_path(&sasrc,*argv,info)) strerr_diefu2x(111,"resolve source path of: ",*argv) ; + if (!ss_resolve_src_path(&sasrc,*argv,info)) log_dieu(LOG_EXIT_SYS,"resolve source path of: ",*argv) ; } start_parser(&sasrc,info,&nbsv) ; - if (!tree_copy(&workdir,info->tree.s,info->treename.s)) strerr_diefu1sys(111,"create tmp working directory") ; + if (!tree_copy(&workdir,info->tree.s,info->treename.s)) log_dieusys(LOG_EXIT_SYS,"create tmp working directory") ; for (unsigned int i = 0; i < genalloc_len(sv_alltype,&gasv); i++) { @@ -137,38 +137,28 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex char *name = keep.s + sv->cname.name ; r = write_services(info,sv, workdir.s,FORCE,CONF) ; if (!r) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"write service: ",name) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"write service: ",name) ; + if (r > 1) continue ; //service already added - VERBO2 strerr_warni2x("write resolve file of: ",name) ; + log_trace("write resolve file of: ",name) ; if (!ss_resolve_setnwrite(sv,info,workdir.s)) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"write revolve file for: ",name) ; - } - VERBO2 strerr_warni2x("Service written successfully: ", name) ; + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"write revolve file for: ",name) ; + + log_trace("Service written successfully: ", name) ; if (sastr_cmp(&tostart,name) == -1) { if (sv->cname.itype == CLASSIC) nclassic++ ; else nlongrun++ ; if (!sastr_add_string(&tostart,name)) - { - cleanup(workdir.s) ; - retstralloc(111,"main") ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"stralloc") ; } } if (nclassic) { if (!svc_switch_to(info,SS_SWBACK)) - { - cleanup(workdir.s) ; - strerr_diefu3x(111,"switch ",info->treename.s," to backup") ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"switch ",info->treename.s," to backup") ; } if(nlongrun) @@ -176,54 +166,42 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex ss_resolve_graph_t graph = RESOLVE_GRAPH_ZERO ; r = ss_resolve_graph_src(&graph,workdir.s,0,1) ; if (!r) - { - cleanup(workdir.s) ; - strerr_diefu2x(111,"resolve source of graph for tree: ",info->treename.s) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"resolve source of graph for tree: ",info->treename.s) ; r = ss_resolve_graph_publish(&graph,0) ; if (r <= 0) { - cleanup(workdir.s) ; - if (r < 0) strerr_dief1x(110,"cyclic graph detected") ; - strerr_diefu1sys(111,"publish service graph") ; + cleanup() ; + if (r < 0) log_die(LOG_EXIT_USER,"cyclic graph detected") ; + log_dieusys(LOG_EXIT_SYS,"publish service graph") ; } if (!ss_resolve_write_master(info,&graph,workdir.s,0)) - { - cleanup(workdir.s) ; - strerr_diefu1sys(111,"update inner bundle") ; - } + log_dieusys_nclean(LOG_EXIT_SYS,&cleanup,"update inner bundle") ; + ss_resolve_graph_free(&graph) ; if (!db_compile(workdir.s,info->tree.s,info->treename.s,envp)) - { - cleanup(workdir.s) ; - strerr_diefu4x(111,"compile ",workdir.s,"/",info->treename.s) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"compile ",workdir.s,"/",info->treename.s) ; + /** this is an important part, we call s6-rc-update here */ if (!db_switch_to(info,envp,SS_SWBACK)) - { - cleanup(workdir.s) ; - strerr_diefu3x(111,"switch ",info->treename.s," to backup") ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"switch ",info->treename.s," to backup") ; } if (!tree_copy_tmp(workdir.s,info)) - { - cleanup(workdir.s) ; - strerr_diefu4x(111,"copy: ",workdir.s," to: ", info->tree.s) ; - } + log_dieu_nclean(LOG_EXIT_SYS,&cleanup,"copy: ",workdir.s," to: ", info->tree.s) ; + - cleanup(workdir.s) ; + cleanup() ; /** parser allocation*/ freed_parser() ; /** inner allocation */ - stralloc_free(&home) ; + //stralloc_free(&home) ; stralloc_free(&workdir) ; stralloc_free(&sasrc) ; for (; pos < tostart.len; pos += strlen(tostart.s + pos) + 1) - VERBO1 strerr_warni2x("Enabled successfully: ", tostart.s + pos) ; + log_info("Enabled successfully: ", tostart.s + pos) ; if (start && tostart.len) { diff --git a/src/lib66/ssexec_env.c b/src/lib66/ssexec_env.c index 81570cbf..fd01c081 100644 --- a/src/lib66/ssexec_env.c +++ b/src/lib66/ssexec_env.c @@ -17,7 +17,7 @@ #include <stdlib.h>//getenv #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/files.h> #include <oblibs/string.h> @@ -50,45 +50,45 @@ int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_ { int opt = getopt_args(argc,argv, ">Ld:r:e", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - case 'L' : if (replace) exitusage(usage_env) ; list = 1 ; break ; + case 'L' : if (replace) log_usage(usage_env) ; list = 1 ; break ; case 'd' : src = l.arg ; break ; case 'r' : if (!stralloc_cats(&var,l.arg) || !stralloc_cats(&var,"\n") || - !stralloc_0(&var)) retstralloc(111,"main") ; + !stralloc_0(&var)) log_die_nomem("stralloc") ; replace = 1 ; break ; - case 'e' : if (replace) exitusage(usage_env) ; + case 'e' : if (replace) log_usage(usage_env) ; edit = 1 ; break ; - default : exitusage(usage_env) ; + default : log_usage(usage_env) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(usage_env) ; + if (argc < 1) log_usage(usage_env) ; sv = argv[0] ; - if (!env_resolve_conf(&sasrc,info->owner)) strerr_diefu1sys(111,"get path of the configuration file") ; + if (!env_resolve_conf(&sasrc,info->owner)) log_dieusys(LOG_EXIT_SYS,"get path of the configuration file") ; if (!src) src = sasrc.s ; - if (!file_readputsa(&salist,src,sv)) strerr_diefu3sys(111,"read: ",src,sv) ; + if (!file_readputsa(&salist,src,sv))log_dieusys(LOG_EXIT_SYS,"read: ",src,sv) ; if (list) { if (buffer_putsflush(buffer_1, salist.s) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; goto freed ; } else if (replace) { if (!env_merge_conf(src,sv,&salist,&var,replace)) - strerr_diefu2x(111,"merge environment file with: ",var.s) ; + log_dieu(LOG_EXIT_SYS,"merge environment file with: ",var.s) ; } else if (edit) { size_t svlen = strlen(sv) ; char t[sasrc.len + svlen + 1] ; editor = getenv("EDITOR") ; - if (!editor) strerr_diefu1sys(111,"get EDITOR") ; + if (!editor) log_dieusys(LOG_EXIT_SYS,"get EDITOR") ; memcpy(t,sasrc.s,sasrc.len) ; memcpy(t + sasrc.len,sv,svlen) ; t[sasrc.len + svlen] = 0 ; diff --git a/src/lib66/ssexec_init.c b/src/lib66/ssexec_init.c index 999e0f8d..25183f22 100644 --- a/src/lib66/ssexec_init.c +++ b/src/lib66/ssexec_init.c @@ -17,7 +17,7 @@ #include <unistd.h>//chown #include <stdio.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h>//scan_mode #include <oblibs/directory.h> #include <oblibs/sastr.h> @@ -50,33 +50,33 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec classic = db = earlier = 0 ; gid_t gidowner ; - if (!yourgid(&gidowner,info->owner)) strerr_diefu1sys(111,"set gid") ; + if (!yourgid(&gidowner,info->owner)) log_dieusys(LOG_EXIT_SYS,"set gid") ; - if (argc != 2) exitusage(usage_init) ; + if (argc != 2) log_usage(usage_init) ; if (*argv[1] == 'c') classic = 1 ; else if (*argv[1] == 'd') db = 1 ; else if (*argv[1] == 'b') classic = db = 1 ; - else strerr_dief2x(110,"uknow command: ",argv[1]) ; + else log_die(LOG_EXIT_USER,"uknow command: ",argv[1]) ; if (!tree_get_permissions(info->tree.s,info->owner)) - strerr_dief2x(110,"You're not allowed to use the tree: ",info->tree.s) ; + log_die(LOG_EXIT_USER,"You're not allowed to use the tree: ",info->tree.s) ; r = scan_mode(info->scandir.s,S_IFDIR) ; - if (r < 0) strerr_dief2x(111,info->scandir.s," conflicted format") ; - if (!r) strerr_dief3x(110,"scandir: ",info->scandir.s," doesn't exist") ; + if (r < 0) log_die(LOG_EXIT_SYS,info->scandir.s," conflicted format") ; + if (!r) log_die(LOG_EXIT_USER,"scandir: ",info->scandir.s," doesn't exist") ; r = scandir_ok(info->scandir.s) ; if (r != 1) earlier = 1 ; r = scan_mode(info->livetree.s,S_IFDIR) ; - if (r < 0) strerr_dief2x(111,info->livetree.s," conflicted format") ; + if (r < 0) log_die(LOG_EXIT_SYS,info->livetree.s," conflicted format") ; if (!r) { - VERBO2 strerr_warni2x("create directory: ",info->livetree.s) ; + log_trace("create directory: ",info->livetree.s) ; r = dir_create(info->livetree.s,0700) ; - if (!r) strerr_diefu2sys(111,"create directory: ",info->livetree.s) ; - VERBO2 strerr_warni2x("chown directory: ",info->livetree.s) ; - if (chown(info->livetree.s,info->owner,gidowner) < 0) strerr_diefu2sys(111,"chown directory: ",info->livetree.s) ; + if (!r) log_dieusys(LOG_EXIT_SYS,"create directory: ",info->livetree.s) ; + log_trace("chown directory: ",info->livetree.s) ; + if (chown(info->livetree.s,info->owner,gidowner) < 0) log_dieusys(LOG_EXIT_SYS,"chown directory: ",info->livetree.s) ; } size_t dirlen ; @@ -90,23 +90,23 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec /** svc already initiated? */ if (classic) { - if (!sastr_dir_get(&sasvc,svdir,"",S_IFDIR)) strerr_diefu2x(111,"get classic services from: ",svdir) ; + if (!sastr_dir_get(&sasvc,svdir,"",S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get classic services from: ",svdir) ; if (!sasvc.len) { - VERBO1 strerr_warni2x("Initialization aborted -- no classic services into tree: ",info->treename.s) ; + log_info("Initialization aborted -- no classic services into tree: ",info->treename.s) ; goto follow ; } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) - strerr_diefu1x(111,"set revolve pointer to source") ; + log_dieu(LOG_EXIT_SYS,"set revolve pointer to source") ; for (i = 0;i < sasvc.len; i += strlen(sasvc.s + i) + 1) { char *name = sasvc.s + i ; ss_resolve_t tmp = RESOLVE_ZERO ; - if (!ss_resolve_check(sares.s,name)) strerr_dief2sys(110,"unknown service: ",name) ; - if (!ss_resolve_read(&tmp,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ; + if (!ss_resolve_check(sares.s,name)) log_diesys(LOG_EXIT_USER,"unknown service: ",name) ; + if (!ss_resolve_read(&tmp,sares.s,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) log_dieusys(LOG_EXIT_SYS,"resolve dependencies of: ",name) ; ss_resolve_free(&tmp) ; } @@ -114,11 +114,11 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec { /** reverse to start first the logger */ genalloc_reverse(ss_resolve_t,&gares) ; - if (!svc_init(info,svdir,&gares)) strerr_diefu2x(111,"initiate service of tree: ",info->treename.s) ; + if (!svc_init(info,svdir,&gares)) log_dieu(LOG_EXIT_SYS,"initiate service of tree: ",info->treename.s) ; } else { - if (!ss_resolve_create_live(info)) strerr_diefu1sys(111,"create live state") ; + if (!ss_resolve_create_live(info)) log_dieusys(LOG_EXIT_SYS,"create live state") ; for (i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) { logname = 0 ; @@ -132,14 +132,14 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec tocopy[dirlen] = '/' ; 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,"copy earlier service: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ; + if (!hiercopy(tocopy,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) log_dieusys(LOG_EXIT_SYS,"copy earlier service: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ; ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_UNKNOWN) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_UNKNOWN) ; - if (!ss_state_write(&sta,string + genalloc_s(ss_resolve_t,&gares)[i].state,name)) strerr_diefu2sys(111,"write state file of: ",name) ; - VERBO1 strerr_warni2x("Initialized successfully: ", logname < 0 ? name : string + genalloc_s(ss_resolve_t,&gares)[i].logreal) ; + if (!ss_state_write(&sta,string + genalloc_s(ss_resolve_t,&gares)[i].state,name)) log_dieusys(LOG_EXIT_SYS,"write state file of: ",name) ; + log_info("Initialized successfully: ", logname < 0 ? name : string + genalloc_s(ss_resolve_t,&gares)[i].logreal) ; } } } @@ -158,13 +158,13 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec { if (db_ok(info->livetree.s,info->treename.s)) { - VERBO1 strerr_warni3x("db of tree: ",info->treename.s," already initialized") ; + log_warn("db of tree: ",info->treename.s," already initialized") ; goto end ; } - }else strerr_dief3x(110,"scandir: ",info->scandir.s," is not running") ; + }else log_die(LOG_EXIT_USER,"scandir: ",info->scandir.s," is not running") ; }else goto end ; - if (!rc_init(info,envp)) strerr_diefu2sys(111,"initiate db of tree: ",info->treename.s) ; + if (!rc_init(info,envp)) log_dieusys(LOG_EXIT_SYS,"initiate db of tree: ",info->treename.s) ; end: return 0 ; diff --git a/src/lib66/ssexec_main.c b/src/lib66/ssexec_main.c index e53786a0..0c28f209 100644 --- a/src/lib66/ssexec_main.c +++ b/src/lib66/ssexec_main.c @@ -13,7 +13,7 @@ */ #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <skalibs/buffer.h> @@ -32,39 +32,39 @@ void set_ssinfo(ssexec_t *info) info->owner = MYUID ; - if (!set_ownersysdir(&info->base,info->owner)) strerr_diefu1sys(111, "set owner directory") ; + if (!set_ownersysdir(&info->base,info->owner)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ; r = tree_sethome(&info->tree,info->base.s,info->owner) ; - if (r < 0) strerr_diefu1x(110,"find the current tree. You must use -t options") ; - if (!r) strerr_diefu2sys(111,"find tree: ", info->tree.s) ; + if (r < 0) log_dieu(LOG_EXIT_USER,"find the current tree. You must use -t options") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"find tree: ", info->tree.s) ; r = tree_setname(&info->treename,info->tree.s) ; - if (r < 0) strerr_diefu1x(111,"set the tree name") ; + if (r < 0) log_dieu(LOG_EXIT_SYS,"set the tree name") ; if (!tree_get_permissions(info->tree.s,info->owner)) - strerr_dief2x(110,"You're not allowed to use the tree: ",info->tree.s) ; + log_die(LOG_EXIT_USER,"You're not allowed to use the tree: ",info->tree.s) ; else info->treeallow = 1 ; r = set_livedir(&info->live) ; - if (!r) exitstralloc("set_ssinfo") ; - if(r < 0) strerr_dief3x(111,"live: ",info->live.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if(r < 0) log_die(LOG_EXIT_SYS,"live: ",info->live.s," must be an absolute path") ; - if (!stralloc_copy(&info->livetree,&info->live)) exitstralloc("set_ssinfo") ; - if (!stralloc_copy(&info->scandir,&info->live)) exitstralloc("set_ssinfo") ; + if (!stralloc_copy(&info->livetree,&info->live)) log_die_nomem("stralloc") ; + if (!stralloc_copy(&info->scandir,&info->live)) log_die_nomem("stralloc") ; r = set_livetree(&info->livetree,info->owner) ; - if (!r) exitstralloc("set_ssinfo") ; - if(r < 0) strerr_dief3x(111,"livetree: ",info->livetree.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if(r < 0) log_die(LOG_EXIT_SYS,"livetree: ",info->livetree.s," must be an absolute path") ; r = set_livescan(&info->scandir,info->owner) ; - if (!r) exitstralloc("set_ssinfo") ; - if(r < 0) strerr_dief3x(111,"scandir: ",info->scandir.s," must be an absolute path") ; + if (!r) log_die_nomem("stralloc") ; + if(r < 0) log_die(LOG_EXIT_SYS,"scandir: ",info->scandir.s," must be an absolute path") ; } static inline void info_help (char const *help) { if (buffer_putsflush(buffer_1, help) < 0) - strerr_diefu1sys(111, "write to stdout") ; + log_dieusys(LOG_EXIT_SYS, "write to stdout") ; } @@ -87,17 +87,17 @@ int ssexec_main(int argc, char const *const *argv,char const *const *envp,ssexec switch (opt) { case 'h' : info_help(info->help); return 0 ; - case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) exitusage(info->usage) ; break ; - case 'l' : if (!stralloc_cats(&info->live,l.arg)) retstralloc(111,"main") ; - if (!stralloc_0(&info->live)) retstralloc(111,"main") ; + case 'v' : if (!uint0_scan(l.arg, &VERBOSITY)) log_usage(info->usage) ; break ; + case 'l' : if (!stralloc_cats(&info->live,l.arg)) log_die_nomem("stralloc") ; + if (!stralloc_0(&info->live)) log_die_nomem("stralloc") ; break ; - case 't' : if(!stralloc_cats(&info->tree,l.arg)) retstralloc(111,"main") ; - if(!stralloc_0(&info->tree)) retstralloc(111,"main") ; + case 't' : if(!stralloc_cats(&info->tree,l.arg)) log_die_nomem("stralloc") ; + if(!stralloc_0(&info->tree)) log_die_nomem("stralloc") ; break ; - case 'T' : if (!uint0_scan(l.arg, &info->timeout)) exitusage(info->usage) ; break ; + case 'T' : if (!uint0_scan(l.arg, &info->timeout)) log_usage(info->usage) ; break ; default : for (int i = 0 ; i < n ; i++) { - if (!argv[l.ind]) exitusage(info->usage) ; + if (!argv[l.ind]) log_usage(info->usage) ; if (obstr_equal(nargv[i],argv[l.ind])) f = 1 ; } diff --git a/src/lib66/ssexec_start.c b/src/lib66/ssexec_start.c index d8d80de0..66d6e1e2 100644 --- a/src/lib66/ssexec_start.c +++ b/src/lib66/ssexec_start.c @@ -16,7 +16,7 @@ #include <stdio.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/types.h> @@ -51,7 +51,7 @@ int svc_sanitize(ssexec_t *info, char const *const *envp) stralloc sares = STRALLOC_ZERO ; if (!ss_resolve_pointo(&sares,info,CLASSIC,SS_RESOLVE_SRC)) { - VERBO1 strerr_warnwu1x("set revolve pointer to source") ; + log_warnu("set revolve pointer to source") ; goto err; } if (genalloc_len(ss_resolve_t,&graph_reload_cl.name)) @@ -60,14 +60,14 @@ int svc_sanitize(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_reload_cl,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!svc_unsupervise(info,&graph_reload_cl.sorted,"-d",envp)) goto err ; genalloc_reverse(ss_resolve_t,&graph_reload_cl.sorted) ; if (!svc_init(info,sares.s,&graph_reload_cl.sorted)) { - VERBO1 strerr_warnwu1x("iniatiate service list") ; + log_warnu("iniatiate service list") ; goto err ; } goto end ; @@ -77,12 +77,12 @@ int svc_sanitize(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_init_cl,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!svc_init(info,sares.s,&graph_init_cl.sorted)) { - VERBO1 strerr_warnwu1x("iniatiate service list") ; + log_warnu("iniatiate service list") ; goto err ; } } @@ -119,7 +119,7 @@ int rc_sanitize(ssexec_t *info, char const *const *envp) } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) { - VERBO1 strerr_warnwu1x("set revolve pointer to source") ; + log_warnu("set revolve pointer to source") ; goto err; } if (genalloc_len(ss_resolve_t,&graph_init_rc.name) && !done) @@ -128,12 +128,12 @@ int rc_sanitize(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_init_rc,ireverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!rc_manage(info,&graph_init_rc.sorted)) { - VERBO1 strerr_warnwu1x("iniatiate service list") ; + log_warnu("iniatiate service list") ; goto err ; } } @@ -142,23 +142,23 @@ int rc_sanitize(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_reload_rc,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!db_switch_to(info,envp,SS_SWBACK)) { - VERBO1 strerr_warnwu3x("switch ",info->treename.s," to backup") ; + log_warnu("switch ",info->treename.s," to backup") ; goto err ; } if (!db_compile(sares.s,info->tree.s, info->treename.s,envp)) { - VERBO1 strerr_diefu4x(111,"compile ",sares.s,"/",info->treename.s) ; + log_warnu("compile ",sares.s,"/",info->treename.s) ; goto err ; } if (!db_switch_to(info,envp,SS_SWSRC)) { - VERBO1 strerr_warnwu3x("switch ",info->treename.s," to source") ; + log_warnu("switch ",info->treename.s," to source") ; goto err ; } @@ -187,10 +187,7 @@ int rc_start(ssexec_t *info,genalloc *ga,char const *signal,char const *const *e if (r >= 1) { if (!db_switch_to(info,envp,SS_SWSRC)) - { - VERBO1 strerr_warnwu3x("switch: ",info->treename.s," to source") ; - return 0 ; - } + log_warnu_return(LOG_EXIT_ZERO,"switch: ",info->treename.s," to source") ; } if (!rc_send(info,ga,sig,envp)) return 0 ; @@ -223,36 +220,36 @@ int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexe { int opt = getopt_args(argc,argv, ">rR", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - case 'r' : if (RELOAD) exitusage(usage_start) ; RELOAD = 1 ; SIG = "-r" ; break ; - case 'R' : if (RELOAD) exitusage(usage_start) ; RELOAD = 2 ; SIG = "-u" ; break ; - default : exitusage(usage_start) ; + case 'r' : if (RELOAD) log_usage(usage_start) ; RELOAD = 1 ; SIG = "-r" ; break ; + case 'R' : if (RELOAD) log_usage(usage_start) ; RELOAD = 2 ; SIG = "-u" ; break ; + default : log_usage(usage_start) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(usage_start) ; + if (argc < 1) log_usage(usage_start) ; - if ((scandir_ok(info->scandir.s)) !=1 ) strerr_dief3sys(111,"scandir: ", info->scandir.s," is not running") ; + if ((scandir_ok(info->scandir.s)) !=1 ) log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ; - if (!ss_resolve_pointo(&sasta,info,SS_NOTYPE,SS_RESOLVE_STATE)) strerr_diefu1sys(111,"set revolve pointer to state") ; + if (!ss_resolve_pointo(&sasta,info,SS_NOTYPE,SS_RESOLVE_STATE)) log_dieusys(LOG_EXIT_SYS,"set revolve pointer to state") ; /** the tree may not initialized already, check it and create * the live directory if it's the case */ if (!scan_mode(sasta.s,S_IFDIR)) - if (!ss_resolve_create_live(info)) strerr_diefu1sys(111,"create live state") ; + if (!ss_resolve_create_live(info)) log_dieusys(LOG_EXIT_SYS,"create live state") ; - 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_SRC)) log_dieusys(LOG_EXIT_SYS,"set revolve pointer to source") ; for (;*argv;argv++) { char const *name = *argv ; - if (!ss_resolve_check(sares.s,name)) strerr_dief2x(110,name," is not enabled") ; - if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (!ss_resolve_append(&gares,&res)) strerr_diefu2sys(111,"append services selection with: ",name) ; + if (!ss_resolve_check(sares.s,name)) log_die(LOG_EXIT_USER,name," is not enabled") ; + if (!ss_resolve_read(&res,sares.s,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (!ss_resolve_append(&gares,&res)) log_dieusys(LOG_EXIT_SYS,"append services selection with: ",name) ; } for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) @@ -269,16 +266,17 @@ int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexe init = 1 ; goto append ; } - else if (!ss_state_read(&sta,sasta.s,name)) strerr_diefu2sys(111,"read state file of: ",name) ; + else if (!ss_state_read(&sta,sasta.s,name)) log_dieusys(LOG_EXIT_SYS,"read state file of: ",name) ; if (obstr_equal(name,SS_MASTER + 1)) goto append ; - if (!pres->disen){ VERBO1 strerr_dief3x(111,"service: ",name," was disabled, you can only stop it") ; } + if (!pres->disen) + log_die(LOG_EXIT_USER,"service: ",name," was disabled, you can only stop it") ; logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; if (logname > 0 && (!ss_resolve_cmp(&gares,string + pres->logassoc))) { - if (RELOAD > 1) strerr_dief1x(111,"-R signal is not allowed to a logger") ; + if (RELOAD > 1) log_die(LOG_EXIT_SYS,"-R signal is not allowed to a logger") ; if (sta.init) reverse = 1 ; } if (RELOAD > 1 || sta.reload) reload = 1 ; @@ -292,15 +290,15 @@ int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexe { reverse = 1 ; if (!ss_resolve_graph_build(&graph_reload_cl,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; } else if (init) { reverse = 0 ; if (!ss_resolve_graph_build(&graph_init_cl,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; } - if (!ss_resolve_append(&nclassic,pres)) strerr_diefu2sys(111,"append services selection with: ",name) ; + if (!ss_resolve_append(&nclassic,pres)) log_dieusys(LOG_EXIT_SYS,"append services selection with: ",name) ; cl++ ; } else @@ -309,46 +307,46 @@ int ssexec_start(int argc, char const *const *argv,char const *const *envp,ssexe { reverse = 1 ; if (!ss_resolve_graph_build(&graph_reload_rc,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; } else if (init) { reverse = 0 ; if (!ss_resolve_graph_build(&graph_init_rc,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; } - if (!ss_resolve_append(&nrc,pres)) strerr_diefu2sys(111,"append services selection with: ",name) ; + if (!ss_resolve_append(&nrc,pres)) log_dieusys(LOG_EXIT_SYS,"append services selection with: ",name) ; rc++; } } if (cl) { - VERBO2 strerr_warni1x("sanitize classic services list...") ; + log_trace("sanitize classic services list...") ; if(!svc_sanitize(info,envp)) - strerr_diefu1x(111,"sanitize classic services list") ; - VERBO2 strerr_warni1x("start classic services list ...") ; + log_dieu(LOG_EXIT_SYS,"sanitize classic services list") ; + log_trace("start classic services list ...") ; if (!svc_send(info,&nclassic,SIG,envp)) - strerr_diefu1x(111,"start classic services list") ; - VERBO2 strerr_warni3x("switch classic service list of: ",info->treename.s," to source") ; + log_dieu(LOG_EXIT_SYS,"start classic services list") ; + log_trace("switch classic service list of: ",info->treename.s," to source") ; if (!svc_switch_to(info,SS_SWSRC)) - strerr_diefu3x(111,"switch classic service list of: ",info->treename.s," to source") ; + log_dieu(LOG_EXIT_SYS,"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 list...") ; + log_trace("sanitize atomic services list...") ; if (!rc_sanitize(info,envp)) - strerr_diefu1x(111,"sanitize atomic services list") ; + log_dieu(LOG_EXIT_SYS,"sanitize atomic services list") ; if (!empty) { - VERBO2 strerr_warni1x("start atomic services list ...") ; + log_trace("start atomic services list ...") ; if (!rc_start(info,&nrc,SIG,envp)) - strerr_diefu1x(111,"start atomic services list ") ; - VERBO2 strerr_warni3x("switch atomic services list of: ",info->treename.s," to source") ; + log_dieu(LOG_EXIT_SYS,"start atomic services list ") ; + log_trace("switch atomic services list of: ",info->treename.s," to source") ; if (!db_switch_to(info,envp,SS_SWSRC)) - strerr_diefu3x(111,"switch atomic services list of: ",info->treename.s," to source") ; + log_dieu(LOG_EXIT_SYS,"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 5a35b429..f5358091 100644 --- a/src/lib66/ssexec_stop.c +++ b/src/lib66/ssexec_stop.c @@ -15,7 +15,7 @@ #include <string.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <skalibs/stralloc.h> @@ -50,7 +50,7 @@ int svc_down(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_unsup_cl,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!svc_unsupervise(info,&graph_unsup_cl.sorted,SIG,envp)) goto err ; @@ -60,7 +60,7 @@ int svc_down(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_cl,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!svc_send(info,&graph_cl.sorted,SIG,envp)) goto err ; @@ -85,7 +85,7 @@ int rc_down(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_unsup_rc,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!rc_unsupervise(info,&graph_unsup_rc.sorted,"-d",envp)) goto err ; @@ -95,7 +95,7 @@ int rc_down(ssexec_t *info, char const *const *envp) r = ss_resolve_graph_publish(&graph_rc,reverse) ; if (r < 0 || !r) { - VERBO1 strerr_warnwu1sys("publish service graph") ; + log_warnusys("publish service graph") ; goto err ; } if (!rc_send(info,&graph_rc.sorted,"-d",envp)) goto err ; @@ -135,31 +135,31 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec { int opt = getopt_args(argc,argv, ">uXK", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { case 'u' : UNSUP = 1 ; break ; - case 'X' : if (sigopt) exitusage(usage_stop) ; sigopt = 1 ; SIG = "-X" ; break ; - case 'K' : if (sigopt) exitusage(usage_stop) ; sigopt = 1 ; SIG = "-K" ; break ; - default : exitusage(usage_stop) ; + case 'X' : if (sigopt) log_usage(usage_stop) ; sigopt = 1 ; SIG = "-X" ; break ; + case 'K' : if (sigopt) log_usage(usage_stop) ; sigopt = 1 ; SIG = "-K" ; break ; + default : log_usage(usage_stop) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1) exitusage(usage_stop) ; + if (argc < 1) log_usage(usage_stop) ; - if ((scandir_ok(info->scandir.s)) !=1 ) strerr_dief3sys(111,"scandir: ", info->scandir.s," is not running") ; + if ((scandir_ok(info->scandir.s)) !=1 ) log_diesys(LOG_EXIT_SYS,"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_SRC)) log_dieusys(LOG_EXIT_SYS,"set revolve pointer to source") ; for (;*argv;argv++) { char const *name = *argv ; - if (!ss_resolve_check(sares.s,name)) strerr_dief2x(110,name," is not enabled") ; - if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (!ss_resolve_append(&gares,&res)) strerr_diefu2sys(111,"append resolve file of: ",name) ; + if (!ss_resolve_check(sares.s,name)) log_die(LOG_EXIT_USER,name," is not enabled") ; + if (!ss_resolve_read(&res,sares.s,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (!ss_resolve_append(&gares,&res)) log_dieusys(LOG_EXIT_SYS,"append resolve file of: ",name) ; } for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++) @@ -170,8 +170,8 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec char const *name = string + pres->name ; char const *state = string + pres->state ; - if (!ss_state_check(state,name)) strerr_dief2x(110,name," : is not initialized") ; - else if (!ss_state_read(&sta,state,name)) strerr_diefu2sys(111,"read state file of: ",name) ; + if (!ss_state_check(state,name)) log_die(LOG_EXIT_USER,name," : is not initialized") ; + else if (!ss_state_read(&sta,state,name)) log_dieusys(LOG_EXIT_SYS,"read state file of: ",name) ; int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; @@ -184,7 +184,7 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec /** logger cannot be unsupervised alone */ if (logname > 0 && (!ss_resolve_cmp(&gares,string + pres->logassoc))) { - if (UNSUP) strerr_dief1x(111,"logger detected - unsupervise request is not allowed") ; + if (UNSUP) log_die(LOG_EXIT_SYS,"logger detected - unsupervise request is not allowed") ; } if (UNSUP) unsup = 1 ; if (sta.unsupervise) unsup = 1 ; @@ -194,12 +194,12 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec if (unsup) { if (!ss_resolve_graph_build(&graph_unsup_cl,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; if (!ss_resolve_add_logger(&graph_unsup_cl.name,sares.s)) - strerr_diefu1sys(111,"append service selection with logger") ; + log_dieusys(LOG_EXIT_SYS,"append service selection with logger") ; } if (!ss_resolve_graph_build(&graph_cl,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; cl++ ; } else @@ -207,12 +207,12 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec if (unsup) { if (!ss_resolve_graph_build(&graph_unsup_rc,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; if (!ss_resolve_add_logger(&graph_unsup_rc.name,sares.s)) - strerr_diefu1sys(111,"append service selection with logger") ; + log_dieusys(LOG_EXIT_SYS,"append service selection with logger") ; } if (!ss_resolve_graph_build(&graph_rc,&genalloc_s(ss_resolve_t,&gares)[i],sares.s,reverse)) - strerr_diefu1sys(111,"build services graph") ; + log_dieusys(LOG_EXIT_SYS,"build services graph") ; rc++; } } @@ -220,31 +220,31 @@ int ssexec_stop(int argc, char const *const *argv,char const *const *envp,ssexec /** rc work */ if (rc) { - VERBO2 strerr_warni1x("stop atomic services ...") ; + log_trace("stop atomic services ...") ; if (!rc_down(info,envp)) - strerr_diefu1x(111,"stop atomic services") ; - VERBO2 strerr_warni3x("switch atomic services of: ",info->treename.s," to source") ; + log_dieusys(LOG_EXIT_SYS,"stop atomic services") ; + log_trace("switch atomic services 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") ; + log_dieusys(LOG_EXIT_SYS,"switch",info->livetree.s,"/",info->treename.s," to source") ; } /** svc work */ if (cl) { - VERBO2 strerr_warni1x("stop classic services ...") ; + log_trace("stop classic services ...") ; if (!svc_down(info,envp)) - strerr_diefu1x(111,"stop classic services") ; - VERBO2 strerr_warni3x("switch classic services of: ",info->treename.s," to source") ; + log_dieusys(LOG_EXIT_SYS,"stop classic services") ; + log_trace("switch classic services 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") ; + log_dieusys(LOG_EXIT_SYS,"switch classic service of: ",info->treename.s," to source") ; } if (UNSUP) { - VERBO2 strerr_warnt2x("send signal -an to scandir: ",info->scandir.s) ; + log_trace("send signal -an to scandir: ",info->scandir.s) ; if (scandir_send_signal(info->scandir.s,"an") <= 0) - strerr_diefu2sys(111,"send signal to scandir: ", info->scandir.s) ; + log_dieusys(LOG_EXIT_SYS,"send signal to scandir: ", info->scandir.s) ; } stralloc_free(&sares) ; ss_resolve_free(&res) ; diff --git a/src/lib66/ssexec_svctl.c b/src/lib66/ssexec_svctl.c index da7474d8..0142ee5b 100644 --- a/src/lib66/ssexec_svctl.c +++ b/src/lib66/ssexec_svctl.c @@ -21,7 +21,7 @@ //#include <stdlib.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <skalibs/types.h> @@ -64,8 +64,8 @@ static int read_file (char const *file, char *buf, size_t n) ssize_t r = openreadnclose_nb(file, buf, n) ; if (r < 0) { - if (errno != ENOENT) VERBO3 strerr_warnwu2sys("open: ", file) ; - return 0 ; + if (errno != ENOENT) + log_warnusys_return(LOG_EXIT_ZERO,"open: ", file) ; } buf[byte_chr(buf, r, '\n')] = 0 ; return 1 ; @@ -76,10 +76,8 @@ static int read_uint (char const *file, unsigned int *fd) char buf[UINT_FMT + 1] ; if (!read_file(file, buf, UINT_FMT)) return 0 ; if (!uint0_scan(buf, fd)) - { - VERBO3 strerr_warnw2x("invalid: ", file) ; - return 0 ; - } + log_warn_return(LOG_EXIT_ZERO,"invalid: ", file) ; + return 1 ; } @@ -90,10 +88,8 @@ int handle_signal_svc(ss_resolve_sig_t *sv_signal) s6_svstatus_t status = S6_SVSTATUS_ZERO ; char *sv = sv_signal->res.sa.s + sv_signal->res.runat ; if (!s6_svstatus_read(sv,&status)) - { - VERBO3 strerr_warnwu2sys("read status of: ",sv) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"read status of: ",sv) ; + sv_signal->pid = status.pid ; if (WIFSIGNALED(status.wstat) && !WEXITSTATUS(status.wstat) && (WTERMSIG(status.wstat) == 15 )) return 1 ; @@ -188,9 +184,7 @@ int handle_case(stralloc *sa, ss_resolve_sig_t *svc) case DEAD: return 2 ; case DONE: return 1 ; case PERM: return 3 ; - default: - VERBO3 strerr_warnw1x("invalid state, make a bug report"); - return 2 ; + default: log_warn_return(2,"invalid state, make a bug report") ; } } return err ; @@ -230,12 +224,9 @@ static void write_state(ss_resolve_sig_t *svc) ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ; // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; - VERBO2 strerr_warni2x("Write state file of: ",sv) ; + log_trace("Write state file of: ",sv) ; if (!ss_state_write(&sta,state,sv)) - { - VERBO1 strerr_warnwu2sys("write state file of: ",sv) ; - } - + log_warnusys("write state file of: ",sv) ; } static int announce(ss_resolve_sig_t *svc) @@ -256,20 +247,20 @@ static int announce(ss_resolve_sig_t *svc) } switch(r) { - case 0: VERBO1 strerr_warni4x(sv," is ",(svc->sig > 3) ? "down" : "up"," but not notified by the daemon itself") ; + case 0: log_info(sv," is ",(svc->sig > 3) ? "down" : "up"," but not notified by the daemon itself") ; break ; - case 1: VERBO1 strerr_warni4x(sv,": ",(svc->sig > 3) ? "stopped" : (svc->sig == 2 || svc->sig == 3) ? "reloaded" : "started"," successfully") ; + case 1: log_info(sv,": ",(svc->sig > 3) ? "stopped" : (svc->sig == 2 || svc->sig == 3) ? "reloaded" : "started"," successfully") ; break ; - case 2: VERBO1 strerr_warnwu2x((svc->sig > 3) ? "stop " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start ", sv) ; + case 2: log_info((svc->sig > 3) ? "stop " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start ", sv) ; break ; - case 3: VERBO1 strerr_warnw3x(sv," report permanent failure -- unable to ",(svc->sig > 1) ? "stop" : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start") ; + case 3: log_info(sv," report permanent failure -- unable to ",(svc->sig > 1) ? "stop" : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start") ; break ; - case 4: VERBO1 strerr_warnwu3x((svc->sig > 3) ? "stop: " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start: ",sv, ": number of try exceeded") ; + case 4: log_info((svc->sig > 3) ? "stop: " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start: ",sv, ": number of try exceeded") ; break ; - case 5: VERBO1 strerr_warnwu3x((svc->sig > 3) ? "stop: " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start: ",sv, ": time out reached") ; + case 5: log_info((svc->sig > 3) ? "stop: " : (svc->sig == 2 || svc->sig == 3) ? "reload" : "start: ",sv, ": time out reached") ; break ; case-1: - default:VERBO1 strerr_warnw3x("unexpected data in state file of: ",sv," -- please make a bug report") ; + default:log_warn("unexpected data in state file of: ",sv," -- please make a bug report") ; break ; } return r ; @@ -288,7 +279,7 @@ static int handle_signal_pipe(genalloc *gakeep) { switch (selfpipe_read()) { - case -1 : strerr_warnwu1sys("selfpipe_read") ; return 0 ; + case -1 : log_warnusys_return(LOG_EXIT_ZERO,"selfpipe_read") ; case 0 : goto end ; case SIGCHLD: for (;;) @@ -298,7 +289,7 @@ static int handle_signal_pipe(genalloc *gakeep) pid_t r = wait_nohang(&wstat) ; if (r < 0) if (errno = ECHILD) break ; - else strerr_diefu1sys(111,"wait for children") ; + else log_dieusys(LOG_EXIT_SYS,"wait for children") ; else if (!r) break ; for (; j < npids ; j++) if (pidindex[j].pid == r) break ; if (j < npids) @@ -319,10 +310,10 @@ static int handle_signal_pipe(genalloc *gakeep) break ; case SIGTERM: case SIGINT: - VERBO2 strerr_warnw1x("received SIGINT, aborting service transition") ; + log_warn("received SIGINT, aborting service transition") ; kill_all() ; break ; - default : strerr_warn1x("unexpected data in selfpipe") ; + default : log_warn("unexpected data in selfpipe") ; } } end: @@ -366,12 +357,12 @@ static void svc_listen(unsigned int nsv,tain_t *deadline) while(j) { r = iopause_g(&x, 1, deadline) ; - if (r < 0) strerr_dief1sys(111,"listen iopause") ; - else if (!r) strerr_dief1x(111,"listen time out") ; + if (r < 0) log_diesys(LOG_EXIT_SYS,"listen iopause") ; + else if (!r) log_die(LOG_EXIT_SYS,"listen time out") ; if (x.revents & IOPAUSE_READ) { i = 0 ; - if (ftrigr_update(&fifo) < 0) strerr_diefu1sys(111,"update fifo") ; + if (ftrigr_update(&fifo) < 0) log_dieusys(LOG_EXIT_SYS,"update fifo") ; for (;i < nsv;i++) { if (did[i]) continue ; @@ -382,7 +373,7 @@ static void svc_listen(unsigned int nsv,tain_t *deadline) { svc_listen_less(5,state,did,&j,i) ; continue ; } sa.len = 0 ; r = ftrigr_checksa(&fifo,svc->ids, &sa) ; - if (r < 0) strerr_diefu1sys(111,"check fifo") ; + if (r < 0) log_dieusys(LOG_EXIT_SYS,"check fifo") ; else if (r) { (*ndeath)-- ; @@ -404,7 +395,7 @@ static int svc_writectl(ss_resolve_sig_t *svc) int r ; char *sv = svc->res.sa.s + svc->res.runat ; size_t siglen = strlen(svc->sigtosend) ; - VERBO2 strerr_warnt6x("send signal: ",svc->sigtosend," to: ", sv,"/",S6_SUPERVISE_CTLDIR) ; + log_trace("send signal: ",svc->sigtosend," to: ", sv,"/",S6_SUPERVISE_CTLDIR) ; r = s6_svc_writectl(sv, S6_SUPERVISE_CTLDIR, svc->sigtosend, siglen) ; if (r == -1) return 111 ; else if (r == -2) return 100 ; @@ -454,8 +445,8 @@ int doit (int spfd, genalloc *gakeep, tain_t *deadline) while (npids) { int r = iopause_g(&x,1,deadline) ; - if (r < 0) strerr_diefu1sys(111,"iopause") ; - if (!r) strerr_dief1x(111,"time out") ; + if (r < 0) log_dieusys(LOG_EXIT_SYS,"iopause") ; + if (!r) log_diesys(LOG_EXIT_SYS,"time out") ; if (!handle_signal_pipe(gakeep)) exitcode = 0 ; } return exitcode ; @@ -494,42 +485,42 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe { int opt = getopt_args(argc,argv, "n:urdXK", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; + if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ; switch (opt) { - 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 'r' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGR ; sig = "r" ; break ; - case 'd' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGDOWN ; sig = "d" ; break ; - case 'X' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGX ; sig = "xd" ; break ; - case 'K' : if (SIGNAL > 0) exitusage(usage_svctl) ; SIGNAL = SIGRDOWN ; sig = "kd" ; break ; + case 'n' : if (!uint0_scan(l.arg, &death)) log_usage(usage_svctl) ; break ; + case 'u' : if (SIGNAL > 0) log_usage(usage_svctl) ; SIGNAL = SIGUP ; sig ="u" ; break ; + case 'r' : if (SIGNAL > 0) log_usage(usage_svctl) ; SIGNAL = SIGR ; sig = "r" ; break ; + case 'd' : if (SIGNAL > 0) log_usage(usage_svctl) ; SIGNAL = SIGDOWN ; sig = "d" ; break ; + case 'X' : if (SIGNAL > 0) log_usage(usage_svctl) ; SIGNAL = SIGX ; sig = "xd" ; break ; + case 'K' : if (SIGNAL > 0) log_usage(usage_svctl) ; SIGNAL = SIGRDOWN ; sig = "kd" ; break ; - default : exitusage(usage_svctl) ; + default : log_usage(usage_svctl) ; } } argc -= l.ind ; argv += l.ind ; } - if (argc < 1 || (SIGNAL < 0)) exitusage(usage_svctl) ; + if (argc < 1 || (SIGNAL < 0)) log_usage(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") ; - if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; + if ((scandir_ok(info->scandir.s)) !=1 ) log_diesys(LOG_EXIT_SYS,"scandir: ", info->scandir.s," is not running") ; + if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) log_dieusys(LOG_EXIT_SYS,"set revolve pointer to source") ; if (SIGNAL > SIGR) reverse = 1 ; for(;*argv;argv++) { char const *name = *argv ; int logname = 0 ; logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; - if (!ss_resolve_check(sares.s,name)) strerr_dief2sys(111,"unknown service: ",name) ; - if (!ss_resolve_read(&res,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ; - if (res.type >= BUNDLE) strerr_dief3x(111,name," has type ",get_keybyid(res.type)) ; + if (!ss_resolve_check(sares.s,name)) log_diesys(LOG_EXIT_SYS,"unknown service: ",name) ; + if (!ss_resolve_read(&res,sares.s,name)) log_dieusys(LOG_EXIT_SYS,"read resolve file of: ",name) ; + if (res.type >= BUNDLE) log_die(LOG_EXIT_SYS,name," has type ",get_keybyid(res.type)) ; if (SIGNAL == SIGR && logname < 0) reverse = 1 ; - if (!ss_resolve_graph_build(&graph,&res,sares.s,reverse)) strerr_diefu1sys(111,"build services graph") ; + if (!ss_resolve_graph_build(&graph,&res,sares.s,reverse)) log_dieusys(LOG_EXIT_SYS,"build services graph") ; } r = ss_resolve_graph_publish(&graph,reverse) ; - if (r < 0) strerr_dief1x(111,"cyclic dependencies detected") ; - if (!r) strerr_diefu1sys(111,"publish service graph") ; + if (r < 0) log_die(LOG_EXIT_SYS,"cyclic dependencies detected") ; + if (!r) log_dieusys(LOG_EXIT_SYS,"publish service graph") ; for(unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,&graph.sorted) ; i++) { @@ -541,20 +532,20 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe size_t svoklen = strlen(svok) ; char file[svoklen + SS_NOTIFICATION_LEN + 1 + 1] ; memcpy(file,svok,svoklen) ; - if (!ss_state_check(state,string + sv_signal.res.name)) strerr_dief2x(111,"unitialized service: ",string + sv_signal.res.name) ; - if (!ss_state_read(&sta,state,string + sv_signal.res.name)) strerr_diefu2sys(111,"read state of: ",string + sv_signal.res.name) ; - if (sta.init) strerr_dief2x(111,"unitialized service: ",string + sv_signal.res.name) ; - if (!s6_svstatus_read(svok,&status)) strerr_diefu2sys(111,"read status of: ",svok) ; + if (!ss_state_check(state,string + sv_signal.res.name)) log_die(LOG_EXIT_SYS,"unitialized service: ",string + sv_signal.res.name) ; + if (!ss_state_read(&sta,state,string + sv_signal.res.name)) log_dieusys(LOG_EXIT_SYS,"read state of: ",string + sv_signal.res.name) ; + if (sta.init) log_die(LOG_EXIT_SYS,"unitialized service: ",string + sv_signal.res.name) ; + if (!s6_svstatus_read(svok,&status)) log_dieusys(LOG_EXIT_SYS,"read status of: ",svok) ; isup = status.pid && !status.flagfinishing ; if (isup && (SIGNAL == SIGUP)) { - VERBO1 strerr_warni2x("Already up: ",string + sv_signal.res.name) ; + log_info("Already up: ",string + sv_signal.res.name) ; continue ; } else if (!isup && (SIGNAL >= SIGDOWN)) { - VERBO1 strerr_warni2x("Already down: ",string + sv_signal.res.name) ; + log_info("Already down: ",string + sv_signal.res.name) ; continue ; } /** special on reload signal, if the process is down @@ -572,12 +563,12 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe e = errno ; errno = 0 ; - if (access(file, F_OK) < 0 && errno != ENOENT) - strerr_warnw1sys("conflicting format of file: " SS_NOTIFICATION) ; + if (access(file, F_OK) < 0 && errno != ENOENT) + log_warnsys("conflicting format of file: " SS_NOTIFICATION) ; else if (errno != ENOENT) { - if (!read_uint(file,&sv_signal.notify)) strerr_diefu2sys(111,"read: ",file) ; + if (!read_uint(file,&sv_signal.notify)) log_dieusys(LOG_EXIT_SYS,"read: ",file) ; if (SIGNAL == SIGUP) { sv_signal.sig = SIGRUP ; sv_signal.sigtosend = "uwU" ; } else if (SIGNAL == SIGR) @@ -592,13 +583,13 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe file[svoklen + SS_MAXDEATHTALLY_LEN + 1] = 0 ; errno = 0 ; if (access(file, F_OK) < 0) - if (errno != ENOENT) strerr_diefu2sys(111, "access ", file) ; + if (errno != ENOENT) log_dieusys(LOG_EXIT_SYS, "access ", file) ; if (errno == ENOENT) sv_signal.ndeath = DEATHSV ; else { - if (!read_uint(file,&sv_signal.ndeath)) strerr_diefu2sys(111,"read: ",file) ; + if (!read_uint(file,&sv_signal.ndeath)) log_dieusys(LOG_EXIT_SYS,"read: ",file) ; } } else sv_signal.ndeath = death ; @@ -624,7 +615,7 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe memcpy(file + svoklen,tm, tmlen) ; file[svoklen + tmlen] = 0 ; if (access(file, F_OK) < 0) - if (errno != ENOENT) strerr_diefu2sys(111, "access ", file) ; + if (errno != ENOENT) log_dieusys(LOG_EXIT_SYS, "access ", file) ; if (errno == ENOENT) { @@ -633,7 +624,7 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe } else { - if (!read_uint(file,&t)) strerr_diefu2sys(111,"read: ",file) ; + if (!read_uint(file,&t)) log_dieusys(LOG_EXIT_SYS,"read: ",file) ; { tain_from_millisecs(&sv_signal.deadline, t) ; tsv_g += t ; @@ -641,7 +632,7 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe } } errno = e ; - if (!genalloc_append(ss_resolve_sig_t,&gakeep,&sv_signal)) strerr_diefu2sys(111,"append services selection with: ",string + sv_signal.res.name) ; + if (!genalloc_append(ss_resolve_sig_t,&gakeep,&sv_signal)) log_dieusys(LOG_EXIT_SYS,"append services selection with: ",string + sv_signal.res.name) ; } /** nothing to do */ if (!genalloc_len(ss_resolve_sig_t,&gakeep)) goto finish ; @@ -652,13 +643,13 @@ int ssexec_svctl(int argc, char const *const *argv,char const *const *envp,ssexe tain_add_g(&ttmain,&ttmain) ; int spfd = selfpipe_init() ; - if (spfd < 0) strerr_diefu1sys(111, "selfpipe_trap") ; - if (selfpipe_trap(SIGCHLD) < 0) strerr_diefu1sys(111, "selfpipe_trap") ; - if (selfpipe_trap(SIGINT) < 0) strerr_diefu1sys(111, "selfpipe_trap") ; - if (selfpipe_trap(SIGTERM) < 0) strerr_diefu1sys(111, "selfpipe_trap") ; - if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111,"ignore SIGPIPE") ; + if (spfd < 0) log_dieusys(LOG_EXIT_SYS, "selfpipe_trap") ; + if (selfpipe_trap(SIGCHLD) < 0) log_dieusys(LOG_EXIT_SYS, "selfpipe_trap") ; + if (selfpipe_trap(SIGINT) < 0) log_dieusys(LOG_EXIT_SYS, "selfpipe_trap") ; + if (selfpipe_trap(SIGTERM) < 0) log_dieusys(LOG_EXIT_SYS, "selfpipe_trap") ; + if (sig_ignore(SIGPIPE) < 0) log_dieusys(LOG_EXIT_SYS,"ignore SIGPIPE") ; - if (!svc_init_pipe(&fifo,&gakeep,&ttmain)) strerr_diefu1x(111,"init pipe") ; + if (!svc_init_pipe(&fifo,&gakeep,&ttmain)) log_dieu(LOG_EXIT_SYS,"init pipe") ; ret = doit(spfd,&gakeep,&ttmain) ; diff --git a/src/lib66/svc_init.c b/src/lib66/svc_init.c index 752ed173..5bd4c867 100644 --- a/src/lib66/svc_init.c +++ b/src/lib66/svc_init.c @@ -18,7 +18,7 @@ #include <stdlib.h> //#include <stdio.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/sastr.h> @@ -57,7 +57,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) if (!ftrigr_startf(&fifo, &deadline, &STAMP)) goto err ; - if (!ss_resolve_create_live(info)) { VERBO1 strerr_warnwu1sys("create live state") ; goto err ; } + if (!ss_resolve_create_live(info)) { log_warnusys("create live state") ; goto err ; } for (i = 0 ; i < genalloc_len(ss_resolve_t,ga); i++) { @@ -67,11 +67,11 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) char *state = string + genalloc_s(ss_resolve_t,ga)[i].state ; if (s6_svc_ok(string + genalloc_s(ss_resolve_t,ga)[i].runat)) { - VERBO1 strerr_warni3x("Initialization aborted -- ",name," already initialized") ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_info("Initialization aborted -- ",name," already initialized") ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } continue ; @@ -93,15 +93,15 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) memcpy(svscan,string + genalloc_s(ss_resolve_t,ga)[i].runat,svscanlen) ; svscan[svscanlen] = 0 ; - VERBO3 strerr_warnt2x("init service: ", string + genalloc_s(ss_resolve_t,ga)[i].name) ; + log_trace("init service: ", string + genalloc_s(ss_resolve_t,ga)[i].name) ; /** if logger was created do not pass here to avoid to erase * the fifo of the logger*/ if (!scan_mode(svscan,S_IFDIR)) { - VERBO3 strerr_warnt4x("copy: ",svsrc, " to ", svscan) ; + log_trace("copy: ",svsrc, " to ", svscan) ; if (!hiercopy(svsrc,svscan)) { - VERBO3 strerr_warnwu4sys("copy: ",svsrc," to: ",svscan) ; + log_warnusys("copy: ",svsrc," to: ",svscan) ; goto err ; } } @@ -119,10 +119,10 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) memcpy(tmp,svsrc,tmplen) ; memcpy(tmp + tmplen,"/log",4) ; tmp[tmplen + 4] = 0 ; - VERBO3 strerr_warnt4x("copy: ",tmp, " to ", svscan) ; + log_trace("copy: ",tmp, " to ", svscan) ; if (!hiercopy(tmp,svscan)) { - VERBO3 strerr_warnwu4sys("copy: ",tmp," to: ",svscan) ; + log_warnusys("copy: ",tmp," to: ",svscan) ; goto err ; } } @@ -133,51 +133,51 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) { if (!sastr_add_string(&sadown,svscan)) { - VERBO3 strerr_warnwu3x("add: ",svscan," to genalloc") ; + log_warnusys("add: ",svscan," to genalloc") ; goto err ; } } - VERBO3 strerr_warnt2x("create file: ",svscan) ; + log_trace("create file: ",svscan) ; if (!touch(svscan)) { - VERBO3 strerr_warnwu2sys("create file: ",svscan) ; + log_warnusys("create file: ",svscan) ; goto err ; } memcpy(svscan + svscanlen, "/event", 6) ; svscan[svscanlen + 6] = 0 ; - VERBO3 strerr_warnt2x("create fifo: ",svscan) ; + log_trace("create fifo: ",svscan) ; if (!ftrigw_fifodir_make(svscan, gid, 0)) { - VERBO3 strerr_warnwu2sys("create fifo: ",svscan) ; + log_warnusys("create fifo: ",svscan) ; goto err ; } - VERBO3 strerr_warnt2x("subcribe to fifo: ",svscan) ; + log_trace("subcribe to fifo: ",svscan) ; /** unsubscribe automatically, options is 0 */ id = ftrigr_subscribe_g(&fifo, svscan, "s", 0, &deadline) ; if (!id) { - VERBO3 strerr_warnwu2x("subcribe to fifo: ",svscan) ; + log_warnusys("subcribe to fifo: ",svscan) ; goto err ; } if (!genalloc_append(uint16_t, &ids, &id)) goto err ; } if (genalloc_len(uint16_t,&ids)) { - VERBO3 strerr_warnt2x("reload scandir: ",info->scandir.s) ; + log_trace("reload scandir: ",info->scandir.s) ; if (scandir_send_signal(info->scandir.s,"an") <= 0) { - VERBO3 strerr_warnwu2sys("reload scandir: ",info->scandir.s) ; + log_warnusys("reload scandir: ",info->scandir.s) ; goto err ; } - VERBO3 strerr_warnt1x("waiting for events on fifo") ; + log_trace("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 ; for (pos = 0 ; pos < sadown.len; pos += strlen(sadown.s + pos) + 1) { - VERBO3 strerr_warnt2x("Delete down file at: ",sadown.s + pos) ; + log_warnusys("Delete down file at: ",sadown.s + pos) ; if (unlink(sadown.s + pos) < 0 && errno != ENOENT) goto err ; } @@ -187,13 +187,13 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) char const *name = string + genalloc_s(ss_resolve_t,ga)[pos].name ; char const *state = string + genalloc_s(ss_resolve_t,ga)[pos].state ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } - VERBO1 strerr_warni2x("Initialized successfully: ",name) ; + log_info("Initialized successfully: ",name) ; } } ftrigr_end(&fifo) ; diff --git a/src/lib66/svc_init_pipe.c b/src/lib66/svc_init_pipe.c index 6e2fc4a5..fc14cb90 100644 --- a/src/lib66/svc_init_pipe.c +++ b/src/lib66/svc_init_pipe.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/genalloc.h> #include <skalibs/stralloc.h> @@ -36,7 +36,7 @@ int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv,tain_t *deadline) ss_resolve_sig_t *svc ; if (!ftrigr_startf_g(fifo, deadline)) - VERBO3 { strerr_warnwu1sys("initiate fifo") ; return 0 ; } + log_warnusys_return(LOG_EXIT_ZERO,"initiate fifo") ; for (; i < genalloc_len(ss_resolve_sig_t,gasv) ; i++) { @@ -48,22 +48,14 @@ int svc_init_pipe(ftrigr_t *fifo,genalloc *gasv,tain_t *deadline) memcpy(svfifo + scanlen, "/event",6) ; svfifo[scanlen + 6] = 0 ; - VERBO3 strerr_warnt2x("clean up fifo: ", svfifo) ; + log_trace("clean up fifo: ", svfifo) ; if (!ftrigw_clean (svok)) - { - VERBO3 strerr_warnwu2sys("clean up fifo: ", svfifo) ; - return 0 ; - } - - VERBO3 strerr_warnt2x("subcribe to fifo: ",svfifo) ; + log_warnusys_return(LOG_EXIT_ZERO,"clean up fifo: ", svfifo) ; + + log_trace("subcribe to fifo: ",svfifo) ; svc->ids = ftrigr_subscribe_g(fifo, svfifo, "[DuUdOxs]", FTRIGR_REPEAT, deadline) ; if (!svc->ids) - { - VERBO3 strerr_warnwu2sys("subcribe to fifo: ",svfifo) ; - goto end ; - } + log_warnusys_return(LOG_EXIT_ZERO,"subcribe to fifo: ",svfifo) ; } return 1 ; - end: - return 0 ; } diff --git a/src/lib66/svc_switch_to.c b/src/lib66/svc_switch_to.c index 8ace91de..3339cb34 100644 --- a/src/lib66/svc_switch_to.c +++ b/src/lib66/svc_switch_to.c @@ -13,7 +13,7 @@ */ -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <string.h> @@ -43,45 +43,38 @@ int svc_switch_to(ssexec_t *info,unsigned int where) r = backup_cmd_switcher(VERBOSITY,cmd,info) ; if (r < 0) - { - VERBO3 strerr_warnwu2sys("find origin of svc service for: ",info->treename.s) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"find origin of svc service for: ",info->treename.s) ; + // point to origin if (!r && where) { - VERBO3 strerr_warnt2x("make a backup of svc service for: ",info->treename.s) ; + log_trace("make a backup of svc service for: ",info->treename.s) ; if (!backup_make_new(info,CLASSIC)) - { - VERBO3 strerr_warnwu2sys("make a backup of svc service for: ",info->treename.s) ; - return 0 ; - } - VERBO3 strerr_warnt3x("switch svc symlink of tree: ",info->treename.s," to backup") ; + log_warnusys_return(LOG_EXIT_ZERO,"make a backup of svc service for: ",info->treename.s) ; + + log_trace("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 symlink of tree: ",info->treename.s," to backup") ; + log_warnusys("switch svc symlink of tree: ",info->treename.s," to backup") ; } } else if (r > 0 && !where) { - VERBO3 strerr_warnt3x("switch svc symlink of tree: ",info->treename.s," to source") ; + log_trace("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 symlink of tree: ",info->treename.s," to source") ; + log_warnusys("switch svc symlink of tree: ",info->treename.s," to source") ; } - VERBO3 strerr_warnt2x("make a backup of svc service for: ",info->treename.s) ; + log_trace("make a backup of svc service for: ",info->treename.s) ; if (!backup_make_new(info,CLASSIC)) - { - VERBO3 strerr_warnwu2sys("make a backup of svc service for: ",info->treename.s) ; - return 0 ; - } + log_warnusys_return(LOG_EXIT_ZERO,"make a backup of svc service for: ",info->treename.s) ; } return 1 ; } diff --git a/src/lib66/svc_unsupervise.c b/src/lib66/svc_unsupervise.c index 3b2cb3e2..e0e98625 100644 --- a/src/lib66/svc_unsupervise.c +++ b/src/lib66/svc_unsupervise.c @@ -16,7 +16,7 @@ #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/genalloc.h> #include <skalibs/stralloc.h> @@ -36,23 +36,23 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons if (!svc_send(info,ga,sig,envp)) { - VERBO1 strerr_warnwu1x("stop services") ; + log_warnu("stop services") ; goto err ; } for (; 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) ; + log_trace("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) ; + log_warnusys("delete: ",string + genalloc_s(ss_resolve_t,ga)[i].runat) ; goto err ; } } if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) { - strerr_warnwu1sys("set revolve pointer to source") ; + log_warnusys("set revolve pointer to source") ; goto err ; } for (i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) @@ -64,9 +64,9 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons // remove the resolve/state file if the service is disabled if (!pres->disen) { - VERBO2 strerr_warni2x("Delete resolve file of: ",name) ; + log_trace("Delete resolve file of: ",name) ; ss_resolve_rmfile(sares.s,name) ; - VERBO2 strerr_warni2x("Delete state file of: ",name) ; + log_trace("Delete state file of: ",name) ; ss_state_rmfile(state,name) ; } else @@ -76,14 +76,14 @@ int svc_unsupervise(ssexec_t *info,genalloc *ga,char const *sig,char const *cons // ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_FALSE) ; ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_FALSE) ; - VERBO2 strerr_warni2x("Write state file of: ",name) ; + log_trace("Write state file of: ",name) ; if (!ss_state_write(&sta,state,name)) { - VERBO1 strerr_warnwu2sys("write state file of: ",name) ; + log_warnusys("write state file of: ",name) ; goto err ; } } - VERBO1 strerr_warni2x("Unsupervised successfully: ",name) ; + log_info("Unsupervised successfully: ",name) ; } stralloc_free(&sares) ; return 1 ; diff --git a/src/lib66/tree_cmd_state.c b/src/lib66/tree_cmd_state.c index e3e6c257..f1503d6d 100644 --- a/src/lib66/tree_cmd_state.c +++ b/src/lib66/tree_cmd_state.c @@ -17,7 +17,7 @@ #include <sys/stat.h> #include <oblibs/obgetopt.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/types.h> #include <oblibs/files.h> @@ -49,7 +49,7 @@ int tree_state(int argc, char const *const *argv) { int opt = getopt_args(argc,argv, "v:sad", &l) ; if (opt == -1) break ; - if (opt == -2){ strerr_warnw1x("options must be set first") ; return 0 ; } + if (opt == -2) log_warn_return(LOG_EXIT_ZERO,"options must be set first") ; switch (opt) { case 'v' : if (!uint0_scan(l.arg, &verbosity)) return 0 ; break ; @@ -72,7 +72,7 @@ int tree_state(int argc, char const *const *argv) if (!set_ownersysdir(&base,owner)) { - VERBO3 strerr_warnwu1sys("set owner directory") ; + log_warnusys("set owner directory") ; stralloc_free(&base) ; stralloc_free(&contents) ; return 0 ; @@ -89,7 +89,7 @@ int tree_state(int argc, char const *const *argv) if (r == -1) { errno = EEXIST ; goto out ; } if (!r) { - VERBO3 strerr_warnwu2sys("find: ",state) ; + log_warnusys("find: ",state) ; goto out ; } @@ -97,7 +97,7 @@ int tree_state(int argc, char const *const *argv) r = openreadfileclose(state,&contents,statesize) ; if(!r) { - VERBO3 strerr_warnwu2sys("open: ", state) ; + log_warnusys("open: ", state) ; goto out ; } @@ -113,14 +113,14 @@ int tree_state(int argc, char const *const *argv) fd = open_append(state) ; if (fd < 0) { - VERBO3 strerr_warnwu2sys("open: ",state) ; + log_warnusys("open: ",state) ; goto out ; } r = write(fd, tree,treelen); r = write(fd, "\n",1); if (r < 0) { - VERBO3 strerr_warnwu5sys("write: ",state," with ", tree," as content") ; + log_warnusys("write: ",state," with ", tree," as content") ; fd_close(fd) ; goto out ; } @@ -141,7 +141,7 @@ int tree_state(int argc, char const *const *argv) fd = open_trunc(state) ; if (fd < 0) { - VERBO3 strerr_warnwu2sys("open_trunc ", state) ; + log_warnusys("open_trunc ", state) ; goto out ; } @@ -154,14 +154,14 @@ int tree_state(int argc, char const *const *argv) r = write(fd, name,namelen); if (r < 0) { - VERBO3 strerr_warnwu5sys("write: ",state," with ", name," as content") ; + log_warnusys("write: ",state," with ", name," as content") ; fd_close(fd) ; goto out ; } r = write(fd, "\n",1); if (r < 0) { - VERBO3 strerr_warnwu5sys("write: ",state," with ", name," as content") ; + log_warnusys("write: ",state," with ", name," as content") ; fd_close(fd) ; goto out ; } @@ -203,7 +203,7 @@ int tree_cmd_state(unsigned int verbosity,char const *cmd, char const *tree) if (!sastr_clean_string(&opts,cmd)) { - VERBO3 strerr_warnwu2x("clean: ",cmd) ; + log_warnu("clean: ",cmd) ; stralloc_free(&opts) ; return 0 ; } diff --git a/src/lib66/tree_copy.c b/src/lib66/tree_copy.c index 5e076b57..b47fe6d7 100644 --- a/src/lib66/tree_copy.c +++ b/src/lib66/tree_copy.c @@ -17,7 +17,6 @@ #include <string.h> #include <oblibs/directory.h> -#include <oblibs/error2.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> diff --git a/src/lib66/tree_copy_tmp.c b/src/lib66/tree_copy_tmp.c index 6316db2c..e4911e54 100644 --- a/src/lib66/tree_copy_tmp.c +++ b/src/lib66/tree_copy_tmp.c @@ -17,7 +17,7 @@ #include <string.h> #include <oblibs/string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/directory.h> #include <oblibs/types.h> @@ -33,15 +33,15 @@ void err(unsigned int *e, unsigned int msg,char const *resolve,char const *swap, { switch (msg) { - case 0: strerr_warnwu1x("set revolve pointer to source") ; + case 0: log_warnu("set revolve pointer to source") ; break ; - case 1: strerr_warnwu1x("set revolve pointer to backup") ; + case 1: log_warnu("set revolve pointer to backup") ; break ; - case 2: strerr_warnwu4sys("copy : ",svdir," to ", resolve) ; + case 2: log_warnu("copy : ",svdir," to ", resolve) ; break ; - case 3: strerr_warnwu2sys("remove directory: ", svdir) ; + case 3: log_warnu("remove directory: ", svdir) ; break ; - case 4: strerr_warnwu1x("set revolve pointer to live") ; + case 4: log_warnu("set revolve pointer to live") ; break ; default: break ; } @@ -120,8 +120,8 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) goto err ; } saresolve.len--; - if (!stralloc_cats(&saresolve,SS_RESOLVE)) retstralloc(0,"tree_copy_tmp") ; - if (!stralloc_0(&saresolve)) retstralloc(0,"tree_copy_tmp") ; + if (!stralloc_cats(&saresolve,SS_RESOLVE)) log_warnsys_return(LOG_EXIT_ZERO,"tree_copy_tmp") ; + if (!stralloc_0(&saresolve)) log_warnsys_return(LOG_EXIT_ZERO,"tree_copy_tmp") ; if (!ss_resolve_pointo(&swap,info,SS_NOTYPE,SS_RESOLVE_BACK)) { @@ -129,8 +129,8 @@ int tree_copy_tmp(char const *workdir, ssexec_t *info) goto err ; } swap.len--; - if (!stralloc_cats(&swap,SS_RESOLVE)) retstralloc(0,"tree_copy_tmp") ; - if (!stralloc_0(&swap)) retstralloc(0,"tree_copy_tmp") ; + if (!stralloc_cats(&swap,SS_RESOLVE)) log_warnsys_return(LOG_EXIT_ZERO,"tree_copy_tmp") ; + if (!stralloc_0(&swap)) log_warnsys_return(LOG_EXIT_ZERO,"tree_copy_tmp") ; if (!hiercopy(swap.s,saresolve.s)) { err(&e,2,saresolve.s,swap.s,svdir) ; diff --git a/src/lib66/tree_find_current.c b/src/lib66/tree_find_current.c index 05ae9a02..27615f12 100644 --- a/src/lib66/tree_find_current.c +++ b/src/lib66/tree_find_current.c @@ -18,7 +18,7 @@ #include <sys/types.h> #include <string.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <oblibs/types.h> #include <skalibs/types.h> @@ -50,7 +50,7 @@ int tree_find_current(stralloc *tree, char const *base,uid_t owner) if(r <= 0) return 0 ; r = sarealpath(tree,sa) ; if (r < 0 ) return 0 ; - if (!stralloc_0(tree)) retstralloc(0,"find_current") ; + if (!stralloc_0(tree)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; tree->len--; return 1 ; } diff --git a/src/lib66/tree_get_permissions.c b/src/lib66/tree_get_permissions.c index e0275272..e1aec911 100644 --- a/src/lib66/tree_get_permissions.c +++ b/src/lib66/tree_get_permissions.c @@ -17,7 +17,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <oblibs/error2.h> #include <oblibs/types.h> #include <skalibs/stralloc.h> diff --git a/src/lib66/tree_sethome.c b/src/lib66/tree_sethome.c index 129ed214..3e74c716 100644 --- a/src/lib66/tree_sethome.c +++ b/src/lib66/tree_sethome.c @@ -20,7 +20,7 @@ #include <sys/types.h> #include <oblibs/types.h> -#include <oblibs/error2.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> @@ -40,10 +40,10 @@ int tree_sethome(stralloc *tree, char const *base,uid_t owner) memcpy(treename,tree->s,tree->len) ; treename[tree->len] = 0 ; tree->len = 0 ; - if (!stralloc_cats(tree,base)) retstralloc(0,"main") ; - if (!stralloc_cats(tree,SS_SYSTEM "/")) retstralloc(0,"main") ; - if (!stralloc_cats(tree,treename)) retstralloc(0,"main") ; - if (!stralloc_0(tree)) retstralloc(0,"main") ; + if (!stralloc_cats(tree,base) || + !stralloc_cats(tree,SS_SYSTEM "/") || + !stralloc_cats(tree,treename) || + !stralloc_0(tree)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; r = scan_mode(tree->s,S_IFDIR) ; if (r < 0) errno = EEXIST ; if (r != 1) return 0 ; diff --git a/src/lib66/tree_switch_current.c b/src/lib66/tree_switch_current.c index fbc076d6..212877d3 100644 --- a/src/lib66/tree_switch_current.c +++ b/src/lib66/tree_switch_current.c @@ -18,7 +18,7 @@ #include <string.h> #include <sys/stat.h> -#include <oblibs/error2.h> +//#include <oblibs/log.h> #include <oblibs/directory.h> #include <oblibs/types.h> -- GitLab