File: lamclean.c

package info (click to toggle)
lam 7.1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 54,668 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,590; perl: 476; fortran: 260; asm: 83
file content (177 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download | duplicates (9)
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
/*
 * Copyright (c) 2001-2003 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: lamclean.c,v 6.15 2003/07/06 01:28:49 jsquyres Exp $
 *
 *	Function:	- command to clean out several daemons on all nodes
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/param.h>
#include <netdb.h>
#include <unistd.h>

#include <args.h>
#include <etc_misc.h>
#include <bfreq.h>
#include <lamdebug.h>
#include <freq.h>
#include <ksignal.h>
#include <laminternal.h>
#include <net.h>
#include <preq.h>
#include <priority.h>
#include <terror.h>
#include <trreq.h>
#include <typical.h>


int
main(int argc, char *argv[])
{
	int4		*all;		/* array of all node IDs */
	int4		i;
	int4		nall;		/* count of all nodes */
	int		fl_verbose;	/* verbosity flag */

	/* Ensure that we are not root */

#ifndef LAM_ALLOW_RUN_AS_ROOT
	if (getuid() == 0 || geteuid() == 0) {
	  show_help(NULL, "deny-root", NULL);
	  exit(EACCES);
	}
#endif

/*
 * Parse command-line arguments.
 */
	validopts("hv");

	if (do_args(&argc, argv) || (argc != 1)) {
		fprintf(stderr, "lamclean [-hv]\n");
		exit(LAM_EEXIT);
	}

	if (opt_taken('h')) {
          show_help("lamclean", "usage", NULL);
          exit(0);
	}

	fl_verbose = opt_taken('v');
/*
 * Initialize and attach to Trollius kernel.
 */
	if (kinit(PRCMD)) {
	  char hostname[MAXHOSTNAMELEN];
	  gethostname(hostname, MAXHOSTNAMELEN);

	  show_help(NULL, "no-lamd", "lamclean", hostname, NULL);
	  exit(LAM_EEXIT);
	}
/*
 * Get an array of all node IDs.
 */
	nall = getnall();
	all = (int4 *) malloc((unsigned) (nall * sizeof(int4)));

	if (all == 0) lamfail("lamclean (malloc)");

	if (getall(all, nall)) lamfail("lamclean (getall)");
/*
 * Doom all appl processes.
 */
	if (fl_verbose) nodespin_init("killing processes,");

	for (i = 0; i < nall; ++i) {

		if (fl_verbose) nodespin_next(all[i]);

		if (rpdoom(all[i], SELECT_APPL, 0, SIGUDIE)) {
			lamfail("lamclean (rpdoom)");
		}
	}
/*
 * Reset file daemons.
 */
	if (fl_verbose) {
		nodespin_end();
		nodespin_init("closing files,");
	}

	for (i = 0; i < nall; ++i) {

		if (fl_verbose) nodespin_next(all[i]);

		if (lam_rfrmfd(all[i], NOTFD)) {
			lamfail("lamclean (rfrmfd)");
		}
	}
/*
 * Reset trace deamons.
 */
	if (fl_verbose) {
		nodespin_end();
		nodespin_init("sweeping traces,");
	}

	for (i = 0; i < nall; ++i) {

		if (fl_verbose) nodespin_next(all[i]);

		if (lam_rtrsweep(all[i], TRANYLIST)) {
			lamfail("lamclean (lam_rtrsweep)");
		}
	}
/*
 * Cleanup registered objects.
 */
	if (fl_verbose) {
		nodespin_end();
		nodespin_init("cleaning up registered objects,");
	}

	for (i = 0; i < nall; ++i) {

		if (fl_verbose) nodespin_next(all[i]);

		if (lam_rtrcleanobjs(all[i])) {
			lamfail("lamclean (lam_rtrcleanobjs)");
		}
	}
/*
 * Reset buffers.
 */
	sleep(1);
	if (fl_verbose) {
		nodespin_end();
		nodespin_init("sweeping messages,");
	}

	for (i = 0; i < nall; ++i) {

		if (fl_verbose) nodespin_next(all[i]);

		if (rbfwipe(all[i])) {
			lamfail("lamclean (rbfwipe)");
		}
	}

	if (fl_verbose) nodespin_end();

	kexit(0);
	return(0);
}