mirror of
https://github.com/troglobit/finit.git
synced 2026-10-27 12:20:54 +00:00
Refactor to share err/warn log API between daemon and client code
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
10437887fc
commit
37e3be9a0d
10 files changed
+53
-32
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ AM_LDFLAGS = -module -avoid-version -shared
|
|||||||
AM_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
AM_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/src -U_FORTIFY_SOURCE
|
AM_CPPFLAGS = -I$(top_srcdir)/src -U_FORTIFY_SOURCE
|
||||||
AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
AM_CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE
|
||||||
AM_CPPFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
AM_CPPFLAGS += -D__FINIT__ $(lite_CFLAGS) $(uev_CFLAGS)
|
||||||
|
|
||||||
if STATIC
|
if STATIC
|
||||||
noinst_LTLIBRARIES = libplug.la
|
noinst_LTLIBRARIES = libplug.la
|
||||||
|
|||||||
+2
-1
@@ -67,6 +67,7 @@ endif
|
|||||||
pkginclude_HEADERS = cgroup.h cond.h conf.h finit.h helpers.h log.h \
|
pkginclude_HEADERS = cgroup.h cond.h conf.h finit.h helpers.h log.h \
|
||||||
plugin.h svc.h service.h
|
plugin.h svc.h service.h
|
||||||
|
|
||||||
|
finit_CPPFLAGS = $(AM_CPPFLAGS) -D__FINIT__
|
||||||
finit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
finit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
finit_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
finit_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
||||||
finit_LDADD = $(lite_LIBS) $(uev_LIBS)
|
finit_LDADD = $(lite_LIBS) $(uev_LIBS)
|
||||||
@@ -78,7 +79,7 @@ endif
|
|||||||
|
|
||||||
initctl_SOURCES = initctl.c initctl.h cgutil.c cgutil.h \
|
initctl_SOURCES = initctl.c initctl.h cgutil.c cgutil.h \
|
||||||
client.c client.h cond.c cond.h reboot.c \
|
client.c client.h cond.c cond.h reboot.c \
|
||||||
serv.c serv.h svc.h util.c util.h
|
serv.c serv.h svc.h util.c util.h log.h
|
||||||
initctl_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
initctl_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
initctl_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
initctl_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
||||||
initctl_LDADD = $(lite_LIBS) $(uev_LIBS)
|
initctl_LDADD = $(lite_LIBS) $(uev_LIBS)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "cgutil.h"
|
#include "cgutil.h"
|
||||||
#include "initctl.h"
|
#include "initctl.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#define CDIM plain ? "" : "\e[2m"
|
#define CDIM plain ? "" : "\e[2m"
|
||||||
#define CRST plain ? "" : "\e[0m"
|
#define CRST plain ? "" : "\e[0m"
|
||||||
|
|||||||
+15
-15
@@ -27,7 +27,7 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "initctl.h"
|
#include "log.h"
|
||||||
|
|
||||||
static int sd = -1;
|
static int sd = -1;
|
||||||
|
|
||||||
@@ -40,13 +40,13 @@ int client_connect(void)
|
|||||||
|
|
||||||
sd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
|
sd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
|
||||||
if (-1 == sd) {
|
if (-1 == sd) {
|
||||||
WARN("Failed creating UNIX domain socket");
|
warn("Failed creating UNIX domain socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connect(sd, (struct sockaddr*)&sun, sizeof(sun)) == -1) {
|
if (connect(sd, (struct sockaddr*)&sun, sizeof(sun)) == -1) {
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
WARNX("Failed connecting to finit");
|
warnx("Failed connecting to finit");
|
||||||
close(sd);
|
close(sd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -81,13 +81,13 @@ int client_send(struct init_request *rq, ssize_t len)
|
|||||||
pfd.fd = sd;
|
pfd.fd = sd;
|
||||||
pfd.events = POLLOUT;
|
pfd.events = POLLOUT;
|
||||||
if (poll(&pfd, 1, 2000) <= 0) {
|
if (poll(&pfd, 1, 2000) <= 0) {
|
||||||
WARN("Timed out waiting for Finit, errno %d", errno);
|
warn("Timed out waiting for Finit, errno %d", errno);
|
||||||
goto exit;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(sd, rq, len) != len) {
|
if (write(sd, rq, len) != len) {
|
||||||
WARN("Failed communicating with Finit, errno %d", errno);
|
warn("Failed communicating with Finit, errno %d", errno);
|
||||||
goto exit;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pfd.fd = sd;
|
pfd.fd = sd;
|
||||||
@@ -95,16 +95,16 @@ int client_send(struct init_request *rq, ssize_t len)
|
|||||||
if ((rc = poll(&pfd, 1, 2000)) <= 0) {
|
if ((rc = poll(&pfd, 1, 2000)) <= 0) {
|
||||||
if (rc) {
|
if (rc) {
|
||||||
if (errno == EINTR) /* shutdown/reboot */
|
if (errno == EINTR) /* shutdown/reboot */
|
||||||
goto exit;
|
return -1;
|
||||||
WARN("poll(), errno %d", errno);
|
warn("poll(), errno %d", errno);
|
||||||
} else
|
} else
|
||||||
WARNX("Timed out waiting for reply from Finit.");
|
warnx("Timed out waiting for reply from Finit.");
|
||||||
goto exit;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(sd, rq, len) != len) {
|
if (read(sd, rq, len) != len) {
|
||||||
WARN("Failed reading reply from Finit, errno %d", errno);
|
warn("Failed reading reply from Finit, errno %d", errno);
|
||||||
goto exit;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rq->cmd == INIT_CMD_NACK)
|
if (rq->cmd == INIT_CMD_NACK)
|
||||||
@@ -144,7 +144,7 @@ svc_t *client_svc_iterator(int first)
|
|||||||
|
|
||||||
return &svc;
|
return &svc;
|
||||||
error:
|
error:
|
||||||
WARN("Failed communicating with finit, error %d", errno);
|
warn("Failed communicating with finit, error %d", errno);
|
||||||
client_disconnect();
|
client_disconnect();
|
||||||
sd = -1;
|
sd = -1;
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ static svc_t *do_cmd(int cmd, const char *arg)
|
|||||||
return &svc;
|
return &svc;
|
||||||
error:
|
error:
|
||||||
client_disconnect();
|
client_disconnect();
|
||||||
WARN("Failed communicating with finit, error %d", errno);
|
warn("Failed communicating with finit, error %d", errno);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -89,7 +89,7 @@ int run_parts (char *dir, char *cmd);
|
|||||||
static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
||||||
{
|
{
|
||||||
if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) {
|
if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) {
|
||||||
_w("Failed creating %s properly.", path);
|
warnx("Failed creating %s properly.", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <syslog.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|||||||
@@ -31,6 +31,35 @@
|
|||||||
#define LOG_CONSOLE (14<<3)
|
#define LOG_CONSOLE (14<<3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __FINIT__
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern int debug;
|
||||||
|
|
||||||
|
static __attribute__ ((format (printf, 1, 2))) inline void dbg(char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if (!debug)
|
||||||
|
return;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* General log macros, similar to those used by initctl. Initially intended
|
||||||
|
* only for bridging client.c in Finit and initctl.
|
||||||
|
*/
|
||||||
|
#define dbg(fmt, args...) logit(LOG_DEBUG, fmt, ##args)
|
||||||
|
#define warnx(fmt, args...) logit(LOG_WARNING, fmt, ##args)
|
||||||
|
#define warn(fmt, args...) logit(LOG_WARNING, fmt ": %s", ##args, strerror(errno))
|
||||||
|
#define errx(rc, fmt, args...) logit(LOG_ERR, fmt, ##args)
|
||||||
|
#define err(rc, fmt, args...) logit(LOG_ERR, fmt ": %s", ##args, strerror(errno))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Developer error and debug messages, otherwise --> use logit() <--
|
* Developer error and debug messages, otherwise --> use logit() <--
|
||||||
* ~~~~~~~~~~~
|
* ~~~~~~~~~~~
|
||||||
@@ -52,5 +81,6 @@ void log_debug (void);
|
|||||||
|
|
||||||
void logit (int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
void logit (int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
void flog (char *file, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
void flog (char *file, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* FINIT_LOG_H_ */
|
#endif /* FINIT_LOG_H_ */
|
||||||
@@ -66,7 +66,7 @@ static inline char *pid_runpath(const char *file, char *path, size_t len)
|
|||||||
|
|
||||||
rc = paste(path, len, prefix, file);
|
rc = paste(path, len, prefix, file);
|
||||||
if (rc < 0 || (size_t)rc >= len)
|
if (rc < 0 || (size_t)rc >= len)
|
||||||
_e("File path '%s' truncated, should end with '%s'", path, file);
|
err(1, "File path '%s' truncated, should end with '%s'", path, file);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
|
|||||||
-13
@@ -28,7 +28,6 @@
|
|||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -87,18 +86,6 @@ int ttcooked (void);
|
|||||||
#define ttcooked() 0
|
#define ttcooked() 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static __attribute__ ((format (printf, 1, 2))) inline void dbg(char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
if (!debug)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline char *strterm(char *str, size_t len)
|
static inline char *strterm(char *str, size_t len)
|
||||||
{
|
{
|
||||||
str[len - 1] = 0;
|
str[len - 1] = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user