summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-09 21:33:04 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-17 01:55:48 -0400
commite0aa3726103448097e5ad7cc6f427e142103a321 (patch)
tree599a0280de5998c9a1ca7c52ad631fda20818e0f
parent6cf487afad4ef4706b5d6d9ba5df24cac68e687a (diff)
activate: export make_socket_fd
Also improve logging to print out the parsed address on error.
-rw-r--r--src/activate/activate.c21
-rw-r--r--src/shared/socket-label.c30
-rw-r--r--src/shared/socket-util.h1
3 files changed, 32 insertions, 20 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c
index 23c484ca96..8c58273997 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -59,25 +59,6 @@ static int add_epoll(int epoll_fd, int fd) {
return 0;
}
-static int make_socket_fd(const char* address, int flags) {
- SocketAddress a;
- int fd, r;
-
- r = socket_address_parse(&a, address);
- if (r < 0) {
- log_error("Failed to parse socket: %s", strerror(-r));
- return r;
- }
-
- fd = socket_address_listen(&a, flags, SOMAXCONN, SOCKET_ADDRESS_DEFAULT, NULL, false, false, 0755, 0644, NULL);
- if (fd < 0) {
- log_error("Failed to listen: %s", strerror(-r));
- return fd;
- }
-
- return fd;
-}
-
static int open_sockets(int *epoll_fd, bool accept) {
char **address;
int n, fd, r;
@@ -119,7 +100,7 @@ static int open_sockets(int *epoll_fd, bool accept) {
STRV_FOREACH(address, arg_listen) {
- fd = make_socket_fd(*address, SOCK_STREAM | (arg_accept*SOCK_CLOEXEC));
+ fd = make_socket_fd(LOG_DEBUG, *address, SOCK_STREAM | (arg_accept*SOCK_CLOEXEC));
if (fd < 0) {
log_open();
log_error("Failed to open '%s': %s", *address, strerror(-fd));
diff --git a/src/shared/socket-label.c b/src/shared/socket-label.c
index c8be17a1d5..1e78dd2569 100644
--- a/src/shared/socket-label.c
+++ b/src/shared/socket-label.c
@@ -143,3 +143,33 @@ int socket_address_listen(
return r;
}
+
+int make_socket_fd(int log_level, const char* address, int flags) {
+ SocketAddress a;
+ int fd, r;
+
+ r = socket_address_parse(&a, address);
+ if (r < 0) {
+ log_error("Failed to parse socket: %s", strerror(-r));
+ return r;
+ }
+
+ fd = socket_address_listen(&a, flags, SOMAXCONN, SOCKET_ADDRESS_DEFAULT,
+ NULL, false, false, 0755, 0644, NULL);
+ if (fd < 0 || log_get_max_level() >= log_level) {
+ char _cleanup_free_ *p = NULL;
+
+ r = socket_address_print(&a, &p);
+ if (r < 0) {
+ log_error("socket_address_print(): %s", strerror(-r));
+ return r;
+ }
+
+ if (fd < 0)
+ log_error("Failed to listen on %s: %s", p, strerror(-r));
+ else
+ log_full(log_level, "Listening on %s", p);
+ }
+
+ return fd;
+}
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index 84ebc302fe..efaaf82ab1 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -84,6 +84,7 @@ int socket_address_listen(
mode_t directory_mode,
mode_t socket_mode,
const char *label);
+int make_socket_fd(int log_level, const char* address, int flags);
bool socket_address_is(const SocketAddress *a, const char *s, int type);
bool socket_address_is_netlink(const SocketAddress *a, const char *s);