65
65
#include "opal/util/opal_getcwd.h"
66
66
#include "opal/util/show_help.h"
67
67
#include "opal/util/fd.h"
68
+ #include "opal/util/daemon_init.h"
68
69
69
70
#include "opal/version.h"
70
71
#include "opal/runtime/opal.h"
@@ -99,6 +100,8 @@ static struct {
99
100
char * report_uri ;
100
101
char * prefix ;
101
102
bool run_as_root ;
103
+ bool set_sid ;
104
+ bool daemonize ;
102
105
} myglobals ;
103
106
104
107
static opal_cmd_line_init_t cmd_line_init [] = {
@@ -118,6 +121,14 @@ static opal_cmd_line_init_t cmd_line_init[] = {
118
121
& myglobals .prefix , OPAL_CMD_LINE_TYPE_STRING ,
119
122
"Prefix to be used to look for ORTE executables" },
120
123
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
+
121
132
{ "orte_debug_daemons" , '\0' , "debug-daemons" , "debug-daemons" , 0 ,
122
133
NULL , OPAL_CMD_LINE_TYPE_BOOL ,
123
134
"Debug daemons" },
@@ -278,6 +289,22 @@ int main(int argc, char *argv[])
278
289
*/
279
290
orte_launch_environ = opal_argv_copy (environ );
280
291
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
+
281
308
/* Intialize our Open RTE environment */
282
309
if (ORTE_SUCCESS != (rc = orte_init (& argc , & argv , ORTE_PROC_MASTER ))) {
283
310
/* cannot call ORTE_ERROR_LOG as it could be the errmgr
0 commit comments