summaryrefslogtreecommitdiff
path: root/src/shared/socket-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-23 17:52:04 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-02-27 22:10:14 -0500
commit2ca0435be9359bde3020eeb528c2a6d72ac1e0b0 (patch)
treed59e868fb0881a72d6ea3aca46b797b1eb907239 /src/shared/socket-util.c
parent5674767ec2cf7d168fe9c30f78074231fbe3408c (diff)
systemd-activate: add a socket-activation test tool
Diffstat (limited to 'src/shared/socket-util.c')
-rw-r--r--src/shared/socket-util.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 6c94d69486..f6ddea3183 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -565,6 +565,45 @@ bool socket_address_matches_fd(const SocketAddress *a, int fd) {
return false;
}
+int make_socket_fd(const char* address, int flags) {
+ SocketAddress a;
+ int fd, r;
+ char _cleanup_free_ *p = NULL;
+
+ r = socket_address_parse(&a, address);
+ if (r < 0) {
+ log_error("failed to parse socket: %s", strerror(-r));
+ return r;
+ }
+
+ fd = socket(socket_address_family(&a), flags, 0);
+ if (fd < 0) {
+ log_error("socket(): %m");
+ return -errno;
+ }
+
+ r = socket_address_print(&a, &p);
+ if (r < 0) {
+ log_error("socket_address_print(): %s", strerror(-r));
+ return r;
+ }
+ log_info("Listening on %s", p);
+
+ r = bind(fd, &a.sockaddr.sa, a.size);
+ if (r < 0) {
+ log_error("bind to %s: %m", address);
+ return -errno;
+ }
+
+ r = listen(fd, SOMAXCONN);
+ if (r < 0) {
+ log_error("listen on %s: %m", address);
+ return -errno;
+ }
+
+ return fd;
+}
+
static const char* const netlink_family_table[] = {
[NETLINK_ROUTE] = "route",
[NETLINK_FIREWALL] = "firewall",