lxc-init: use cleanup macros

parent 5c7dbbbe
...@@ -353,6 +353,7 @@ init_lxc_SOURCES = cmd/lxc_init.c \ ...@@ -353,6 +353,7 @@ init_lxc_SOURCES = cmd/lxc_init.c \
compiler.h \ compiler.h \
error.h \ error.h \
initutils.c initutils.h \ initutils.c initutils.h \
memory_utils.h \
parse.c parse.h \ parse.c parse.h \
raw_syscalls.c raw_syscalls.h \ raw_syscalls.c raw_syscalls.h \
string_utils.c string_utils.h string_utils.c string_utils.h
...@@ -401,6 +402,7 @@ init_lxc_static_SOURCES = cmd/lxc_init.c \ ...@@ -401,6 +402,7 @@ init_lxc_static_SOURCES = cmd/lxc_init.c \
file_utils.c file_utils.h \ file_utils.c file_utils.h \
log.c log.h \ log.c log.h \
macro.h \ macro.h \
memory_utils.h \
namespace.c namespace.h \ namespace.c namespace.h \
string_utils.c string_utils.h string_utils.c string_utils.h
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "config.h" #include "config.h"
#include "error.h" #include "error.h"
#include "initutils.h" #include "initutils.h"
#include "memory_utils.h"
#include "parse.h" #include "parse.h"
#include "raw_syscalls.h" #include "raw_syscalls.h"
#include "string_utils.h" #include "string_utils.h"
...@@ -100,10 +101,10 @@ static struct arguments my_args = { ...@@ -100,10 +101,10 @@ static struct arguments my_args = {
static void prevent_forking(void) static void prevent_forking(void)
{ {
FILE *f; __do_free char *line = NULL;
size_t len = 0; __do_fclose FILE *f = NULL;
char *line = NULL;
char path[PATH_MAX]; char path[PATH_MAX];
size_t len = 0;
f = fopen("/proc/self/cgroup", "r"); f = fopen("/proc/self/cgroup", "r");
if (!f) if (!f)
...@@ -138,14 +139,14 @@ static void prevent_forking(void) ...@@ -138,14 +139,14 @@ static void prevent_forking(void)
if (ret < 0 || (size_t)ret >= sizeof(path)) { if (ret < 0 || (size_t)ret >= sizeof(path)) {
if (my_args.quiet) if (my_args.quiet)
fprintf(stderr, "Failed to create string\n"); fprintf(stderr, "Failed to create string\n");
goto on_error; return;
} }
fd = open(path, O_WRONLY); fd = open(path, O_WRONLY);
if (fd < 0) { if (fd < 0) {
if (my_args.quiet) if (my_args.quiet)
fprintf(stderr, "Failed to open \"%s\"\n", path); fprintf(stderr, "Failed to open \"%s\"\n", path);
goto on_error; return;
} }
ret = write(fd, "1", 1); ret = write(fd, "1", 1);
...@@ -153,17 +154,13 @@ static void prevent_forking(void) ...@@ -153,17 +154,13 @@ static void prevent_forking(void)
fprintf(stderr, "Failed to write to \"%s\"\n", path); fprintf(stderr, "Failed to write to \"%s\"\n", path);
close(fd); close(fd);
break; return;
} }
on_error:
free(line);
fclose(f);
} }
static void kill_children(pid_t pid) static void kill_children(pid_t pid)
{ {
FILE *f; __do_fclose FILE *f = NULL;
char path[PATH_MAX]; char path[PATH_MAX];
int ret; int ret;
...@@ -187,15 +184,12 @@ static void kill_children(pid_t pid) ...@@ -187,15 +184,12 @@ static void kill_children(pid_t pid)
if (fscanf(f, "%d ", &find_pid) != 1) { if (fscanf(f, "%d ", &find_pid) != 1) {
if (my_args.quiet) if (my_args.quiet)
fprintf(stderr, "Failed to retrieve pid\n"); fprintf(stderr, "Failed to retrieve pid\n");
fclose(f);
return; return;
} }
(void)kill_children(find_pid); (void)kill_children(find_pid);
(void)kill(find_pid, SIGKILL); (void)kill(find_pid, SIGKILL);
} }
fclose(f);
} }
static void remove_self(void) static void remove_self(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment