Skip to content

Commit cfce565

Browse files
author
Ralph Castain
authored
Merge pull request #2763 from naughtont3/tjn-ortedvm-daemonize
dvm: add daemonize and set-sid options
2 parents 33d97b2 + 39d335a commit cfce565

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

orte/tools/orte-dvm/orte-dvm.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "opal/util/opal_getcwd.h"
6666
#include "opal/util/show_help.h"
6767
#include "opal/util/fd.h"
68+
#include "opal/util/daemon_init.h"
6869

6970
#include "opal/version.h"
7071
#include "opal/runtime/opal.h"
@@ -99,6 +100,8 @@ static struct {
99100
char *report_uri;
100101
char *prefix;
101102
bool run_as_root;
103+
bool set_sid;
104+
bool daemonize;
102105
} myglobals;
103106

104107
static opal_cmd_line_init_t cmd_line_init[] = {
@@ -118,6 +121,14 @@ static opal_cmd_line_init_t cmd_line_init[] = {
118121
&myglobals.prefix, OPAL_CMD_LINE_TYPE_STRING,
119122
"Prefix to be used to look for ORTE executables" },
120123

124+
{ "orte_daemonize", '\0', NULL, "daemonize", 0,
125+
&myglobals.daemonize, OPAL_CMD_LINE_TYPE_BOOL,
126+
"Daemonize the orte-dvm into the background" },
127+
128+
{ NULL, '\0', NULL, "set-sid", 0,
129+
&myglobals.set_sid, OPAL_CMD_LINE_TYPE_BOOL,
130+
"Direct the orte-dvm to separate from the current session"},
131+
121132
{ "orte_debug_daemons", '\0', "debug-daemons", "debug-daemons", 0,
122133
NULL, OPAL_CMD_LINE_TYPE_BOOL,
123134
"Debug daemons" },
@@ -278,6 +289,22 @@ int main(int argc, char *argv[])
278289
*/
279290
orte_launch_environ = opal_argv_copy(environ);
280291

292+
#if defined(HAVE_SETSID)
293+
/* see if we were directed to separate from current session */
294+
if (myglobals.set_sid) {
295+
setsid();
296+
}
297+
#endif
298+
299+
/* detach from controlling terminal
300+
* otherwise, remain attached so output can get to us
301+
*/
302+
if(!orte_debug_flag &&
303+
!orte_debug_daemons_flag &&
304+
myglobals.daemonize) {
305+
opal_daemon_init(NULL);
306+
}
307+
281308
/* Intialize our Open RTE environment */
282309
if (ORTE_SUCCESS != (rc = orte_init(&argc, &argv, ORTE_PROC_MASTER))) {
283310
/* cannot call ORTE_ERROR_LOG as it could be the errmgr

0 commit comments

Comments
 (0)