mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-29 20:23:01 +02:00
src/confd: replace local run() function with systemf() from libite
It started its life as a copy of systemf() anyway, time to clean up. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user