diff --git a/Makefile b/Makefile index e050c74decfa0c4a577f21df5ab2eb5abd664936..78b2edec82df100ab5d41f5e51163d06468a203d 100644 --- a/Makefile +++ b/Makefile @@ -53,12 +53,10 @@ AR := $(CROSS_COMPILE)ar RANLIB := $(CROSS_COMPILE)ranlib STRIP := $(CROSS_COMPILE)strip INSTALL := ./tools/install.sh -ENV_TARGETS := $(servicedir)/env ALL_BINS := $(LIBEXEC_TARGETS) $(BIN_TARGETS) ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) $(INTERNAL_LIBS) ALL_INCLUDES := $(wildcard src/include/$(package)/*.h) -ALL_ENV := $(DESTDIR)$(ENV_TARGETS) all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES) @@ -84,15 +82,13 @@ ifneq ($(strip $(ALL_BINS)$(SHARED_LIBS)),) exec $(STRIP) -R .note -R .comment -R .note.GNU-stack $(ALL_BINS) $(SHARED_LIBS) endif -install: install-dynlib install-libexec install-bin install-lib install-include install-env +install: install-dynlib install-libexec install-bin install-lib install-include install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so) install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%) install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%) install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a) install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h) -install-env: - exec install -d -m 1777 $(ALL_ENV) - + ifneq ($(exthome),) $(DESTDIR)$(exthome): $(DESTDIR)$(home) @@ -112,8 +108,8 @@ $(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(dynlibdir)/lib% endif -$(DESTDIR)$(servicedir)/%: src/etc/% - exec $(INSTALL) -D -m 1777 $< $@ +$(DESTDIR)$(system_log)/% $(DESTDIR)$(service_packager)/% $(DESTDIR)$(service_sys)/% $(DESTDIR)$(service_sysconf)/% : + exec $(INSTALL) -D -m 0755 $< $@ $(DESTDIR)$(dynlibdir)/lib%.so: lib%.so.xyzzy $(INSTALL) -D -m 755 $< $@.$(version) && \ @@ -149,6 +145,6 @@ lib%.a.xyzzy: lib%.so.xyzzy: exec $(REALCC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) $^ $(EXTRA_LIBS) $(LDLIBS) -.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include install-env +.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include .DELETE_ON_ERROR: diff --git a/configure b/configure index 84696ee5edd75c0283812657d235dae7b666981b..5e67743fc80067ec90b1e2a32c857abf7b9f086b 100755 --- a/configure +++ b/configure @@ -9,49 +9,57 @@ Usage: $0 [OPTION]... [TARGET] Defaults for the options are specified in brackets. System types: - --target=TARGET configure to run on target TARGET [detected] - --host=TARGET same as --target + --target=TARGET configure to run on target TARGET [detected] + --host=TARGET same as --target Installation directories: - --prefix=PREFIX main installation prefix [/] - --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] + --prefix=PREFIX main installation prefix [/] + --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] Fine tuning of the installation directories: - --dynlibdir=DIR shared library files [PREFIX/lib] - --bindir=BINDIR user executables [EPREFIX/bin] - --libexecdir=DIR package-scoped executables [EPREFIX/libexec] - --libdir=DIR static library files [PREFIX/lib/$package] - --includedir=DIR C header files [PREFIX/include] + --dynlibdir=DIR shared library files [PREFIX/lib] + --bindir=BINDIR user executables [EPREFIX/bin] + --libexecdir=DIR package-scoped executables [EPREFIX/libexec] + --libdir=DIR static library files [PREFIX/lib/$package] + --includedir=DIR C header files [PREFIX/include] - --shebangdir=DIR absolute path for #! invocations [BINDIR] - --livedir=DIR default live directory [/run/66] - --with-system-dir=DIR working directory for s6 tools as root[PREFIX/lib/66] - --with-user-dir=DIR working directory for s6 tools as user[.66] - --with-system-logpath=DIR log directory for root[/var/log/66] - --with-user-logpath=DIR log directory for user[.66/log] - --with-service-path=DIR service source directory[/etc/66] - - Do not set an absolute path but a $HOME relative path for --with-user-dir - and --with-user-logpath. The $HOME prefix will be appened at the pathname - automatically in function of the user. + --shebangdir=DIR absolute path for #! invocations [BINDIR] + --livedir=DIR default live directory [/run/66] + --with-system-dir=DIR 66 tools root working directory[PREFIX/lib/66] + --with-user-dir=DIR 66 tools user working directory[.66] + --with-system-log=DIR root service log directory[PREFIX/log/66] + --with-user-log=DIR user service log directory[.66/log] + --with-packager-service=DIR packager service installation directory[/etc/66/service] + --with-sys-service=DIR sysadmin service directory[/etc/66/sysadmin/service] + --with-user-service=DIR user service directory[.66/service] + --with-sys-service-conf=DIR sysadmin service configuration directory[/etc/66/conf] + --with-user-service-conf=DIR user service configuration directory[.66/conf] + + Do not set an absolute path but a $HOME relative path for --with-user-dir, + --with-user-log, --with-user-service, --with-user-service-conf. The $HOME prefix + will be appened at the pathname automatically in function of the user. For example , by default the final path for --with-user-dir will be $HOME/.66. - If no --prefix option is given, by default with-system-dir will be /var/lib/66. + --with-packager-service and --with-sys-service directory must be two differents path. + For example do not set --with-sys-service=/etc/66/service/sysadmin with packager service + --with-sys-service=/etc/66/service. + + If no --prefix option is given, by default --with-system-dir will be /var/lib/66. Dependencies: - --with-include=DIR add DIR to the list of searched directories for headers - --with-lib=DIR add DIR to the list of searched directories for static libraries - --with-dynlib=DIR add DIR to the list of searched directories for shared libraries + --with-include=DIR add DIR to the list of searched directories for headers + --with-lib=DIR add DIR to the list of searched directories for static libraries + --with-dynlib=DIR add DIR to the list of searched directories for shared libraries Optional features: - --enable-shared build shared libraries [disabled] - --disable-static do not build static libraries [enabled] - --disable-allstatic do not prefer linking against static libraries [enabled] - --enable-static-libc make entirely static binaries [disabled] - --enable-all-pic build everything as PIC [enabled iff toolchain builds PIE] - --enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled] - --enable-absolute-paths do not rely on PATH to access this package's binaries, - hardcode absolute BINDIR/foobar paths instead [disabled] + --enable-shared build shared libraries [disabled] + --disable-static do not build static libraries [enabled] + --disable-allstatic do not prefer linking against static libraries [enabled] + --enable-static-libc make entirely static binaries [disabled] + --enable-all-pic build everything as PIC [enabled iff toolchain builds PIE] + --enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled] + --enable-absolute-paths do not rely on PATH to access this package's binaries, + hardcode absolute BINDIR/foobar paths instead [disabled] EOF exit 0 } @@ -150,9 +158,13 @@ shebangdir='$bindir' livedir='/run/66' system_dir='$prefix/lib/66' user_dir='.66' -system_logpath='/var/log/66' -user_logpath='.66/log' -service_path='/etc/66' +system_log='/var/log/66' +user_log='.66/log' +service_packager='/etc/66/service' +service_sys='/etc/66/sysadmin/service' +service_user='.66/service' +service_sysconf='/etc/66/conf' +service_userconf='.66/conf' shared=false static=true allpic=detect @@ -185,9 +197,13 @@ for arg ; do --livedir=*) livedir=${arg#*=} ;; --with-system-dir=*) system_dir=${arg#*=} ;; --with-user-dir=*) user_dir=${arg#*=} ;; - --with-system-logpath=*) system_logpath=${arg#*=} ;; - --with-user-logpath=*) user_logpath=${arg#*=} ;; - --with-service-path=*) service_path=${arg#*=} ;; + --with-system-log=*) system_log=${arg#*=} ;; + --with-user-log=*) user_log=${arg#*=} ;; + --with-packager-service=*) service_packager=${arg#*=} ;; + --with-sys-service=*) service_sys=${arg#*=} ;; + --with-user-service=*) service_user=${arg#*=} ;; + --with-sys-service-conf=*) service_sysconf=${arg#*=} ;; + --with-user-service-conf=*) service_userconf=${arg#*=} ;; --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;; --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;; --with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;; @@ -231,7 +247,7 @@ fi # Expand installation directories stripdir prefix -for i in exec_prefix dynlibdir libexecdir bindir libdir includedir shebangdir sproot livedir service_path; do +for i in exec_prefix dynlibdir libexecdir bindir libdir includedir shebangdir sproot system_dir; do eval tmp=\${$i} eval $i=$tmp stripdir $i @@ -381,7 +397,17 @@ libexecdir := $libexecdir bindir := $bindir libdir := $libdir includedir := $includedir -servicedir := $service_path +shebangdir := $bindir +livedir := $livedir +system_dir := $system_dir +user_dir := $user_dir +system_log := $system_log +user_log := $user_log +service_packager := $service_packager +service_sys := $service_sys +service_user := $service_user +service_sysconf := $service_sysconf +service_userconf := $service_userconf slashpackage := $slashpackage sproot := $sproot version := $version @@ -442,14 +468,19 @@ All rights reserved.*/ #define ${package_macro_name}_CONFIG_H #define ${package_macro_name}_VERSION "$version" -#define ${package_macro_name}_SYSTEM_DIRECTORY "$system_dir/" -#define ${package_macro_name}_LOGGER_SYS_DIRECTORY "$system_logpath/" #define ${package_macro_name}_LIVE "$livedir/" -#define ${package_macro_name}_SERVICEDIR "$service_path/" +#define ${package_macro_name}_SYSTEM_DIR "$system_dir/" +#define ${package_macro_name}_LOGGER_SYSDIR "$system_log/" +#define ${package_macro_name}_SERVICE_PACKDIR "$service_packager/" +#define ${package_macro_name}_SERVICE_SYSDIR "$service_sys/" +#define ${package_macro_name}_SERVICE_SYSCONFDIR "$service_sysconf/" + /** Do not use absolute path but a $HOME relative path * The /home/name_of_user prefix will be automatically added to the pathname */ -#define ${package_macro_name}_USER_DIRECTORY "$user_dir/" -#define ${package_macro_name}_LOGGER_USER_DIRECTORY "$user_logpath/" +#define ${package_macro_name}_USER_DIR "$user_dir/" +#define ${package_macro_name}_LOGGER_USERDIR "$user_log/" +#define ${package_macro_name}_SERVICE_USERDIR "$service_user/" +#define ${package_macro_name}_SERVICE_USERCONFDIR "$service_userconf/" EOF if $slashpackage ; then diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index d8af82c58832b0a25b7b69a8972f1d1016f39bd3..c91e0072f677255b716b1e70bf32723290ee82c7 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -228,7 +228,7 @@ int write_log(char const *scandir, char const *scanname) if (!OWNER) { - if (!stralloc_cats(&path,SS_LOGGER_SYS_DIRECTORY)) retstralloc(0,"write_log") ; + if (!stralloc_cats(&path,SS_LOGGER_SYSDIR)) retstralloc(0,"write_log") ; } else { @@ -238,7 +238,7 @@ int write_log(char const *scandir, char const *scanname) return 0 ; } //path.len-- ; - if (!stralloc_cats(&path,SS_LOGGER_USER_DIRECTORY)) retstralloc(0,"write_log") ; + if (!stralloc_cats(&path,SS_LOGGER_USERDIR)) retstralloc(0,"write_log") ; } pathless = path.len ; if (!stralloc_0(&path)) retstralloc(0,"write_log") ; diff --git a/src/66/66-tree.c b/src/66/66-tree.c index ceac290363b042280fd5c1aed2225c6548b24de1..4a55d6c171594cd773990979fcdd85e7cb9811e6 100644 --- a/src/66/66-tree.c +++ b/src/66/66-tree.c @@ -66,7 +66,21 @@ void cleanup(char const *tree){ rm_rf(tree) ; } -int sanitize_tree(stralloc *dstree, char const *base, char const *tree) +int sanitize_extra(char const *dst) +{ + int r ; + size_t dstlen, slash ; + dstlen = strlen(dst) - 1 ;//-1 remove last slash + char parentdir[dstlen + 1] ; + memcpy(parentdir,dst,dstlen) ; + slash = get_rlen_until(dst,'/',dstlen) ; + parentdir[slash] = '\0' ; + r = dir_create_under(parentdir,dst+slash+1,0755) ; + + return r ; +} + +int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t owner) { ssize_t r ; @@ -93,6 +107,27 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree) VERBO3 strerr_warnwu3sys("create ",dst,SS_SYSTEM) ; return -1 ; } + /** create extra directory for service part */ + if (!owner) + { + if (sanitize_extra(SS_LOGGER_SYSDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + if (sanitize_extra(SS_SERVICE_PACKDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + if (sanitize_extra(SS_SERVICE_SYSDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + if (sanitize_extra(SS_SERVICE_SYSCONFDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + } + else + { + if (sanitize_extra(SS_LOGGER_USERDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + if (sanitize_extra(SS_SERVICE_USERDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + if (sanitize_extra(SS_SERVICE_USERCONFDIR) < 0) + { VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; } + } } if (!dir_search(dst,SS_TREE_CURRENT,S_IFDIR)) { @@ -459,7 +494,7 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!set_ownersysdir(&base, owner)) strerr_diefu1sys(111, "set owner directory") ; VERBO2 strerr_warni3x("sanitize ",tree," ..." ) ; - r = sanitize_tree(&dstree,base.s,tree) ; + r = sanitize_tree(&dstree,base.s,tree,owner) ; if (r < 0){ strerr_diefu2x(111,"sanitize ",tree) ; } diff --git a/src/include/66/constants.h b/src/include/66/constants.h index b52bc373418e9cc60e4e1856dad6f64072acef30..8f555114a78be7cdd8217ca8a438cfb508e3c7fe 100644 --- a/src/include/66/constants.h +++ b/src/include/66/constants.h @@ -46,9 +46,6 @@ #define SS_CONTENTS "contents" #define SS_CONTENTS_LEN (sizeof SS_CONTENTS - 1) -#define SS_SERVICE_DIR SS_SERVICEDIR SS_SERVICE -#define SS_SERVICE_DIR_LEN ((sizeof SS_SERVICEDIR - 1) + SS_SERVICE_LEN) - /** logger */ #define SS_LOG_RCSUFFIX "-log" #define SS_LOG_RCSUFFIX_LEN (sizeof SS_LOG_RCSUFFIX - 1) diff --git a/src/include/66/parser.h b/src/include/66/parser.h index a0f5c49dfe83cc1c709fa4dab982516d49e0ddec..4760ef777de60db47907d66f4967638a56aa4cc9 100644 --- a/src/include/66/parser.h +++ b/src/include/66/parser.h @@ -298,9 +298,9 @@ extern int add_env(char *line,genalloc *ga,stralloc *sa) ; extern int parse_env(keynocheck *nocheck) ; -extern int resolve_srcdeps(sv_alltype *sv_before,char const *svmain,char const *src, char const *tree,unsigned int *nbsv,stralloc *sasv) ; +extern int resolve_srcdeps(sv_alltype *sv_before,char const *svmain,char const *src, char const *tree,unsigned int *nbsv,stralloc *sasv,unsigned int force) ; -extern int parse_service_before(char const *src,char const *sv,char const *tree, unsigned int *nbsv, stralloc *sasv) ; +extern int parse_service_before(char const *src,char const *sv,char const *tree, unsigned int *nbsv, stralloc *sasv,unsigned int force) ; extern int keep_common(sv_alltype *service,keynocheck *nocheck) ; diff --git a/src/lib66/parser.c b/src/lib66/parser.c index e24b29deb9ef828b04feaa6132ab73e39f606c2e..ccebbec51b5e82afb39c729f459fc7aba97ebeac 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -270,66 +270,66 @@ static int start_parser(stralloc *sasv,char const *name,sv_alltype *sv_before) stralloc_free(sasv) ; return 0 ; } -static int deps_src(stralloc *newsrc,char const *src, char const *name, char const *tree) +static int deps_src(stralloc *newsrc,char const *src, char const *name, char const *tree, unsigned int force) { - int r ; + int r, err ; uint32_t avlid ; + unsigned int found = 0 ; + uid_t owner = MYUID ; VERBO3 strerr_warni3x("Resolving source of ", name, " service dependency") ; r = avltree_search(&deps_map,name,&avlid) ; if (r) return 2 ; //already added nothing to do genalloc tmpsrc = GENALLOC_ZERO ; //type diuint32 + stralloc sa = STRALLOC_ZERO ; *newsrc = stralloc_zero ; - - /** Search in current dir*/ - if (!stralloc_cats(newsrc,src)) retstralloc(0,"resolve_srcdeps") ; - if (!stralloc_0(newsrc)) retstralloc(0,"resolve_srcdeps") ; - r = dir_search(newsrc->s,name,S_IFREG) ; - if (!r) - { - /** Search on current tree*/ - if (!stralloc_obreplace(newsrc, tree)) retstralloc(0,"resolve_deps") ; - if (!stralloc_cats(newsrc,tree)) retstralloc(0,"resolve_deps") ; - if (!stralloc_cats(newsrc,SS_SVDIRS)) retstralloc(0,"resolve_deps") ; - if (!stralloc_cats(newsrc,SS_DB)) retstralloc(0,"resolve_deps") ; - if (!stralloc_cats(newsrc,SS_SRC)) retstralloc(0,"resolve_deps") ; - if (!stralloc_0(newsrc)) retstralloc(0,"resolve_deps") ; - - r = dir_search(newsrc->s,name,S_IFDIR) ; - - if (r) return 2 ;// already on the tree, nothing to do here - else - if (!r) - { - stralloc sa = STRALLOC_ZERO ; - unsigned int found = 0 ; - if (!stralloc_obreplace(newsrc, SS_SERVICE_DIR)) retstralloc(0,"resolve_deps") ; - if (!resolve_src(&tmpsrc,&sa,name,newsrc->s,&found)) - { - VERBO3 strerr_warnwu2sys("find dependency ",name) ; - return 0 ; - } - if (!stralloc_obreplace(newsrc, sa.s + genalloc_s(diuint32,&tmpsrc)->right)) retstralloc(0,"resolve_deps") ; - stralloc_free(&sa) ; - } - } - else - if (r < 0) + err = 1 ; + if (!owner) src = SS_SERVICE_SYSDIR ; + else src = SS_SERVICE_USERDIR ; + + if (!stralloc_cats(newsrc,tree)) retstralloc(0,"deps_src") ; + if (!stralloc_cats(newsrc,SS_SVDIRS)) retstralloc(0,"deps_src") ; + if (!stralloc_cats(newsrc,SS_DB)) retstralloc(0,"deps_src") ; + if (!stralloc_cats(newsrc,SS_SRC)) retstralloc(0,"deps_src") ; + if (!stralloc_0(newsrc)) retstralloc(0,"deps_src") ; + r = dir_search(newsrc->s,name,S_IFDIR) ; + if (r && force) goto end ; + else if (r && !force) { err=2 ; goto end ; } + else if (r < 0) { VERBO3 strerr_warnw3x("Conflicting format type for ",name," service file") ; return 0 ; } - genalloc_free(diuint32,&tmpsrc) ; + if (!owner) + { + if (!stralloc_obreplace(newsrc, SS_SERVICE_SYSDIR)) retstralloc(0,"deps_src") ; + }else if (!stralloc_obreplace(newsrc, SS_SERVICE_USERDIR)) retstralloc(0,"deps_src") ; - return 1 ; + + if (!resolve_src(&tmpsrc,&sa,name,newsrc->s,&found)) + { + if (!stralloc_obreplace(newsrc, SS_SERVICE_PACKDIR)) retstralloc(0,"deps_src") ; + { + VERBO3 strerr_warnwu2sys("find dependency ",name) ; + err = 0 ; + goto end ; + } + } + + if (!stralloc_obreplace(newsrc, sa.s + genalloc_s(diuint32,&tmpsrc)->right)) retstralloc(0,"deps_src") ; + + end: + genalloc_free(diuint32,&tmpsrc) ; + stralloc_free(&sa) ; + return err ; } /** @Return 0 on fail * @Return 1 on success * @Return 2 service already added */ -int resolve_srcdeps(sv_alltype *sv_before,char const *mainsv, char const *src, char const *tree,unsigned int *nbsv, stralloc *sasv) +int resolve_srcdeps(sv_alltype *sv_before,char const *mainsv, char const *src, char const *tree,unsigned int *nbsv, stralloc *sasv,unsigned int force) { int r, insta ; @@ -426,7 +426,7 @@ int resolve_srcdeps(sv_alltype *sv_before,char const *mainsv, char const *src, c return 0 ; } } - r = deps_src(&newsrc,src,dname.s,tree) ; + r = deps_src(&newsrc,src,dname.s,tree,force) ; if (!r) return 0 ; if (insta > 0) { @@ -440,7 +440,7 @@ int resolve_srcdeps(sv_alltype *sv_before,char const *mainsv, char const *src, c if (!start_parser(sasv,dname.s,&sv_before_deps)) return 0 ; - r = resolve_srcdeps(&sv_before_deps,dname.s,newsrc.s,tree,nbsv,sasv) ; + r = resolve_srcdeps(&sv_before_deps,dname.s,newsrc.s,tree,nbsv,sasv,force) ; if (!r) return 0 ; if (r == 2) continue ; @@ -461,7 +461,7 @@ int resolve_srcdeps(sv_alltype *sv_before,char const *mainsv, char const *src, c -int parse_service_before(char const *src,char const *sv,char const *tree, unsigned int *nbsv, stralloc *sasv) +int parse_service_before(char const *src,char const *sv,char const *tree, unsigned int *nbsv, stralloc *sasv,unsigned int force) { int r = 0 ; @@ -503,7 +503,7 @@ int parse_service_before(char const *src,char const *sv,char const *tree, unsign if (sv_before.cname.itype > CLASSIC) { - r = resolve_srcdeps(&sv_before,sv,src,tree,nbsv,sasv) ; + r = resolve_srcdeps(&sv_before,sv,src,tree,nbsv,sasv,force) ; if (!r) return 0 ; } else if (!add_sv(&sv_before,newsv.s,nbsv)) return 0 ; diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 125742acddec7898edb096092ea9c0d20566c79b..8904a3a3d536feb8128e3d54c76f2d5ef6c40c4d 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -493,12 +493,12 @@ int write_logger(char const *workdir, sv_alltype *sv, sv_execlog *log,char const if (!stralloc_cats(&destlog,userhome)) retstralloc(0,"write_logger") ; if (!stralloc_cats(&destlog,"/")) retstralloc(0,"write_logger") ; - if (!stralloc_cats(&destlog,SS_LOGGER_USER_DIRECTORY)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&destlog,SS_LOGGER_USERDIR)) retstralloc(0,"write_logger") ; if (!stralloc_cats(&destlog,svname)) retstralloc(0,"write_logger") ; } else { - if (!stralloc_cats(&destlog,SS_LOGGER_SYS_DIRECTORY)) retstralloc(0,"write_logger") ; + if (!stralloc_cats(&destlog,SS_LOGGER_SYSDIR)) retstralloc(0,"write_logger") ; if (!stralloc_cats(&destlog,svname)) retstralloc(0,"write_logger") ; } } @@ -752,23 +752,12 @@ int write_common(sv_alltype *sv, char const *dst) /** environment */ if (sv->opts[2]) { - stralloc sa = STRALLOC_ZERO ; - if (!set_ownersysdir(&sa,MYUID)) - { - VERBO3 strerr_warnwu1sys("get home system directory") ; - return 0 ; - } - - /** /etc/env/sv_name*/ - size_t sslen = sa.len - 1 ;//-1 for last '/' + char *dst = 0 ; + if (!MYUID) dst = SS_SERVICE_SYSCONFDIR ; + else dst = SS_SERVICE_USERCONFDIR ; + char *name = keep.s + sv->cname.name ; - char dst[sslen + SS_ENVDIR_LEN + 1] ; - memcpy(dst,sa.s,sslen) ; - memcpy(dst + sslen,SS_ENVDIR,SS_ENVDIR_LEN) ; - dst[sslen + SS_ENVDIR_LEN] = 0 ; - - stralloc_free(&sa) ; - + r = scan_mode(dst,S_IFDIR) ; if (r < 0) { @@ -777,11 +766,8 @@ int write_common(sv_alltype *sv, char const *dst) } if (!r) { - if (!dir_create(dst,0755)) - { - VERBO3 strerr_warnwu2sys("create environment directory: ",dst) ; - return 0 ; - } + VERBO3 strerr_warnw2sys(dst,"environment directory doesn't exist") ; + return 0 ; } if (!write_env(name,&sv->env,&saenv,dst)) @@ -810,21 +796,10 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in stralloc runuser = STRALLOC_ZERO ; stralloc execute = STRALLOC_ZERO ; - stralloc sa = STRALLOC_ZERO ; - if (!set_ownersysdir(&sa,MYUID)) - { - VERBO3 strerr_warnwu1sys("get home system directory") ; - return 0 ; - } - size_t envdstlen = sa.len - 1 ;//-1 last '/' - char envdata[envdstlen + SS_ENVDIR_LEN + 1] ; - memcpy(envdata,sa.s,envdstlen) ; - memcpy(envdata + envdstlen, SS_ENVDIR,SS_ENVDIR_LEN) ; - envdata[envdstlen + SS_ENVDIR_LEN] = 0 ; - - - stralloc_free(&sa) ; - + char *envdata = 0 ; + if (!MYUID) envdata = SS_SERVICE_SYSCONFDIR ; + else envdata = SS_SERVICE_USERCONFDIR ; + switch (exec->build) { case AUTO: @@ -997,16 +972,13 @@ int write_env(char const *name, genalloc *env,stralloc *sa,char const *dst) r = scan_mode(dst,S_IFDIR) ; if (r < 0) { - VERBO3 strerr_warnwu2sys("invalid environment directory: ",dst) ; + VERBO3 strerr_warnw2sys("invalid environment directory: ",dst) ; return 0 ; } if (!r) { - if (!dir_create(dst,0755)) - { - VERBO3 strerr_warnwu2sys("create service environment directory: ",dst) ; - return 0 ; - } + VERBO3 strerr_warnw2sys(dst,"service environment directory doesn't exist") ; + return 0 ; } for (unsigned int i = 0 ; i < genalloc_len(diuint32,env) ; i++) { diff --git a/src/lib66/set_ownersysdir.c b/src/lib66/set_ownersysdir.c index b3fcefaa8e843a500af096a4ac58ad792a7f99a8..58b40e3ff68975f9526535bf053ca93dd770f1b1 100644 --- a/src/lib66/set_ownersysdir.c +++ b/src/lib66/set_ownersysdir.c @@ -42,12 +42,12 @@ int set_ownersysdir(stralloc *base, uid_t owner) 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_DIRECTORY)) retstralloc(0,"set_ownersysdir") ; + if (!stralloc_cats(base,SS_USER_DIR)) retstralloc(0,"set_ownersysdir") ; if (!stralloc_0(base)) retstralloc(0,"set_ownersysdir") ; } else { - if (!stralloc_cats(base,SS_SYSTEM_DIRECTORY)) retstralloc(0,"set_ownersysdir") ; + if (!stralloc_cats(base,SS_SYSTEM_DIR)) retstralloc(0,"set_ownersysdir") ; if (!stralloc_0(base)) retstralloc(0,"set_ownersysdir") ; } base->len--; diff --git a/src/lib66/ssexec_enable.c b/src/lib66/ssexec_enable.c index 861ebbd1d43992f5ed306f2c38f80ece7fa2f005..07a5ff480450727c4b3464162f373580e4958b12 100644 --- a/src/lib66/ssexec_enable.c +++ b/src/lib66/ssexec_enable.c @@ -57,7 +57,7 @@ static int start_parser(char const *src,char const *svname,char const *tree, uns { stralloc sasv = STRALLOC_ZERO ; - if (!parse_service_before(src,svname,tree,nbsv,&sasv)) strerr_dief4x(111,"invalid service file: ",src,"/",svname) ; + if (!parse_service_before(src,svname,tree,nbsv,&sasv,FORCE)) strerr_dief4x(111,"invalid service file: ",src,"/",svname) ; stralloc_free(&sasv) ; @@ -72,7 +72,7 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex int r ; unsigned int nbsv, nlongrun, nclassic, start ; - char const *src = SS_SERVICE_DIR ; + char const *src ; stralloc workdir = STRALLOC_ZERO ;//working dir directory stralloc sasrc = STRALLOC_ZERO ; @@ -88,6 +88,9 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex r = nbsv = nclassic = nlongrun = start = 0 ; + if (!info->owner) src = SS_SERVICE_SYSDIR ; + else src = SS_SERVICE_USERDIR ; + //PROG = "66-enable" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -112,7 +115,12 @@ int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssex for(;*argv;argv++) { unsigned int found = 0 ; - if (!resolve_src(&gasrc,&sasrc,*argv,src,&found)) strerr_diefu2x(111,"resolve source of service file: ",*argv) ; + if (!resolve_src(&gasrc,&sasrc,*argv,src,&found)) + { + src = SS_SERVICE_PACKDIR ; + if (!resolve_src(&gasrc,&sasrc,*argv,src,&found)) + strerr_diefu2x(111,"resolve source of service file: ",*argv) ; + } } for (unsigned int i = 0 ; i < genalloc_len(diuint32,&gasrc) ; i++)