mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Refactor: drop do_ prefix from iterate_proc() and switch_root()
The do_ prefix is conventionally reserved for local helper functions. Move switch_root() declaration to private.h alongside iterate_proc() and remove the now-empty initramfs.h header.
This commit is contained in:
+1
-1
@@ -63,7 +63,7 @@ finit_SOURCES = api.c cgroup.c cgroup.h \
|
||||
exec.c finit.c finit.h \
|
||||
stty.c \
|
||||
helpers.c helpers.h \
|
||||
initramfs.c initramfs.h \
|
||||
initramfs.c \
|
||||
iwatch.c iwatch.h \
|
||||
log.c log.h \
|
||||
mdadm.c mount.c \
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "cond.h"
|
||||
#include "conf.h"
|
||||
#include "helpers.h"
|
||||
#include "initramfs.h"
|
||||
#include "log.h"
|
||||
#include "plugin.h"
|
||||
#include "private.h"
|
||||
@@ -250,7 +249,7 @@ static void bypass_shutdown(void *unused)
|
||||
* Handle switch_root API command.
|
||||
* Parses data: "newroot\0newinit\0"
|
||||
* Sends ACK before attempting switch_root since it doesn't return on success.
|
||||
* Returns: result from do_switch_root() on failure, doesn't return on success.
|
||||
* Returns: result from switch_root() on failure, doesn't return on success.
|
||||
*/
|
||||
static int do_switch_root_api(int sd, struct init_request *rq)
|
||||
{
|
||||
@@ -271,7 +270,7 @@ static int do_switch_root_api(int sd, struct init_request *rq)
|
||||
|
||||
/*
|
||||
* Send ACK first, since we won't return from
|
||||
* do_switch_root() on success.
|
||||
* switch_root() on success.
|
||||
*/
|
||||
rq->cmd = INIT_CMD_ACK;
|
||||
if (write(sd, rq, sizeof(*rq)) != sizeof(*rq))
|
||||
@@ -279,7 +278,7 @@ static int do_switch_root_api(int sd, struct init_request *rq)
|
||||
close(sd);
|
||||
|
||||
/* This does not return on success */
|
||||
result = do_switch_root(newroot, newinit);
|
||||
result = switch_root(newroot, newinit);
|
||||
if (result)
|
||||
logit(LOG_ERR, "switch_root failed: %s", strerror(errno));
|
||||
|
||||
|
||||
+3
-4
@@ -43,7 +43,6 @@
|
||||
#include "finit.h"
|
||||
#include "cond.h"
|
||||
#include "helpers.h"
|
||||
#include "initramfs.h"
|
||||
#include "log.h"
|
||||
#include "plugin.h"
|
||||
#include "private.h"
|
||||
@@ -142,7 +141,7 @@ static int kill_cb(int pid, void *data)
|
||||
* This function does not return on success - it exec's the new init.
|
||||
* On failure, it returns -1 and sets errno.
|
||||
*/
|
||||
int do_switch_root(const char *newroot, const char *newinit)
|
||||
int switch_root(const char *newroot, const char *newinit)
|
||||
{
|
||||
struct stat newroot_st, oldroot_st;
|
||||
char init_path[PATH_MAX];
|
||||
@@ -209,11 +208,11 @@ int do_switch_root(const char *newroot, const char *newinit)
|
||||
|
||||
/* Kill remaining processes (except kernel threads and ourselves) */
|
||||
signo = SIGTERM;
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
iterate_proc(kill_cb, &signo);
|
||||
do_usleep(500000); /* Give them 500ms */
|
||||
|
||||
signo = SIGKILL;
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
iterate_proc(kill_cb, &signo);
|
||||
|
||||
/* Reap zombies */
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* Initramfs switch_root support
|
||||
*
|
||||
* Copyright (c) 2008-2025 Joachim Wiberg <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.
|
||||
*/
|
||||
|
||||
#ifndef FINIT_INITRAMFS_H_
|
||||
#define FINIT_INITRAMFS_H_
|
||||
|
||||
int do_switch_root(const char *newroot, const char *newinit);
|
||||
|
||||
#endif /* FINIT_INITRAMFS_H_ */
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
+2
-1
@@ -59,7 +59,8 @@ void plugin_script_run(hook_point_t no);
|
||||
int plugin_init (uev_ctx_t *ctx);
|
||||
void plugin_exit (void);
|
||||
|
||||
void do_iterate_proc (int (*cb)(int, void *), void *data);
|
||||
void iterate_proc (int (*cb)(int, void *), void *data);
|
||||
int switch_root (const char *newroot, const char *newinit);
|
||||
|
||||
#endif /* FINIT_PRIVATE_H_ */
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ static void fs_swapoff(void)
|
||||
*
|
||||
* https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/
|
||||
*/
|
||||
void do_iterate_proc(int (*cb)(int, void *), void *data)
|
||||
void iterate_proc(int (*cb)(int, void *), void *data)
|
||||
{
|
||||
DIR *dirp;
|
||||
|
||||
@@ -290,7 +290,7 @@ static int do_wait(int secs)
|
||||
;
|
||||
has_proc = 0;
|
||||
iterations--;
|
||||
do_iterate_proc(status_cb, &has_proc);
|
||||
iterate_proc(status_cb, &has_proc);
|
||||
}
|
||||
while (has_proc && iterations > 0);
|
||||
|
||||
@@ -322,10 +322,10 @@ void do_shutdown(shutop_t op)
|
||||
* Tell remaining non-monitored processes to exit, give them
|
||||
* time to exit gracefully, 2 sec was customary, we go for 1.
|
||||
*/
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
iterate_proc(kill_cb, &signo);
|
||||
if (do_wait(1)) {
|
||||
signo = SIGKILL;
|
||||
do_iterate_proc(kill_cb, &signo);
|
||||
iterate_proc(kill_cb, &signo);
|
||||
}
|
||||
|
||||
/* Exit plugins gracefully */
|
||||
|
||||
Reference in New Issue
Block a user