Commit 1d4c6fe9 authored by Timothy Stack's avatar Timothy Stack
Browse files

Add '-m' option to emulab-sync to check if the current node is where

the sync-server is running.  Basically, its a quick way to determine
which node is the "master" when you are using a single startup script
on all of the nodes.
parent 121400f8
......@@ -13,6 +13,7 @@ emulab-sync \- Simple distributed synchronization client.
[\fB-a\fR]
[\fB-u\fR]
[\fB-e \fIerror-number\fR]
[\fB-m\fR]
.SH DESCRIPTION
The
.B emulab-sync
......@@ -96,6 +97,14 @@ Specify the error code for this client. The value must be greater than zero
(indicating no error) and less than 240 because we reserve the range [240, 256)
for internal use. The error codes for all of the clients are collected by the
server and the maximum is returned by the clients when they exit. (Default: 0)
.TP
\fB-m
Check if this node is where the default sync server is running and then
immediately exit. If this node
.I is
running the server, the return value is zero, otherwise it is one. This mode
is useful for detecting the "master" node when the experimental nodes all run
the same startup script.
.SH RETURN VALUES
.TP
A \fB-e \fRerror value
......@@ -115,8 +124,15 @@ If the server name lookup failed.
64
If there was an invalid command line argument.
.TP
1
If the
.B -m
option was used and this node is not the master.
.TP
0
If the barrier was successfully crossed without error.
If the barrier was successfully crossed without error or the
.B -m
option was used and this node is the master.
.SH EXAMPLES
.PP
To synchronize one machine with another:
......@@ -155,6 +171,42 @@ To synchronize and report an error code of "100":
100
.PD
.RE
.PP
To use a single script to synchronize N nodes:
.PP
.RS
.PD 0
#! /bin/sh
# Get number of nodes to synchronize against.
.P
node_count=${1}
# Synchronize first.
.P
\fBif\fR emulab-sync -m; \fBthen\fR
.P
# This is the master node, initialize the
.P
# barrier to N - 1 since the master node
.P
# is not counted.
.P
emulab-sync -i `expr ${node_count} - 1`
.P
\fBelse\fR
.P
# This is a regular node, just do a regular
.P
# sync.
.P
emulab-sync
.P
\fBfi\fR
# ... then do something interesting.
.RE
.PD
.SH FILES
.TP
/var/emulab/boot/syncserver
......
......@@ -55,6 +55,7 @@ char *usagestr =
" -a Master returns immediately when initializing barrier\n"
" -u Use UDP instead of TCP\n"
" -e errornum Signal an error (must be zero or >= 32)\n"
" -m Test whether or not this is the 'master' node\n"
"\n";
void
......@@ -79,8 +80,9 @@ main(int argc, char **argv)
char *barrier= DEFAULT_BARRIER;
barrier_req_t barrier_req;
extern char build_info[];
int mastercheck = 0;
while ((ch = getopt(argc, argv, "hVds:p:ui:n:ae:")) != -1)
while ((ch = getopt(argc, argv, "hVds:p:ui:n:ae:m")) != -1)
switch(ch) {
case 'a':
nowait++;
......@@ -172,6 +174,9 @@ main(int argc, char **argv)
fprintf(stderr, "%s", usagestr);
exit(0);
break;
case 'm':
mastercheck = 1;
break;
default:
usage();
}
......@@ -223,6 +228,15 @@ main(int argc, char **argv)
"experiment.\n\n");
usage();
}
if (mastercheck) {
char nodename[BUFSIZ];
gethostname(nodename, sizeof(nodename));
if (strcmp(server, nodename) == 0)
exit(0);
else
exit(1);
}
/*
* Map server to IP.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment