summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xclient.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/client.js b/client.js
index f6c2278..6a111a3 100755
--- a/client.js
+++ b/client.js
@@ -11,6 +11,30 @@ var fs=require("fs"),
var HOSTNAME=process.argv[2]||"tomsmeding.nl",HTTPPORT=42420;
console.log("Using server "+HOSTNAME);
+
+var lockfiledesc;
+var lockfilename="/tmp/.lock_serverstore_client_"+HOSTNAME;
+try {lockfiledesc=fs.openSync(lockfilename,"wx");}
+catch(e){
+ var lockedpid=+fs.readFileSync(lockfilename);
+ var canoverwrite=false;
+ if(isNaN(lockedpid))canoverwrite=true;
+ try {process.kill(lockedpid,0);}
+ catch(e){canoverwrite=true;}
+ if(!canoverwrite){
+ console.log("Another copy of the serverstore client with the same hostname seems to be running.");
+ console.log("If this is not the case, or intentional, delete the file "+lockfilename+" and try again.");
+ process.exit(1);
+ }
+ lockfiledesc=fs.openSync(lockfilename,"w");
+}
+fs.write(lockfiledesc,process.pid+"\n");
+process.on("exit",function(){
+ fs.closeSync(lockfiledesc);
+ fs.unlinkSync(lockfilename);
+});
+
+
var userid="0",password="-";