mirror of
https://github.com/troglobit/finit.git
synced 2026-11-01 13:10:32 +00: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:
1 parent
ff73dab447
commit
06759d3544
6 files changed
+51
-52
No files matched your search
@@ -34,6 +34,10 @@ mandir = $(prefix)/share/man/man8
|
|||||||
|
|
||||||
# Plugin directory, fall back to this directory if unset in environment
|
# Plugin directory, fall back to this directory if unset in environment
|
||||||
PLUGIN_DIR ?= $(prefix)/lib/finit/plugins
|
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 ?= $(shell git tag -l | tail -1)
|
||||||
VERSION ?= 1.2
|
VERSION ?= 1.2
|
||||||
@@ -49,7 +53,8 @@ CFLAGS += -W -Wall -Werror -Os
|
|||||||
CPPFLAGS += -U_FORTIFY_SOURCE
|
CPPFLAGS += -U_FORTIFY_SOURCE
|
||||||
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
|
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
|
||||||
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
|
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
|
LDFLAGS += -rdynamic
|
||||||
LDLIBS += -ldl
|
LDLIBS += -ldl
|
||||||
|
|
||||||
|
|||||||
@@ -33,21 +33,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.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 */
|
/* Distribution configuration */
|
||||||
|
|
||||||
#if defined EMBEDDED_SYSTEM
|
#if defined EMBEDDED_SYSTEM
|
||||||
@@ -79,42 +64,14 @@
|
|||||||
#define USERNAME_SIZE 16
|
#define USERNAME_SIZE 16
|
||||||
#define HOSTNAME_SIZE 32
|
#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 *sdown;
|
||||||
extern char *network;
|
extern char *network;
|
||||||
extern char *hostname;
|
extern char *hostname;
|
||||||
extern char *username;
|
extern char *username;
|
||||||
|
|
||||||
/* strlcpy.c */
|
|
||||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
|
||||||
|
|
||||||
/* conf.c */
|
/* conf.c */
|
||||||
void parse_finit_conf(char *file);
|
void parse_finit_conf(char *file);
|
||||||
|
|
||||||
|
|
||||||
#endif /* FINIT_H_ */
|
#endif /* FINIT_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,44 @@
|
|||||||
#ifndef FINIT_HELPERS_H_
|
#ifndef FINIT_HELPERS_H_
|
||||||
#define 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);
|
int makepath (char *path);
|
||||||
void ifconfig (char *ifname, char *addr, char *mask, int up);
|
void ifconfig (char *ifname, char *addr, char *mask, int up);
|
||||||
void copyfile (char *src, char *dst, int size);
|
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[]);
|
pid_t run_getty (char *cmd, char *argv[]);
|
||||||
int run_parts (char *dir, ...);
|
int run_parts (char *dir, ...);
|
||||||
|
|
||||||
|
/* strlcpy.c */
|
||||||
|
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
|
|
||||||
#endif /* FINIT_HELPERS_H_ */
|
#endif /* FINIT_HELPERS_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-4
@@ -23,10 +23,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h> /* O_RDONLY et al */
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "finit.h"
|
#include "helpers.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
#define INIT_MAGIC 0x03091969
|
#define INIT_MAGIC 0x03091969
|
||||||
@@ -40,7 +41,6 @@ struct init_request {
|
|||||||
char data[368];
|
char data[368];
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LISTEN_INITCTL
|
|
||||||
/* Standard reboot/shutdown utilities talk to init using /dev/initctl.
|
/* Standard reboot/shutdown utilities talk to init using /dev/initctl.
|
||||||
* We should check if the fifo was recreated and reopen it.
|
* We should check if the fifo was recreated and reopen it.
|
||||||
*/
|
*/
|
||||||
@@ -109,8 +109,6 @@ PLUGIN_EXIT(plugin_exit)
|
|||||||
plugin_unregister(&plugin);
|
plugin_unregister(&plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LISTEN_INITCTL */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* version-control: t
|
* version-control: t
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ static void __connect_shm(void)
|
|||||||
if (!services) {
|
if (!services) {
|
||||||
/* This should never happen, but if it does we're probably
|
/* This should never happen, but if it does we're probably
|
||||||
* knee-deep in more serious problems already... */
|
* 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();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,8 @@ static inline svc_t *finit_svc_connect(void)
|
|||||||
|
|
||||||
if ((void *)-1 == ptr) {
|
if ((void *)-1 == ptr) {
|
||||||
ptr = shmat (shmget (ID, sizeof(svc_t) * MAX_NUM_SVC, 0600 | IPC_CREAT), NULL, 0);
|
ptr = shmat (shmget (ID, sizeof(svc_t) * MAX_NUM_SVC, 0600 | IPC_CREAT), NULL, 0);
|
||||||
if ((void *)-1 == ptr) {
|
if ((void *)-1 == ptr)
|
||||||
_d("Failed allocating shared memory, error %d: %s", errno, strerror (errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (svc_t *)ptr;
|
return (svc_t *)ptr;
|
||||||
|
|||||||
Reference in new issue
Block a user