File: rtrfget.c

package info (click to toggle)
lam 7.1.2-1.4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 54,608 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,589; perl: 476; fortran: 260; asm: 83
file content (190 lines) | stat: -rw-r--r-- 3,751 bytes parent folder | download | duplicates (10)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * 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$
 *	Ohio Trollius
 *	Copyright 1994 The Ohio State University
 *	GDB
 * 
 *	Function:	- unloads trace data from remote trace daemon
 */

#include <lam_config.h>

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>

#include <etc_misc.h>
#include <events.h>
#include <ksignal.h>
#include <net.h>
#include <trreq.h>
#include <typical.h>

/*
 * local functions
 */
static int4		rtr();

/*
 *	lam_rtrfget
 *
 *	Function:	- reads trace data from remote node
 *	Accepts:	- target node ID
 *			- list number
 *			- process ID
 *			- file descriptor
 *	Returns:	- total length of received trace data
 */
int4
lam_rtrfget(nodeid, lnum, pid, fd)

int4			nodeid;
int4			lnum;
int4			pid;
int			fd;

{
	return(rtr(nodeid, lnum, pid, fd, TRQGET));
}

/*
 *	lam_rtrfforget
 *
 *	Function:	- destructively reads trace data from remote node
 *	Accepts:	- target node ID
 *			- list number
 *			- process ID
 *			- file descriptor
 *	Returns:	- total length of received trace data
 */
int4
lam_rtrfforget(nodeid, lnum, pid, fd)

int4			nodeid;
int4			lnum;
int4			pid;
int			fd;

{
	return(rtr(nodeid, lnum, pid, fd, TRQFORGET));
}

/*
 *	rtr
 *
 *	Function:	- unloads trace data from remote node
 *			- writes trace data into file
 *	Accepts:	- target node ID
 *			- list number
 *			- process ID
 *			- file descriptor
 *			- traced request code
 *	Returns:	- total length of received trace data
 */
static int4
rtr(nodeid, lnum, pid, fd, req)

int4			nodeid;
int4			lnum;
int4			pid;
int4			req;
int			fd;

{
	struct nmsg	nhead;		/* network message desc. */
	struct trreq  	*request;	/* traced request */
	struct trreply	*reply;		/* traced reply */
	int4		trtotal;	/* total matching traces */
	int4		trleft;		/* traces left to receive */
	int4		mask;		/* favourite index */

	request = (struct trreq *) nhead.nh_data;
	reply = (struct trreply *) nhead.nh_data;

	request->trq_src_node = (nodeid == LOCAL) ? nodeid : getnodeid();
	request->trq_src_event = -lam_getpid();
	request->trq_req = req;
	request->trq_lnum = lnum;
	request->trq_pid = pid;

	nhead.nh_node = nodeid;
	nhead.nh_event = EVTRACED;
	nhead.nh_type = 0;
	nhead.nh_flags = 0;
	nhead.nh_length = 0;
	nhead.nh_msg = 0;

	mask = ksigblock(sigmask(SIGUDIE) | sigmask(SIGARREST));

	if (nsend(&nhead)) {
		ksigsetmask(mask);
		return(LAMERROR);
	}
/*
 * Receive total trace length.
 */
	nhead.nh_event = -lam_getpid();
	nhead.nh_type = 0;
	nhead.nh_length = 0;
	nhead.nh_msg = 0;

	if (nrecv(&nhead)) {
		ksigsetmask(mask);
		return(LAMERROR);
	}

	trtotal = reply->trr_length;
	trleft = reply->trr_length;

	if (trtotal > 0) {
		nhead.nh_msg = malloc((unsigned) MAXNMSGLEN);

		if (nhead.nh_msg == 0) {
			ksigsetmask(mask);
			return(LAMERROR);
		}
	}

	while ((trleft > 0) && (reply->trr_errno == 0)) {
		nhead.nh_type = 0;
		nhead.nh_length = MAXNMSGLEN;

		if (nrecv(&nhead)) {
			free(nhead.nh_msg);
			ksigsetmask(mask);
			return(LAMERROR);
		}

		if (write(fd, nhead.nh_msg, nhead.nh_length) < 0) {
			free(nhead.nh_msg);
			ksigsetmask(mask);
			return(LAMERROR);
		}

		trleft -= nhead.nh_length;
	}

	ksigsetmask(mask);

	if (trtotal > 0) {
		free(nhead.nh_msg);
	}

	if (reply->trr_errno) {
		errno = reply->trr_errno;
		return(LAMERROR);
	} else {
		return(trtotal);
	}
}