diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-11-06 14:43:47 -0500 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-11-06 14:43:47 -0500 |
| commit | 93427b8cb602abaabc4e3768b4b4dd9105e940eb (patch) | |
| tree | 9c221d64dd8575b030ea51b0b2a2272449462863 /main.cpp | |
| parent | 5d7fea20470a1c45be53e1a3c5fb1f1aa69c7714 (diff) | |
| download | infinitytier-93427b8cb602abaabc4e3768b4b4dd9105e940eb.tar.gz infinitytier-93427b8cb602abaabc4e3768b4b4dd9105e940eb.zip | |
Installer work, add .pid file writing on *nix systems to main.cpp.
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
@@ -160,23 +160,42 @@ int main(int argc,char **argv) #ifdef __UNIX_LIKE__ mkdir(homeDir,0755); // will fail if it already exists + { + char pidpath[4096]; + Utils::snrpintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir); + FILE *pf = fopen(pidpath,"w"); + if (pf) { + fprintf(pf,"%ld",(long)getpid()); + fclose(pf); + } + } #endif int exitCode = 0; - node = new Node(homeDir,port,controlPort); - const char *termReason = (char *)0; - switch(node->run()) { - case Node::NODE_UNRECOVERABLE_ERROR: - exitCode = -1; - termReason = node->reasonForTermination(); - fprintf(stderr,"%s: abnormal termination: %s\n",argv[0],(termReason) ? termReason : "(unknown reason)"); - break; - default: - break; + try { + node = new Node(homeDir,port,controlPort); + const char *termReason = (char *)0; + switch(node->run()) { + case Node::NODE_UNRECOVERABLE_ERROR: + exitCode = -1; + termReason = node->reasonForTermination(); + fprintf(stderr,"%s: abnormal termination: %s\n",argv[0],(termReason) ? termReason : "(unknown reason)"); + break; + default: + break; + } + delete node; + node = (Node *)0; + } catch ( ... ) {} + +#ifdef __UNIX_LIKE__ + { + char pidpath[4096]; + Utils::snrpintf(pidpath,sizeof(pidpath),"%s/zerotier-one.pid",homeDir); + Utils::rm(pidpath); } - delete node; - node = (Node *)0; +#endif return exitCode; } |
