mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Bug fix in zerotier-cli (Unix)
This commit is contained in:
parent
b13845e528
commit
b809dad94a
2 changed files with 13 additions and 7 deletions
|
@ -39,6 +39,7 @@ struct _NodeControlClientImpl
|
||||||
{
|
{
|
||||||
void (*resultHandler)(void *,const char *);
|
void (*resultHandler)(void *,const char *);
|
||||||
void *arg;
|
void *arg;
|
||||||
|
bool ignoreNextBreak;
|
||||||
IpcConnection *ipcc;
|
IpcConnection *ipcc;
|
||||||
std::string err;
|
std::string err;
|
||||||
};
|
};
|
||||||
|
@ -46,8 +47,11 @@ struct _NodeControlClientImpl
|
||||||
static void _CBipcResultHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *result)
|
static void _CBipcResultHandler(void *arg,IpcConnection *ipcc,IpcConnection::EventType event,const char *result)
|
||||||
{
|
{
|
||||||
if ((event == IpcConnection::IPC_EVENT_COMMAND)&&(result)) {
|
if ((event == IpcConnection::IPC_EVENT_COMMAND)&&(result)) {
|
||||||
if (strcmp(result,"200 auth OK"))
|
if (!strcmp(result,"200 auth OK")) {
|
||||||
((_NodeControlClientImpl *)arg)->resultHandler(((_NodeControlClientImpl *)arg)->arg,result);
|
((_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;
|
_NodeControlClientImpl *impl = (_NodeControlClientImpl *)_impl;
|
||||||
impl->resultHandler = resultHandler;
|
impl->resultHandler = resultHandler;
|
||||||
impl->arg = arg;
|
impl->arg = arg;
|
||||||
|
impl->ignoreNextBreak = false;
|
||||||
try {
|
try {
|
||||||
impl->ipcc = new IpcConnection(ep,ZT_IPC_TIMEOUT,&_CBipcResultHandler,_impl);
|
impl->ipcc = new IpcConnection(ep,ZT_IPC_TIMEOUT,&_CBipcResultHandler,_impl);
|
||||||
impl->ipcc->printf("auth %s"ZT_EOL_S,authToken);
|
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) {
|
||||||
if ((line[0] == '.')&&(line[1] == (char)0)) {
|
if ((line[0] == '.')&&(line[1] == (char)0)) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
*((bool *)arg) = true;
|
::exit(0); // terminate CLI on end of message
|
||||||
} else fprintf(stdout,"%s"ZT_EOL_S,line);
|
} else {
|
||||||
|
fprintf(stdout,"%s"ZT_EOL_S,line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,15 +182,14 @@ static int main(const char *homeDir,int argc,char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile bool done = false;
|
NodeControlClient client((std::string(ZT_IPC_ENDPOINT_BASE) + id.address().toString()).c_str(),authToken.c_str(),&_CBresultHandler,(void *)0);
|
||||||
NodeControlClient client((std::string(ZT_IPC_ENDPOINT_BASE) + id.address().toString()).c_str(),authToken.c_str(),&_CBresultHandler,(void *)&done);
|
|
||||||
const char *err = client.error();
|
const char *err = client.error();
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
|
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],err);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
client.send(query.c_str());
|
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) {
|
} catch (std::exception &exc) {
|
||||||
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],exc.what());
|
fprintf(stderr,"%s: fatal error: unable to connect (is ZeroTier One running?) (%s)"ZT_EOL_S,argv[0],exc.what());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue