mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
Restructure start by calling the plugin loader earlier. This makes it
possible to run hooks even earlier. This also adds a new hook:
HOOK_ROOTFS_UP which runs as soon as the system root (/) is available.
Another very notable change is the slow refactor of helpers.c into a finit
helper library called libite.so (-lite). This is a light-weight
Also, lots of misc. fixes all over the place. Signal handling still really
needs to be looked into once more!
Makefile:
Add dependency handling for parallell build
Add libite library
ChangeLog:
Update with new 1.4 release. There is a lot of fixes!
libite/:
Collection of utility functions and C library extensions for
finit & its plugins
reboot.c:
New reboot tool. Simply sends SIGINT to PID 1
finit.h:
Cleanup old LISTEN_INITCTL define, code is in an optional plugin now
finit.c:
Let mdev/udev run *after* cls()
Add useful debug statement for /proc/cmdline
Earlier plugin load => new early hook point
Show OK/FAIL for total plugin load, not for each plugin => speedup
helpers.h:
Rename syslog macros to prevent common name clashes (DEBUG/ERROR)
Add __FILE__ to _e(), _d() and _pe() macros
helpers.c:
In ifconfig() the addr and mask arguments are now optional
The copyfile() has been moved to libite.so
Temporarily remove const directive from some functions to build
Use DFLSIG() macro in run_getty() to simplify code
plugin.h:
Add new HOOK_ROOTFS_UP hook
plugin.c:
Fix init_plugins() to actually register the plugin's I/O fd
Skip verbose listing of all plugins in plugin_load_all()
svc.c:
svc_start(): Dito
plugins/Makefile:
Inherit CFLAGS and LDFLAGS, but make sure to filter out -rdynamic
from LDFLAGS, it's used by the daemon, only
plugins/initctl.c:
New includes after helpers.h refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
121 lines
3.1 KiB
C
121 lines
3.1 KiB
C
/* Optional /dev/initctl FIFO monitor
|
|
*
|
|
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
|
* Copyright (c) 2008-2012 Joachim Nilsson <troglobit@gmail.com>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h> /* O_RDONLY et al */
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <unistd.h> /* read() */
|
|
|
|
#include "helpers.h"
|
|
#include "plugin.h"
|
|
#include "sig.h"
|
|
|
|
#define INIT_MAGIC 0x03091969
|
|
#define INIT_CMD_RUNLVL 1
|
|
|
|
struct init_request {
|
|
int magic; /* Magic number */
|
|
int cmd; /* What kind of request */
|
|
int runlevel; /* Runlevel to change to */
|
|
int sleeptime; /* Time between TERM and KILL */
|
|
char data[368];
|
|
};
|
|
|
|
/* Standard reboot/shutdown utilities talk to init using /dev/initctl.
|
|
* We should check if the fifo was recreated and reopen it.
|
|
*/
|
|
static void read_initctl(void *UNUSED(arg), int fd, int UNUSED(events))
|
|
{
|
|
struct init_request request;
|
|
|
|
_d("Receiving request on %s...", FINIT_FIFO);
|
|
while (1) {
|
|
ssize_t len = read(fd, &request, sizeof(request));
|
|
|
|
if (-1 == len) {
|
|
_d("Error %d", errno);
|
|
break; /* Probably EAGAIN */
|
|
}
|
|
|
|
if (request.magic != INIT_MAGIC)
|
|
continue;
|
|
|
|
_d("Magic OK...");
|
|
if (request.cmd == INIT_CMD_RUNLVL) {
|
|
switch (request.runlevel) {
|
|
case '0':
|
|
_d("Halting system (SIGUSR2)");
|
|
do_shutdown(SIGUSR2);
|
|
break;
|
|
|
|
case '6':
|
|
_d("Rebooting system (SIGUSR1)");
|
|
do_shutdown(SIGUSR1);
|
|
break;
|
|
|
|
default:
|
|
_d("Unsupported runlevel: %d", request.runlevel);
|
|
break;
|
|
}
|
|
} else {
|
|
_d("Unsupported cmd: %d", request.cmd);
|
|
}
|
|
}
|
|
}
|
|
|
|
static plugin_t plugin = {
|
|
.io = {
|
|
.cb = read_initctl,
|
|
.flags = PLUGIN_IO_READ,
|
|
},
|
|
};
|
|
|
|
PLUGIN_INIT(plugin_init)
|
|
{
|
|
_d("Setting up %s", FINIT_FIFO);
|
|
mkfifo(FINIT_FIFO, 0600);
|
|
|
|
plugin.io.fd = open(FINIT_FIFO, O_RDONLY | O_NONBLOCK);
|
|
if (-1 == plugin.io.fd) {
|
|
_e("Failed opening %s FIFO, error %d: %s", FINIT_FIFO, errno, strerror(errno));
|
|
return;
|
|
}
|
|
|
|
plugin_register(&plugin);
|
|
}
|
|
|
|
PLUGIN_EXIT(plugin_exit)
|
|
{
|
|
plugin_unregister(&plugin);
|
|
}
|
|
|
|
/**
|
|
* Local Variables:
|
|
* version-control: t
|
|
* indent-tabs-mode: t
|
|
* c-file-style: "linux"
|
|
* End:
|
|
*/
|