passing client options to distributed clients, ready to actually distribute work

git-svn-id: svn://anubis/fart/trunk@223 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-04-05 18:12:44 +00:00
1 parent 1dbe7040e4
commit 6fdaf01214
5 files changed
+83 -37

No files matched your search

+33 -10
View File
@@ -22,6 +22,8 @@ int distrib::readHostFile(const char * filename)
while ( ! ifs.eof() )
{
ifs >> host;
if ( ifs.eof() )
break;
m_hosts.push_back(host);
}
@@ -29,17 +31,18 @@ int distrib::readHostFile(const char * filename)
return 0;
}
int distrib::connect()
int distrib::connect(const std::vector<std::string> & client_options)
{
int err = 0;
for (int i = 0, sz = m_hosts.size(); i < sz; i++)
{
err += connect(m_hosts[i]);
err += connect(m_hosts[i], client_options);
}
return err;
}
int distrib::connect(const string & host)
int distrib::connect(const string & host,
const std::vector<std::string> & client_options)
{
int id = fork();
if (id < 0) /* check for fork() error */
@@ -55,10 +58,30 @@ int distrib::connect(const string & host)
{
char server_port_str[15];
sprintf(server_port_str, "%d", m_serverport);
execlp("ssh", "ssh", host.c_str(),
"fart", "--host", m_servername.c_str(),
"--port", server_port_str,
(char *) NULL);
vector<string> args;
args.push_back("ssh");
args.push_back(host);
args.push_back("fart");
args.push_back("--host");
args.push_back(m_servername);
args.push_back("--port");
args.push_back(server_port_str);
for (int i = 0, sz = client_options.size(); i < sz; i++)
args.push_back(client_options[i]);
const char * char_star_args[args.size() + 1];
for (int i = 0, sz = args.size(); i < sz; i++)
char_star_args[i] = args[i].c_str();
char_star_args[args.size()] = (char *) NULL;
#if 0
/* debug */
cout << "executing: 'ssh', ";
for (int i = 0, sz = args.size(); i < sz; i++)
cout << "'" << char_star_args[i] << "', ";
cout << endl;
#endif
execvp("ssh", (char * const *) char_star_args);
/* we should not get here */
cerr << "Error " << errno << " with execlp()!" << endl;
@@ -68,10 +91,8 @@ int distrib::connect(const string & host)
return 0;
}
int distrib::startServer()
int distrib::startServer(const std::vector<std::string> & client_options)
{
connect();
char hostname[1000];
gethostname(&hostname[0], 1000);
m_servername = hostname;
@@ -109,6 +130,8 @@ int distrib::startServer()
<< m_serverport
<< endl;
connect(client_options);
return 0;
}
+4 -3
View File
@@ -9,12 +9,13 @@ class distrib
{
public:
int readHostFile(const char * filename);
int startServer();
int startServer(const std::vector<std::string> & client_options);
int startClient(const char * server, int port);
protected:
int connect();
int connect(const std::string & host);
int connect(const std::vector<std::string> & client_options);
int connect(const std::string & host,
const std::vector<std::string> & client_options);
std::vector<std::string> m_hosts;
std::vector<int> m_children;