summaryrefslogtreecommitdiff
path: root/src/socket-proxy
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-23 05:11:31 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-11-23 06:22:30 +0900
commita160567e20ab067cd7ff793bc649c8f8b677965c (patch)
treeb7c4483d54f6eaea8b98bddcd31156dbac9cb5c9 /src/socket-proxy
parentdd2fd972b7a13cbadf1f0d426640dccbe3b7796f (diff)
downloadsystemd-a160567e20ab067cd7ff793bc649c8f8b677965c.tar.gz
socket-proxy: define main through macro
Diffstat (limited to 'src/socket-proxy')
-rw-r--r--src/socket-proxy/socket-proxyd.c59
1 files changed, 24 insertions, 35 deletions
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index 62b7051073..47a2156aa2 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -18,6 +18,7 @@
#include "alloc-util.h"
#include "fd-util.h"
#include "log.h"
+#include "main-func.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
@@ -74,7 +75,7 @@ static void connection_free(Connection *c) {
free(c);
}
-static void context_free(Context *context) {
+static void context_clear(Context *context) {
assert(context);
set_free_with_destructor(context->listen, sd_event_source_unref);
@@ -616,8 +617,8 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
-int main(int argc, char *argv[]) {
- Context context = {};
+static int run(int argc, char *argv[]) {
+ _cleanup_(context_clear) Context context = {};
int r, n, fd;
log_parse_environment();
@@ -625,53 +626,41 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv);
if (r <= 0)
- goto finish;
+ return r;
r = sd_event_default(&context.event);
- if (r < 0) {
- log_error_errno(r, "Failed to allocate event loop: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate event loop: %m");
r = sd_resolve_default(&context.resolve);
- if (r < 0) {
- log_error_errno(r, "Failed to allocate resolver: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate resolver: %m");
r = sd_resolve_attach_event(context.resolve, context.event, 0);
- if (r < 0) {
- log_error_errno(r, "Failed to attach resolver: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to attach resolver: %m");
sd_event_set_watchdog(context.event, true);
- n = sd_listen_fds(1);
- if (n < 0) {
- log_error("Failed to receive sockets from parent.");
- r = n;
- goto finish;
- } else if (n == 0) {
- log_error("Didn't get any sockets passed in.");
- r = -EINVAL;
- goto finish;
- }
+ r = sd_listen_fds(1);
+ if (r < 0)
+ return log_error_errno(r, "Failed to receive sockets from parent.");
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Didn't get any sockets passed in.");
+
+ n = r;
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
r = add_listen_socket(&context, fd);
if (r < 0)
- goto finish;
+ return r;
}
r = sd_event_loop(context.event);
- if (r < 0) {
- log_error_errno(r, "Failed to run event loop: %m");
- goto finish;
- }
-
-finish:
- context_free(&context);
+ if (r < 0)
+ return log_error_errno(r, "Failed to run event loop: %m");
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return 0;
}
+
+DEFINE_MAIN_FUNCTION(run);