mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00: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 parent
373738f3d1
commit
8e7d1b7bb5
6 files changed
+13
-50
No files matched your search
+1
-1
@@ -63,7 +63,7 @@ finit_SOURCES = api.c cgroup.c cgroup.h \
|
|||||||
exec.c finit.c finit.h \
|
exec.c finit.c finit.h \
|
||||||
stty.c \
|
stty.c \
|
||||||
helpers.c helpers.h \
|
helpers.c helpers.h \
|
||||||
initramfs.c initramfs.h \
|
initramfs.c \
|
||||||
iwatch.c iwatch.h \
|
iwatch.c iwatch.h \
|
||||||
log.c log.h \
|
log.c log.h \
|
||||||
mdadm.c mount.c \
|
mdadm.c mount.c \
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
#include "cond.h"
|
#include "cond.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "initramfs.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
@@ -250,7 +249,7 @@ static void bypass_shutdown(void *unused)
|
|||||||
* Handle switch_root API command.
|
* Handle switch_root API command.
|
||||||
* Parses data: "newroot\0newinit\0"
|
* Parses data: "newroot\0newinit\0"
|
||||||
* Sends ACK before attempting switch_root since it doesn't return on success.
|
* 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)
|
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
|
* Send ACK first, since we won't return from
|
||||||
* do_switch_root() on success.
|
* switch_root() on success.
|
||||||
*/
|
*/
|
||||||
rq->cmd = INIT_CMD_ACK;
|
rq->cmd = INIT_CMD_ACK;
|
||||||
if (write(sd, rq, sizeof(*rq)) != sizeof(*rq))
|
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);
|
close(sd);
|
||||||
|
|
||||||
/* This does not return on success */
|
/* This does not return on success */
|
||||||
result = do_switch_root(newroot, newinit);
|
result = switch_root(newroot, newinit);
|
||||||
if (result)
|
if (result)
|
||||||
logit(LOG_ERR, "switch_root failed: %s", strerror(errno));
|
logit(LOG_ERR, "switch_root failed: %s", strerror(errno));
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -43,7 +43,6 @@
|
|||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
#include "cond.h"
|
#include "cond.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "initramfs.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "private.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.
|
* This function does not return on success - it exec's the new init.
|
||||||
* On failure, it returns -1 and sets errno.
|
* 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;
|
struct stat newroot_st, oldroot_st;
|
||||||
char init_path[PATH_MAX];
|
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) */
|
/* Kill remaining processes (except kernel threads and ourselves) */
|
||||||
signo = SIGTERM;
|
signo = SIGTERM;
|
||||||
do_iterate_proc(kill_cb, &signo);
|
iterate_proc(kill_cb, &signo);
|
||||||
do_usleep(500000); /* Give them 500ms */
|
do_usleep(500000); /* Give them 500ms */
|
||||||
|
|
||||||
signo = SIGKILL;
|
signo = SIGKILL;
|
||||||
do_iterate_proc(kill_cb, &signo);
|
iterate_proc(kill_cb, &signo);
|
||||||
|
|
||||||
/* Reap zombies */
|
/* Reap zombies */
|
||||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
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);
|
int plugin_init (uev_ctx_t *ctx);
|
||||||
void plugin_exit (void);
|
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_ */
|
#endif /* FINIT_PRIVATE_H_ */
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ static void fs_swapoff(void)
|
|||||||
*
|
*
|
||||||
* https://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons/
|
* 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;
|
DIR *dirp;
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ static int do_wait(int secs)
|
|||||||
;
|
;
|
||||||
has_proc = 0;
|
has_proc = 0;
|
||||||
iterations--;
|
iterations--;
|
||||||
do_iterate_proc(status_cb, &has_proc);
|
iterate_proc(status_cb, &has_proc);
|
||||||
}
|
}
|
||||||
while (has_proc && iterations > 0);
|
while (has_proc && iterations > 0);
|
||||||
|
|
||||||
@@ -322,10 +322,10 @@ void do_shutdown(shutop_t op)
|
|||||||
* Tell remaining non-monitored processes to exit, give them
|
* Tell remaining non-monitored processes to exit, give them
|
||||||
* time to exit gracefully, 2 sec was customary, we go for 1.
|
* 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)) {
|
if (do_wait(1)) {
|
||||||
signo = SIGKILL;
|
signo = SIGKILL;
|
||||||
do_iterate_proc(kill_cb, &signo);
|
iterate_proc(kill_cb, &signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit plugins gracefully */
|
/* Exit plugins gracefully */
|
||||||
|
|||||||
Reference in new issue
Block a user