mirror of
https://github.com/troglobit/finit.git
synced 2026-10-09 16:50:59 +07: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:
+2
-1
@@ -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)
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "cgutil.h"
|
||||
#include "initctl.h"
|
||||
#include "log.h"
|
||||
|
||||
#define CDIM plain ? "" : "\e[2m"
|
||||
#define CRST plain ? "" : "\e[0m"
|
||||
|
||||
+15
-15
@@ -27,7 +27,7 @@
|
||||
#include <sys/un.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
+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)
|
||||
{
|
||||
if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) {
|
||||
_w("Failed creating %s properly.", path);
|
||||
warnx("Failed creating %s properly.", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <paths.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
@@ -31,6 +31,35 @@
|
||||
#define LOG_CONSOLE (14<<3)
|
||||
#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() <--
|
||||
* ~~~~~~~~~~~
|
||||
@@ -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_ */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#endif
|
||||
#include <regex.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
|
||||
-13
@@ -28,7 +28,6 @@
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <termios.h>
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user