diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d4b878c5..45affcab 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -3,7 +3,7 @@ AM_LDFLAGS = -module -avoid-version -shared AM_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99 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 += $(lite_CFLAGS) $(uev_CFLAGS) +AM_CPPFLAGS += -D__FINIT__ $(lite_CFLAGS) $(uev_CFLAGS) if STATIC noinst_LTLIBRARIES = libplug.la diff --git a/src/Makefile.am b/src/Makefile.am index 0bae8480..1d3fb29c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,6 +67,7 @@ endif pkginclude_HEADERS = cgroup.h cond.h conf.h finit.h helpers.h log.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 += $(lite_CFLAGS) $(uev_CFLAGS) finit_LDADD = $(lite_LIBS) $(uev_LIBS) @@ -78,7 +79,7 @@ endif initctl_SOURCES = initctl.c initctl.h cgutil.c cgutil.h \ 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 += $(lite_CFLAGS) $(uev_CFLAGS) initctl_LDADD = $(lite_LIBS) $(uev_LIBS) diff --git a/src/cgutil.c b/src/cgutil.c index b2d366b9..ddceca7b 100644 --- a/src/cgutil.c +++ b/src/cgutil.c @@ -38,6 +38,7 @@ #include "cgutil.h" #include "initctl.h" +#include "log.h" #define CDIM plain ? "" : "\e[2m" #define CRST plain ? "" : "\e[0m" diff --git a/src/client.c b/src/client.c index c5d5a1b8..2956dc80 100644 --- a/src/client.c +++ b/src/client.c @@ -27,7 +27,7 @@ #include #include "client.h" -#include "initctl.h" +#include "log.h" static int sd = -1; @@ -40,13 +40,13 @@ int client_connect(void) sd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (-1 == sd) { - WARN("Failed creating UNIX domain socket"); + warn("Failed creating UNIX domain socket"); return -1; } if (connect(sd, (struct sockaddr*)&sun, sizeof(sun)) == -1) { if (errno != ENOENT) - WARNX("Failed connecting to finit"); + warnx("Failed connecting to finit"); close(sd); return -1; } @@ -81,13 +81,13 @@ int client_send(struct init_request *rq, ssize_t len) pfd.fd = sd; pfd.events = POLLOUT; if (poll(&pfd, 1, 2000) <= 0) { - WARN("Timed out waiting for Finit, errno %d", errno); - goto exit; + warn("Timed out waiting for Finit, errno %d", errno); + return -1; } if (write(sd, rq, len) != len) { - WARN("Failed communicating with Finit, errno %d", errno); - goto exit; + warn("Failed communicating with Finit, errno %d", errno); + return -1; } 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) { if (errno == EINTR) /* shutdown/reboot */ - goto exit; - WARN("poll(), errno %d", errno); + return -1; + warn("poll(), errno %d", errno); } else - WARNX("Timed out waiting for reply from Finit."); - goto exit; + warnx("Timed out waiting for reply from Finit."); + return -1; } if (read(sd, rq, len) != len) { - WARN("Failed reading reply from Finit, errno %d", errno); - goto exit; + warn("Failed reading reply from Finit, errno %d", errno); + return -1; } if (rq->cmd == INIT_CMD_NACK) @@ -144,7 +144,7 @@ svc_t *client_svc_iterator(int first) return &svc; error: - WARN("Failed communicating with finit, error %d", errno); + warn("Failed communicating with finit, error %d", errno); client_disconnect(); sd = -1; @@ -175,7 +175,7 @@ static svc_t *do_cmd(int cmd, const char *arg) return &svc; error: client_disconnect(); - WARN("Failed communicating with finit, error %d", errno); + warn("Failed communicating with finit, error %d", errno); return NULL; } diff --git a/src/helpers.h b/src/helpers.h index c8deb2f9..53bfcf81 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -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) { if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) { - _w("Failed creating %s properly.", path); + warnx("Failed creating %s properly.", path); return -1; } diff --git a/src/initctl.c b/src/initctl.c index 6cdb904f..841e5e07 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/log.h b/src/log.h index 989dba8b..c4f6ada4 100644 --- a/src/log.h +++ b/src/log.h @@ -31,6 +31,35 @@ #define LOG_CONSOLE (14<<3) #endif +#ifndef __FINIT__ +#include +#include +#include + +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() <-- * ~~~~~~~~~~~ @@ -52,5 +81,6 @@ void log_debug (void); void logit (int prio, 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_ */ diff --git a/src/pid.h b/src/pid.h index 94fe2d10..3a1bb32f 100644 --- a/src/pid.h +++ b/src/pid.h @@ -66,7 +66,7 @@ static inline char *pid_runpath(const char *file, char *path, size_t len) rc = paste(path, len, prefix, file); 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; } diff --git a/src/util.c b/src/util.c index 22bd6493..d03fffc6 100644 --- a/src/util.c +++ b/src/util.c @@ -30,6 +30,7 @@ #endif #include #include +#include #include #ifdef HAVE_TERMIOS_H # include diff --git a/src/util.h b/src/util.h index 3444e90c..7eb894be 100644 --- a/src/util.h +++ b/src/util.h @@ -28,7 +28,6 @@ #ifdef HAVE_TERMIOS_H #include #include -#include #include #include #endif @@ -87,18 +86,6 @@ int ttcooked (void); #define ttcooked() 0 #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) { str[len - 1] = 0;