summaryrefslogtreecommitdiffstats
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-03-21 18:08:27 +0100
committerGitHub <noreply@github.com>2019-03-21 18:08:27 +0100
commitc82cfae00b5a1be59f556ca05576f69db9c4d1ab (patch)
treef7b06f8f5602a1519dc35cc5312ac88a2e31a4e3 /src/nspawn
parentnspawn: add --no-pager switch (diff)
parentnspawn: voidify sd_notify() calls (diff)
downloadsystemd-c82cfae00b5a1be59f556ca05576f69db9c4d1ab.tar.xz
systemd-c82cfae00b5a1be59f556ca05576f69db9c4d1ab.zip
Merge pull request #12062 from poettering/nspawn-main-func
nspawn: port to DEFINE_MAIN_FUNCTION()
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn.c109
1 files changed, 58 insertions, 51 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index a753c806fd..f3842f70c6 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -57,6 +57,7 @@
#include "loopback-setup.h"
#include "machine-image.h"
#include "macro.h"
+#include "main-func.h"
#include "missing.h"
#include "mkdir.h"
#include "mount-util.h"
@@ -120,7 +121,7 @@
typedef enum ContainerStatus {
CONTAINER_TERMINATED,
- CONTAINER_REBOOTED
+ CONTAINER_REBOOTED,
} ContainerStatus;
static char *arg_directory = NULL;
@@ -229,6 +230,38 @@ static size_t arg_n_extra_nodes = 0;
static char **arg_sysctl = NULL;
static ConsoleMode arg_console_mode = _CONSOLE_MODE_INVALID;
+STATIC_DESTRUCTOR_REGISTER(arg_directory, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_template, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_chdir, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_pivot_root_new, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_pivot_root_old, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_user, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_supplementary_gids, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_machine, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_hostname, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_slice, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_setenv, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_interfaces, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_macvlan, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_ipvlan, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_veth_extra, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_bridge, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_zone, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_network_namespace_path, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_oci_bundle, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_property_message, sd_bus_message_unrefp);
+STATIC_DESTRUCTOR_REGISTER(arg_parameters, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_root_hash, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_syscall_whitelist, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_syscall_blacklist, strv_freep);
+#if HAVE_SECCOMP
+STATIC_DESTRUCTOR_REGISTER(arg_seccomp, seccomp_releasep);
+#endif
+STATIC_DESTRUCTOR_REGISTER(arg_cpuset, CPU_FREEp);
+STATIC_DESTRUCTOR_REGISTER(arg_sysctl, strv_freep);
+
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
@@ -3591,11 +3624,11 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
return log_oom();
if (strv_find(tags, "READY=1"))
- sd_notifyf(false, "READY=1\n");
+ (void) sd_notifyf(false, "READY=1\n");
p = strv_find_startswith(tags, "STATUS=");
if (p)
- sd_notifyf(false, "STATUS=Container running: %s", p);
+ (void) sd_notifyf(false, "STATUS=Container running: %s", p);
return 0;
}
@@ -4027,7 +4060,7 @@ static int load_oci_bundle(void) {
return merge_settings(settings, arg_oci_bundle);
}
-static int run(int master,
+static int run_container(int master,
const char* console,
DissectedImage *dissected_image,
bool secondary,
@@ -4447,9 +4480,9 @@ static int run(int master,
* will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */
etc_passwd_lock = safe_close(etc_passwd_lock);
- sd_notifyf(false,
- "STATUS=Container running.\n"
- "X_NSPAWN_LEADER_PID=" PID_FMT, *pid);
+ (void) sd_notifyf(false,
+ "STATUS=Container running.\n"
+ "X_NSPAWN_LEADER_PID=" PID_FMT, *pid);
if (!arg_notify_ready)
(void) sd_notify(false, "READY=1\n");
@@ -4615,7 +4648,7 @@ static int initialize_rlimits(void) {
return 0;
}
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
_cleanup_free_ char *console = NULL;
_cleanup_close_ int master = -1;
_cleanup_fdset_free_ FDSet *fds = NULL;
@@ -4972,22 +5005,22 @@ int main(int argc, char *argv[]) {
}
for (;;) {
- r = run(master,
- console,
- dissected_image,
- secondary,
- fds,
- veth_name, &veth_created,
- &exposed,
- &pid, &ret);
+ r = run_container(master,
+ console,
+ dissected_image,
+ secondary,
+ fds,
+ veth_name, &veth_created,
+ &exposed,
+ &pid, &ret);
if (r <= 0)
break;
}
finish:
- sd_notify(false,
- r == 0 && ret == EXIT_FORCE_RESTART ? "STOPPING=1\nSTATUS=Restarting..." :
- "STOPPING=1\nSTATUS=Terminating...");
+ (void) sd_notify(false,
+ r == 0 && ret == EXIT_FORCE_RESTART ? "STOPPING=1\nSTATUS=Restarting..." :
+ "STOPPING=1\nSTATUS=Terminating...");
if (pid > 0)
(void) kill(pid, SIGKILL);
@@ -5034,41 +5067,15 @@ finish:
(void) remove_veth_links(veth_name, arg_network_veth_extra);
(void) remove_bridge(arg_network_zone);
- free(arg_directory);
- free(arg_template);
- free(arg_image);
- free(arg_machine);
- free(arg_hostname);
- free(arg_user);
- free(arg_supplementary_gids);
- free(arg_pivot_root_new);
- free(arg_pivot_root_old);
- free(arg_chdir);
- strv_free(arg_setenv);
- free(arg_network_bridge);
- strv_free(arg_network_interfaces);
- strv_free(arg_network_macvlan);
- strv_free(arg_network_ipvlan);
- strv_free(arg_network_veth_extra);
- strv_free(arg_parameters);
- free(arg_network_zone);
- free(arg_network_namespace_path);
- strv_free(arg_property);
- sd_bus_message_unref(arg_property_message);
custom_mount_free_all(arg_custom_mounts, arg_n_custom_mounts);
expose_port_free_all(arg_expose_ports);
- free(arg_root_hash);
rlimit_free_all(arg_rlimit);
- strv_free(arg_syscall_whitelist);
- strv_free(arg_syscall_blacklist);
-#if HAVE_SECCOMP
- seccomp_release(arg_seccomp);
-#endif
- arg_cpuset = cpu_set_mfree(arg_cpuset);
- free(arg_oci_bundle);
device_node_free_many(arg_extra_nodes, arg_n_extra_nodes);
- strv_free(arg_sysctl);
- free(arg_slice);
- return r < 0 ? EXIT_FAILURE : ret;
+ if (r < 0)
+ return r;
+
+ return ret;
}
+
+DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);