changeset 10776:b43e44ecc365 jdk-10+39

8194488: "javapackager -singleton" is not working in linux Reviewed-by: almatvee
author vdrozdov
date Mon, 08 Jan 2018 22:25:50 -0800
parents e2e750c9aa4a
children 2d23a39c6cdb 95b258c53752 ca9e4d30eb64
files modules/jdk.packager/src/main/native/library/common/PosixPlatform.cpp modules/jdk.packager/src/main/native/library/common/PosixPlatform.h
diffstat 2 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/jdk.packager/src/main/native/library/common/PosixPlatform.cpp	Mon Jan 08 22:08:58 2018 -0800
+++ b/modules/jdk.packager/src/main/native/library/common/PosixPlatform.cpp	Mon Jan 08 22:25:50 2018 -0800
@@ -50,6 +50,7 @@
 #include <limits.h>
 #include <pwd.h>
 #include <iostream>
+#include <algorithm>
 #include <dlfcn.h>
 #include <signal.h>
 
@@ -76,6 +77,15 @@
     return homedir;
 }
 
+TString PosixPlatform::fixName(const TString& name) {
+    TString fixedName(name);
+    const TString chars("?:*<>/\\");
+    for (TString::const_iterator it = chars.begin(); it != chars.end(); it++) {
+        fixedName.erase(std::remove(fixedName.begin(), fixedName.end(), *it), fixedName.end());
+    }
+    return fixedName;
+}
+
 // returns true if another instance is already running.
 // if false, we need to continue regular launch.
 bool PosixPlatform::CheckForSingleInstance(TString appName) {
@@ -85,7 +95,7 @@
         return false;
     }
 
-    TString lockFile = tmpDir + "/" + appName;
+    TString lockFile = tmpDir + "/" + fixName(appName);
     SingleInstanceFile = lockFile;
     int pid_file = open(lockFile.c_str(), O_CREAT | O_RDWR, 0666);
     int rc = flock(pid_file, LOCK_EX | LOCK_NB);
--- a/modules/jdk.packager/src/main/native/library/common/PosixPlatform.h	Mon Jan 08 22:08:58 2018 -0800
+++ b/modules/jdk.packager/src/main/native/library/common/PosixPlatform.h	Mon Jan 08 22:25:50 2018 -0800
@@ -43,6 +43,8 @@
 protected:
     TString SingleInstanceFile;
 
+    TString fixName(const TString& name);
+
     virtual TString getTmpDirString() = 0;
 
 public: