summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-11-06 14:43:47 -0500
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-11-06 14:43:47 -0500
commit93427b8cb602abaabc4e3768b4b4dd9105e940eb (patch)
tree9c221d64dd8575b030ea51b0b2a2272449462863 /main.cpp
parent5d7fea20470a1c45be53e1a3c5fb1f1aa69c7714 (diff)
downloadinfinitytier-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.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/main.cpp b/main.cpp
index 8bf1bd00..93911c98 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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;
}