1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* Copyright (c) 2001-2002 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 1998-2001 University of Notre Dame.
* All rights reserved.
* Copyright (c) 1994-1998 The Ohio State University.
* All rights reserved.
*
* This file is part of the LAM/MPI software package. For license
* information, see the LICENSE file in the top level directory of the
* LAM/MPI source distribution.
*
* $HEADER$
*
* $Id: rfpathfind.c,v 1.3 2003/03/11 00:46:08 jsquyres Exp $
*
* Function: - find a file in the $PATH on a remote node
* Accepts: - bare file name
* Returns: - absolute file name
*/
#include <lam_config.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <events.h>
#include <net.h>
#include <ksignal.h>
#include <freq.h>
#include <typical.h>
#include <etc_misc.h>
/*
* Local variables
*/
static char buf[MAXNMSGLEN];
char *
lam_rfpathfind(const char *name, const char *cwd, int nodeid)
{
struct nmsg nhead;
struct freq *request;
struct freply *reply;
int mask;
request = (struct freq *) nhead.nh_data;
reply = (struct freply *) nhead.nh_data;
LAM_ZERO_ME(nhead);
request->fq_src_node = getnodeid();
request->fq_src_event = -lam_getpid();
request->fq_req = FQPATHFIND;
nhead.nh_node = nodeid;
nhead.nh_event = EVFILED;
nhead.nh_type = 0;
nhead.nh_flags = 0;
nhead.nh_length = strlen(name) + 1;
if (cwd != NULL)
nhead.nh_length += strlen(cwd) + 1;
if (nhead.nh_length > MAXNMSGLEN) {
errno = ENAMETOOLONG;
return NULL;
}
nhead.nh_msg = (char *) buf;
if (cwd != NULL) {
snprintf(buf, MAXNMSGLEN, "%s%c%s", name, '\0', cwd);
} else {
snprintf(buf, MAXNMSGLEN, "%s%c%c", name, '\0', '\0');
}
buf[MAXNMSGLEN - 1] = '\0';
mask = ksigblock(sigmask(SIGUDIE) | sigmask(SIGARREST));
if (nsend(&nhead)) {
ksigsetmask(mask);
return NULL;
}
nhead.nh_event = -lam_getpid();
nhead.nh_length = MAXNMSGLEN;
nhead.nh_msg = buf;
if (nrecv(&nhead)) {
ksigsetmask(mask);
return NULL;
}
ksigsetmask(mask);
if (reply->fr_errno != 0) {
errno = reply->fr_errno;
return NULL;
}
/* Found it */
return buf;
}
|