* [PATCH] opensm: Add support for PID file
@ 2011-07-10 12:04 Alex Netes
[not found] ` <20110710120442.GA11284-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Alex Netes @ 2011-07-10 12:04 UTC (permalink / raw)
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Aleksey Senin
When OpenSM executed, opensm.pid created by default in /var/run
and contains PID of the last executed instance of OpenSM.
opensm.pid is used by opensm.init stop, to kill only the last
executed instance of OpenSM.
Signed-off-by: Aleksey Senin <alekseys-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
configure.in | 25 +++++++++++++++++++++++++
include/opensm/osm_base.h | 18 ++++++++++++++++++
include/opensm/osm_subnet.h | 1 +
man/opensm.8.in | 5 +++++
opensm/main.c | 16 ++++++++++++++++
opensm/osm_subnet.c | 2 ++
scripts/opensm.init.in | 5 ++++-
7 files changed, 71 insertions(+), 1 deletions(-)
diff --git a/configure.in b/configure.in
index 7c5eb65..c6f5d53 100644
--- a/configure.in
+++ b/configure.in
@@ -231,6 +231,31 @@ dnl Checks for headers and libraries
OPENIB_APP_OSMV_CHECK_HEADER
OPENIB_APP_OSMV_CHECK_LIB
+dnl Where to place opensm.pid
+piddir=/var/run
+dnl make sure the directory exists
+if test ! -d $piddir ; then
+ piddir=`eval echo ${sysconfdir}`
+ case $piddir in
+ NONE/*) piddir=`echo $piddir | sed "s~NONE~$ac_default_prefix~"` ;;
+ esac
+fi
+
+AC_ARG_WITH(pid-dir,
+ [ --with-pid-dir=<dir> define the dir of opensm.pid file (default is /var/run)],
+ [
+ if test -n "$withval" && test "x$withval" != "xno" && \
+ test "x${withval}" != "xyes"; then
+ piddir=$withval
+ if test ! -d $piddir ; then
+ AC_MSG_WARN([** no $piddir directory on this system **])
+ fi
+ fi
+ ]
+)
+AC_DEFINE_UNQUOTED(OPENSM_PID_DIR, "$piddir", [Specify location of opensm.pid])
+AC_SUBST(piddir)
+
AC_CONFIG_FILES([man/opensm.8 man/torus-2QoS.8 man/torus-2QoS.conf.5 scripts/opensm.init scripts/redhat-opensm.init scripts/sldd.sh])
dnl Create the following Makefiles
diff --git a/include/opensm/osm_base.h b/include/opensm/osm_base.h
index c1a52b5..13bfbb0 100644
--- a/include/opensm/osm_base.h
+++ b/include/opensm/osm_base.h
@@ -318,6 +318,24 @@ BEGIN_C_DECLS
#endif
/***********/
+/****d* OpenSM: Base/OSM_DEFAULT_PID_FILE
+* NAME
+* OSM_DEFAULT_PID_FILE
+*
+* DESCRIPTION
+* Specifies the default pid file name
+*
+* SYNOPSIS
+*/
+#if defined(HAVE_DEFAULT_PID_FILE)
+#define OSM_DEFAULT_PID_FILE HAVE_DEFAULT_PID_FILE
+#elif defined(OPENSM_PID_DIR)
+#define OSM_DEFAULT_PID_FILE OPENSM_PID_DIR "/opensm.pid"
+#else
+#define OSM_DEFAULT_PID_FILE "/var/run/opensm.pid"
+#endif
+/***********/
+
/****d* OpenSM: Base/OSM_DEFAULT_SWEEP_INTERVAL_SECS
* NAME
* OSM_DEFAULT_SWEEP_INTERVAL_SECS
diff --git a/include/opensm/osm_subnet.h b/include/opensm/osm_subnet.h
index 6d17c31..9bbbd2f 100644
--- a/include/opensm/osm_subnet.h
+++ b/include/opensm/osm_subnet.h
@@ -208,6 +208,7 @@ typedef struct osm_subn_opt {
char *sa_db_file;
boolean_t sa_db_dump;
char *torus_conf_file;
+ char *pid_file;
boolean_t do_mesh_analysis;
boolean_t exit_on_fatal;
boolean_t honor_guid2lid_file;
diff --git a/man/opensm.8.in b/man/opensm.8.in
index f360739..76096c0 100644
--- a/man/opensm.8.in
+++ b/man/opensm.8.in
@@ -55,6 +55,7 @@ opensm \- InfiniBand subnet manager and administration (SM/SA)
[\-\-consolidate_ipv6_snm_req]
[\-\-log_prefix <prefix text>]
[\-\-torus_config <path to file>]
+[\-\-pid_file <path to file>]
[\-v(erbose)] [\-V] [\-D <flags>] [\-d(ebug) <number>]
[\-h(elp)] [\-?]
@@ -407,6 +408,10 @@ This option defines the file name for the extra configuration
information needed for the torus-2QoS routing engine. The default
name is \fB\%@OPENSM_CONFIG_DIR@/@TORUS2QOS_CONF_FILE@\fP
.TP
+\fB\-\-pid_file\fR <path to pid file>
+Specifies the file that contains the process ID of the opensm daemon.
+The default is \fB/var/run/opensm.pid\fP
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
This option increases the log verbosity level.
The -v option may be specified multiple times
diff --git a/opensm/main.c b/opensm/main.c
index 798cb20..30594bf 100644
--- a/opensm/main.c
+++ b/opensm/main.c
@@ -347,6 +347,9 @@ static void show_usage(void)
printf("--consolidate_ipv6_snm_req\n"
" Use shared MLID for IPv6 Solicited Node Multicast groups\n"
" per MGID scope and P_Key.\n\n");
+ printf("--pid_file <path to file>\n"
+ " Specifies the file that contains the process ID of the\n"
+ " opensm daemon.The default is /var/run/opensm.pid\n");
printf("--log_prefix <prefix text>\n"
" Prefix to syslog messages from OpenSM.\n\n");
printf("--verbose, -v\n"
@@ -638,6 +641,7 @@ int main(int argc, char *argv[])
{"retries", 1, NULL, 8},
{"log_prefix", 1, NULL, 9},
{"torus_config", 1, NULL, 10},
+ {"pid_file", 1, NULL, 15},
{NULL, 0, NULL, 0} /* Required at the end of the array */
};
@@ -1047,6 +1051,9 @@ int main(int argc, char *argv[])
SET_STR_OPT(opt.torus_conf_file, optarg);
printf("Torus-2QoS config file = %s\n", opt.torus_conf_file);
break;
+ case 15:
+ SET_STR_OPT(opt.pid_file, optarg);
+ break;
case 'h':
case '?':
case ':':
@@ -1116,6 +1123,14 @@ int main(int argc, char *argv[])
setup_signals();
+ FILE *f = fopen(opt.pid_file, "w");
+ if (f == NULL)
+ printf("Couldn't create pid file \"%s\"\n", opt.pid_file);
+ else {
+ fprintf(f, "%ld\n", (long) getpid());
+ fclose(f);
+ }
+
osm_opensm_sweep(&osm);
if (run_once_flag == TRUE) {
@@ -1147,6 +1162,7 @@ int main(int argc, char *argv[])
}
Exit:
+ unlink(opt.pid_file);
osm_opensm_destroy(&osm);
complib_exit();
diff --git a/opensm/osm_subnet.c b/opensm/osm_subnet.c
index 0b79d3a..3de622e 100644
--- a/opensm/osm_subnet.c
+++ b/opensm/osm_subnet.c
@@ -404,6 +404,7 @@ static const opt_rec_t opt_tbl[] = {
{ "no_clients_rereg", OPT_OFFSET(no_clients_rereg), opts_parse_boolean, NULL, 1 },
{ "prefix_routes_file", OPT_OFFSET(prefix_routes_file), opts_parse_charp, NULL, 0 },
{ "consolidate_ipv6_snm_req", OPT_OFFSET(consolidate_ipv6_snm_req), opts_parse_boolean, NULL, 1 },
+ { "pid_file", OPT_OFFSET(pid_file), opts_parse_charp, NULL, 0},
{ "lash_start_vl", OPT_OFFSET(lash_start_vl), opts_parse_uint8, NULL, 1 },
{ "sm_sl", OPT_OFFSET(sm_sl), opts_parse_uint8, NULL, 1 },
{ "log_prefix", OPT_OFFSET(log_prefix), opts_parse_charp, NULL, 1 },
@@ -791,6 +792,7 @@ void osm_subn_set_default_opt(IN osm_subn_opt_t * p_opt)
p_opt->no_clients_rereg = FALSE;
p_opt->prefix_routes_file = strdup(OSM_DEFAULT_PREFIX_ROUTES_FILE);
p_opt->consolidate_ipv6_snm_req = FALSE;
+ p_opt->pid_file = strdup(OSM_DEFAULT_PID_FILE);
p_opt->lash_start_vl = 0;
p_opt->sm_sl = OSM_DEFAULT_SL;
p_opt->log_prefix = NULL;
diff --git a/scripts/opensm.init.in b/scripts/opensm.init.in
index 0c84bd3..f8bbfb1 100644
--- a/scripts/opensm.init.in
+++ b/scripts/opensm.init.in
@@ -42,6 +42,9 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
+piddir=@piddir@
+
+PIDFILE=${piddir}/opensm.pid
# Source function library.
if [[ -s /etc/init.d/functions ]]; then
@@ -74,7 +77,7 @@ start () {
stop () {
echo -n "Shutting down opensm: "
- killproc opensm
+ killproc -p $PIDFILE opensm
if [[ $RETVAL -eq 0 ]]; then
rm -f /var/lock/subsys/opensm
success
--
1.7.6
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110710120442.GA11284-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2011-07-12 23:27 ` Ira Weiny
[not found] ` <20110712162740.29e2d7d1.weiny2-i2BcT+NCU+M@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Ira Weiny @ 2011-07-12 23:27 UTC (permalink / raw)
To: Alex Netes
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Aleksey Senin
I agree this is an issue. However, usually the PID is generated from the
startup script so that only the PID which is started by it is stopped.
Specifically, think of the use case of starting multiple SM's on different
ports. For example a local user may do this to manage 2 subnets from one
node. Your patch will, by default, overwrite the PID file with each instance.
(yes --pid-file can be specified but this is not very standard.)
I think a better (and more standard) approach is to do the following (untested):
diff --git a/scripts/opensm.init.in b/scripts/opensm.init.in
index 0c84bd3..1e053c4 100644
--- a/scripts/opensm.init.in
+++ b/scripts/opensm.init.in
@@ -42,6 +42,8 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
+piddir=@localstatedir@
+PIDFILE=${piddir}/opensm.pid
# Source function library.
if [[ -s /etc/init.d/functions ]]; then
@@ -62,7 +64,7 @@ fi
start () {
echo -n "Starting opensm: "
- @sbindir@/opensm --daemon $OPTIONS > /dev/null
+ daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null
if [[ $RETVAL -eq 0 ]]; then
touch /var/lock/subsys/opensm
success
@@ -74,7 +76,7 @@ start () {
stop () {
echo -n "Shutting down opensm: "
- killproc opensm
+ killproc -p $PIDFILE opensm
if [[ $RETVAL -eq 0 ]]; then
rm -f /var/lock/subsys/opensm
success
@@ -85,7 +87,8 @@ stop () {
}
Xstatus () {
- pid="`pidof opensm`"
+ pid=`cat $PIDFILE`
+ ps -p $pid
ret=$?
if [ $ret -eq 0 ] ; then
echo "OpenSM is running... pid=$pid"
@@ -117,11 +120,11 @@ case "$1" in
[ -e /var/lock/subsys/opensm ] && restart
;;
resweep)
- killall -HUP opensm
+ kill -s 1 `cat $PIDFILE`
RETVAL=$?
;;
rotatelog)
- killall -USR1 opensm
+ kill -s 10 `cat $PIDFILE`
RETVAL=$?
;;
*)
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110712162740.29e2d7d1.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2011-07-12 23:52 ` Jason Gunthorpe
[not found] ` <20110712235222.GG10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Jason Gunthorpe @ 2011-07-12 23:52 UTC (permalink / raw)
To: Ira Weiny
Cc: Alex Netes, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Aleksey Senin
On Tue, Jul 12, 2011 at 04:27:40PM -0700, Ira Weiny wrote:
> - @sbindir@/opensm --daemon $OPTIONS > /dev/null
> + daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null
You need to drop the --daemon from opensm if you run it under daemon..
The usual way to do this is to have the daemon drop a pidfile to the
location set by its --pidfile argument after it forks, but before the
command returns.
If --pidfile is not given it should not drop a pidfile anyplace.
Generally the daemon should make sure it can run without exiting
before forking, which is why this approach is prefered to using the
daemon command.
Jason
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110712235222.GG10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2011-07-12 23:58 ` Ira Weiny
[not found] ` <20110712165817.16076a3d.weiny2-i2BcT+NCU+M@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Ira Weiny @ 2011-07-12 23:58 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Alex Netes, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Aleksey Senin
On Tue, 12 Jul 2011 16:52:22 -0700
Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote:
> On Tue, Jul 12, 2011 at 04:27:40PM -0700, Ira Weiny wrote:
>
> > - @sbindir@/opensm --daemon $OPTIONS > /dev/null
> > + daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null
>
> You need to drop the --daemon from opensm if you run it under daemon..
>
> The usual way to do this is to have the daemon drop a pidfile to the
> location set by its --pidfile argument after it forks, but before the
> command returns.
You mean like Alex's patch did? I have not seen this done before. I checked out apache's httpd command and I don't see it doing this.
>
> If --pidfile is not given it should not drop a pidfile anyplace.
"it" is opensm in this case?
>
> Generally the daemon should make sure it can run without exiting
> before forking, which is why this approach is prefered to using the
> daemon command.
Ok, perhaps I am backwards, as I said I have not seen this done before.
Ira
>
> Jason
--
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110712165817.16076a3d.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2011-07-13 4:14 ` Jason Gunthorpe
[not found] ` <20110713041441.GA26663-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Jason Gunthorpe @ 2011-07-13 4:14 UTC (permalink / raw)
To: Ira Weiny
Cc: Alex Netes, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Aleksey Senin
On Tue, Jul 12, 2011 at 04:58:17PM -0700, Ira Weiny wrote:
> > The usual way to do this is to have the daemon drop a pidfile to the
> > location set by its --pidfile argument after it forks, but before the
> > command returns.
>
> You mean like Alex's patch did? I have not seen this done before.
> I checked out apache's httpd command and I don't see it doing this.
I didn't look closely..
At least sshd, ntpd, acpid, and dbus are working that way on my ubuntu
system.. Some commands write a default pidfile automaticaly rather
than doing nothing, but upstart and systemd eliminate the need
for a pid file at all, so I prefer to see a no write option.
> > If --pidfile is not given it should not drop a pidfile anyplace.
>
> "it" is opensm in this case?
Yes
Jason
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110713041441.GA26663-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2011-07-13 8:26 ` Alex Netes
[not found] ` <20110713082640.GA2024-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Alex Netes @ 2011-07-13 8:26 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Ira Weiny, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Aleksey Senin
On 22:14 Tue 12 Jul , Jason Gunthorpe wrote:
> On Tue, Jul 12, 2011 at 04:58:17PM -0700, Ira Weiny wrote:
>
> > > The usual way to do this is to have the daemon drop a pidfile to the
> > > location set by its --pidfile argument after it forks, but before the
> > > command returns.
> >
> > You mean like Alex's patch did? I have not seen this done before.
> > I checked out apache's httpd command and I don't see it doing this.
>
> I didn't look closely..
>
> At least sshd, ntpd, acpid, and dbus are working that way on my ubuntu
> system.. Some commands write a default pidfile automaticaly rather
> than doing nothing, but upstart and systemd eliminate the need
> for a pid file at all, so I prefer to see a no write option.
I based on sshd/ntpd approach when doing this. But now I agree with Jason.
We should have this as a backward compatibility support for SysV and it should
be off by default, unless you are running with --daemon, which is designed for
SysV. I'm not familiar with upstart, but systemd doesn't need the double fork
stuff within main.c: daemonize().
Bellow is a revised patch.
When OpenSM executed as daemon, opensm.pid created by default
in /var/run and contains PID of the last executed instance of OpenSM.
opensm.pid is used by opensm.init stop, to kill only the last
executed instance of OpenSM.
Signed-off-by: Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
Changes since ver1:
-create pid file only when executed as daemon
---
configure.in | 25 +++++++++++++++++++++++++
include/opensm/osm_base.h | 18 ++++++++++++++++++
include/opensm/osm_subnet.h | 1 +
man/opensm.8.in | 5 +++++
opensm/main.c | 18 ++++++++++++++++++
opensm/osm_subnet.c | 2 ++
scripts/opensm.init.in | 5 ++++-
7 files changed, 73 insertions(+), 1 deletions(-)
diff --git a/configure.in b/configure.in
index 7c5eb65..c6f5d53 100644
--- a/configure.in
+++ b/configure.in
@@ -231,6 +231,31 @@ dnl Checks for headers and libraries
OPENIB_APP_OSMV_CHECK_HEADER
OPENIB_APP_OSMV_CHECK_LIB
+dnl Where to place opensm.pid
+piddir=/var/run
+dnl make sure the directory exists
+if test ! -d $piddir ; then
+ piddir=`eval echo ${sysconfdir}`
+ case $piddir in
+ NONE/*) piddir=`echo $piddir | sed "s~NONE~$ac_default_prefix~"` ;;
+ esac
+fi
+
+AC_ARG_WITH(pid-dir,
+ [ --with-pid-dir=<dir> define the dir of opensm.pid file (default is /var/run)],
+ [
+ if test -n "$withval" && test "x$withval" != "xno" && \
+ test "x${withval}" != "xyes"; then
+ piddir=$withval
+ if test ! -d $piddir ; then
+ AC_MSG_WARN([** no $piddir directory on this system **])
+ fi
+ fi
+ ]
+)
+AC_DEFINE_UNQUOTED(OPENSM_PID_DIR, "$piddir", [Specify location of opensm.pid])
+AC_SUBST(piddir)
+
AC_CONFIG_FILES([man/opensm.8 man/torus-2QoS.8 man/torus-2QoS.conf.5 scripts/opensm.init scripts/redhat-opensm.init scripts/sldd.sh])
dnl Create the following Makefiles
diff --git a/include/opensm/osm_base.h b/include/opensm/osm_base.h
index c1a52b5..13bfbb0 100644
--- a/include/opensm/osm_base.h
+++ b/include/opensm/osm_base.h
@@ -318,6 +318,24 @@ BEGIN_C_DECLS
#endif
/***********/
+/****d* OpenSM: Base/OSM_DEFAULT_PID_FILE
+* NAME
+* OSM_DEFAULT_PID_FILE
+*
+* DESCRIPTION
+* Specifies the default pid file name
+*
+* SYNOPSIS
+*/
+#if defined(HAVE_DEFAULT_PID_FILE)
+#define OSM_DEFAULT_PID_FILE HAVE_DEFAULT_PID_FILE
+#elif defined(OPENSM_PID_DIR)
+#define OSM_DEFAULT_PID_FILE OPENSM_PID_DIR "/opensm.pid"
+#else
+#define OSM_DEFAULT_PID_FILE "/var/run/opensm.pid"
+#endif
+/***********/
+
/****d* OpenSM: Base/OSM_DEFAULT_SWEEP_INTERVAL_SECS
* NAME
* OSM_DEFAULT_SWEEP_INTERVAL_SECS
diff --git a/include/opensm/osm_subnet.h b/include/opensm/osm_subnet.h
index 6d17c31..9bbbd2f 100644
--- a/include/opensm/osm_subnet.h
+++ b/include/opensm/osm_subnet.h
@@ -208,6 +208,7 @@ typedef struct osm_subn_opt {
char *sa_db_file;
boolean_t sa_db_dump;
char *torus_conf_file;
+ char *pid_file;
boolean_t do_mesh_analysis;
boolean_t exit_on_fatal;
boolean_t honor_guid2lid_file;
diff --git a/man/opensm.8.in b/man/opensm.8.in
index f360739..76096c0 100644
--- a/man/opensm.8.in
+++ b/man/opensm.8.in
@@ -55,6 +55,7 @@ opensm \- InfiniBand subnet manager and administration (SM/SA)
[\-\-consolidate_ipv6_snm_req]
[\-\-log_prefix <prefix text>]
[\-\-torus_config <path to file>]
+[\-\-pid_file <path to file>]
[\-v(erbose)] [\-V] [\-D <flags>] [\-d(ebug) <number>]
[\-h(elp)] [\-?]
@@ -407,6 +408,10 @@ This option defines the file name for the extra configuration
information needed for the torus-2QoS routing engine. The default
name is \fB\%@OPENSM_CONFIG_DIR@/@TORUS2QOS_CONF_FILE@\fP
.TP
+\fB\-\-pid_file\fR <path to pid file>
+Specifies the file that contains the process ID of the opensm daemon.
+The default is \fB/var/run/opensm.pid\fP
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
This option increases the log verbosity level.
The -v option may be specified multiple times
diff --git a/opensm/main.c b/opensm/main.c
index 798cb20..7aedcd5 100644
--- a/opensm/main.c
+++ b/opensm/main.c
@@ -347,6 +347,9 @@ static void show_usage(void)
printf("--consolidate_ipv6_snm_req\n"
" Use shared MLID for IPv6 Solicited Node Multicast groups\n"
" per MGID scope and P_Key.\n\n");
+ printf("--pid_file <path to file>\n"
+ " Specifies the file that contains the process ID of the\n"
+ " opensm daemon.The default is /var/run/opensm.pid\n");
printf("--log_prefix <prefix text>\n"
" Prefix to syslog messages from OpenSM.\n\n");
printf("--verbose, -v\n"
@@ -638,6 +641,7 @@ int main(int argc, char *argv[])
{"retries", 1, NULL, 8},
{"log_prefix", 1, NULL, 9},
{"torus_config", 1, NULL, 10},
+ {"pid_file", 1, NULL, 15},
{NULL, 0, NULL, 0} /* Required at the end of the array */
};
@@ -1047,6 +1051,9 @@ int main(int argc, char *argv[])
SET_STR_OPT(opt.torus_conf_file, optarg);
printf("Torus-2QoS config file = %s\n", opt.torus_conf_file);
break;
+ case 15:
+ SET_STR_OPT(opt.pid_file, optarg);
+ break;
case 'h':
case '?':
case ':':
@@ -1116,6 +1123,16 @@ int main(int argc, char *argv[])
setup_signals();
+ if (opt.daemon) {
+ FILE *f = fopen(opt.pid_file, "w");
+ if (f == NULL)
+ printf("Couldn't create pid file \"%s\"\n", opt.pid_file);
+ else {
+ fprintf(f, "%ld\n", (long) getpid());
+ fclose(f);
+ }
+ }
+
osm_opensm_sweep(&osm);
if (run_once_flag == TRUE) {
@@ -1147,6 +1164,7 @@ int main(int argc, char *argv[])
}
Exit:
+ unlink(opt.pid_file);
osm_opensm_destroy(&osm);
complib_exit();
diff --git a/opensm/osm_subnet.c b/opensm/osm_subnet.c
index 0b79d3a..3de622e 100644
--- a/opensm/osm_subnet.c
+++ b/opensm/osm_subnet.c
@@ -404,6 +404,7 @@ static const opt_rec_t opt_tbl[] = {
{ "no_clients_rereg", OPT_OFFSET(no_clients_rereg), opts_parse_boolean, NULL, 1 },
{ "prefix_routes_file", OPT_OFFSET(prefix_routes_file), opts_parse_charp, NULL, 0 },
{ "consolidate_ipv6_snm_req", OPT_OFFSET(consolidate_ipv6_snm_req), opts_parse_boolean, NULL, 1 },
+ { "pid_file", OPT_OFFSET(pid_file), opts_parse_charp, NULL, 0},
{ "lash_start_vl", OPT_OFFSET(lash_start_vl), opts_parse_uint8, NULL, 1 },
{ "sm_sl", OPT_OFFSET(sm_sl), opts_parse_uint8, NULL, 1 },
{ "log_prefix", OPT_OFFSET(log_prefix), opts_parse_charp, NULL, 1 },
@@ -791,6 +792,7 @@ void osm_subn_set_default_opt(IN osm_subn_opt_t * p_opt)
p_opt->no_clients_rereg = FALSE;
p_opt->prefix_routes_file = strdup(OSM_DEFAULT_PREFIX_ROUTES_FILE);
p_opt->consolidate_ipv6_snm_req = FALSE;
+ p_opt->pid_file = strdup(OSM_DEFAULT_PID_FILE);
p_opt->lash_start_vl = 0;
p_opt->sm_sl = OSM_DEFAULT_SL;
p_opt->log_prefix = NULL;
diff --git a/scripts/opensm.init.in b/scripts/opensm.init.in
index 0c84bd3..f8bbfb1 100644
--- a/scripts/opensm.init.in
+++ b/scripts/opensm.init.in
@@ -42,6 +42,9 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
+piddir=@piddir@
+
+PIDFILE=${piddir}/opensm.pid
# Source function library.
if [[ -s /etc/init.d/functions ]]; then
@@ -74,7 +77,7 @@ start () {
stop () {
echo -n "Shutting down opensm: "
- killproc opensm
+ killproc -p $PIDFILE opensm
if [[ $RETVAL -eq 0 ]]; then
rm -f /var/lock/subsys/opensm
success
--
1.7.6
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110713082640.GA2024-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2011-07-13 16:48 ` Jason Gunthorpe
2011-07-14 0:40 ` Roland Dreier
1 sibling, 0 replies; 11+ messages in thread
From: Jason Gunthorpe @ 2011-07-13 16:48 UTC (permalink / raw)
To: Alex Netes
Cc: Ira Weiny, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Aleksey Senin
On Wed, Jul 13, 2011 at 11:26:40AM +0300, Alex Netes wrote:
> @@ -407,6 +408,10 @@ This option defines the file name for the extra configuration
> information needed for the torus-2QoS routing engine. The default
> name is \fB\%@OPENSM_CONFIG_DIR@/@TORUS2QOS_CONF_FILE@\fP
> .TP
> +\fB\-\-pid_file\fR <path to pid file>
> +Specifies the file that contains the process ID of the opensm daemon.
> +The default is \fB/var/run/opensm.pid\fP
> +.TP
Should use a configure substitution for /var/run/opensm.pid here..
> + printf("--pid_file <path to file>\n"
> + " Specifies the file that contains the process ID of the\n"
> + " opensm daemon.The default is /var/run/opensm.pid\n");
And this should be OSM_DEFAULT_PID_FILE
> + if (opt.daemon) {
> + FILE *f = fopen(opt.pid_file, "w");
Need a "wt" in case the file already exists
Jason
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110713082640.GA2024-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2011-07-13 16:48 ` Jason Gunthorpe
@ 2011-07-14 0:40 ` Roland Dreier
[not found] ` <CAL1RGDVXJd7Sq0-CcYR6heN_HCsrmc1CtrkKfxLWxYe3WN=ghA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
1 sibling, 1 reply; 11+ messages in thread
From: Roland Dreier @ 2011-07-14 0:40 UTC (permalink / raw)
To: Alex Netes
Cc: Jason Gunthorpe, Ira Weiny,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Aleksey Senin
On Wed, Jul 13, 2011 at 1:26 AM, Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> +dnl Where to place opensm.pid
> +piddir=/var/run
FWIW the future seems to be /run instead of /var/run, eg
http://lists.fedoraproject.org/pipermail/devel/2011-March/150031.html
Not sure what the best way to handle this in a way that doesn't cause
hassles for packagers is.
- R.
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <CAL1RGDVXJd7Sq0-CcYR6heN_HCsrmc1CtrkKfxLWxYe3WN=ghA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2011-07-14 16:10 ` Jason Gunthorpe
[not found] ` <20110714161056.GB4502-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Jason Gunthorpe @ 2011-07-14 16:10 UTC (permalink / raw)
To: Roland Dreier
Cc: Alex Netes, Ira Weiny,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Aleksey Senin
On Wed, Jul 13, 2011 at 05:40:57PM -0700, Roland Dreier wrote:
> On Wed, Jul 13, 2011 at 1:26 AM, Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> > +dnl Where to place opensm.pid
> > +piddir=/var/run
>
> FWIW the future seems to be /run instead of /var/run, eg
> http://lists.fedoraproject.org/pipermail/devel/2011-March/150031.html
>
> Not sure what the best way to handle this in a way that doesn't cause
> hassles for packagers is.
Donno, I find it still unclear if /run is just for early boot stuff
that might start prior to /var being mounted or a general replacement
for all /run directories - I think it is the just for early boot
stuff, and /var/run will bind mount/symlink to it (maybe forever?)?
In any event, it is the packager's responsibility to understand details
like this for their distribution..
Jason
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110714161056.GB4502-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2011-07-14 16:21 ` Ira Weiny
[not found] ` <20110714092129.b29a7ca0.weiny2-i2BcT+NCU+M@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Ira Weiny @ 2011-07-14 16:21 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Roland Dreier, Alex Netes,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Aleksey Senin
On Thu, 14 Jul 2011 09:10:56 -0700
Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote:
> On Wed, Jul 13, 2011 at 05:40:57PM -0700, Roland Dreier wrote:
> > On Wed, Jul 13, 2011 at 1:26 AM, Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> > > +dnl Where to place opensm.pid
> > > +piddir=/var/run
> >
> > FWIW the future seems to be /run instead of /var/run, eg
> > http://lists.fedoraproject.org/pipermail/devel/2011-March/150031.html
> >
> > Not sure what the best way to handle this in a way that doesn't cause
> > hassles for packagers is.
>
> Donno, I find it still unclear if /run is just for early boot stuff
> that might start prior to /var being mounted or a general replacement
> for all /run directories - I think it is the just for early boot
> stuff, and /var/run will bind mount/symlink to it (maybe forever?)?
>
> In any event, it is the packager's responsibility to understand details
> like this for their distribution..
It seems like the right thing to do would be to use an autoconf variable like "localstatedir". But every reference I find seems to indicate it is not automatic to say the least...
http://www.linuxfromscratch.org/pipermail/lfs-support/2003-June/017720.html
http://openbsd.monkey.org/ports/200001/msg00065.html
http://www.spinics.net/lists/ac/msg04439.html
http://fedoraforum.org/forum/showthread.php?t=262824
https://bugzilla.redhat.com/show_bug.cgi?id=702769
:-(
Ira
>
> Jason
--
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
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] 11+ messages in thread
* Re: [PATCH] opensm: Add support for PID file
[not found] ` <20110714092129.b29a7ca0.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2011-07-26 12:57 ` Alex Netes
0 siblings, 0 replies; 11+ messages in thread
From: Alex Netes @ 2011-07-26 12:57 UTC (permalink / raw)
To: Ira Weiny
Cc: Jason Gunthorpe, Roland Dreier,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Aleksey Senin
On 09:21 Thu 14 Jul , Ira Weiny wrote:
> On Thu, 14 Jul 2011 09:10:56 -0700
> Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote:
>
> > On Wed, Jul 13, 2011 at 05:40:57PM -0700, Roland Dreier wrote:
> > > On Wed, Jul 13, 2011 at 1:26 AM, Alex Netes <alexne-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org> wrote:
> > > > +dnl Where to place opensm.pid
> > > > +piddir=/var/run
> > >
> > > FWIW the future seems to be /run instead of /var/run, eg
> > > http://lists.fedoraproject.org/pipermail/devel/2011-March/150031.html
> > >
> > > Not sure what the best way to handle this in a way that doesn't cause
> > > hassles for packagers is.
> >
> > Donno, I find it still unclear if /run is just for early boot stuff
> > that might start prior to /var being mounted or a general replacement
> > for all /run directories - I think it is the just for early boot
> > stuff, and /var/run will bind mount/symlink to it (maybe forever?)?
> >
> > In any event, it is the packager's responsibility to understand details
> > like this for their distribution..
>
There is a Filesystem Hierarchy Standard from 2004, which
define the use of /var/run/ as:
This directory contains system information data describing the system since it
was booted. Files under this directory must be cleared (removed or truncated
as appropriate) at the beginning of the boot process. Programs may have a
subdirectory of /var/run; this is encouraged for programs that use more than
one run-time file. [42] Process identifier (PID) files, which were originally
placed in /etc, must be placed in /var/run. The naming convention for PID
files is <program-name>.pid. For example, the crond PID file is named
/var/run/crond.pid.
http://proton.pathname.com/fhs/pub/fhs-2.3.html#VARRUNRUNTIMEVARIABLEDATA
> It seems like the right thing to do would be to use an autoconf variable like "localstatedir". But every reference I find seems to indicate it is not automatic to say the least...
>
> http://www.linuxfromscratch.org/pipermail/lfs-support/2003-June/017720.html
> http://openbsd.monkey.org/ports/200001/msg00065.html
> http://www.spinics.net/lists/ac/msg04439.html
>
> http://fedoraforum.org/forum/showthread.php?t=262824
> https://bugzilla.redhat.com/show_bug.cgi?id=702769
>
> :-(
>
There is some confusion about the usage of localstatedir. Here is a
definition of localstatedir:
http://www.gnu.org/prep/standards/html_node/Directory-Variables.html#Directory-Variables
‘localstatedir’
The directory for installing data files which the programs modify while they
run, and that pertain to one specific machine. Users should never need to
modify files in this directory to configure the package’s operation; put such
configuration information in separate files that go in ‘$(datadir)’ or
‘$(sysconfdir)’. ‘$(localstatedir)’ should normally be ‘/usr/local/var’, but
write it as ‘$(prefix)/var’. (If you are using Autoconf, write it as
‘@localstatedir@’.)
Moreover, localstatedir= ${prefix}/var could be overwritten by using
config.stte script as described here:
http://www.gnu.org/software/autoconf/manual/autoconf.html#Site-Defaults
So I guess we can define the default piddir=@localstatedir@/run/ unless the
user decides to overwrite it and hope that the packager is using
appropriate site.conf. But if he doesn't, the default would be
/usr/local/var/run which isn't a good thing though.
> Ira
>
> >
> > Jason
>
>
> --
> Ira Weiny
> Math Programmer/Computer Scientist
> Lawrence Livermore National Lab
> 925-423-8008
> weiny2-i2BcT+NCU+M@public.gmane.org
> --
> 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
--
-- 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] 11+ messages in thread
end of thread, other threads:[~2011-07-26 12:57 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-10 12:04 [PATCH] opensm: Add support for PID file Alex Netes
[not found] ` <20110710120442.GA11284-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2011-07-12 23:27 ` Ira Weiny
[not found] ` <20110712162740.29e2d7d1.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-12 23:52 ` Jason Gunthorpe
[not found] ` <20110712235222.GG10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-12 23:58 ` Ira Weiny
[not found] ` <20110712165817.16076a3d.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-13 4:14 ` Jason Gunthorpe
[not found] ` <20110713041441.GA26663-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-13 8:26 ` Alex Netes
[not found] ` <20110713082640.GA2024-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2011-07-13 16:48 ` Jason Gunthorpe
2011-07-14 0:40 ` Roland Dreier
[not found] ` <CAL1RGDVXJd7Sq0-CcYR6heN_HCsrmc1CtrkKfxLWxYe3WN=ghA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-07-14 16:10 ` Jason Gunthorpe
[not found] ` <20110714161056.GB4502-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-14 16:21 ` Ira Weiny
[not found] ` <20110714092129.b29a7ca0.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-26 12:57 ` Alex Netes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox