* [PATCH 5/6] opensm: Add command-line option --pidfile
@ 2012-09-11 14:20 Bart Van Assche
[not found] ` <504F48A9.3030802-HInyCGIudOg@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2012-09-11 14:20 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; +Cc: Alex Netes
This option is necessary to control opensm from an LSB-compliant
init script.
Signed-off-by: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>
---
opensm/main.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
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.7
--
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] 2+ messages in thread
* Re: [PATCH 5/6] opensm: Add command-line option --pidfile
[not found] ` <504F48A9.3030802-HInyCGIudOg@public.gmane.org>
@ 2012-09-19 14:46 ` Alex Netes
0 siblings, 0 replies; 2+ messages in thread
From: Alex Netes @ 2012-09-19 14:46 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Hi Bart,
On 16:20 Tue 11 Sep , Bart Van Assche wrote:
> This option is necessary to control opensm from an LSB-compliant
> init script.
>
This option should also be added to opensm.conf and documented in the man page.
-- Alex
--
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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-19 14:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 14:20 [PATCH 5/6] opensm: Add command-line option --pidfile Bart Van Assche
[not found] ` <504F48A9.3030802-HInyCGIudOg@public.gmane.org>
2012-09-19 14:46 ` Alex Netes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).