From: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>
To: Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH 1/4 for opensm] Add command-line option --pidfile
Date: Fri, 21 Sep 2012 16:42:04 +0200 [thread overview]
Message-ID: <505C7CBC.3050803@acm.org> (raw)
This option is necessary to control opensm from an LSB-compliant
init script.
Signed-off-by: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>
---
man/opensm.8.in | 5 +++++
opensm/main.c | 26 ++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/man/opensm.8.in b/man/opensm.8.in
index 4e61c2e..37e2eee 100644
--- a/man/opensm.8.in
+++ b/man/opensm.8.in
@@ -52,6 +52,7 @@ opensm \- InfiniBand subnet manager and administration (SM/SA)
[\-\-cckey <key>]
[\-y | \-\-stay_on_fatal]
[\-B | \-\-daemon]
+[\-J | \-\-pidfile <file_name>]
[\-I | \-\-inactive]
[\-\-perfmgr]
[\-\-perfmgr_sweep_time_s <seconds>]
@@ -403,6 +404,10 @@ By default, the SM will exit on these errors.
\fB\-B\fR, \fB\-\-daemon\fR
Run in daemon mode - OpenSM will run in the background.
.TP
+\fB\-J\fR, \fB\-\-pidfile <file_name>\fR
+Makes the SM write its own PID to the specified file when started in daemon
+mode.
+.TP
\fB\-I\fR, \fB\-\-inactive\fR
Start SM in inactive rather than init SM state. This
option can be used in conjunction with the perfmgr so as to
diff --git a/opensm/main.c b/opensm/main.c
index e9a0b4c..1a061a8 100644
--- a/opensm/main.c
+++ b/opensm/main.c
@@ -68,6 +68,7 @@ volatile unsigned int osm_exit_flag = 0;
static volatile unsigned int osm_hup_flag = 0;
static volatile unsigned int osm_usr1_flag = 0;
+static char *pidfile;
#define MAX_LOCAL_IBPORTS 64
#define INVALID_GUID (0xFFFFFFFFFFFFFFFFULL)
@@ -498,10 +499,17 @@ static ib_net64_t get_port_guid(IN osm_opensm_t * p_osm, uint64_t port_guid)
return attr_array[choice].port_guid;
}
+static void remove_pidfile(void)
+{
+ if (pidfile)
+ unlink(pidfile);
+}
+
static int daemonize(osm_opensm_t * osm)
{
pid_t pid;
int fd;
+ FILE *f;
fd = open("/dev/null", O_WRONLY);
if (fd < 0) {
@@ -523,6 +531,18 @@ static int daemonize(osm_opensm_t * osm)
} else if (pid > 0)
exit(0);
+ if (pidfile) {
+ remove_pidfile();
+ f = fopen(pidfile, "w");
+ if (f) {
+ fprintf(f, "%d\n", getpid());
+ fclose(f);
+ } else {
+ perror("fopen");
+ exit(1);
+ }
+ }
+
close(0);
close(1);
close(2);
@@ -649,6 +669,7 @@ int main(int argc, char *argv[])
{"console-port", 1, NULL, 'C'},
#endif
{"daemon", 0, NULL, 'B'},
+ {"pidfile", 1, NULL, 'J'},
{"inactive", 0, NULL, 'I'},
#ifdef ENABLE_OSM_PERF_MGR
{"perfmgr", 0, NULL, 1},
@@ -887,6 +908,10 @@ int main(int argc, char *argv[])
printf(" Creating new log file\n");
break;
+ case 'J':
+ pidfile = optarg;
+ break;
+
case 'P':
SET_STR_OPT(opt.partition_config_file, optarg);
break;
@@ -1212,6 +1237,7 @@ int main(int argc, char *argv[])
Exit:
osm_opensm_destroy(&osm);
complib_exit();
+ remove_pidfile();
exit(0);
}
--
1.7.10.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
next reply other threads:[~2012-09-21 14:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-21 14:42 Bart Van Assche [this message]
[not found] ` <505C7CBC.3050803-HInyCGIudOg@public.gmane.org>
2012-10-25 15:39 ` [PATCH 1/4 for opensm] Add command-line option --pidfile Alex Netes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=505C7CBC.3050803@acm.org \
--to=bvanassche-hinycgiudog@public.gmane.org \
--cc=alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.