2004-08-24 01:39:22 +04:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#include "ompi_config.h"
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-08-24 01:39:22 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-24 01:39:22 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-08-24 01:39:22 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-24 12:44:37 +04:00
|
|
|
#include <stdlib.h>
|
2004-08-24 01:39:22 +04:00
|
|
|
|
|
|
|
#include "include/constants.h"
|
|
|
|
#include "util/daemon_init.h"
|
|
|
|
|
2004-08-30 23:25:14 +04:00
|
|
|
int ompi_daemon_init(char *working_dir)
|
2004-08-24 01:39:22 +04:00
|
|
|
{
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
/* it seems that there is an entirely different way to write daemons in
|
|
|
|
WINDOWS land. Firstly, they are called services and the way to
|
|
|
|
go about it is to get a service handle annd then call CreateService()
|
|
|
|
So, I am guessing that this piece of code is called only by UNIX versions */
|
|
|
|
|
2004-08-24 01:39:22 +04:00
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
if ((pid = fork()) < 0) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
} else if (pid != 0) {
|
|
|
|
exit(0); /* parent goes bye-bye */
|
|
|
|
}
|
|
|
|
/* child continues */
|
|
|
|
setsid(); /* become session leader */
|
|
|
|
|
|
|
|
if (NULL != working_dir) {
|
|
|
|
chdir(working_dir); /* change working directory */
|
|
|
|
}
|
|
|
|
|
|
|
|
umask(0); /* clear file mode creation mask */
|
|
|
|
return OMPI_SUCCESS;
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
printf ("This function has not been implemented in windows yet, file %s line %d\n", __FILE__, __LINE__);
|
|
|
|
abort();
|
|
|
|
#endif
|
2004-08-24 01:39:22 +04:00
|
|
|
}
|