diff --git a/src/confd/src/Makefile.am b/src/confd/src/Makefile.am index 9a2178df..fca460b9 100644 --- a/src/confd/src/Makefile.am +++ b/src/confd/src/Makefile.am @@ -7,5 +7,5 @@ plugin_LTLIBRARIES = confd-plugin.la confd_plugin_la_CFLAGS = $(augeas_CFLAGS) $(libite_CFLAGS) $(sysrepo_CFLAGS) $(CFLAGS) confd_plugin_la_LIBADD = $(augeas_LIBS) $(libite_LIBS) $(sysrepo_LIBS) confd_plugin_la_LDFLAGS = -module -avoid-version -shared -confd_plugin_la_SOURCES = core.c core.h run.c sr_ext.c sr_ext.h srx_val.c srx_val.h \ +confd_plugin_la_SOURCES = core.c core.h sr_ext.c sr_ext.h srx_val.c srx_val.h \ ietf-system.c ietf-interfaces.c diff --git a/src/confd/src/core.c b/src/confd/src/core.c index b3a0a952..042bd943 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -7,7 +7,7 @@ static struct confd confd; static int startup_save_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { - if (run("sysrepocfg -X/cfg/startup-config.cfg -d startup -f json")) + if (systemf("sysrepocfg -X/cfg/startup-config.cfg -d startup -f json")) return SR_ERR_SYS; return SR_ERR_OK; diff --git a/src/confd/src/core.h b/src/confd/src/core.h index 3872a99f..45726150 100644 --- a/src/confd/src/core.h +++ b/src/confd/src/core.h @@ -75,10 +75,6 @@ static inline int register_rpc(sr_session_ctx_t *session, const char *xpath, return rc; } - -/* core.c */ -int run(const char *fmt, ...); - /* ietf-interfaces.c */ int ietf_interfaces_init(struct confd *confd); diff --git a/src/confd/src/ietf-system.c b/src/confd/src/ietf-system.c index 45733b86..2630f5f2 100644 --- a/src/confd/src/ietf-system.c +++ b/src/confd/src/ietf-system.c @@ -189,7 +189,7 @@ static int rpc_exec(sr_session_ctx_t *session, uint32_t sub_id, const char *path { DEBUG("path: %s", path); - if (run(priv)) + if (systemf(priv)) return SR_ERR_INTERNAL; return SR_ERR_OK; @@ -248,7 +248,7 @@ done: static int sys_reload_services(void) { - return run("initctl -nbq touch sysklogd lldpd"); + return systemf("initctl -nbq touch sysklogd lldpd"); } int sr_get_int(sr_session_ctx_t *session, const char *fmt, ...) @@ -388,7 +388,7 @@ static int change_clock(sr_session_ctx_t *session, uint32_t sub_id, const char * } remove("/etc/localtime+"); - if (run("ln -s /usr/share/zoneinfo/%s /etc/localtime+", timezone)) { + if (systemf("ln -s /usr/share/zoneinfo/%s /etc/localtime+", timezone)) { ERROR("No such timezone %s", timezone); return SR_ERR_VALIDATION_FAILED; } @@ -437,15 +437,15 @@ static int change_ntp(sr_session_ctx_t *session, uint32_t sub_id, const char *mo rename(CHRONY_CONF, CHRONY_PREV); rename(CHRONY_NEXT, CHRONY_CONF); if (!sr_get_bool(session, "/ietf-system:system/ntp/enabled")) { - run("initctl -nbq disable chronyd"); + systemf("initctl -nbq disable chronyd"); return SR_ERR_OK; } /* * If chrony is alrady enabled we tell Finit it's been * modified , so Finit restarts it, otherwise enable it. */ - run("initctl -nbq touch chronyd"); - run("initctl -nbq enable chronyd"); + systemf("initctl -nbq touch chronyd"); + systemf("initctl -nbq enable chronyd"); return SR_ERR_OK; default: @@ -555,10 +555,10 @@ static int change_dns(sr_session_ctx_t *session, uint32_t sub_id, const char *mo rename(RESOLV_NEXT, RESOLV_CONF); /* in bootstrap, another resolvconf will soon take your call */ - if (run("initctl cond get hook/sys/up")) + if (systemf("initctl cond get hook/sys/up")) return 0; - run("resolvconf -u"); + systemf("resolvconf -u"); return SR_ERR_OK; default: diff --git a/src/confd/src/run.c b/src/confd/src/run.c deleted file mode 100644 index 1a809c68..00000000 --- a/src/confd/src/run.c +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ - -#include "core.h" - -/** - * Like system(), but takes a formatted string as argument. - * @param fmt printf style format list to command to run - * - * This system() wrapper greatly simplifies operations that usually - * consist of composing a command from parts into a dynamic buffer - * before calling it. The return value from system() is also parsed, - * checking for proper exit and signals. - * - * @returns If the command exits normally, the return code of the command - * is returned. Otherwise, if the command is signalled, the return code - * is -1 and @a errno is set to @c EINTR. - */ -int run(const char *fmt, ...) -{ - va_list ap; - char *cmd; - int len; - int rc; - - va_start(ap, fmt); - len = vsnprintf(NULL, 0, fmt, ap); - va_end(ap); - - cmd = alloca(++len); - if (!cmd) { - errno = ENOMEM; - return -1; - } - - va_start(ap, fmt); - vsnprintf(cmd, len, fmt, ap); - va_end(ap); - - rc = system(cmd); - if (rc == -1) - return -1; - - if (WIFEXITED(rc)) { - errno = 0; - rc = WEXITSTATUS(rc); - } else if (WIFSIGNALED(rc)) { - errno = EINTR; - rc = -1; - } - - return rc; -}