diff --git a/src/include/66/write.h b/src/include/66/write.h index 1a66d4593cd8d839770f58f1eb7c6d6949b72794..e20b3cf9c2b8cd6d84b1ab7026d0c6b6ddbe53b3 100644 --- a/src/include/66/write.h +++ b/src/include/66/write.h @@ -18,12 +18,12 @@ #include <stdint.h> #include <66/service.h> -extern int write_services(resolve_service_t *res, char const *workdir, uint8_t force) ; -extern void write_classic(resolve_service_t *res, char const *dst, uint8_t force) ; +extern void write_services(resolve_service_t *res, char const *workdir) ; +extern void write_classic(resolve_service_t *res, char const *dst) ; extern void write_common(resolve_service_t *res, char const *dst) ; extern void write_environ(char const *name, char const *contents, char const *dst) ; extern void write_execute_scripts(char const *file, char const *contents, char const *dst) ; -extern void write_logger(resolve_service_t *res, char const *destination, uint8_t force) ; +extern void write_logger(resolve_service_t *res, char const *destination) ; extern void write_oneshot(resolve_service_t *res, char const *dst) ; extern void write_uint(char const *dst, char const *name, uint32_t ui) ; diff --git a/src/lib66/write/write_classic.c b/src/lib66/write/write_classic.c index 6b38afcd51ac2ac2f614bbae6ca2dbf2f3ab2f69..5b73f04f566c2d52d0fd0c7b1daa664b1dba67ef 100644 --- a/src/lib66/write/write_classic.c +++ b/src/lib66/write/write_classic.c @@ -22,7 +22,7 @@ /* dst e.g. /var/lib/66/system/<tree>/servicedirs/svc/<name> */ -void write_classic(resolve_service_t *res, char const *dst, uint8_t force) +void write_classic(resolve_service_t *res, char const *dst) { log_flow() ; @@ -42,16 +42,4 @@ void write_classic(resolve_service_t *res, char const *dst, uint8_t force) /** finish.user file */ if (res->execute.finish.run_user) write_execute_scripts("finish.user", res->sa.s + res->execute.finish.run_user, dst) ; - - /** logger */ - if (res->logger.name) { - - char destination[strlen(dst) + 1] ; - - if (!ob_dirname(destination, dst)) - log_dieu(LOG_EXIT_SYS, "get dirname of: ", dst) ; - - write_logger(res, destination, force) ; - } - } diff --git a/src/lib66/write/write_logger.c b/src/lib66/write/write_logger.c index f30150e4b3a9bf42d83f63757c02f351bf08c222..3bc5434d9915e465f5bc63a16eb24c312826ba29 100644 --- a/src/lib66/write/write_logger.c +++ b/src/lib66/write/write_logger.c @@ -40,49 +40,31 @@ /** @destination -> /var/lib/66/system/<tree>/servicedirs/svc/ */ -void write_logger(resolve_service_t *res, char const *destination, uint8_t force) +void write_logger(resolve_service_t *res, char const *destination) { log_flow() ; - int r ; uid_t log_uid ; gid_t log_gid ; uint8_t owner = res->owner ; - char *logrunner = res->logger.execute.run.runas ? res->sa.s + res->logger.execute.run.runas : SS_LOGGER_RUNNER ; + char *logrunner = res->execute.run.runas ? res->sa.s + res->execute.run.runas : SS_LOGGER_RUNNER ; - char dst[strlen(destination) + strlen(res->sa.s + res->logger.name) + 1] ; - auto_strings(dst, destination, res->sa.s + res->logger.name) ; + if (res->execute.timeout.kill) + write_uint(destination, "timeout-kill", res->execute.timeout.kill) ; - r = scan_mode(dst, S_IFDIR) ; - if (r && force) { - - if (!dir_rm_rf(dst)) - log_dieusys(LOG_EXIT_SYS, "delete: ", dst) ; - - } else if (r) { - - log_warn("ignoring ", dst, " -- already exist") ; - return ; - } - - if (!dir_create_parent(dst, 0755)) - log_dieusys(LOG_EXIT_SYS, "create directory: ", dst) ; - - if (res->logger.execute.timeout.kill) - write_uint(dst, "timeout-kill", res->logger.execute.timeout.kill) ; - - if (res->logger.execute.timeout.finish) - write_uint(dst, "timeout-finish", res->logger.execute.timeout.finish) ; + if (res->execute.timeout.finish) + write_uint(destination, "timeout-finish", res->execute.timeout.finish) ; /** notification */ - write_uint(dst, "notification-fd", 3) ; + write_uint(destination, "notification-fd", 3) ; /** log destination */ + log_trace("create directory: ", res->sa.s + res->logger.destination) ; if (!dir_create_parent(res->sa.s + res->logger.destination, 0755)) log_dieusys(LOG_EXIT_SYS, "create directory: ", res->sa.s + res->logger.destination) ; - if (!owner && ((res->logger.execute.run.build == BUILD_AUTO) || (!res->logger.execute.run.build))) { + if (!owner && ((res->execute.run.build == BUILD_AUTO) || (!res->execute.run.build))) { if (!youruid(&log_uid, logrunner) || !yourgid(&log_gid, log_uid)) log_dieusys(LOG_EXIT_SYS, "get uid and gid of: ", logrunner) ; @@ -91,22 +73,22 @@ void write_logger(resolve_service_t *res, char const *destination, uint8_t force log_dieusys(LOG_EXIT_SYS, "chown: ", res->sa.s + res->logger.destination) ; } - char write[strlen(dst) + 10] ; + char write[strlen(destination) + 10] ; /** run script */ - if (!file_write_unsafe(dst, "run", res->sa.s + res->logger.execute.run.run, strlen(res->sa.s + res->logger.execute.run.run))) - log_dieusys(LOG_EXIT_SYS, "write: ", dst, "/run.user") ; + if (!file_write_unsafe(destination, "run", res->sa.s + res->execute.run.run, strlen(res->sa.s + res->execute.run.run))) + log_dieusys(LOG_EXIT_SYS, "write: ", destination, "/run.user") ; - auto_strings(write, dst, "/run") ; + auto_strings(write, destination, "/run") ; if (chmod(write, 0755) < 0) log_dieusys(LOG_EXIT_SYS, "chmod", write) ; /** run.user script */ - if (!file_write_unsafe(dst, "run.user", res->sa.s + res->logger.execute.run.run_user, strlen(res->sa.s + res->logger.execute.run.run_user))) - log_dieusys(LOG_EXIT_SYS, "write: ", dst, "/run.user") ; + if (!file_write_unsafe(destination, "run.user", res->sa.s + res->execute.run.run_user, strlen(res->sa.s + res->execute.run.run_user))) + log_dieusys(LOG_EXIT_SYS, "write: ", destination, "/run.user") ; - auto_strings(write, dst, "/run.user") ; + auto_strings(write, destination, "/run.user") ; if (chmod(write, 0755) < 0) log_dieusys(LOG_EXIT_SYS, "chmod", write) ; diff --git a/src/lib66/write/write_service.c b/src/lib66/write/write_service.c index 9dc71ede3176503de9458281f9e163892bea78ab..f8e72e83d280a397018f0c5a0923ad68ce118a09 100644 --- a/src/lib66/write/write_service.c +++ b/src/lib66/write/write_service.c @@ -27,6 +27,7 @@ #include <66/enum.h> #include <66/write.h> #include <66/constants.h> +#include <66/sanitize.h> /** @Return 0 on fail * @Return 1 on success @@ -34,35 +35,16 @@ * * @workdir -> /var/lib/66/system/<tree>/servicedirs/ * */ -int write_services(resolve_service_t *res, char const *workdir, uint8_t force) +void write_services(resolve_service_t *res, char const *workdir) { log_flow() ; - int r ; - size_t workdirlen = strlen(workdir) ; char *name = res->sa.s + res->name ; - size_t namelen = strlen(name) ; - int type = res->type ; - - { - resolve_service_t fres = RESOLVE_SERVICE_ZERO ; - resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &fres) ; - ss_state_t ste = STATE_ZERO ; - if (resolve_check(workdir, name)) { - if (!resolve_read(wres, workdir, name)) - log_dieu(LOG_EXIT_SYS, "read resolve file of: ", name) ; - - if (state_check(fres.sa.s + fres.path.home, name)) { - - if (!state_read(&ste, fres.sa.s + fres.path.home, name)) - log_dieu(LOG_EXIT_SYS, "read state file of: ", name) ; - - if (fres.type != type && FLAGS_ISSET(ste.isenabled, STATE_FLAGS_TRUE)) - log_die(LOG_EXIT_SYS, "Detection of incompatible type format for: ", name, " -- current: ", get_key_by_enum(ENUM_TYPE, type), " previous: ", get_key_by_enum(ENUM_TYPE, fres.type)) ; - } - } - resolve_free(wres) ; - } + uint32_t type = res->type ; + char logname = get_rstrlen_until(name, SS_LOG_SUFFIX) ; + if (logname > 0) + type = 4 ; + /** * * @@ -74,28 +56,8 @@ int write_services(resolve_service_t *res, char const *workdir, uint8_t force) * * * */ - char wname[workdirlen + SS_SVC_LEN + 1 + namelen + 1] ; - auto_strings(wname, workdir, SS_SVC, "/", name) ; - - r = scan_mode(wname, S_IFDIR) ; - if (r < 0) - log_die(LOG_EXIT_SYS, "unvalide source: ", wname) ; - - if ((r && force) || !r) { - - if (!dir_rm_rf(wname)) - log_dieusys(LOG_EXIT_SYS, "remove: ", wname) ; - - if (!dir_create_parent(wname, 0755)) - log_dieusys(LOG_EXIT_SYS, "create ", wname) ; - } else if (r && !force) { - - log_info("Ignoring: ", name, " service: already written") ; - return 2 ; - } - - log_trace("Write service ", name, " ...") ; + log_trace("write service ", name) ; switch(type) { @@ -105,19 +67,23 @@ int write_services(resolve_service_t *res, char const *workdir, uint8_t force) case TYPE_CLASSIC: - write_classic(res, wname, force) ; + write_classic(res, workdir) ; break ; case TYPE_ONESHOT: - write_oneshot(res, wname) ; + write_oneshot(res, workdir) ; + break ; + + case 4: + + write_logger(res, workdir) ; break ; default: log_die(LOG_EXIT_SYS, "unkown type: ", get_key_by_enum(ENUM_TYPE, type)) ; } - return 1 ; } diff --git a/src/lib66/write/write_uint.c b/src/lib66/write/write_uint.c index 6ec3e99aadaae2676c44325a28db44d59fb3bd5a..b14e01e72a9c3c5c9ceddbe0e4af888536b35550 100644 --- a/src/lib66/write/write_uint.c +++ b/src/lib66/write/write_uint.c @@ -15,6 +15,7 @@ #include <stdint.h> #include <oblibs/log.h> +#include <oblibs/string.h> #include <oblibs/files.h> #include <skalibs/types.h>