root/mpich2/trunk/src/pm/hydra/bootstrap/ssh/ssh_launch.c @ 4887

Revision 4887, 3.4 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 "ssh.h"
11
12/*
13 * HYD_BSCD_ssh_launch_procs: For each process, we create an
14 * executable which reads like "ssh 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_ssh_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("ssh", &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("ssh");
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/ssh");
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        /* Allow X forwarding only if explicitly requested */
63        if (HYD_BSCI_info.enablex == 1)
64            client_arg[arg++] = HYDU_strdup("-X");
65        else if (HYD_BSCI_info.enablex == 0)
66            client_arg[arg++] = HYDU_strdup("-x");
67        else    /* default mode is disable X */
68            client_arg[arg++] = HYDU_strdup("-x");
69
70        /* ssh does not support any partition names other than host names */
71        client_arg[arg++] = HYDU_strdup(partition->base->name);
72
73        for (i = 0; global_args[i]; i++)
74            client_arg[arg++] = HYDU_strdup(global_args[i]);
75
76        if (partition_id_str) {
77            client_arg[arg++] = HYDU_strdup(partition_id_str);
78            client_arg[arg++] = HYDU_int_to_str(partition->base->partition_id);
79        }
80
81        client_arg[arg++] = NULL;
82
83        if (HYD_BSCI_info.debug) {
84            HYDU_Dump("Launching process: ");
85            HYDU_print_strlist(client_arg);
86        }
87
88        /* The stdin pointer will be some value for process_id 0; for
89         * everyone else, it's NULL. */
90        status = HYDU_create_process(client_arg, NULL,
91                                     (process_id == 0 ? &partition->base->in : NULL),
92                                     &partition->base->out, &partition->base->err,
93                                     &partition->base->pid, -1);
94        HYDU_ERR_POP(status, "create process returned error\n");
95
96        HYDU_free_strlist(client_arg);
97
98        process_id++;
99    }
100
101  fn_exit:
102    if (test_path)
103        HYDU_FREE(test_path);
104    if (path)
105        HYDU_FREE(path);
106    HYDU_FUNC_EXIT();
107    return status;
108
109  fn_fail:
110    goto fn_exit;
111}
Note: See TracBrowser for help on using the browser.