From 06759d354405b79edd9d5cb57c50b3a668fac3c0 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 27 Sep 2012 22:10:00 +0200 Subject: [PATCH] Streamline plugin include files plugin.h, svc.h, and helpers.h Move utility macros from finit.h to helpers.h and continue refactoring and streamlining of public plugin API. Signed-off-by: Joachim Nilsson --- Makefile | 7 ++++++- finit.h | 43 ------------------------------------------- helpers.h | 41 +++++++++++++++++++++++++++++++++++++++++ plugins/initctl.c | 6 ++---- svc.c | 2 +- svc.h | 4 +--- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index a1c389a8..84cf295c 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,10 @@ mandir = $(prefix)/share/man/man8 # Plugin directory, fall back to this directory if unset in environment PLUGIN_DIR ?= $(prefix)/lib/finit/plugins +# The initctl FIFO, should probably be in /run, not /dev +FINIT_FIFO ?= /dev/initctl +FINIT_CONF ?= $(sysconfdir)/finit.conf +FINIT_RCSD ?= $(sysconfdir)/finit.d #VERSION ?= $(shell git tag -l | tail -1) VERSION ?= 1.2 @@ -49,7 +53,8 @@ CFLAGS += -W -Wall -Werror -Os CPPFLAGS += -U_FORTIFY_SOURCE CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\" -CPPFLAGS += -DPLUGIN_PATH=\"$(PLUGIN_DIR)\" +CPPFLAGS += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\" +CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(PLUGIN_DIR)\" LDFLAGS += -rdynamic LDLIBS += -ldl diff --git a/finit.h b/finit.h index 5367d485..458979ed 100644 --- a/finit.h +++ b/finit.h @@ -33,21 +33,6 @@ #include #include -#include -#define DO_LOG(level, fmt, args...) \ -{ \ - openlog("finit", LOG_CONS | LOG_PID, LOG_DAEMON); \ - syslog(LOG_DEBUG, fmt, ##args); \ - closelog(); \ -} - -#define DEBUG(fmt, args...) DO_LOG(LOG_DEBUG, fmt, ##args) -#define ERROR(fmt, args...) DO_LOG(LOG_CRIT, fmt, ##args) - -#define FINIT_FIFO "/dev/initctl" -#define FINIT_CONF "/etc/finit.conf" -#define FINIT_RCSD "/etc/finit.d" - /* Distribution configuration */ #if defined EMBEDDED_SYSTEM @@ -79,42 +64,14 @@ #define USERNAME_SIZE 16 #define HOSTNAME_SIZE 32 -#ifndef touch -# define touch(x) mknod((x), S_IFREG|0644, 0) -#endif -#ifndef chardev -# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min))) -#endif -#ifndef blkdev -# define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min))) -#endif -#ifndef fexist -# define fexist(x) (access(x, F_OK) != -1) -#endif - -#ifndef UNUSED -#define UNUSED(x) UNUSED_ ## x __attribute__ ((unused)) -#endif - -#define echo(fmt, args...) do { if (1) { fprintf(stderr, fmt "\n", ##args); } } while (0) -#define _d(fmt, args...) do { if (debug) { fprintf(stderr, "finit:%s() - " fmt "\n", __func__, ##args); } } while (0) -#define _e(fmt, args...) do { fprintf(stderr, "finit:%s() - " fmt "\n", __func__, ##args); } while (0) -#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s() - " fmt ". Error %d: %s\n", __func__, ##args, errno, strerror(errno)); } while (0) - -extern int debug; -extern int verbose; extern char *sdown; extern char *network; extern char *hostname; extern char *username; -/* strlcpy.c */ -size_t strlcpy(char *dst, const char *src, size_t siz); - /* conf.c */ void parse_finit_conf(char *file); - #endif /* FINIT_H_ */ /** diff --git a/helpers.h b/helpers.h index 35b57e2b..eab2b87e 100644 --- a/helpers.h +++ b/helpers.h @@ -25,6 +25,44 @@ #ifndef FINIT_HELPERS_H_ #define FINIT_HELPERS_H_ +#include +#include + +#define DO_LOG(level, fmt, args...) \ +{ \ + openlog("finit", LOG_CONS | LOG_PID, LOG_DAEMON); \ + syslog(LOG_DEBUG, fmt, ##args); \ + closelog(); \ +} + +#define DEBUG(fmt, args...) DO_LOG(LOG_DEBUG, fmt, ##args) +#define ERROR(fmt, args...) DO_LOG(LOG_CRIT, fmt, ##args) + +#ifndef touch +# define touch(x) mknod((x), S_IFREG|0644, 0) +#endif +#ifndef chardev +# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min))) +#endif +#ifndef blkdev +# define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min))) +#endif +#ifndef fexist +# define fexist(x) (access(x, F_OK) != -1) +#endif + +#ifndef UNUSED +#define UNUSED(x) UNUSED_ ## x __attribute__ ((unused)) +#endif + +#define echo(fmt, args...) do { if (1) { fprintf(stderr, fmt "\n", ##args); } } while (0) +#define _d(fmt, args...) do { if (debug) { fprintf(stderr, "finit:%s() - " fmt "\n", __func__, ##args); } } while (0) +#define _e(fmt, args...) do { fprintf(stderr, "finit:%s() - " fmt "\n", __func__, ##args); } while (0) +#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s() - " fmt ". Error %d: %s\n", __func__, ##args, errno, strerror(errno)); } while (0) + +extern int debug; +extern int verbose; + int makepath (char *path); void ifconfig (char *ifname, char *addr, char *mask, int up); void copyfile (char *src, char *dst, int size); @@ -52,6 +90,9 @@ int run_interactive (char *cmd, char *fmt, ...); pid_t run_getty (char *cmd, char *argv[]); int run_parts (char *dir, ...); +/* strlcpy.c */ +size_t strlcpy(char *dst, const char *src, size_t siz); + #endif /* FINIT_HELPERS_H_ */ /** diff --git a/plugins/initctl.c b/plugins/initctl.c index fba0fdd9..e7b2efa2 100644 --- a/plugins/initctl.c +++ b/plugins/initctl.c @@ -23,10 +23,11 @@ */ #include +#include /* O_RDONLY et al */ #include #include -#include "finit.h" +#include "helpers.h" #include "plugin.h" #define INIT_MAGIC 0x03091969 @@ -40,7 +41,6 @@ struct init_request { char data[368]; }; -#ifdef LISTEN_INITCTL /* Standard reboot/shutdown utilities talk to init using /dev/initctl. * We should check if the fifo was recreated and reopen it. */ @@ -109,8 +109,6 @@ PLUGIN_EXIT(plugin_exit) plugin_unregister(&plugin); } -#endif /* LISTEN_INITCTL */ - /** * Local Variables: * version-control: t diff --git a/svc.c b/svc.c index 44b7db3e..62bbf53b 100644 --- a/svc.c +++ b/svc.c @@ -46,7 +46,7 @@ static void __connect_shm(void) if (!services) { /* This should never happen, but if it does we're probably * knee-deep in more serious problems already... */ - _e("Failed setting up shared memory for service monitor.\n"); + _e("Failed allocating shared memory, error %d: %s", errno, strerror (errno)); abort(); } } diff --git a/svc.h b/svc.h index 909c931e..b82774a3 100644 --- a/svc.h +++ b/svc.h @@ -72,10 +72,8 @@ static inline svc_t *finit_svc_connect(void) if ((void *)-1 == ptr) { ptr = shmat (shmget (ID, sizeof(svc_t) * MAX_NUM_SVC, 0600 | IPC_CREAT), NULL, 0); - if ((void *)-1 == ptr) { - _d("Failed allocating shared memory, error %d: %s", errno, strerror (errno)); + if ((void *)-1 == ptr) return NULL; - } } return (svc_t *)ptr;