mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -33,21 +33,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <syslog.h>
|
||||
#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_ */
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,44 @@
|
||||
#ifndef FINIT_HELPERS_H_
|
||||
#define FINIT_HELPERS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#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_ */
|
||||
|
||||
/**
|
||||
|
||||
+2
-4
@@ -23,10 +23,11 @@
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* O_RDONLY et al */
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user