From 09caead4ae14c868cee0ad71f8bb8648746a81a0 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 6 Dec 2013 19:51:57 +0000 Subject: [PATCH] fcoemon: systemd socket activation Implement systemd socket activation on the CLIF socket. Signed-off-by: Hannes Reinecke Signed-off-by: Robert Love --- Makefile.am | 2 +- etc/systemd/fcoe.service | 3 ++- etc/systemd/fcoemon.socket | 6 ++++++ fcoemon.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 etc/systemd/fcoemon.socket diff --git a/Makefile.am b/Makefile.am index 012b560..e7df6f5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,7 @@ dist_fcoe_config_DATA = etc/cfg-ethx ## install systemd service files if HAVE_SYSTEMD -systemdsystemunit_DATA = etc/systemd/fcoe.service +systemdsystemunit_DATA = etc/systemd/fcoe.service etc/systemd/fcoemon.socket endif ## man pages for fcoeadm and fcoemon diff --git a/etc/systemd/fcoe.service b/etc/systemd/fcoe.service index 4834e43..5e5c8a2 100644 --- a/etc/systemd/fcoe.service +++ b/etc/systemd/fcoe.service @@ -3,7 +3,7 @@ Description=Open-FCoE initiator daemon After=syslog.target network.target [Service] -Type=forking +Type=simple EnvironmentFile=/etc/sysconfig/fcoe ExecStartPre=/sbin/modprobe -qa $SUPPORTED_DRIVERS ExecStart=/usr/sbin/fcoemon $FCOEMON_OPTS @@ -11,3 +11,4 @@ ExecStart=/usr/sbin/fcoemon $FCOEMON_OPTS [Install] WantedBy=multi-user.target Also=lldpad.socket +Also=fcoemon.socket diff --git a/etc/systemd/fcoemon.socket b/etc/systemd/fcoemon.socket new file mode 100644 index 0000000..4de8715 --- /dev/null +++ b/etc/systemd/fcoemon.socket @@ -0,0 +1,6 @@ +[Socket] +ListenDatagram=@/com/intel/fcoemon +PassCredentials=true + +[Install] +WantedBy=sockets.target diff --git a/fcoemon.c b/fcoemon.c index be4c74d..5e4f8d7 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -3546,12 +3546,54 @@ err: sendto(snum, rbuf, MSG_RBUF, 0, (struct sockaddr *)&from, fromlen); } +static int fcm_systemd_socket(void) +{ + char *env, *ptr; + unsigned int p, l; + + env = getenv("LISTEN_PID"); + if (!env) + return -1; + + p = strtoul(env, &ptr, 10); + if (ptr && ptr == env) { + FCM_LOG_DBG("Invalid value '%s' for LISTEN_PID\n", env); + return -1; + } + if ((pid_t)p != getpid()) { + FCM_LOG_DBG("Invalid PID '%d' from LISTEN_PID\n", p); + return -1; + } + env = getenv("LISTEN_FDS"); + if (!env) { + FCM_LOG_DBG("LISTEN_FDS is not set\n"); + return -1; + } + l = strtoul(env, &ptr, 10); + if (ptr && ptr == env) { + FCM_LOG_DBG("Invalid value '%s' for LISTEN_FDS\n", env); + return -1; + } + if (l != 1) { + FCM_LOG_DBG("LISTEN_FDS specified %d fds\n", l); + return -1; + } + /* systemd returns fds with an offset of '3' */ + return 3; +} + static int fcm_srv_create(struct fcm_srv_info *srv_info) { socklen_t addrlen; struct sockaddr_un addr; int rc = 0; + srv_info->srv_sock = fcm_systemd_socket(); + if (srv_info->srv_sock > 0) { + FCM_LOG_DBG("Using systemd socket\n"); + goto out_done; + } + srv_info->srv_sock = socket(AF_LOCAL, SOCK_DGRAM, 0); if (srv_info->srv_sock < 0) { FCM_LOG_ERR(errno, "Failed to create socket\n"); @@ -3570,7 +3612,7 @@ static int fcm_srv_create(struct fcm_srv_info *srv_info) rc = errno; goto err_close; } - +out_done: sa_select_add_fd(srv_info->srv_sock, fcm_srv_receive, NULL, NULL, srv_info); -- 1.7.1