root/mpich2/trunk/src/pm/hydra/bootstrap/rsh/rsh_launch.c @ 4887

Revision 4887, 3.0 KB (checked in by balaji, 5 months ago)

Warning stomp.

Line 
1/* -*- Mode: C; c-basic-offset:4 ; -*- */
2/*
3 *  (C) 2008 by Argonne National Laboratory.
4 *      See COPYRIGHT in top-level directory.
5 */
6
7#include "hydra_utils.h"
8#include "bsci.h"
9#include "bscu.h"
10#include "rsh.h"
11
12/*
13 * HYD_BSCD_rsh_launch_procs: For each process, we create an
14 * executable which reads like "rsh exec args" and the list of
15 * environment variables. We fork a worker process that sets the
16 * environment and execvp's this executable.
17 */
18HYD_Status HYD_BSCD_rsh_launch_procs(char **global_args, const char *partition_id_str,
19                                     struct HYD_Partition *partition_list)
20{
21    struct HYD_Partition *partition;
22    char *client_arg[HYD_NUM_TMP_STRINGS];
23    char *tmp[HYD_NUM_TMP_STRINGS], *path = NULL, *test_path = NULL;
24    int i, arg, process_id;
25    HYD_Status status = HYD_SUCCESS;
26
27    HYDU_FUNC_ENTER();
28
29    /*
30     * We use the following priority order for the executable path:
31     *    1. User-specified
32     *    2. Search in path
33     *    3. Hard-coded location
34     */
35    if (HYD_BSCI_info.bootstrap_exec) {
36        path = HYDU_strdup(HYD_BSCI_info.bootstrap_exec);
37    }
38    else {
39        status = HYDU_find_in_path("rsh", &test_path);
40        HYDU_ERR_POP(status, "error while searching for executable in user path\n");
41
42        if (test_path) {
43            tmp[0] = HYDU_strdup(test_path);
44            tmp[1] = HYDU_strdup("rsh");
45            tmp[2] = NULL;
46
47            status = HYDU_str_alloc_and_join(tmp, &path);
48            HYDU_ERR_POP(status, "error joining strings\n");
49
50            HYDU_free_strlist(tmp);
51        }
52        else
53            path = HYDU_strdup("/usr/bin/rsh");
54    }
55
56    process_id = 0;
57    FORALL_ACTIVE_PARTITIONS(partition, partition_list) {
58        /* Setup the executable arguments */
59        arg = 0;
60        client_arg[arg++] = HYDU_strdup(path);
61
62        /* rsh does not support any partition names other than host names */
63        client_arg[arg++] = HYDU_strdup(partition->base->name);
64
65        for (i = 0; global_args[i]; i++)
66            client_arg[arg++] = HYDU_strdup(global_args[i]);
67
68        if (partition_id_str) {
69            client_arg[arg++] = HYDU_strdup(partition_id_str);
70            client_arg[arg++] = HYDU_int_to_str(partition->base->partition_id);
71        }
72
73        client_arg[arg++] = NULL;
74
75        if (HYD_BSCI_info.debug) {
76            HYDU_Dump("Launching process: ");
77            HYDU_print_strlist(client_arg);
78        }
79
80        /* The stdin pointer will be some value for process_id 0; for
81         * everyone else, it's NULL. */
82        status = HYDU_create_process(client_arg, NULL,
83                                     (process_id == 0 ? &partition->base->in : NULL),
84                                     &partition->base->out, &partition->base->err,
85                                     &partition->base->pid, -1);
86        HYDU_ERR_POP(status, "create process returned error\n");
87
88        HYDU_free_strlist(client_arg);
89
90        process_id++;
91    }
92
93  fn_exit:
94    HYDU_FUNC_EXIT();
95    return status;
96
97  fn_fail:
98    goto fn_exit;
99}
Note: See TracBrowser for help on using the browser.