2006-06-29 02:33:54 +04:00
|
|
|
/*
|
2007-03-17 02:11:45 +03:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2006-06-29 02:33:54 +04:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2008-07-22 21:41:06 +04:00
|
|
|
* Copyright (c) 2007-2008 Sun Microsystems, Inc. All rights reserved.
|
2007-06-05 07:03:59 +04:00
|
|
|
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2006-06-29 02:33:54 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
#include "orte_config.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/constants.h"
|
2006-06-29 02:33:54 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2006-07-11 09:25:41 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2006-06-29 02:33:54 +04:00
|
|
|
#include <unistd.h>
|
2006-07-11 09:25:41 +04:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
2006-06-29 02:33:54 +04:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif /* HAVE_STDLIB_H */
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_SYS_STAT_H */
|
2006-06-29 02:33:54 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_SYS_TYPES_H */
|
2006-06-29 02:33:54 +04:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_SYS_WAIT_H */
|
2007-02-03 04:11:35 +03:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_SYS_PARAM_H */
|
2006-06-29 02:33:54 +04:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif /* HAVE_STRING_H */
|
2007-02-03 03:25:42 +03:00
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif /* HAVE_DIRENT_H */
|
|
|
|
#include <signal.h>
|
2008-03-24 02:10:15 +03:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif /* HAVE_PWD_H */
|
2006-06-29 02:33:54 +04:00
|
|
|
|
|
|
|
#include "opal/util/cmd_line.h"
|
|
|
|
#include "opal/util/argv.h"
|
|
|
|
#include "opal/util/opal_environ.h"
|
2006-07-11 09:50:15 +04:00
|
|
|
#include "opal/util/os_dirpath.h"
|
2008-07-22 21:41:06 +04:00
|
|
|
#include "opal/util/basename.h"
|
2006-06-29 02:33:54 +04:00
|
|
|
#include "opal/mca/base/base.h"
|
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
|
|
|
|
2008-06-09 18:53:58 +04:00
|
|
|
#include "orte/util/show_help.h"
|
2006-06-29 02:33:54 +04:00
|
|
|
#include "orte/util/proc_info.h"
|
|
|
|
#include "opal/util/os_path.h"
|
|
|
|
#include "orte/util/session_dir.h"
|
|
|
|
|
|
|
|
#include "opal/runtime/opal.h"
|
2007-03-17 02:11:45 +03:00
|
|
|
#if OPAL_ENABLE_FT == 1
|
|
|
|
#include "opal/runtime/opal_cr.h"
|
|
|
|
#endif
|
2006-06-29 02:33:54 +04:00
|
|
|
#include "orte/runtime/runtime.h"
|
|
|
|
|
|
|
|
/******************
|
|
|
|
* Local Functions
|
|
|
|
******************/
|
|
|
|
static int parse_args(int argc, char *argv[]);
|
2007-02-03 03:25:42 +03:00
|
|
|
#if !defined(__WINDOWS__)
|
|
|
|
static void kill_procs(void);
|
|
|
|
#endif /* !defined(__WINDOWS__) */
|
2006-06-29 02:33:54 +04:00
|
|
|
|
|
|
|
/*****************************************
|
|
|
|
* Global Vars for Command line Arguments
|
|
|
|
*****************************************/
|
|
|
|
typedef struct {
|
2007-01-11 17:07:15 +03:00
|
|
|
bool help;
|
|
|
|
bool verbose;
|
2008-07-22 21:41:06 +04:00
|
|
|
bool debug;
|
2006-06-29 02:33:54 +04:00
|
|
|
} orte_clean_globals_t;
|
|
|
|
|
|
|
|
orte_clean_globals_t orte_clean_globals;
|
|
|
|
|
|
|
|
opal_cmd_line_init_t cmd_line_opts[] = {
|
|
|
|
{ NULL, NULL, NULL,
|
|
|
|
'h', NULL, "help",
|
|
|
|
0,
|
|
|
|
&orte_clean_globals.help, OPAL_CMD_LINE_TYPE_BOOL,
|
|
|
|
"This help message" },
|
|
|
|
|
|
|
|
{ NULL, NULL, NULL,
|
|
|
|
'v', NULL, "verbose",
|
|
|
|
0,
|
|
|
|
&orte_clean_globals.verbose, OPAL_CMD_LINE_TYPE_BOOL,
|
2007-02-03 03:25:42 +03:00
|
|
|
"Generate verbose output" },
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2008-07-22 21:41:06 +04:00
|
|
|
{ NULL, NULL, NULL,
|
|
|
|
'd', NULL, "debug",
|
|
|
|
0,
|
|
|
|
&orte_clean_globals.debug, OPAL_CMD_LINE_TYPE_BOOL,
|
|
|
|
"Extra debug output for developers to ensure that orte-clean is working" },
|
|
|
|
|
2006-06-29 02:33:54 +04:00
|
|
|
/* End of list */
|
|
|
|
{ NULL, NULL, NULL,
|
|
|
|
'\0', NULL, NULL,
|
|
|
|
0,
|
|
|
|
NULL, OPAL_CMD_LINE_TYPE_NULL,
|
|
|
|
NULL }
|
|
|
|
};
|
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* This utility will do a brute force clean of a node. It will
|
|
|
|
* attempt to clean up any files in the user's session directory.
|
|
|
|
* It will also look for any orted and orterun processes that are
|
|
|
|
* not part of this job, and kill them off.
|
|
|
|
*/
|
2006-06-29 02:33:54 +04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2008-07-22 21:41:06 +04:00
|
|
|
int ret = ORTE_SUCCESS;
|
|
|
|
char *tmp_env_var;
|
|
|
|
|
|
|
|
/* This is needed so we can print the help message */
|
|
|
|
if (ORTE_SUCCESS != (ret = opal_init_util())) {
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-29 02:33:54 +04:00
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (ret = parse_args(argc, argv))) {
|
|
|
|
return ret;
|
|
|
|
}
|
2008-07-22 21:41:06 +04:00
|
|
|
|
|
|
|
#if OPAL_ENABLE_FT == 1
|
|
|
|
/* Disable the checkpoint notification routine for this
|
|
|
|
* tool. As we will never need to checkpoint this tool.
|
|
|
|
* Note: This must happen before opal_init().
|
|
|
|
*/
|
|
|
|
opal_cr_set_enabled(false);
|
|
|
|
|
|
|
|
/* Select the none component, since we don't actually use a checkpointer */
|
|
|
|
tmp_env_var = mca_base_param_env_var("crs");
|
|
|
|
opal_setenv(tmp_env_var,
|
|
|
|
"none",
|
|
|
|
true, &environ);
|
|
|
|
free(tmp_env_var);
|
|
|
|
tmp_env_var = NULL;
|
|
|
|
|
|
|
|
tmp_env_var = mca_base_param_env_var("opal_cr_is_tool");
|
|
|
|
opal_setenv(tmp_env_var,
|
|
|
|
"1", true, NULL);
|
|
|
|
free(tmp_env_var);
|
|
|
|
#endif
|
|
|
|
tmp_env_var = NULL; /* Silence compiler warning */
|
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (ret = orte_init(ORTE_TOOL_WITH_NAME))) {
|
|
|
|
return ret;
|
2006-06-29 02:33:54 +04:00
|
|
|
}
|
2008-07-22 21:41:06 +04:00
|
|
|
|
2006-06-29 02:33:54 +04:00
|
|
|
/*
|
2008-02-28 04:57:57 +03:00
|
|
|
* Clean out all session directories - we don't have to protect
|
|
|
|
* our own session directory because (since we are a tool) we
|
|
|
|
* didn't create one!
|
2006-06-29 02:33:54 +04:00
|
|
|
*/
|
2008-02-28 04:57:57 +03:00
|
|
|
if (orte_clean_globals.verbose) {
|
|
|
|
fprintf(stderr, "orte-clean: cleaning session dir tree %s\n",
|
|
|
|
orte_process_info.top_session_dir);
|
|
|
|
}
|
|
|
|
opal_os_dirpath_destroy(orte_process_info.top_session_dir, true, NULL);
|
|
|
|
|
|
|
|
/* now kill any lingering procs, if we can */
|
2007-02-03 03:25:42 +03:00
|
|
|
#if !defined(__WINDOWS__)
|
|
|
|
kill_procs();
|
|
|
|
#endif /* !defined(__WINDOWS__) */
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2006-08-23 06:35:00 +04:00
|
|
|
orte_finalize();
|
2007-09-12 23:50:58 +04:00
|
|
|
|
2008-07-22 21:41:06 +04:00
|
|
|
return ORTE_SUCCESS;
|
2006-06-29 02:33:54 +04:00
|
|
|
}
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* Parse the command line arguments using the functions command
|
|
|
|
* line utility functions.
|
|
|
|
*/
|
2006-06-29 02:33:54 +04:00
|
|
|
static int parse_args(int argc, char *argv[]) {
|
2007-09-12 23:50:58 +04:00
|
|
|
int ret;
|
2006-06-29 02:33:54 +04:00
|
|
|
opal_cmd_line_t cmd_line;
|
2008-07-22 21:41:06 +04:00
|
|
|
orte_clean_globals_t tmp = { false, false, false };
|
2007-01-11 17:30:32 +03:00
|
|
|
|
|
|
|
/* NOTE: There is a bug in the PGI 6.2 series that causes the
|
|
|
|
compiler to choke when copying structs containing bool members
|
|
|
|
by value. So do a memcpy here instead. */
|
|
|
|
memcpy(&orte_clean_globals, &tmp, sizeof(tmp));
|
2007-09-12 23:50:58 +04:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* Initialize list of available command line options.
|
|
|
|
*/
|
2006-06-29 02:33:54 +04:00
|
|
|
opal_cmd_line_create(&cmd_line, cmd_line_opts);
|
|
|
|
ret = opal_cmd_line_parse(&cmd_line, true, argc, argv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Now start parsing our specific arguments
|
|
|
|
*/
|
|
|
|
if (OPAL_SUCCESS != ret ||
|
|
|
|
orte_clean_globals.help) {
|
|
|
|
char *args = NULL;
|
|
|
|
args = opal_cmd_line_get_usage_msg(&cmd_line);
|
This commit represents a bunch of work on a Mercurial side branch. As
such, the commit message back to the master SVN repository is fairly
long.
= ORTE Job-Level Output Messages =
Add two new interfaces that should be used for all new code throughout
the ORTE and OMPI layers (we already make the search-and-replace on
the existing ORTE / OMPI layers):
* orte_output(): (and corresponding friends ORTE_OUTPUT,
orte_output_verbose, etc.) This function sends the output directly
to the HNP for processing as part of a job-specific output
channel. It supports all the same outputs as opal_output()
(syslog, file, stdout, stderr), but for stdout/stderr, the output
is sent to the HNP for processing and output. More on this below.
* orte_show_help(): This function is a drop-in-replacement for
opal_show_help(), with two differences in functionality:
1. the rendered text help message output is sent to the HNP for
display (rather than outputting directly into the process' stderr
stream)
1. the HNP detects duplicate help messages and does not display them
(so that you don't see the same error message N times, once from
each of your N MPI processes); instead, it counts "new" instances
of the help message and displays a message every ~5 seconds when
there are new ones ("I got X new copies of the help message...")
opal_show_help and opal_output still exist, but they only output in
the current process. The intent for the new orte_* functions is that
they can apply job-level intelligence to the output. As such, we
recommend that all new ORTE and OMPI code use the new orte_*
functions, not thei opal_* functions.
=== New code ===
For ORTE and OMPI programmers, here's what you need to do differently
in new code:
* Do not include opal/util/show_help.h or opal/util/output.h.
Instead, include orte/util/output.h (this one header file has
declarations for both the orte_output() series of functions and
orte_show_help()).
* Effectively s/opal_output/orte_output/gi throughout your code.
Note that orte_output_open() takes a slightly different argument
list (as a way to pass data to the filtering stream -- see below),
so you if explicitly call opal_output_open(), you'll need to
slightly adapt to the new signature of orte_output_open().
* Literally s/opal_show_help/orte_show_help/. The function signature
is identical.
=== Notes ===
* orte_output'ing to stream 0 will do similar to what
opal_output'ing did, so leaving a hard-coded "0" as the first
argument is safe.
* For systems that do not use ORTE's RML or the HNP, the effect of
orte_output_* and orte_show_help will be identical to their opal
counterparts (the additional information passed to
orte_output_open() will be lost!). Indeed, the orte_* functions
simply become trivial wrappers to their opal_* counterparts. Note
that we have not tested this; the code is simple but it is quite
possible that we mucked something up.
= Filter Framework =
Messages sent view the new orte_* functions described above and
messages output via the IOF on the HNP will now optionally be passed
through a new "filter" framework before being output to
stdout/stderr. The "filter" OPAL MCA framework is intended to allow
preprocessing to messages before they are sent to their final
destinations. The first component that was written in the filter
framework was to create an XML stream, segregating all the messages
into different XML tags, etc. This will allow 3rd party tools to read
the stdout/stderr from the HNP and be able to know exactly what each
text message is (e.g., a help message, another OMPI infrastructure
message, stdout from the user process, stderr from the user process,
etc.).
Filtering is not active by default. Filter components must be
specifically requested, such as:
{{{
$ mpirun --mca filter xml ...
}}}
There can only be one filter component active.
= New MCA Parameters =
The new functionality described above introduces two new MCA
parameters:
* '''orte_base_help_aggregate''': Defaults to 1 (true), meaning that
help messages will be aggregated, as described above. If set to 0,
all help messages will be displayed, even if they are duplicates
(i.e., the original behavior).
* '''orte_base_show_output_recursions''': An MCA parameter to help
debug one of the known issues, described below. It is likely that
this MCA parameter will disappear before v1.3 final.
= Known Issues =
* The XML filter component is not complete. The current output from
this component is preliminary and not real XML. A bit more work
needs to be done to configure.m4 search for an appropriate XML
library/link it in/use it at run time.
* There are possible recursion loops in the orte_output() and
orte_show_help() functions -- e.g., if RML send calls orte_output()
or orte_show_help(). We have some ideas how to fix these, but
figured that it was ok to commit before feature freeze with known
issues. The code currently contains sub-optimal workarounds so
that this will not be a problem, but it would be good to actually
solve the problem rather than have hackish workarounds before v1.3 final.
This commit was SVN r18434.
2008-05-14 00:00:55 +04:00
|
|
|
orte_show_help("help-orte-clean.txt", "usage", true,
|
2006-06-29 02:33:54 +04:00
|
|
|
args);
|
|
|
|
free(args);
|
|
|
|
return ORTE_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
OBJ_DESTRUCT(&cmd_line);
|
|
|
|
|
2006-06-29 02:33:54 +04:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
#if !defined(__WINDOWS__)
|
2008-02-28 04:57:57 +03:00
|
|
|
static char *orte_getline(FILE *fp)
|
|
|
|
{
|
|
|
|
char *ret, *buff;
|
|
|
|
char input[1024];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = fgets(input, 1024, fp);
|
|
|
|
if (NULL != ret) {
|
|
|
|
/* remove trailing spaces */
|
|
|
|
for (i=strlen(input)-2; i > 0; i--) {
|
|
|
|
if (input[i] != ' ') {
|
|
|
|
input[i+1] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buff = strdup(input);
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* This function makes a call to "ps" to find out the processes that
|
|
|
|
* are running on this node. It then attempts to kill off any orteds
|
|
|
|
* and orteruns that are not related to this job.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
void kill_procs(void) {
|
2007-02-06 01:03:58 +03:00
|
|
|
int ortedpid;
|
2008-07-22 21:41:06 +04:00
|
|
|
char *fullprocname;
|
2008-02-28 04:57:57 +03:00
|
|
|
char *procname;
|
|
|
|
char *pidstr;
|
|
|
|
char *user;
|
2007-02-03 03:25:42 +03:00
|
|
|
int procpid;
|
|
|
|
FILE *psfile;
|
2008-07-22 21:41:06 +04:00
|
|
|
char *inputline;
|
2008-03-24 02:10:15 +03:00
|
|
|
char *this_user;
|
|
|
|
int uid;
|
2008-07-22 21:41:06 +04:00
|
|
|
struct passwd *pwdent;
|
|
|
|
char *separator = " \t"; /* output can be delimited by space or tab */
|
2008-03-24 02:10:15 +03:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* This is the command that is used to get the information about
|
|
|
|
* all the processes that are running. The output looks like the
|
|
|
|
* following:
|
|
|
|
* COMMAND PID USER
|
|
|
|
* tcsh 12556 rolfv
|
|
|
|
* ps 14424 rolfv
|
|
|
|
* etc.
|
|
|
|
* Currently, we do not make use of the USER field, but we may later
|
|
|
|
* on so we grab it also.
|
|
|
|
*/
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* The configure determines if there is a valid ps command for us to
|
|
|
|
* use. If it is set to unknown, then we skip this section.
|
|
|
|
*/
|
|
|
|
char command[] = ORTE_CLEAN_PS_CMD;
|
2008-02-28 04:57:57 +03:00
|
|
|
if (0 == strcmp("unknown", command)) {
|
|
|
|
return;
|
2007-02-03 03:25:42 +03:00
|
|
|
}
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
if (orte_clean_globals.verbose) {
|
|
|
|
fprintf(stderr, "orte-clean: killing any lingering procs\n");
|
2007-02-03 03:25:42 +03:00
|
|
|
}
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* Get our parent pid which is the pid of the orted.
|
|
|
|
*/
|
|
|
|
ortedpid = getppid();
|
2006-06-29 02:33:54 +04:00
|
|
|
|
2008-07-22 21:41:06 +04:00
|
|
|
/* get the name of the user */
|
2008-03-24 02:10:15 +03:00
|
|
|
uid = getuid();
|
|
|
|
#ifdef HAVE_GETPWUID
|
|
|
|
pwdent = getpwuid(uid);
|
|
|
|
#else
|
|
|
|
pwdent = NULL;
|
|
|
|
#endif
|
|
|
|
if (NULL != pwdent) {
|
|
|
|
this_user = strdup(pwdent->pw_name);
|
|
|
|
} else {
|
|
|
|
if (0 > asprintf(&this_user, "%d", uid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-29 02:33:54 +04:00
|
|
|
/*
|
2007-02-03 03:25:42 +03:00
|
|
|
* There is a race condition here. The problem is that we are looking
|
|
|
|
* for any processes named orted. However, one may erroneously find more
|
|
|
|
* orteds then there really are because the orted is doing a series of
|
|
|
|
* fork/execs. If we run with more than one orte-clean on a node, then
|
|
|
|
* one of the orte-cleans may catch the other one while it has forked,
|
|
|
|
* but not exec'ed. It will therefore kill an orte-clean. Now one
|
|
|
|
* can argue it is silly to run more than one orte-clean on a node, and
|
|
|
|
* this is true. We will have to figure out how to prevent this. For
|
|
|
|
* now, we use a big hammer and just sleep a second to decrease the
|
|
|
|
* probability.
|
2006-06-29 02:33:54 +04:00
|
|
|
*/
|
2007-02-03 03:25:42 +03:00
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
psfile = popen(command, "r");
|
2006-06-29 02:33:54 +04:00
|
|
|
/*
|
2007-02-03 03:25:42 +03:00
|
|
|
* Read the first line of the output. We just throw it away
|
|
|
|
* as it is the header consisting of the words COMMAND, PID and
|
|
|
|
* USER.
|
2006-06-29 02:33:54 +04:00
|
|
|
*/
|
2008-02-28 04:57:57 +03:00
|
|
|
if (NULL == (inputline = orte_getline(psfile))) {
|
2008-03-24 02:10:15 +03:00
|
|
|
free(this_user);
|
2007-02-03 03:25:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-02-28 04:57:57 +03:00
|
|
|
free(inputline); /* dump the header line */
|
|
|
|
|
|
|
|
while (NULL != (inputline = orte_getline(psfile))) {
|
2008-07-22 21:41:06 +04:00
|
|
|
|
|
|
|
/* The three fields are typically seperated by spaces */
|
|
|
|
fullprocname = strtok(inputline, separator);
|
|
|
|
pidstr = strtok(NULL, separator);
|
|
|
|
user = strtok(NULL, separator);
|
|
|
|
|
|
|
|
if (orte_clean_globals.debug) {
|
|
|
|
fprintf(stdout, "\norte-clean: user(pid)=%s, me=%s\n",
|
|
|
|
user, this_user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the user is not us, and the user is not root, then skip
|
|
|
|
* further checking. If the user is root, then continue on as
|
|
|
|
* we want root to kill off everybody. */
|
|
|
|
if ((0 != strcmp(user, this_user)) && (0 != strcmp("root", this_user))) {
|
2008-02-28 04:57:57 +03:00
|
|
|
/* not us */
|
|
|
|
free(inputline);
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-22 21:41:06 +04:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
procpid = atoi(pidstr);
|
2008-07-22 21:41:06 +04:00
|
|
|
procname = opal_basename(fullprocname);
|
|
|
|
if (orte_clean_globals.debug) {
|
|
|
|
fprintf(stdout, "orte-clean: fullname=%s, basename=%s, pid=%d\n",
|
|
|
|
fullprocname, procname, procpid);
|
2008-02-28 04:57:57 +03:00
|
|
|
}
|
2008-07-22 21:41:06 +04:00
|
|
|
|
2007-02-03 03:25:42 +03:00
|
|
|
/*
|
|
|
|
* Look for any orteds that are not our parent and attempt to
|
|
|
|
* kill them. We currently do not worry whether we are the
|
|
|
|
* owner or not. If we are not, we will just fail to send
|
|
|
|
* the signal and that is OK. This also allows a root process
|
|
|
|
* to kill all orteds.
|
2008-02-28 04:57:57 +03:00
|
|
|
*
|
|
|
|
* NOTE: need to also look for "(orted)" as a non-active
|
|
|
|
* proc is sometimes reported that way
|
2007-02-03 03:25:42 +03:00
|
|
|
*/
|
2008-02-28 04:57:57 +03:00
|
|
|
if (0 == strncmp("orted", procname, strlen("orted")) ||
|
|
|
|
0 == strncmp("(orted)", procname, strlen("(orted)"))) {
|
2007-02-03 03:25:42 +03:00
|
|
|
if (procpid != ortedpid) {
|
|
|
|
if (orte_clean_globals.verbose) {
|
2008-02-28 04:57:57 +03:00
|
|
|
fprintf(stderr, "orte-clean: found potential rogue orted process"
|
|
|
|
" (pid=%d,user=%s), sending SIGKILL...\n",
|
|
|
|
procpid, user);
|
2007-02-03 03:25:42 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We ignore the return code here as we do not really
|
|
|
|
* care whether this worked or not.
|
|
|
|
*/
|
|
|
|
(void)kill(procpid, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now check for any orteruns.
|
|
|
|
*/
|
2008-02-28 04:57:57 +03:00
|
|
|
if (0 == strncmp("orterun", procname, strlen("orterun")) ||
|
|
|
|
0 == strncmp("mpirun", procname, strlen("mpirun"))) {
|
|
|
|
/* if we are on the same node as the HNP, then the ortedpid
|
|
|
|
* is the same as that of our orterun, so don't kill it
|
|
|
|
*/
|
|
|
|
if (procpid != ortedpid) {
|
|
|
|
if (orte_clean_globals.verbose) {
|
|
|
|
fprintf(stderr, "orte-clean: found potential rogue orterun process"
|
|
|
|
" (pid=%d,user=%s), sending SIGKILL...\n",
|
|
|
|
procpid, user);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* if we are a singleton, check the hnp_pid as well */
|
|
|
|
if (orte_process_info.singleton) {
|
|
|
|
if (procpid != orte_process_info.hnp_pid) {
|
|
|
|
(void)kill(procpid, SIGKILL);
|
2007-02-03 03:25:42 +03:00
|
|
|
}
|
2008-02-28 04:57:57 +03:00
|
|
|
} else {
|
|
|
|
/* We ignore the return code here as we do not really
|
2007-02-03 03:25:42 +03:00
|
|
|
* care whether this worked or not.
|
|
|
|
*/
|
|
|
|
(void)kill(procpid, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-28 04:57:57 +03:00
|
|
|
free(inputline);
|
2008-07-22 21:41:06 +04:00
|
|
|
free(procname);
|
2006-06-29 02:33:54 +04:00
|
|
|
}
|
2008-03-24 02:10:15 +03:00
|
|
|
free(this_user);
|
2007-02-03 03:25:42 +03:00
|
|
|
return;
|
2006-06-29 02:33:54 +04:00
|
|
|
}
|
2007-02-03 03:25:42 +03:00
|
|
|
#endif /* !defined(__WINDOWS__) */
|