1: #include <sys/types.h>
2: #include <sys/socket.h>
3: #include <netinet/in.h>
4: #include <stdio.h>
5: #include <errno.h>
6: #include <sys/wait.h>
7: #include <signal.h>
8: #include <sys/time.h>
9: #include "dsh.h"
10: #include "dbid.h"
11:
12: #define MAXWAIT 90 /* maximum time to wait */
13: #define MINWAIT 30 /* minimum time to wait */
14:
15: int errno; /* global error location */
16: bool hflg; /* TRUE if specific host called for */
17: char *spechost; /* the specific host */
18:
19: struct bid *thebid; /* pointer to the bids */
20:
21: char *myhostname();
22: long myhostaddr();
23: bool aflg;
24:
25: /*
26: * get bids from the machines
27: */
28: getbids (av, thehost)
29: char *av[]; /* the command */
30: struct hostdef *thehost; /* the hosts to use */
31: {
32: int sock, port;
33: char portstr[10];
34: int waiting;
35: int fds, readfds;
36: int rv, nodes, responses;
37: int argc, ac;
38: char *argv[100];
39: struct sockaddr_in addr;
40: struct bidmsg bm;
41: struct hostdef *hp;
42: struct bid *bp;
43: bool done;
44: struct timeval timeout;
45:
46: port = 0;
47: sock = makedgsocket (&port);
48: for (nodes = 0, hp = thehost; hp != 0; nodes++, hp = hp->h_next) {
49:
50: if (!hflg || (strcmp (spechost, hp->h_name) == 0)) {
51:
52: /* build the command */
53: argc = 0;
54: argv[argc++] = BIDCMD;
55: argv[argc++] = "\"";
56: for (ac = 0; av[ac] != 0; ac++) {
57: argv[argc++] = av[ac];
58: }
59: argv[argc++] = "\"";
60: argv[argc++] = myhostname();
61: sprintf (portstr, "%d", port);
62: argv[argc++] = portstr;
63: argv[argc++] = hp->h_name;
64: argv[argc] = 0;
65:
66: /* start up the bidcommand */
67: rshell (hp, argv, FALSE, TRUE, FALSE, TRUE);
68: }
69: }
70:
71: /* wait for replies */
72: waiting = responses = 0;
73: thebid = 0;
74: done = FALSE;
75: do {
76: readfds = 1<<sock;
77: timeout.tv_sec = 2;
78: timeout.tv_usec = 0;
79: fds = select (20, &readfds, 0, 0, &timeout);
80: if (fds == 0)
81: waiting += 2;
82: if (readfds & (1<<sock)) {
83: rv = recvdg (sock, &bm, sizeof (struct bidmsg));
84: if (rv < 0) {
85: warn ("receiving bid");
86: }
87: for (hp = thehost; hp != 0; hp = hp->h_next) {
88: if (strcmp (bm.bm_host, hp->h_name) == 0) {
89: strcpy (hp->h_dir, bm.bm_dir);
90: bp = new (struct bid);
91: bp->b_next = thebid;
92: /*
93: printf ("%s %s %f %f\n", hp->h_name, hp->h_dir,
94: hp->h_weight, bm.bm_bid);
95: */
96: bp->b_bid = bm.bm_bid * hp->h_weight;
97: bp->b_host = hp;
98: thebid = bp;
99: responses++;
100: break;
101: }
102: }
103: }
104: if (!aflg) {
105: done = (waiting > MINWAIT && responses > 0) || (waiting > MAXWAIT)
106: || (nodes <= responses);
107: } else {
108: done = (waiting > MAXWAIT) || (nodes <= responses);
109: }
110: } while (!done);
111: }
112:
113:
114: /*
115: * find the highest bidder
116: */
117: struct hostdef *
118: highest()
119: {
120: struct bid *bp, *bpp;
121: double high;
122:
123: /* find the highest bid */
124: high = 0.0;
125: bpp = 0;
126: for (bp = thebid; bp != 0; bp = bp->b_next) {
127: if (bp->b_bid > high) {
128: high = bp->b_bid;
129: bpp = bp;
130: }
131: }
132:
133: if (bpp == 0) {
134: return (0);
135: } else {
136:
137: /* remove highest from the list */
138: if (bpp == thebid) {
139: thebid = bpp->b_next;
140: } else {
141: for (bp = thebid; bp->b_next != bpp; bp = bp->b_next);
142: bp->b_next = bpp->b_next;
143: }
144: return (bpp->b_host);
145: }
146: }
Defined functions
Defined variables
errno
defined in line
15;
never used
Defined macros