* [PATCH rdma-core 1/8] srp_daemon: Move the setup of the wakeup_pipe after openlog
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2017-07-26 19:59 ` Jason Gunthorpe
[not found] ` <1501099152-6344-2-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-26 19:59 ` [PATCH rdma-core 2/8] srp_daemon: Fix missing free_config for ibsrpdm Jason Gunthorpe
` (6 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Bart Van Assche
Pipe setup failure triggers logging calls which shouldn't happen until
logging has been setup. Instead move this setup to after each of the
two configuration steps.
Bart says that wakeup_pipe[] is not used by ibsrpdm, so this also
drops the pipe setup and signal change from that code path.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
srp_daemon/srp_daemon.c | 98 ++++++++++++++++++++++++++++++-------------------
1 file changed, 60 insertions(+), 38 deletions(-)
diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c
index c0e8d23d58faf5..ec394b686d55ff 100644
--- a/srp_daemon/srp_daemon.c
+++ b/srp_daemon/srp_daemon.c
@@ -1955,6 +1955,58 @@ static void ts_sub(const struct timespec *a, const struct timespec *b,
}
}
+static void cleanup_wakeup_fd(void)
+{
+ struct sigaction sa = {};
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SRP_CATAS_ERR, &sa, NULL);
+
+ close(wakeup_pipe[1]);
+ close(wakeup_pipe[0]);
+ wakeup_pipe[0] = -1;
+ wakeup_pipe[1] = -1;
+}
+
+static int setup_wakeup_fd(void)
+{
+ struct sigaction sa = {};
+ int ret;
+ int i;
+ int flags;
+
+ ret = pipe(wakeup_pipe);
+ if (ret < 0) {
+ pr_err("could not create pipe\n");
+ return -1;
+ }
+ for (i = 0; i < 2; i++) {
+ flags = fcntl(wakeup_pipe[i], F_GETFL);
+ if (flags < 0) {
+ pr_err("fcntl F_GETFL failed for %d\n", wakeup_pipe[i]);
+ goto close_pipe;
+ }
+ if (fcntl(wakeup_pipe[i], F_SETFL, flags | O_NONBLOCK) < 0) {
+ pr_err("fcntl F_SETFL failed for %d\n", wakeup_pipe[i]);
+ goto close_pipe;
+ }
+ }
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = signal_handler;
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+ sigaction(SRP_CATAS_ERR, &sa, NULL);
+ return 0;
+
+close_pipe:
+ cleanup_wakeup_fd();
+ return -1;
+}
+
static int ibsrpdm(int argc, char *argv[])
{
char* umad_dev = NULL;
@@ -2032,13 +2084,12 @@ umad_done:
int main(int argc, char *argv[])
{
- int ret, i, flags;
+ int ret;
struct resources *res;
uint16_t lid;
uint16_t pkey;
union umad_gid gid;
struct target_details *target;
- struct sigaction sa;
int subscribed;
int lockfd = -1;
int received_signal = 0;
@@ -2059,35 +2110,10 @@ int main(int argc, char *argv[])
BUILD_ASSERT(sizeof(struct srp_dm_iou_info) == 132);
BUILD_ASSERT(sizeof(struct srp_dm_ioc_prof) == 128);
- ret = pipe(wakeup_pipe);
- if (ret < 0) {
- pr_err("could not create pipe\n");
- goto out;
- }
- for (i = 0; i < 2; i++) {
- flags = fcntl(wakeup_pipe[i], F_GETFL);
- if (flags < 0) {
- pr_err("fcntl F_GETFL failed for %d\n", wakeup_pipe[i]);
- goto close_pipe;
- }
- if (fcntl(wakeup_pipe[i], F_SETFL, flags | O_NONBLOCK) < 0) {
- pr_err("fcntl F_SETFL failed for %d\n", wakeup_pipe[i]);
- goto close_pipe;
- }
-
- }
-
- memset(&sa, 0, sizeof(sa));
- sigemptyset(&sa.sa_mask);
- sa.sa_handler = signal_handler;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SRP_CATAS_ERR, &sa, NULL);
-
if (strcmp(argv[0] + max_t(int, 0, strlen(argv[0]) - strlen("ibsrpdm")),
"ibsrpdm") == 0) {
ret = ibsrpdm(argc, argv);
- goto restore_sig;
+ goto out;
}
openlog("srp_daemon", LOG_PID | LOG_PERROR, LOG_DAEMON);
@@ -2115,6 +2141,10 @@ int main(int argc, char *argv[])
}
}
+ ret = setup_wakeup_fd();
+ if (ret)
+ goto cleanup_wakeup;
+
catas_start:
subscribed = 0;
@@ -2279,20 +2309,12 @@ clean_umad:
close_lockfd:
if (lockfd >= 0)
close(lockfd);
+cleanup_wakeup:
+ cleanup_wakeup_fd();
free_config:
free_config(config);
close_log:
closelog();
-restore_sig:
- sa.sa_handler = SIG_DFL;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SRP_CATAS_ERR, &sa, NULL);
-close_pipe:
- close(wakeup_pipe[1]);
- close(wakeup_pipe[0]);
- wakeup_pipe[0] = -1;
- wakeup_pipe[1] = -1;
out:
exit(ret ? 1 : 0);
}
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 2/8] srp_daemon: Fix missing free_config for ibsrpdm
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-26 19:59 ` [PATCH rdma-core 1/8] srp_daemon: Move the setup of the wakeup_pipe after openlog Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
[not found] ` <1501099152-6344-3-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-26 19:59 ` [PATCH rdma-core 3/8] srp_daemon: Add a --systemd option Jason Gunthorpe
` (5 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Bart Van Assche
Doesn't really matter since this just exits the process right after.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
srp_daemon/srp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c
index ec394b686d55ff..836e2e5d1487b5 100644
--- a/srp_daemon/srp_daemon.c
+++ b/srp_daemon/srp_daemon.c
@@ -2053,7 +2053,7 @@ static int ibsrpdm(int argc, char *argv[])
ret = set_conf_dev_and_port(umad_dev, config);
if (ret) {
pr_err("Failed to build config\n");
- return 1;
+ goto out;
}
umad_init();
@@ -2076,7 +2076,7 @@ static int ibsrpdm(int argc, char *argv[])
free_res(res);
umad_done:
umad_done();
-
+out:
free_config(config);
return ret;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 3/8] srp_daemon: Add a --systemd option
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-26 19:59 ` [PATCH rdma-core 1/8] srp_daemon: Move the setup of the wakeup_pipe after openlog Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 2/8] srp_daemon: Fix missing free_config for ibsrpdm Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
[not found] ` <1501099152-6344-4-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-26 19:59 ` [PATCH rdma-core 4/8] Consistently open syslog in daemons Jason Gunthorpe
` (4 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Bart Van Assche
This changes how logging is setup to send log messages only to syslog,
instead of to stderr and to syslog. If messages are sent to both
places then systemd will create duplicate log entries.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
srp_daemon/srp_daemon.1.in | 3 +++
srp_daemon/srp_daemon.c | 38 ++++++++++++++++++++++++++++++++--
srp_daemon/srp_daemon_port@.service.in | 2 +-
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/srp_daemon/srp_daemon.1.in b/srp_daemon/srp_daemon.1.in
index 82dc3241ea5e36..0534cf4301a916 100644
--- a/srp_daemon/srp_daemon.1.in
+++ b/srp_daemon/srp_daemon.1.in
@@ -91,6 +91,9 @@ Perform \fIretries\fR retries on each send to MAD (default: 3 retries).
.TP
\fB\-n\fR
New format - use also initiator_ext in the connection command.
+.TP
+\fB\--systemd\fR
+Enable systemd integration.
.SH FILES
@CMAKE_INSTALL_FULL_SYSCONFDIR@/srp_daemon.conf -
diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c
index 836e2e5d1487b5..4fc029e9d0c875 100644
--- a/srp_daemon/srp_daemon.c
+++ b/srp_daemon/srp_daemon.c
@@ -42,6 +42,7 @@
#include <assert.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -234,6 +235,7 @@ static void usage(const char *argv0)
fprintf(stderr, "-t <timeout> Timeout for mad response in milliseconds\n");
fprintf(stderr, "-r <retries> number of send Retries for each mad\n");
fprintf(stderr, "-n New connection command format - use also initiator extension\n");
+ fprintf(stderr, "--systemd Enable systemd integration.\n");
fprintf(stderr, "\nExample: srp_daemon -e -n -i mthca0 -p 1 -R 60\n");
}
@@ -1595,6 +1597,29 @@ out:
return ret;
}
+static const struct option long_opts[] = {
+ { "systemd", 0, NULL, 'S' },
+ {}
+};
+static const char short_opts[] = "caveod:i:j:p:t:r:R:T:l:Vhnf:";
+
+/* Check if the --systemd options was passed in very early so we can setup
+ * logging properly.
+ */
+static bool is_systemd(int argc, char *argv[])
+{
+ while (1) {
+ int c;
+
+ c = getopt_long(argc, argv, short_opts, long_opts, NULL);
+ if (c == -1)
+ break;
+ if (c == 'S')
+ return true;
+
+ }
+ return false;
+}
static int get_config(struct config_t *conf, int argc, char *argv[])
{
@@ -1621,10 +1646,11 @@ static int get_config(struct config_t *conf, int argc, char *argv[])
conf->rules = NULL;
conf->tl_retry_count = 0;
+ optind = 1;
while (1) {
int c;
- c = getopt(argc, argv, "caveod:i:j:p:t:r:R:T:l:Vhnf:");
+ c = getopt_long(argc, argv, short_opts, long_opts, NULL);
if (c == -1)
break;
@@ -1721,6 +1747,8 @@ static int get_config(struct config_t *conf, int argc, char *argv[])
return -1;
}
break;
+ case 'S':
+ break;
case 'h':
default:
usage(argv[0]);
@@ -2093,6 +2121,7 @@ int main(int argc, char *argv[])
int subscribed;
int lockfd = -1;
int received_signal = 0;
+ bool systemd;
#ifndef __CHECKER__
/*
@@ -2116,7 +2145,12 @@ int main(int argc, char *argv[])
goto out;
}
- openlog("srp_daemon", LOG_PID | LOG_PERROR, LOG_DAEMON);
+ systemd = is_systemd(argc, argv);
+
+ if (systemd)
+ openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
+ else
+ openlog("srp_daemon", LOG_PID, LOG_DAEMON);
config = calloc(1, sizeof(*config));
if (!config) {
diff --git a/srp_daemon/srp_daemon_port@.service.in b/srp_daemon/srp_daemon_port@.service.in
index 0ec966f912aec8..acec1a228fec89 100644
--- a/srp_daemon/srp_daemon_port@.service.in
+++ b/srp_daemon/srp_daemon_port@.service.in
@@ -9,7 +9,7 @@ Before=remote-fs-pre.target
[Service]
Type=simple
-ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/srp_daemon -e -c -n -j %I -R 60
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/srp_daemon --systemd -e -c -n -j %I -R 60
MemoryDenyWriteExecute=yes
PrivateNetwork=yes
PrivateTmp=yes
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 4/8] Consistently open syslog in daemons
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
` (2 preceding siblings ...)
2017-07-26 19:59 ` [PATCH rdma-core 3/8] srp_daemon: Add a --systemd option Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 5/8] iwpmd: Move iwpmd.1 man page to iwpmd.8 Jason Gunthorpe
` (3 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Tatyana Nikolova, Steve Wise
These days we can use the POSIX 2008 format to automatically
set the program name. We always want fallback to console if syslog
is broken, and if we are calling openlog should take effect
immediately.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
iwpmd/iwarp_pm_server.c | 2 +-
rdma-ndd/rdma-ndd.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index 53f61b2876b9b5..a0a877b91b0c60 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -1400,7 +1400,7 @@ int main(int argc, char *argv[])
FILE *fp;
int ret = EXIT_FAILURE;
- openlog("iWarpPortMapper", LOG_CONS | LOG_PID, LOG_DAEMON);
+ openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
daemonize_iwpm_server();
diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c
index e7be22b12ad6a1..3e99d2dc5332dc 100644
--- a/rdma-ndd/rdma-ndd.c
+++ b/rdma-ndd/rdma-ndd.c
@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
{
bool foreground = false;
- openlog("rdma-ndd", LOG_PID, LOG_DAEMON);
+ openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
while (1) {
int opt_idx = 0;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 5/8] iwpmd: Move iwpmd.1 man page to iwpmd.8
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
` (3 preceding siblings ...)
2017-07-26 19:59 ` [PATCH rdma-core 4/8] Consistently open syslog in daemons Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 6/8] iwpm: Use daemon() instead of open coding a version Jason Gunthorpe
` (2 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Tatyana Nikolova, Steve Wise
Section 8 is appropriate for root only daemons.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
debian/iwpmd.install | 4 ++--
iwpmd/CMakeLists.txt | 2 +-
iwpmd/{iwpmd.1.in => iwpmd.8.in} | 2 +-
iwpmd/iwpmd.conf.5.in | 2 +-
redhat/rdma-core.spec | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
rename iwpmd/{iwpmd.1.in => iwpmd.8.in} (98%)
diff --git a/debian/iwpmd.install b/debian/iwpmd.install
index bff17f15abf7d9..30ff49ccaefa41 100644
--- a/debian/iwpmd.install
+++ b/debian/iwpmd.install
@@ -1,6 +1,6 @@
etc/init.d/iwpmd
etc/iwpmd.conf
lib/systemd/system/iwpmd.service
-usr/bin/iwpmd
-usr/share/man/man1/iwpmd.1
+usr/sbin/iwpmd
+usr/share/man/man8/iwpmd.8
usr/share/man/man5/iwpmd.conf.5
diff --git a/iwpmd/CMakeLists.txt b/iwpmd/CMakeLists.txt
index ee9e5a3dfeb24e..56dabdcf409638 100644
--- a/iwpmd/CMakeLists.txt
+++ b/iwpmd/CMakeLists.txt
@@ -9,7 +9,7 @@ target_link_libraries(iwpmd LINK_PRIVATE
)
rdma_man_pages(
- iwpmd.1.in
+ iwpmd.8.in
iwpmd.conf.5.in
)
diff --git a/iwpmd/iwpmd.1.in b/iwpmd/iwpmd.8.in
similarity index 98%
rename from iwpmd/iwpmd.1.in
rename to iwpmd/iwpmd.8.in
index 88eece7f6522a6..c42f2dd3de2b8a 100644
--- a/iwpmd/iwpmd.1.in
+++ b/iwpmd/iwpmd.8.in
@@ -1,4 +1,4 @@
-.TH "iwpmd" 1 "2016-09-16" "iwpmd" "iwpmd" iwpmd
+.TH "iwpmd" 8 "2016-09-16" "iwpmd" "iwpmd" iwpmd
.SH NAME
iwpmd \- port mapping services for iWARP.
.SH SYNOPSIS
diff --git a/iwpmd/iwpmd.conf.5.in b/iwpmd/iwpmd.conf.5.in
index 1baae82b76da73..019525f7ae0053 100644
--- a/iwpmd/iwpmd.conf.5.in
+++ b/iwpmd/iwpmd.conf.5.in
@@ -1,4 +1,4 @@
-.TH "iwpmd.conf" 5 "2016-09-16" "iwpmd.conf" "iwpmd.conf" iwpmd.conf
+.TH "iwpmd.conf" 1 "2016-09-16" "iwpmd.conf" "iwpmd.conf" iwpmd.conf
.SH NAME
iwpmd.conf \- iWARP port mapper config file.
.SH SYNOPSIS
diff --git a/redhat/rdma-core.spec b/redhat/rdma-core.spec
index 80a78265d02bfb..4f1ab71e5c4e27 100644
--- a/redhat/rdma-core.spec
+++ b/redhat/rdma-core.spec
@@ -394,7 +394,7 @@ rm -rf %{buildroot}/%{_sbindir}/srp_daemon.sh
%{_bindir}/iwpmd
%{_unitdir}/iwpmd.service
%config(noreplace) %{_sysconfdir}/iwpmd.conf
-%{_mandir}/man1/iwpmd.*
+%{_mandir}/man8/iwpmd.*
%{_mandir}/man5/iwpmd.*
%files -n libibcm
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 6/8] iwpm: Use daemon() instead of open coding a version
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
` (4 preceding siblings ...)
2017-07-26 19:59 ` [PATCH rdma-core 5/8] iwpmd: Move iwpmd.1 man page to iwpmd.8 Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 7/8] iwpmd: Add --systemd option Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 8/8] rdma-ndd: Tidy getopt_long call Jason Gunthorpe
7 siblings, 0 replies; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Tatyana Nikolova, Steve Wise
This fixes a bug in the open coded version, stdin/err/out should never
be left as a closed file descriptor as libraries are hardwired to use
those FDs in emergencies.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
iwpmd/iwarp_pm_server.c | 33 ++++-----------------------------
1 file changed, 4 insertions(+), 29 deletions(-)
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index a0a877b91b0c60..ec5721020e224c 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -1358,39 +1358,14 @@ iwarp_port_mapper_exit:
*/
static void daemonize_iwpm_server(void)
{
- pid_t pid, sid;
-
- /* check if already a daemon */
- if (getppid() == 1) return;
-
- pid = fork();
- if (pid < 0) {
- syslog(LOG_WARNING, "daemonize_iwpm_server: Couldn't fork a new process\n");
- exit(EXIT_FAILURE);
- }
-
- /* exit the parent process */
- if (pid > 0)
- exit(EXIT_SUCCESS);
-
+ if (daemon(0, 0) != 0) {
+ syslog(LOG_ERR, "Failed to daemonize\n");
+ exit(EXIT_FAILURE);
+ }
umask(0); /* change file mode mask */
- sid = setsid(); /* create a new session, new group, no tty */
- if (sid < 0) {
- syslog(LOG_WARNING, "daemonize_iwpm_server: Couldn't create new session\n");
- exit(EXIT_FAILURE);
- }
-
- if ((chdir("/")) < 0) {
- syslog(LOG_WARNING, "daemonize_iwpm_server: Couldn't change the current directory\n");
- exit(EXIT_FAILURE);
- }
syslog(LOG_WARNING, "daemonize_iwpm_server: Starting iWarp Port Mapper V%d process\n",
iwpm_version);
- /* close standard IO streams */
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
}
int main(int argc, char *argv[])
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 7/8] iwpmd: Add --systemd option
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
` (5 preceding siblings ...)
2017-07-26 19:59 ` [PATCH rdma-core 6/8] iwpm: Use daemon() instead of open coding a version Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
2017-07-26 19:59 ` [PATCH rdma-core 8/8] rdma-ndd: Tidy getopt_long call Jason Gunthorpe
7 siblings, 0 replies; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Tatyana Nikolova, Steve Wise
This avoids daemonizing the server and forking as systemd does
all of that for us. The notable benefit is to allow stderr to
be routed to the journal in case there is any sort of internal
fault (eg a glibc memory failure)
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
iwpmd/iwarp_pm_server.c | 29 ++++++++++++++++++++++++++---
iwpmd/iwpmd.8.in | 4 ++++
iwpmd/{iwpmd.service => iwpmd.service.in} | 3 +--
3 files changed, 31 insertions(+), 5 deletions(-)
rename iwpmd/{iwpmd.service => iwpmd.service.in} (75%)
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index ec5721020e224c..928b8631fe89d3 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -32,6 +32,7 @@
*/
#include "config.h"
+#include <getopt.h>
#include "iwarp_pm.h"
static const char iwpm_ulib_name [] = "iWarpPortMapperUser";
@@ -1355,14 +1356,13 @@ iwarp_port_mapper_exit:
/**
* daemonize_iwpm_server - Make iwarp port mapper a daemon process
- */
+ */
static void daemonize_iwpm_server(void)
{
if (daemon(0, 0) != 0) {
syslog(LOG_ERR, "Failed to daemonize\n");
exit(EXIT_FAILURE);
}
- umask(0); /* change file mode mask */
syslog(LOG_WARNING, "daemonize_iwpm_server: Starting iWarp Port Mapper V%d process\n",
iwpm_version);
@@ -1374,10 +1374,33 @@ int main(int argc, char *argv[])
int known_clients;
FILE *fp;
int ret = EXIT_FAILURE;
+ bool systemd = false;
+
+ while (1) {
+ static const struct option long_opts[] = {
+ {"systemd", 0, NULL, 's'},
+ {}
+ };
+
+ int c = getopt_long(argc, argv, "fs", long_opts, NULL);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 's':
+ systemd = true;
+ break;
+ default:
+ break;
+
+ }
+ }
openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
- daemonize_iwpm_server();
+ if (!systemd)
+ daemonize_iwpm_server();
+ umask(0); /* change file mode mask */
fp = fopen(IWPM_CONFIG_FILE, "r");
if (fp) {
diff --git a/iwpmd/iwpmd.8.in b/iwpmd/iwpmd.8.in
index c42f2dd3de2b8a..76efaa46e8a014 100644
--- a/iwpmd/iwpmd.8.in
+++ b/iwpmd/iwpmd.8.in
@@ -45,6 +45,10 @@ which then releases the TCP port.
The message exchange between iwpmd and the iWARP Connection Manager
(between user space and kernel space) is implemented using netlink
sockets.
+.SH OPTIONS
+.sp
+\fB\-s, \-\-systemd\fP
+Enable systemd integration.
.SH "SIGNALS"
SIGUSR1 will force a dump of the current mappings
to the system message log.
diff --git a/iwpmd/iwpmd.service b/iwpmd/iwpmd.service.in
similarity index 75%
rename from iwpmd/iwpmd.service
rename to iwpmd/iwpmd.service.in
index 6d093fb2fda5a7..25740ebdcf9a82 100644
--- a/iwpmd/iwpmd.service
+++ b/iwpmd/iwpmd.service.in
@@ -4,9 +4,8 @@ Documentation=man:iwpmd file:/etc/iwpmd.conf
After=network.target
[Service]
-ExecStart=/usr/bin/iwpmd
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/iwpmd --systemd
LimitNOFILE=102400
-KillMode=process
[Install]
WantedBy=multi-user.target
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH rdma-core 8/8] rdma-ndd: Tidy getopt_long call
[not found] ` <1501099152-6344-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
` (6 preceding siblings ...)
2017-07-26 19:59 ` [PATCH rdma-core 7/8] iwpmd: Add --systemd option Jason Gunthorpe
@ 2017-07-26 19:59 ` Jason Gunthorpe
7 siblings, 0 replies; 17+ messages in thread
From: Jason Gunthorpe @ 2017-07-26 19:59 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
struct option should be const and opt_idx can just be NULL.
Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
rdma-ndd/rdma-ndd.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/rdma-ndd/rdma-ndd.c b/rdma-ndd/rdma-ndd.c
index 3e99d2dc5332dc..180cbb34a8e29b 100644
--- a/rdma-ndd/rdma-ndd.c
+++ b/rdma-ndd/rdma-ndd.c
@@ -289,15 +289,14 @@ int main(int argc, char *argv[])
openlog(NULL, LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
while (1) {
- int opt_idx = 0;
- static struct option long_opts[] = {
+ static const struct option long_opts[] = {
{ "foreground", 0, NULL, 'f' },
{ "help", 0, NULL, 'h' },
{ "debug", 0, NULL, 'd' },
{ }
};
- int c = getopt_long(argc, argv, "fh", long_opts, &opt_idx);
+ int c = getopt_long(argc, argv, "fh", long_opts, NULL);
if (c == -1)
break;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 17+ messages in thread