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

Provide the 66 general tool

parent 629db2e2
No related branches found
No related tags found
No related merge requests found
Showing
with 548 additions and 625 deletions
${LIB66}
-ls6
-loblibs
-lskarnet
${LIB66}
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${SPAWN_LIB}
${LIB66}
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${LIB66}
-ls6
-loblibs
-lskarnet
${SYSCLOCK_LIB}
${LIB66}
-ls6
-loblibs
-lskarnet
${SPAWN_LIB}
......@@ -111,6 +111,16 @@ extern ssexec_func_t ssexec_svctl ;
extern ssexec_func_t ssexec_env ;
extern ssexec_func_t ssexec_all ;
extern ssexec_func_t ssexec_tree ;
extern ssexec_func_t ssexec_reconfigure ;
extern ssexec_func_t ssexec_reload ;
extern ssexec_func_t ssexec_restart ;
extern ssexec_func_t ssexec_inresolve ;
extern ssexec_func_t ssexec_instate ;
extern ssexec_func_t ssexec_intree ;
extern ssexec_func_t ssexec_inservice ;
extern ssexec_func_t ssexec_boot ;
extern ssexec_func_t ssexec_scanctl ;
extern ssexec_func_t ssexec_scandir ;
extern char const *usage_parse ;
extern char const *help_parse ;
......@@ -132,18 +142,43 @@ extern char const *usage_all ;
extern char const *help_all ;
extern char const *usage_tree ;
extern char const *help_tree ;
extern char const *usage_reconfigure ;
extern char const *help_reconfigure ;
extern char const *usage_reload ;
extern char const *help_reload ;
extern char const *usage_restart ;
extern char const *help_restart ;
extern char const *usage_unsupervise ;
extern char const *help_unsupervise ;
extern char const *usage_inresolve ;
extern char const *help_inresolve ;
extern char const *usage_instate ;
extern char const *help_instate ;
extern char const *usage_intree ;
extern char const *help_intree ;
extern char const *usage_inservice ;
extern char const *help_inservice ;
extern char const *usage_boot ;
extern char const *help_boot ;
extern char const *usage_scanctl ;
extern char const *help_scanctl ;
extern char const *usage_scandir ;
extern char const *help_scandir ;
extern char const *usage_66 ;
#define OPTS_SUBSTART "P"
#define OPTS_SUBSTART_LEN (sizeof OPTS_SUBSTART - 1)
#define OPTS_PARSE "fFcmCI"
#define OPTS_PARSE_LEN (sizeof OPTS_PARSE - 1)
#define OPTS_INIT "o:"
#define OPTS_INIT ""
#define OPTS_INIT_LEN (sizeof OPTS_INIT - 1)
#define OPTS_ENABLE "fFSI"
#define OPTS_ENABLE_LEN (sizeof OPTS_ENABLE - 1)
#define OPTS_DISABLE "SFR"
#define OPTS_DISABLE_LEN (sizeof OPTS_DISABLE - 1)
#define OPTS_START "rR"
#define OPTS_START "P"
#define OPTS_START_LEN (sizeof OPTS_START - 1)
#define OPTS_STOP "uXK"
#define OPTS_STOP "P"
#define OPTS_STOP_LEN (sizeof OPTS_STOP - 1)
#define OPTS_SVCTL "abqhkti12pcyroduxOw:P"
#define OPTS_SVCTL_LEN (sizeof OPTS_SVCTL - 1)
......@@ -153,9 +188,21 @@ extern char const *help_tree ;
#define OPTS_ALL_LEN (sizeof OPTS_ALL - 1)
#define OPTS_TREE "na:d:cS:EDRC:o:"
#define OPTS_TREE_LEN (sizeof OPTS_TREE - 1)
#define OPTS_INRESOLVE ""
#define OPTS_INRESOLVE_LEN (sizeof OPTS_INRESOLVE - 1)
#define OPTS_INSTATE ""
#define OPTS_INSTATE_LEN (sizeof OPTS_INSTATE - 1)
#define OPTS_INTREE "no:grd:l:"
#define OPTS_INTREE_LEN (sizeof OPTS_INTREE - 1)
#define OPTS_INSERVICE "no:grd:t:p:"
#define OPTS_INSERVICE_LEN (sizeof OPTS_INSERVICE - 1)
#define OPTS_BOOT "ms:e:d:b:l:"
#define OPTS_BOOT_LEN (sizeof OPTS_BOOT - 1)
#define OPTS_SCANCTL "o:d:t:e:"
#define OPTS_SCANCTL_LEN (sizeof OPTS_SCANCTL - 1)
#define OPTS_SCANDIR "bl:s:o:L:cB"
#define OPTS_SCANDIR_LEN (sizeof OPTS_SCANDIR - 1)
extern int ssexec_main(int argc, char const *const *argv, char const *const *envp,ssexec_func_t *func,ssexec_t *info) ;
extern void ssexec_set_info(ssexec_t *info) ;
extern int ssexec_set_treeinfo(ssexec_t *info) ;
#endif
ssexec_all.o
ssexec_boot.o
ssexec_disable.o
ssexec_enable.o
ssexec_env.o
ssexec_free.o
ssexec_help.o
ssexec_init.o
ssexec_main.o
ssexec_inresolve.o
ssexec_inservice.o
ssexec_instate.o
ssexec_intree.o
ssexec_parse.o
ssexec_reconfigure.o
ssexec_reload.o
ssexec_restart.o
ssexec_scanctl.o
ssexec_scandir.o
ssexec_start.o
ssexec_stop.o
ssexec_svctl.o
......
/*
* 66-boot.c
* ssexec_boot.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -29,10 +29,10 @@
#include <oblibs/log.h>
#include <oblibs/files.h>
#include <oblibs/string.h>
#include <oblibs/obgetopt.h>
#include <oblibs/environ.h>
#include <oblibs/sastr.h>
#include <skalibs/sgetopt.h>
#include <skalibs/djbunix.h>
#include <skalibs/stralloc.h>
#include <skalibs/types.h>
......@@ -40,6 +40,7 @@
#include <66/config.h>
#include <66/constants.h>
#include <66/ssexec.h>
static mode_t mask = SS_BOOT_UMASK ;
static unsigned int rescan = SS_BOOT_RESCAN ;
......@@ -57,22 +58,19 @@ static char const *envdir = 0 ;
static char const *fifo = 0 ;
static char const *log_user = SS_LOGGER_RUNNER ;
static char const *cver = 0 ;
static char tpath[MAXENV + 1] ;
static char trcinit[MAXENV + 1] ;
static char trcinit_container[MAXENV + 1] ;
static char tlive[MAXENV + 1] ;
static char ttree[MAXENV + 1] ;
static char confile[MAXENV + 1] ;
static char tpath[SS_MAX_PATH_LEN + 1] ;
static char trcinit[SS_MAX_PATH_LEN + 1] ;
static char trcinit_container[SS_MAX_PATH_LEN + 1] ;
static char tlive[SS_MAX_PATH_LEN + 1] ;
static char ttree[SS_MAX_PATH_LEN + 1] ;
static char confile[SS_MAX_PATH_LEN + 1 + SS_BOOT_CONF_LEN + 1] ;
static char const *const *genv = 0 ;
static int fdin ;
static char const *proc_cmdline="/proc/cmdline" ;
static stralloc sacmdline = STRALLOC_ZERO ;
static int notifpipe[2] ;
#define MAXBUF 1024*64*2
#define USAGE "66-boot [ -h ] [ -z ] [ -m ] [ -s skel ] [ -l log_user ] [ -e environment ] [ -d dev ] [ -b banner ]"
static void sulogin(char const *msg,char const *arg)
{
static char const *const newarg[2] = { SS_EXTBINPREFIX "sulogin" , 0 } ;
......@@ -84,81 +82,13 @@ static void sulogin(char const *msg,char const *arg)
if (*msg) log_warnu(msg,arg) ;
pid = child_spawn0(newarg[0],newarg,genv) ;
if (waitpid_nointr(pid,&wstat, 0) < 0)
log_dieusys(LOG_EXIT_SYS,"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) log_dieu(LOG_EXIT_SYS,"duplicate stdin -- you are on your own") ;
close(0) ;
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)
{
DEFAULT_MSG = 0 ;
static char const *help =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -m: mount parent live directory\n"
" -s: skeleton directory\n"
" -l: run catch-all logger as log_user user\n"
" -e: environment directory or file\n"
" -d: dev directory\n"
" -b: banner to display\n"
;
log_info(USAGE,"\n",help) ;
}
static int read_line(stralloc *dst, char const *line)
{
log_flow() ;
char b[MAXBUF] ;
int fd ;
unsigned int n = 0, m = MAXBUF ;
fd = open(line, O_RDONLY) ;
if (fd == -1) return 0 ;
for(;;)
{
ssize_t r = read(fd,b+n,m-n);
if (r == -1)
{
if (errno == EINTR) continue ;
break ;
}
n += r ;
// buffer is full
if (n == m)
{
--n ;
break ;
}
// end of file
if (r == 0) break ;
}
close(fd) ;
if(n)
{
int i = n ;
// remove trailing zeroes
while (i && b[i-1] == '\0') --i ;
while (i--)
if (b[i] == '\n' || b[i] == '\0') b[i] = ' ' ;
if (b[n-1] == ' ') b[n-1] = '\0' ;
}
b[n] = '\0';
if (!stralloc_cats(dst,b) ||
!stralloc_0(dst)) sulogin("close stralloc",dst->s) ;
return n ;
}
static int get_value(stralloc *val,char const *key)
{
if (!environ_get_val_of_key(val,key)) return 0 ;
......@@ -204,51 +134,46 @@ static void parse_conf(void)
int r ;
unsigned int j = 0 ;
uint8_t empty = 0 ;
size_t filesize = 0 ;
char u[UINT_FMT] ;
char *gvalue = 0 ;
stralloc src = STRALLOC_ZERO ;
stralloc cmdline = STRALLOC_ZERO ;
stralloc val = STRALLOC_ZERO ;
if (skel[0] != '/') sulogin("skeleton directory must be an aboslute path: ",skel) ;
size_t skelen = strlen(skel) ;
memcpy(confile,skel,skelen) ;
confile[skelen] = '/' ;
memcpy(confile + skelen + 1, SS_BOOT_CONF, SS_BOOT_CONF_LEN) ;
confile[skelen + 1 + SS_BOOT_CONF_LEN] = 0 ;
size_t filesize=file_get_size(confile) ;
if (skel[0] != '/')
sulogin("skeleton directory must be an aboslute path: ",skel) ;
auto_strings(confile, skel, "/", SS_BOOT_CONF) ;
filesize = file_get_size(confile) ;
/** skeleton file */
r = openreadfileclose(confile,&src,filesize) ;
if(!r) sulogin("open configuration file: ",confile) ;
if (!stralloc_0(&src)) sulogin("append stralloc of file: ",confile) ;
/** /proc/cmdline */
if (!read_line(&cmdline,proc_cmdline)) {
/** we don't want to die here */
log_warnu("read: ",proc_cmdline) ;
}
else if (!sastr_split_element_in_nline(&cmdline)) {
log_warnu("split: ",proc_cmdline) ;
cmdline.len = 0 ;
}
for (char const *const *p = valid;*p;p++,j++)
r = openreadfileclose(confile, &src, filesize) ;
if(!r)
sulogin("open configuration file: ",confile) ;
if (!stralloc_0(&src))
sulogin("append stralloc of file: ",confile) ;
for (char const *const *p = valid; *p; p++, j++)
{
empty = 0 ;
/** try first to read from /proc/cmdline.
/** try first to read from kernel environment.
* If the key is not found, try to read the skeleton file.
* Finally keep the default value if we cannot get a correct
* key=value pair */
if (cmdline.len > 0) {
if (!stralloc_copy(&val,&cmdline)) sulogin("copy stralloc of file: ",proc_cmdline) ;
gvalue = getenv(*p) ;
if (gvalue) {
}
else if (!stralloc_copy(&val,&src)) sulogin("copy stralloc of file: ",confile) ;
if (!auto_stra(&val, *p, "=", gvalue))
sulogin("copy value of key: ", *p) ;
} else {
if (!stralloc_copy(&val, &src))
sulogin("copy stralloc of file: ",confile) ;
if (!get_value(&val,*p))
empty = 1 ;
if (!get_value(&val,*p))
{
if (cmdline.len > 0) {
if (!stralloc_copy(&val,&src)) sulogin("copy stralloc of file: ",confile) ;
if (!get_value(&val,*p)) empty = 1 ;
}
else empty = 1 ;
}
switch (j)
......@@ -368,7 +293,6 @@ static void parse_conf(void)
if (!sastr_split_string_in_nline(&sacmdline)) sulogin("split string: ",sacmdline.s) ;
stralloc_free(&val) ;
stralloc_free(&cmdline) ;
stralloc_free(&src) ;
}
......@@ -475,33 +399,35 @@ static inline void run_stage2 (char const *const *envp, size_t envlen, char cons
xmexec_fm(newargv, envp, envlen, t, tlen) ;
}
static inline void run_cmdline(char const *const *newargv, char const *const *envp, char const *msg,char const *arg)
static inline void make_cmdline(char const *prog,char const **add,int len,char const *msg,char const *arg,char const *const *envp)
{
log_flow() ;
pid_t pid ;
int wstat ;
pid = child_spawn0(newargv[0],newargv,envp) ;
if (waitpid_nointr(pid,&wstat, 0) < 0)
sulogin("wait for: ",newargv[0]) ;
if (wstat) sulogin(msg,arg) ;
}
static inline void make_cmdline(char const *prog,char const **add,int len,char const *msg,char const *arg,char const *const *envp)
{
log_flow() ;
int m = 6 + len, i = 0, n = 0 ;
int m = 7 + len, i = 0, n = 0 ;
char const *newargv[m] ;
newargv[n++] = "66" ;
newargv[n++] = prog ;
newargv[n++] = "-v" ;
newargv[n++] = cver ;
newargv[n++] = "-l" ;
newargv[n++] = live ;
for (;i<len;i++)
newargv[n++] = add[i] ;
newargv[n] = 0 ;
run_cmdline(newargv,envp,msg,arg) ;
pid = child_spawn0(newargv[0], newargv, envp) ;
if (waitpid_nointr(pid, &wstat, 0) < 0)
sulogin("wait for: ", newargv[0]) ;
if (wstat)
sulogin(msg, arg) ;
}
static void cad(void)
......@@ -515,7 +441,7 @@ static void cad(void)
int fd ;
fd = open("/dev/tty0", O_RDONLY | O_NOCTTY) ;
if (fd < 0) {
log_warnusys("open /dev/", "tty0 (kbrequest will not be handled)") ;
log_warnusys("open /dev/tty0 (kbrequest will not be handled)") ;
}
else {
......@@ -532,7 +458,7 @@ static void cad(void)
}
int main(int argc, char const *const *argv,char const *const *envp)
int ssexec_boot(int argc, char const *const *argv, ssexec_t *info)
{
VERBOSITY = 0 ;
unsigned int r , tmpfs = 0, opened = 0 ;
......@@ -541,30 +467,25 @@ int main(int argc, char const *const *argv,char const *const *envp)
char verbo[UINT_FMT] ;
cver = verbo ;
stralloc envmodifs = STRALLOC_ZERO ;
genv = envp ;
genv = (char const *const *)environ ;
log_color = &log_color_disable ;
PROG = "66-boot" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hzms:e:d:b:l:", &l) ;
int opt = subgetopt_r(argc, argv, OPTS_BOOT, &l) ;
if (opt == -1) break ;
if (opt == -2) sulogin("options must be set first","") ;
switch (opt)
{
case 'h' : info_help(); return 0 ;
case 'z' : log_color = !isatty(1) ? &log_color_disable : &log_color_enable ; break ;
case 'm' : tmpfs = 1 ; break ;
case 's' : skel = l.arg ; break ;
case 'e' : envdir = l.arg ; break ;
case 'd' : slashdev = l.arg ; break ;
case 'b' : banner = l.arg ; break ;
case 'l' : log_user = l.arg ; break ;
default : log_usage(USAGE) ;
default : log_usage(usage_boot) ;
}
}
argc -= l.ind ; argv += l.ind ;
......@@ -684,13 +605,14 @@ int main(int argc, char const *const *argv,char const *const *envp)
t[m++] = log_user ;
t[m++] = "create" ;
log_info("Create live scandir at: ",live) ;
make_cmdline(SS_EXTBINPREFIX "66-scandir",t,nargc,"create live scandir at: ",live,envp) ;
make_cmdline("scandir", t, nargc, "create live scandir at: ", live, genv) ;
}
/** initiate earlier service */
{
char const *t[] = { "-t",tree,"classic" } ;
char const *t[] = { tree } ;
log_info("Initiate earlier service of tree: ",tree) ;
make_cmdline(SS_EXTBINPREFIX "66-init",t,3,"initiate earlier service of tree: ",tree,envp) ;
make_cmdline("init", t, 1, "initiate earlier service of tree: ", tree, genv) ;
}
if (envdir) {
......@@ -716,8 +638,9 @@ int main(int argc, char const *const *argv,char const *const *envp)
char fmtfd[2 + UINT_FMT] = "-" ;
size_t m = 0 ;
static char const *newargv[7] ;
newargv[m++] = SS_EXTBINPREFIX "66-scanctl" ;
static char const *newargv[8] ;
newargv[m++] = "66" ;
newargv[m++] = "scanctl" ;
newargv[m++] = "-v0" ;
if (!catch_log)
newargv[m++] = fmtfd ;
......
......@@ -14,43 +14,40 @@
#include <66/ssexec.h>
char const *usage_enable = "66-enable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f|F ] [ -I ] [ -S ] service(s)" ;
char const *usage_parse = "66 parse [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -f|F ] [ -I ] service" ;
char const *help_enable =
char const *help_parse =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: name of the tree to use\n"
" -f: force to overwrite the service(s)\n"
" -F: force to overwrite the service(s) and its dependencies\n"
" -f: force to overwrite existing destination\n"
" -F: also force to overwrite its dependencies\n"
" -I: do not import modified configuration files from previous version\n"
" -S: enable and start the service\n"
;
char const *usage_dbctl = "66-dbctl [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u | d | r ] service(s)" ;
char const *usage_enable = "66 enable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f|F ] [ -I ] [ -S ] service(s)" ;
char const *help_dbctl =
char const *help_enable =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -T: timeout\n"
" -l: live directory\n"
" -t: tree to use\n"
" -u: bring up service in database of tree\n"
" -d: bring down service in database of tree\n"
" -r: reload service\n"
" -t: name of the tree to use\n"
" -f: force to overwrite the service(s)\n"
" -F: force to overwrite the service(s) and its dependencies\n"
" -I: do not import modified configuration files from previous version\n"
" -S: enable and start the service\n"
;
char const *usage_disable = "66-disable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -S ] [ -F ] [ -R ] service(s)" ;
char const *usage_disable = "66 disable [ -h ] [ -z ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -S ] [ -F ] [ -R ] service(s)" ;
char const *help_disable =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
......@@ -61,38 +58,35 @@ char const *help_disable =
" -R: disable the service and remove its configuration and logger files\n"
;
char const *usage_init = "66-init [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] classic|database|both" ;
char const *usage_init = "66 init [ -h ] [ -z ] [ -v verbosity ] [ -l live ] tree" ;
char const *help_init =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: name of the tree to use\n"
;
char const *usage_start = "66-start [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -r | R ] service(s)" ;
char const *usage_start = "66 start [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] service(s)" ;
char const *help_start =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: timeout\n"
" -r: reload the service(s)\n"
" -R: reload service(s) file(s) and the service(s) itself\n"
;
char const *usage_stop = "66-stop [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u ] [ -X ] [ -K ] service(s)" ;
char const *usage_stop = "66 stop [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -u ] service(s)" ;
char const *help_stop =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
......@@ -100,34 +94,26 @@ char const *help_stop =
" -T: timeout\n"
" -t: tree to use\n"
" -u: unsupervise service(s)\n"
" -X: bring down the service(s) and kill his supervisor\n"
" -K: kill the service(s) and keep it down\n"
;
char const *usage_svctl = "66-svctl [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -n death ] [ -u | d | r | K | X ] service(s)" ;
char const *usage_svctl = "66 svctl [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -abqhkti12pcyoduxOr ] service(s)" ;
char const *help_svctl =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: service timeout\n"
" -n: number of death\n"
" -u: bring up the service(s)\n"
" -d: bring down the service(s)\n"
" -r: reload\n"
" -X: bring down the service(s) and the kill his supervisor\n"
" -K: kill the service(s) and keep it down\n"
;
char const *usage_env = "66-env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e editor ] service" ;
char const *usage_env = "66 env [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] [ -c version ] [ -s version ] [ -V|L ] [ -r key=value ] [ -i src,dst ] [ -e editor ] service" ;
char const *help_env =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
......@@ -141,11 +127,11 @@ char const *help_env =
" -e: edit the file with editor\n"
;
char const *usage_all = "66-all [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
char const *usage_all = "66 all [ -h ] [ -z ] [ -v verbosity ] [ -T timeout ] [ -l live ] [ -t tree ] [ -f ] up|down|unsupervise" ;
char const *help_all =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
......@@ -155,11 +141,11 @@ char const *help_all =
" -f: fork the process\n"
;
char const *usage_tree = "66-tree [ -h ] [ -z ] [ -v verbosity ] [ -c ] [ -o depends=:... ] [ -E|D ] [ -R ] tree" ;
char const *usage_tree = "66 tree [ -h ] [ -z ] [ -v verbosity ] [ -c ] [ -o depends=:... ] [ -E|D ] [ -R ] tree" ;
char const *help_tree =
"\n"
"options :\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
......@@ -180,3 +166,208 @@ char const *help_tree =
" clone=: make a clone of tree\n"
" noseed: do not use seed file to build the tree\n"
;
char const *usage_tree = "66 treectl [ -h ] [ -z ] [ -v verbosity ] tree" ;
char const *help_treectl =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
;
char const *usage_reconfigure = "66 reconfigure [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -P ] service(s)" ;
char const *help_reconfigure =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: timeout\n"
" -P: do not propagate signal to its dependencies\n"
;
char const *usage_reload = "66 reload [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -P ] service(s)" ;
char const *help_reload =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: timeout\n"
" -P: do not propagate signal to its dependencies\n"
;
char const *usage_restart = "66 restart [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -P ] service(s)" ;
char const *help_restart =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: timeout\n"
" -P: do not propagate signal to its dependencies\n"
;
char const *usage_unsupervise = "66 unsupervise [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -t tree ] [ -T timeout ] [ -P ] service(s)" ;
char const *help_unsupervise =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: tree to use\n"
" -T: timeout\n"
" -P: do not propagate signal to its dependencies\n"
;
char const *usage_inresolve = "66 inresolve [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] tree|service name" ;
char const *help_inresolve =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -t: only search at the specified tree\n"
" tree: search for tree name\n"
" service: search for service name\n"
;
char const *usage_instate = "66 instate [ -h ] [ -z ] [ -v verbosity ] service" ;
char const *help_instate =
"\n"
"options:\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
;
char const *usage_intree = "66 intree [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -n ] [ -o name,init,enabled,... ] [ -g ] [ -d depth ] [ -r ] tree" ;
char const *help_intree =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -n: do not display the names of fields\n"
" -o: comma separated list of field to display\n"
" -g: displays the contents field as graph\n"
" -d: limit the depth of the contents field recursion\n"
" -r: reverse the contents field\n"
"\n"
"valid fields for -o options are:\n"
"\n"
" name: displays the name of the tree\n"
" current: displays a boolean value of the current state\n"
" enabled: displays a boolean value of the enable state\n"
" init: displays a boolean value of the initialization state\n"
" depends: displays the list of tree(s) started before\n"
" requiredby: displays the list of tree(s) started after\n"
" allowed: displays a list of allowed user to use the tree\n"
" symlinks: displays the target of tree's symlinks\n"
" contents: displays the contents of the tree\n"
;
char const *usage_inservice = "66 inservice [ -h ] [ -z ] [ -v verbosity ] [ -n ] [ -o name,intree,status,... ] [ -g ] [ -d depth ] [ -r ] [ -t tree ] [ -p nline ] service" ;
char const *help_inservice =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -n: do not display the field name\n"
" -o: comma separated list of field to display\n"
" -g: displays the contents field as graph\n"
" -d: limit the depth of the contents field recursion\n"
" -r: reverse the contents field\n"
" -t: only search service at the specified tree\n"
" -p: print n last lines of the log file\n"
"\n"
"valid fields for -o options are:\n"
"\n"
" name: displays the name\n"
" version: displays the version of the service\n"
" intree: displays the service's tree name\n"
" status: displays the status\n"
" type: displays the service type\n"
" description: displays the description\n"
" source: displays the source of the service's frontend file\n"
" live: displays the service's live directory\n"
" depends: displays the service's dependencies\n"
" requiredby: displays the service(s) which depends on service\n"
" extdepends: displays the service's external dependencies\n"
" optsdepends: displays the service's optional dependencies\n"
" start: displays the service's start script\n"
" stop: displays the service's stop script\n"
" envat: displays the source of the environment file\n"
" envfile: displays the contents of the environment file\n"
" logname: displays the logger's name\n"
" logdst: displays the logger's destination\n"
" logfile: displays the contents of the log file\n"
;
char const *usage_boot = "66 boot [ -h ] [ -z ] [ -m ] [ -s skel ] [ -l log_user ] [ -e environment ] [ -d dev ] [ -b banner ]" ;
char const *help_boot =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -m: mount parent live directory\n"
" -s: skeleton directory\n"
" -l: run catch-all logger as log_user user\n"
" -e: environment directory or file\n"
" -d: dev directory\n"
" -b: banner to display\n"
;
char const *usage_scanctl = "66 scanctl [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -d notif ] [ -t rescan ] [ -e environment ] [ -o owner ] start|stop|reload|quit|nuke|zombies or any s6-svscanctl options" ;
char const *help_scanctl =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -d: notify readiness on file descriptor\n"
" -t: rescan scandir every milliseconds\n"
" -e: environment directory\n"
" -o: handles scandir of owner\n"
;
char const *usage_scandir = "66 scandir [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -b|B ] [ -c ] [ -L log_user ] [ -s skel ] [ -o owner ] create|remove" ;
char const *help_scandir =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -b: create scandir for a boot process\n"
" -B: create scandir for a boot process inside a container\n"
" -c: do not catch log\n"
" -L: run catch-all logger as log_user user\n"
" -s: skeleton directory\n"
" -o: handles owner scandir\n"
;
char const *usage_66 = "66 start|stop|unsupervise|enable|disable|all|init|env|parse|svctl|tree|reconfigure|reload|restart|scanctl|scandir|boot service(s)|tree" ;
/*
* 66-inresolve.c
* ssexec_inresolve.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -18,7 +18,6 @@
#include <oblibs/log.h>
#include <oblibs/sastr.h>
#include <oblibs/string.h>
#include <oblibs/obgetopt.h>
#include <oblibs/types.h>
#include <skalibs/types.h>
......@@ -27,6 +26,7 @@
#include <skalibs/buffer.h>
#include <66/resolve.h>
#include <66/ssexec.h>
#include <66/tree.h>
#include <66/service.h>
#include <66/info.h>
......@@ -40,24 +40,6 @@
static wchar_t const field_suffix[] = L" :" ;
static char fields[INFO_NKEY][INFO_FIELD_MAXLEN] = {{ 0 }} ;
#define USAGE "66-inresolve [ -h ] [ -z ] [ -v verbosity ] [ -t tree ] tree|service name"
static inline void info_help (void)
{
DEFAULT_MSG = 0 ;
static char const *help =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -t: only search service at the specified tree\n"
;
log_info(USAGE,"\n",help) ;
}
static inline unsigned int lookup (char const *const *table, char const *data)
{
log_flow() ;
......@@ -199,63 +181,24 @@ static void info_display_service_field(resolve_service_t *res)
}
int main(int argc, char const *const *argv)
int ssexec_inresolve(int argc, char const *const *argv, ssexec_t *info)
{
int found = 0, what = 0 ;
uint8_t master = 0 ;
stralloc sa = STRALLOC_ZERO ;
char const *svname = 0 ;
char const *treename = 0 ;
char const *treename = info->treename.s ;
char atree[SS_MAX_TREENAME + 1] ;
log_color = &log_color_disable ;
PROG = "66-inresolve" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hv:zt:", &l) ;
if (opt == -1) break ;
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))
log_usage(USAGE) ;
break ;
case 'z' :
log_color = !isatty(1) ? &log_color_disable : &log_color_enable ;
break ;
case 't' :
treename = l.arg ;
break ;
default :
log_usage(USAGE) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
argc-- ;
argv++ ;
if (argc < 2) log_usage(USAGE) ;
if (argc < 2) log_usage(usage_inresolve) ;
what = parse_what(*argv) ;
if (what == 2)
log_usage(USAGE) ;
log_usage(usage_inresolve) ;
argv++;
argc--;
......
This diff is collapsed.
/*
* 66-instate.c
* ssexec_instate.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -27,6 +27,7 @@
#include <skalibs/buffer.h>
#include <66/resolve.h>
#include <66/ssexec.h>
#include <66/info.h>
#include <66/utils.h>
#include <66/constants.h>
......@@ -83,7 +84,7 @@ static void info_display_int(char const *field,unsigned int id)
info_display_string(field,str) ;
}
int main(int argc, char const *const *argv)
int ssexec_instate(int argc, char const *const *argv, ssexec_t *info)
{
int found = 0 ;
resolve_service_t res = RESOLVE_SERVICE_ZERO ;
......@@ -94,8 +95,6 @@ int main(int argc, char const *const *argv)
char const *ste = 0 ;
char atree[SS_MAX_TREENAME + 1] ;
log_color = &log_color_disable ;
char buf[MAXOPTS][INFO_FIELD_MAXLEN] = {
"toinit",
"toreload",
......@@ -108,47 +107,10 @@ int main(int argc, char const *const *argv)
"issupervised",
"isup" } ;
PROG = "66-instate" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hv:zt:", &l) ;
if (opt == -1) break ;
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))
log_usage(USAGE) ;
break ;
case 'z' :
log_color = !isatty(1) ? &log_color_disable : &log_color_enable ;
break ;
case 't' :
log_1_warn("deprecated option -t -- ignore it") ;
break ;
default :
log_usage(USAGE) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
argc-- ;
argv++ ;
if (!argc) log_usage(USAGE) ;
if (!argc) log_usage(usage_instate) ;
svname = *argv ;
if (!set_ownersysdir_stack(base, getuid()))
......
/*
* 66-intree.c
* ssexec_intree.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -22,12 +22,11 @@
#include <oblibs/sastr.h>
#include <oblibs/log.h>
#include <oblibs/obgetopt.h>
#include <oblibs/types.h>
#include <oblibs/string.h>
#include <oblibs/files.h>
#include <skalibs/stralloc.h>
#include <skalibs/sgetopt.h>
#include <skalibs/genalloc.h>
#include <skalibs/lolstdio.h>
#include <skalibs/bytestr.h>
......@@ -40,8 +39,8 @@
#include <66/enum.h>
#include <66/resolve.h>
#include <66/service.h>
#include <66/backup.h>
#include <66/graph.h>
#include <66/ssexec.h>
static unsigned int REVERSE = 0 ;
static unsigned int NOFIELD = 1 ;
......@@ -65,7 +64,7 @@ static void info_display_allow(char const *field,char const *treename) ;
static void info_display_symlink(char const *field,char const *treename) ;
static void info_display_contents(char const *field,char const *treename) ;
static void info_display_groups(char const *field,char const *treename) ;
info_graph_style *STYLE = &graph_default ;
static info_graph_style *T_STYLE = &graph_default ;
info_opts_map_t const opts_tree_table[] =
{
......@@ -86,41 +85,6 @@ info_opts_map_t const opts_tree_table[] =
#define checkopts(n) if (n >= MAXOPTS) log_die(LOG_EXIT_USER, "too many options")
#define DELIM ','
#define USAGE "66-intree [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -n ] [ -o name,init,enabled,... ] [ -g ] [ -d depth ] [ -r ] tree"
static inline void info_help (void)
{
DEFAULT_MSG = 0 ;
static char const *help =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -n: do not display the names of fields\n"
" -o: comma separated list of field to display\n"
" -g: displays the contents field as graph\n"
" -d: limit the depth of the contents field recursion\n"
" -r: reverse the contents field\n"
"\n"
"valid fields for -o options are:\n"
"\n"
" name: displays the name of the tree\n"
" current: displays a boolean value of the current state\n"
" enabled: displays a boolean value of the enable state\n"
" init: displays a boolean value of the initialization state\n"
" depends: displays the list of tree(s) started before\n"
" requiredby: displays the list of tree(s) started after\n"
" allowed: displays a list of allowed user to use the tree\n"
" symlinks: displays the target of tree's symlinks\n"
" contents: displays the contents of the tree\n"
;
log_info(USAGE,"\n",help) ;
}
static void info_display_name(char const *field, char const *treename)
{
if (NOFIELD) info_display_field_name(field) ;
......@@ -187,10 +151,9 @@ static void info_display_depends(char const *field, char const *treename)
if (NOFIELD) padding = info_display_field_name(field) ;
else { field = 0 ; padding = 0 ; }
if (!graph_build_g(&graph, base.s, treename, DATA_TREE, 0))
log_dieu(LOG_EXIT_SYS,"build the graph") ;
graph_build_tree(&graph, base.s) ;
r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 0) ;
r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 0, 0) ;
if (r < 0)
log_dieu(LOG_EXIT_SYS, "get the dependencies list") ;
......@@ -203,7 +166,7 @@ static void info_display_depends(char const *field, char const *treename)
depth_t d = info_graph_init() ;
if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 0, REVERSE, &d, padding, STYLE))
if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 0, REVERSE, &d, padding, T_STYLE))
log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ;
goto freed ;
......@@ -224,7 +187,7 @@ static void info_display_depends(char const *field, char const *treename)
if (!bprintf(buffer_1,"%s\n","/"))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", STYLE->last, log_color->warning,"None",log_color->off))
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
} else {
......@@ -248,10 +211,9 @@ static void info_display_requiredby(char const *field, char const *treename)
if (NOFIELD) padding = info_display_field_name(field) ;
else { field = 0 ; padding = 0 ; }
if (!graph_build_g(&graph, base.s, treename, DATA_TREE, 0))
log_dieu(LOG_EXIT_SYS,"build the graph") ;
graph_build_tree(&graph, base.s) ;
r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 1) ;
r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 1, 0) ;
if (r < 0)
log_dieu(LOG_EXIT_SYS, "get the dependencies list") ;
......@@ -265,7 +227,7 @@ static void info_display_requiredby(char const *field, char const *treename)
depth_t d = info_graph_init() ;
if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 1, REVERSE, &d, padding, STYLE))
if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 1, REVERSE, &d, padding, T_STYLE))
log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ;
goto freed ;
......@@ -287,7 +249,7 @@ static void info_display_requiredby(char const *field, char const *treename)
if (!bprintf(buffer_1,"%s\n","/"))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", STYLE->last, log_color->warning,"None",log_color->off))
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
} else {
......@@ -339,6 +301,7 @@ static void info_display_allow(char const *field, char const *treename)
static void info_display_symlink(char const *field, char const *treename)
{
/*
if (NOFIELD) info_display_field_name(field) ;
ssexec_t info = SSEXEC_ZERO ;
if (!auto_stra(&info.treename,treename)) log_die_nomem("stralloc") ;
......@@ -369,6 +332,7 @@ static void info_display_symlink(char const *field, char const *treename)
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
ssexec_free(&info) ;
*/
}
static void info_display_contents(char const *field, char const *treename)
......@@ -385,7 +349,7 @@ static void info_display_contents(char const *field, char const *treename)
auto_strings(tmp, src.s, treename, SS_SVDIRS) ;
if (!graph_build_service_bytree(&graph, tmp, 2))
if (!graph_build_service_bytree(&graph, tmp, 2, 0))
log_dieu(LOG_EXIT_SYS,"build the graph dependencies") ;
if (!graph_matrix_sort_tosa(&sa, &graph))
......@@ -400,7 +364,7 @@ static void info_display_contents(char const *field, char const *treename)
depth_t d = info_graph_init() ;
if (!info_walk(&graph, 0, treename, &info_graph_display_service, 0, REVERSE, &d, padding, STYLE))
if (!info_walk(&graph, 0, treename, &info_graph_display_service, 0, REVERSE, &d, padding, T_STYLE))
log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ;
goto freed ;
......@@ -421,7 +385,7 @@ static void info_display_contents(char const *field, char const *treename)
if (!bprintf(buffer_1,"%s\n","/"))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", STYLE->last, log_color->warning,"None",log_color->off))
if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off))
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
}
else
......@@ -524,15 +488,13 @@ static void info_parse_options(char const *str,int *what)
stralloc_free(&sa) ;
}
int main(int argc, char const *const *argv, char const *const *envp)
int ssexec_intree(int argc, char const *const *argv, ssexec_t *info)
{
unsigned int legacy = 1 ;
size_t pos, newlen, livelen ;
int what[MAXOPTS] = { 0 } ;
log_color = &log_color_disable ;
char const *treename = 0 ;
for (int i = 0 ; i < MAXOPTS ; i++)
......@@ -554,29 +516,25 @@ int main(int argc, char const *const *argv, char const *const *envp)
stralloc satree = STRALLOC_ZERO ;
PROG = "66-intree" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hzv:no:grd:l:", &l) ;
int opt = subgetopt_r(argc, argv, OPTS_INTREE, &l) ;
if (opt == -1) break ;
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)) log_usage(USAGE) ; break ;
case 'z' : log_color = !isatty(1) ? &log_color_disable : &log_color_enable ; break ;
case 'n' : NOFIELD = 0 ; 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)) log_usage(USAGE) ; break ;
case 'l' : if (!stralloc_cats(&live,l.arg)) log_usage(USAGE) ;
if (!stralloc_0(&live)) log_usage(USAGE) ;
case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) log_usage(usage_intree) ; break ;
case 'l' : if (!stralloc_cats(&live,l.arg)) log_usage(usage_intree) ;
if (!stralloc_0(&live)) log_usage(usage_intree) ;
break ;
default : log_usage(USAGE) ;
default : log_usage(usage_intree) ;
}
}
argc -= l.ind ; argv += l.ind ;
......@@ -602,7 +560,7 @@ int main(int argc, char const *const *argv, char const *const *envp)
setlocale(LC_ALL, "");
if(!str_diff(nl_langinfo(CODESET), "UTF-8")) {
STYLE = &graph_utf8;
T_STYLE = &graph_utf8;
}
if (!set_ownersysdir(&base,OWNER)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ;
......@@ -634,7 +592,7 @@ int main(int argc, char const *const *argv, char const *const *envp)
}
else
{
char const *exclude[3] = { SS_BACKUP + 1, SS_RESOLVE + 1, 0 } ;
char const *exclude[2] = { SS_RESOLVE + 1, 0 } ;
if (!stralloc_0(&src)) log_die_nomem("stralloc") ;
if (!sastr_dir_get(&satree, src.s,exclude, S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get list of tree at: ",src.s) ;
......
/*
* 66-scanctl.c
* ssexec_scanctl.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -16,10 +16,10 @@
#include <fcntl.h>
#include <oblibs/log.h>
#include <oblibs/obgetopt.h>
#include <oblibs/string.h>
#include <oblibs/environ.h>
#include <skalibs/sgetopt.h>
#include <skalibs/stralloc.h>
#include <skalibs/types.h>
#include <skalibs/djbunix.h>
......@@ -31,31 +31,10 @@
#include <66/svc.h>
#include <66/utils.h>
#include <66/ssexec.h>
static char TMPENV[MAXENV + 1] ;
#define USAGE "66-scanctl [ -h ] [ -z ] [ -v verbosity ] [ -l live ] [ -d notif ] [ -t rescan ] [ -e environment ] [ -o owner ] start|stop|reload|quit|nuke|zombies or any s6-svscanctl options"
static inline void info_help (void)
{
DEFAULT_MSG = 0 ;
static char const *help =
"\n"
"options :\n"
" -h: print this help\n"
" -z: use color\n"
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -d: notify readiness on file descriptor\n"
" -t: rescan scandir every milliseconds\n"
" -e: environment directory\n"
" -o: handles scandir of owner\n"
;
log_info(USAGE,"\n",help) ;
}
static inline unsigned int lookup (char const *const *table, char const *signal)
{
log_flow() ;
......@@ -175,7 +154,7 @@ static void scandir_up(char const *scandir, unsigned int timeout, unsigned int n
xexec_ae(newup[0], newup, envp) ;
}
int main(int argc, char const *const *argv, char const *const *envp)
int ssexec_scanctl(int argc, char const *const *argv, ssexec_t *info)
{
int r ;
uid_t owner = MYUID ;
......@@ -183,53 +162,21 @@ int main(int argc, char const *const *argv, char const *const *envp)
char const *newenv[MAXENV+1] ;
char const *const *genv = 0 ;
char const *const *genvp = (char const *const *)environ ;
char const *signal ;
char str[UINT_FMT] ;
stralloc scandir = STRALLOC_ZERO ;
stralloc envdir = STRALLOC_ZERO ;
log_color = &log_color_disable ;
PROG = "66-scanctl" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hv:zl:o:d:t:e:", &l) ;
if (opt == -1) break ;
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))
log_usage(USAGE) ;
break ;
case 'z' :
log_color = !isatty(1) ? &log_color_disable : &log_color_enable ;
break ;
case 'l' :
str[uint_fmt(str, SS_MAX_PATH)] = 0 ;
for (;;) {
if (strlen(l.arg) > SS_MAX_PATH)
log_die(LOG_EXIT_USER,"live path is too long -- it can not exceed ", str) ;
int opt = subgetopt_r(argc,argv, OPTS_SCANCTL, &l) ;
if (opt == -1) break ;
if (!auto_stra(&scandir,l.arg))
log_die_nomem("stralloc") ;
break ;
switch (opt) {
case 'o' :
......@@ -244,7 +191,7 @@ int main(int argc, char const *const *argv, char const *const *envp)
case 'd' :
if (!uint0_scan(l.arg, &notif))
log_usage(USAGE) ;
log_usage(usage_scanctl) ;
if (notif < 3)
log_die(LOG_EXIT_USER, "notification fd must be 3 or more") ;
......@@ -257,7 +204,7 @@ int main(int argc, char const *const *argv, char const *const *envp)
case 't' :
if (!uint0_scan(l.arg, &timeout))
log_usage(USAGE) ;
log_usage(usage_scanctl) ;
break ;
......@@ -270,13 +217,13 @@ int main(int argc, char const *const *argv, char const *const *envp)
default :
log_usage(USAGE) ;
log_usage(usage_scanctl) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
if (argc < 1) log_usage(USAGE) ;
if (argc < 1) log_usage(usage_scanctl) ;
signal = argv[0] ;
r = set_livedir(&scandir) ;
if (r < 0) log_die(LOG_EXIT_USER,"live: ",scandir.s," must be an absolute path") ;
......@@ -294,20 +241,21 @@ int main(int argc, char const *const *argv, char const *const *envp)
if (!environ_clean_envfile_unexport(&modifs,envdir.s))
log_dieu(LOG_EXIT_SYS,"clean environment file of: ",envdir.s) ;
size_t envlen = env_len(envp) ;
size_t n = env_len(envp) + 1 + byte_count(modifs.s,modifs.len,'\0') ;
size_t envlen = env_len(genvp) ;
size_t n = env_len(genvp) + 1 + byte_count(modifs.s,modifs.len,'\0') ;
size_t mlen = modifs.len ;
memcpy(TMPENV,modifs.s,mlen) ;
TMPENV[mlen] = 0 ;
if (!env_merge(newenv, n, envp, envlen, TMPENV, mlen))
if (!env_merge(newenv, n, genvp, envlen, TMPENV, mlen))
log_dieu(LOG_EXIT_SYS,"merge environment") ;
stralloc_free(&modifs) ;
genv = newenv ;
}
else genv = envp ;
else genv = genvp ;
sig = parse_signal(signal) ;
......
/*
* 66-scandir.c
* ssexec_scandir.c
*
* Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org>
*
......@@ -19,7 +19,6 @@
#include <sys/stat.h>
#include <stdarg.h>
#include <oblibs/obgetopt.h>
#include <oblibs/log.h>
#include <oblibs/directory.h>
#include <oblibs/types.h>
......@@ -28,6 +27,7 @@
#include <oblibs/environ.h>
#include <skalibs/stralloc.h>
#include <skalibs/sgetopt.h>
#include <skalibs/djbunix.h>
#include <skalibs/types.h>
#include <skalibs/env.h>
......@@ -39,6 +39,7 @@
#include <execline/config.h>
#include <66/config.h>
#include <66/ssexec.h>
#include <66/svc.h>
#include <66/utils.h>
#include <66/enum.h>
......@@ -763,7 +764,7 @@ void sanitize_live(char const *live)
auto_check(tmp,0755,PERM1777,AUTO_CRTE_CHW_CHM) ;
}
int main(int argc, char const *const *argv, char const *const *envp)
int ssexec_scandir(int argc, char const *const *argv, ssexec_t *info)
{
int r ;
unsigned int cmd, create, remove ;
......@@ -771,41 +772,22 @@ int main(int argc, char const *const *argv, char const *const *envp)
stralloc live = STRALLOC_ZERO ;
stralloc scandir = STRALLOC_ZERO ;
log_color = &log_color_disable ;
CONFIG_STR_LEN = compute_buf_size(SS_BINPREFIX, SS_EXTBINPREFIX, SS_EXTLIBEXECPREFIX, SS_LIBEXECPREFIX, SS_EXECLINE_SHEBANGPREFIX, 0) ;
cmd = create = remove = 0 ;
OWNER = MYUID ;
PROG = "66-scandir" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">hzv:bl:s:o:L:cB", &l) ;
int opt = subgetopt_r(argc, argv, OPTS_SCANDIR, &l) ;
if (opt == -1) break ;
if (opt == -2) log_die(LOG_EXIT_USER,"options must be set first") ;
switch (opt)
{
case 'h' :
info_help() ;
return 0 ;
case 'z' :
log_color = !isatty(1) ? &log_color_disable : &log_color_enable ;
break ;
case 'v' :
if (!uint0_scan(l.arg, &VERBOSITY))
log_usage(USAGE) ;
break ;
case 'b' :
BOOT = 1 ;
......@@ -850,19 +832,19 @@ int main(int argc, char const *const *argv, char const *const *envp)
default :
log_usage(USAGE) ;
log_usage(usage_scandir) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
if (!argc)
log_usage(USAGE) ;
log_usage(usage_scandir) ;
cmd = parse_command(argv[0]) ;
if (cmd == 3) {
log_usage(USAGE) ;
log_usage(usage_scandir) ;
} else if (!cmd) {
create = 1 ;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment