diff --git a/src/confd/configure.ac b/src/confd/configure.ac index 639ba8b69..0f7f721f9 100644 --- a/src/confd/configure.ac +++ b/src/confd/configure.ac @@ -62,7 +62,7 @@ PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES([crypt], [libxcrypt >= 4.4.27]) PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.50 gio-2.0 gio-unix-2.0]) PKG_CHECK_MODULES([jansson], [jansson >= 2.0.0]) -PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) +PKG_CHECK_MODULES([libite], [libite >= 2.6.1]) PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36]) PKG_CHECK_MODULES([libsrx], [libsrx >= 1.0.0]) diff --git a/src/libsrx/src/helpers.c b/src/libsrx/src/helpers.c index 0ffbc3593..20ec9f104 100644 --- a/src/libsrx/src/helpers.c +++ b/src/libsrx/src/helpers.c @@ -20,201 +20,6 @@ int debug; /* Sets debug level (0:off) */ int vasprintf(char **strp, const char *fmt, va_list ap); #endif -/* - * Run cmd in background after delay microseconds. - */ -int runbg(char *const args[], int delay) -{ - int pid = fork(); - - if (!pid) { - usleep(delay * 300); - _exit(execvp(args[0], args)); - } - - return pid; -} - -/* - * Reap forked child from runbg() - */ -int run_status(int pid) -{ - int rc; - - /* WNOHANG */ - if (waitpid(pid, &rc, 0) == -1) - return -1; - - if (WIFEXITED(rc)) { - errno = 0; - rc = WEXITSTATUS(rc); - } else if (WIFSIGNALED(rc)) { - errno = EINTR; - rc = -1; - } - - return rc; -} - -int fexistf(const char *fmt, ...) -{ - va_list ap; - char *file; - int len; - - va_start(ap, fmt); - len = vsnprintf(NULL, 0, fmt, ap); - va_end(ap); - - file = alloca(len + 1); - if (!file) { - errno = ENOMEM; - return -1; - } - - va_start(ap, fmt); - vsnprintf(file, len + 1, fmt, ap); - va_end(ap); - - return fexist(file); -} - -FILE *popenf(const char *type, const char *cmdf, ...) -{ - va_list ap; - char *cmd; - FILE *fp; - int len; - - va_start(ap, cmdf); - len = vasprintf(&cmd, cmdf, ap); - va_end(ap); - - if (len < 0) { - errno = ENOMEM; - return NULL; - } - - fp = popen(cmd, type); - free(cmd); - return fp; -} - -/* XXX: -lite v2.6.0 has vfopenf() to replace this. */ -static FILE *open_file(const char *mode, const char *fmt, va_list ap) -{ - va_list apc; - char *file; - int len; - - va_copy(apc, ap); - len = vsnprintf(NULL, 0, fmt, apc); - va_end(apc); - - file = alloca(len + 1); - if (!file) { - errno = ENOMEM; - return NULL; - } - - va_copy(apc, ap); - vsnprintf(file, len + 1, fmt, apc); - va_end(apc); - - return fopen(file, mode); -} - -int vreadllf(long long *value, const char *fmt, va_list ap) -{ - char line[0x100]; - FILE *fp; - - fp = open_file("r", fmt, ap); - if (!fp) - return -1; - - if (!fgets(line, sizeof(line), fp)) { - fclose(fp); - return -1; - } - - fclose(fp); - - errno = 0; - *value = strtoll(line, NULL, 0); - - return errno ? -1 : 0; -} - -int readllf(long long *value, const char *fmt, ...) -{ - va_list ap; - int rc; - - va_start(ap, fmt); - rc = vreadllf(value, fmt, ap); - va_end(ap); - - return rc; -} - -int readdf(int *value, const char *fmt, ...) -{ - long long tmp; - va_list ap; - int rc; - - va_start(ap, fmt); - rc = vreadllf(&tmp, fmt, ap); - va_end(ap); - - if (rc) - return rc; - - if (tmp < INT_MIN || tmp > INT_MAX) - return -1; - - *value = tmp; - return 0; -} - -/* - * Write interger value to a file composed from fmt and optional args. - */ -int writedf(int value, const char *mode, const char *fmt, ...) -{ - va_list ap; - FILE *fp; - - va_start(ap, fmt); - fp = open_file(mode, fmt, ap); - va_end(ap); - if (!fp) - return -1; - - fprintf(fp, "%d\n", value); - return fclose(fp); -} - -/* - * Write str to a file composed from fmt and optional args. - */ -int writesf(const char *str, const char *mode, const char *fmt, ...) -{ - va_list ap; - FILE *fp; - - va_start(ap, fmt); - fp = open_file(mode, fmt, ap); - va_end(ap); - if (!fp) - return -1; - - fprintf(fp, "%s\n", str); - return fclose(fp); -} - char *unquote(char *buf) { char q = buf[0]; diff --git a/src/libsrx/src/helpers.h b/src/libsrx/src/helpers.h index 0c197531a..55e29429d 100644 --- a/src/libsrx/src/helpers.h +++ b/src/libsrx/src/helpers.h @@ -7,25 +7,6 @@ int vasprintf(char **strp, const char *fmt, va_list ap); -int runbg(char *const args[], int delay); -int run_status(int pid); - -int fexistf(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -FILE *popenf(const char *type, const char *cmdf, ...) - __attribute__ ((format (printf, 2, 3))); - -int vreadllf(long long *value, const char *fmt, va_list ap); -int readllf(long long *value, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); -int readdf(int *value, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); - -int writedf(int value, const char *mode, const char *fmt, ...) - __attribute__ ((format (printf, 3, 4))); -int writesf(const char *str, const char *mode, const char *fmt, ...) - __attribute__ ((format (printf, 3, 4))); - char *unquote(char *buf); char *fgetkey(const char *file, const char *key); diff --git a/src/statd/configure.ac b/src/statd/configure.ac index cae62bc1c..0748dc85e 100644 --- a/src/statd/configure.ac +++ b/src/statd/configure.ac @@ -28,7 +28,7 @@ AM_CONDITIONAL(CONTAINERS, [test "x$enable_containers" != "xno"]) PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES([jansson], [jansson >= 2.0.0]) -PKG_CHECK_MODULES([libite], [libite >= 2.5.0]) +PKG_CHECK_MODULES([libite], [libite >= 2.6.1]) PKG_CHECK_MODULES([libyang], [libyang >= 2.1.80]) PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36]) PKG_CHECK_MODULES([libsrx], [libsrx >= 1.0.0]) diff --git a/src/statd/shared.c b/src/statd/shared.c index a0b3c4a0e..762fbc74f 100644 --- a/src/statd/shared.c +++ b/src/statd/shared.c @@ -4,9 +4,9 @@ #include #include #include +#include #include -#include json_t *json_get_output(const char *cmd) {