mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-31 00:23:58 +00:00
Bug fix in zerotier-cli (Unix)
This commit is contained in:
parent
b13845e528
commit
b809dad94a
@ -39,6 +39,7 @@ struct _NodeControlClientImpl
|
||||
{
|
||||
void (*resultHandler)(void *,const char *);
|
||||
void *arg;
|
||||
bool ignoreNextBreak;
|
||||
IpcConnection *ipcc;
|
||||
std::string err;
|
||||
};
|
||||
@ -46,8 +47,11 @@ struct _NodeControlClientImpl
|
||||
static void _CBipcResultHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *result)
|
||||
{
|
||||
if ((event == IpcConnection::IPC_EVENT_COMMAND)&&(result)) {
|
||||
if (strcmp(result,"200 auth OK"))
|
||||
((_NodeControlClientImpl *)arg)->resultHandler(((_NodeControlClientImpl *)arg)->arg,result);
|
||||
if (!strcmp(result,"200 auth OK")) {
|
||||
((_NodeControlClientImpl *)arg)->ignoreNextBreak = true;
|
||||
} else if ((((_NodeControlClientImpl *)arg)->ignoreNextBreak)&&(!strcmp(result,"."))) {
|
||||
((_NodeControlClientImpl *)arg)->ignoreNextBreak = false;
|
||||
} else ((_NodeControlClientImpl *)arg)->resultHandler(((_NodeControlClientImpl *)arg)->arg,result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +62,7 @@ NodeControlClient::NodeControlClient(const char *ep,const char *authToken,void (
|
||||
_NodeControlClientImpl *impl = (_NodeControlClientImpl *)_impl;
|
||||
impl->resultHandler = resultHandler;
|
||||
impl->arg = arg;
|
||||
impl->ignoreNextBreak = false;
|
||||
try {
|
||||
impl->ipcc = new IpcConnection(ep,ZT_IPC_TIMEOUT,&_CBipcResultHandler,_impl);
|
||||
impl->ipcc->printf("auth %s"ZT_EOL_S,authToken);
|
||||
|
11
main.cpp
11
main.cpp
@ -119,8 +119,10 @@ static void _CBresultHandler(void *arg,const char *line)
|
||||
if (line) {
|
||||
if ((line[0] == '.')&&(line[1] == (char)0)) {
|
||||
fflush(stdout);
|
||||
*((bool *)arg) = true;
|
||||
} else fprintf(stdout,"%s"ZT_EOL_S,line);
|
||||
::exit(0); // terminate CLI on end of message
|
||||
} else {
|
||||
fprintf(stdout,"%s"ZT_EOL_S,line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,15 +182,14 @@ static int main(const char *homeDir,int argc,char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
volatile bool done = false;
|
||||
NodeControlClient client((std::string(ZT_IPC_ENDPOINT_BASE) + id.address().toString()).c_str(),authToken.c_str(),&_CBresultHandler,(void *)&done);
|
||||
NodeControlClient client((std::string(ZT_IPC_ENDPOINT_BASE) + id.address().toString()).c_str(),authToken.c_str(),&_CBresultHandler,(void *)0);
|
||||
const char *err = client.error();
|
||||
if (err) {
|
||||
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
|
||||
return 1;
|
||||
}
|
||||
client.send(query.c_str());
|
||||
while (!done) Thread::sleep(100); // dis be ghetto
|
||||
for(;;) { Thread::sleep(60000); } // exit() is called at end of message from handler
|
||||
} catch (std::exception &exc) {
|
||||
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],exc.what());
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user