author | herrick |
Thu, 25 Jul 2019 08:13:44 -0400 | |
branch | JDK-8200758-branch |
changeset 57531 | d24019d561da |
parent 57194 | 9d5fccd97421 |
child 57543 | bcd1ab268a7d |
permissions | -rw-r--r-- |
57194
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
1 |
/* |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
4 |
* |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
10 |
* |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
15 |
* accompanied this code). |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
16 |
* |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
20 |
* |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
23 |
* questions. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
24 |
*/ |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
25 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
26 |
#include "PosixPlatform.h" |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
27 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
28 |
#include "PlatformString.h" |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
29 |
#include "FilePath.h" |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
30 |
#include "Helpers.h" |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
31 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
32 |
#include <assert.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
33 |
#include <stdbool.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
34 |
#include <sys/types.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
35 |
#include <unistd.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
36 |
#include <sys/sysctl.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
37 |
#include <sys/file.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
38 |
#include <sys/stat.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
39 |
#include <sys/wait.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
40 |
#include <errno.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
41 |
#include <limits.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
42 |
#include <pwd.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
43 |
#include <iostream> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
44 |
#include <algorithm> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
45 |
#include <dlfcn.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
46 |
#include <signal.h> |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
47 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
48 |
using namespace std; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
49 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
50 |
PosixPlatform::PosixPlatform(void) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
51 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
52 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
53 |
PosixPlatform::~PosixPlatform(void) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
54 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
55 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
56 |
TString PosixPlatform::GetTempDirectory() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
57 |
struct passwd* pw = getpwuid(getuid()); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
58 |
TString homedir(pw->pw_dir); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
59 |
homedir += getTmpDirString(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
60 |
if (!FilePath::DirectoryExists(homedir)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
61 |
if (!FilePath::CreateDirectory(homedir, false)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
62 |
homedir.clear(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
63 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
64 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
65 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
66 |
return homedir; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
67 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
68 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
69 |
TString PosixPlatform::fixName(const TString& name) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
70 |
TString fixedName(name); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
71 |
const TString chars("?:*<>/\\"); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
72 |
for (TString::const_iterator it = chars.begin(); it != chars.end(); it++) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
73 |
fixedName.erase(std::remove(fixedName.begin(), |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
74 |
fixedName.end(), *it), fixedName.end()); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
75 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
76 |
return fixedName; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
77 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
78 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
79 |
MessageResponse PosixPlatform::ShowResponseMessage(TString title, |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
80 |
TString description) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
81 |
MessageResponse result = mrCancel; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
82 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
83 |
printf("%s %s (Y/N)\n", PlatformString(title).toPlatformString(), |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
84 |
PlatformString(description).toPlatformString()); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
85 |
fflush(stdout); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
86 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
87 |
std::string input; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
88 |
std::cin >> input; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
89 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
90 |
if (input == "Y") { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
91 |
result = mrOK; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
92 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
93 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
94 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
95 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
96 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
97 |
Module PosixPlatform::LoadLibrary(TString FileName) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
98 |
return dlopen(StringToFileSystemString(FileName), RTLD_LAZY); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
99 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
100 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
101 |
void PosixPlatform::FreeLibrary(Module AModule) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
102 |
dlclose(AModule); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
103 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
104 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
105 |
Procedure PosixPlatform::GetProcAddress(Module AModule, |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
106 |
std::string MethodName) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
107 |
return dlsym(AModule, PlatformString(MethodName)); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
108 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
109 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
110 |
Process* PosixPlatform::CreateProcess() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
111 |
return new PosixProcess(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
112 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
113 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
114 |
void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
115 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
116 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
117 |
void Platform::CopyString(char *Destination, |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
118 |
size_t NumberOfElements, const char *Source) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
119 |
strncpy(Destination, Source, NumberOfElements); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
120 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
121 |
if (NumberOfElements > 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
122 |
Destination[NumberOfElements - 1] = '\0'; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
123 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
124 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
125 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
126 |
void Platform::CopyString(wchar_t *Destination, |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
127 |
size_t NumberOfElements, const wchar_t *Source) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
128 |
wcsncpy(Destination, Source, NumberOfElements); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
129 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
130 |
if (NumberOfElements > 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
131 |
Destination[NumberOfElements - 1] = '\0'; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
132 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
133 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
134 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
135 |
// Owner must free the return value. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
136 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
137 |
MultibyteString Platform::WideStringToMultibyteString( |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
138 |
const wchar_t* value) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
139 |
MultibyteString result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
140 |
size_t count = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
141 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
142 |
if (value == NULL) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
143 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
144 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
145 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
146 |
count = wcstombs(NULL, value, 0); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
147 |
if (count > 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
148 |
result.data = new char[count + 1]; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
149 |
result.data[count] = '\0'; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
150 |
result.length = count; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
151 |
wcstombs(result.data, value, count); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
152 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
153 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
154 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
155 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
156 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
157 |
// Owner must free the return value. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
158 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
159 |
WideString Platform::MultibyteStringToWideString(const char* value) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
160 |
WideString result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
161 |
size_t count = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
162 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
163 |
if (value == NULL) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
164 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
165 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
166 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
167 |
count = mbstowcs(NULL, value, 0); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
168 |
if (count > 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
169 |
result.data = new wchar_t[count + 1]; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
170 |
result.data[count] = '\0'; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
171 |
result.length = count; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
172 |
mbstowcs(result.data, value, count); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
173 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
174 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
175 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
176 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
177 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
178 |
void PosixPlatform::InitStreamLocale(wios *stream) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
179 |
// Nothing to do for POSIX platforms. |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
180 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
181 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
182 |
PosixProcess::PosixProcess() : Process() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
183 |
FChildPID = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
184 |
FRunning = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
185 |
FOutputHandle = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
186 |
FInputHandle = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
187 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
188 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
189 |
PosixProcess::~PosixProcess() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
190 |
Terminate(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
191 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
192 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
193 |
bool PosixProcess::ReadOutput() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
194 |
bool result = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
195 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
196 |
if (FOutputHandle != 0 && IsRunning() == true) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
197 |
char buffer[4096] = {0}; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
198 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
199 |
ssize_t count = read(FOutputHandle, buffer, sizeof (buffer)); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
200 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
201 |
if (count == -1) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
202 |
if (errno == EINTR) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
203 |
// continue; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
204 |
} else { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
205 |
perror("read"); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
206 |
exit(1); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
207 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
208 |
} else if (count == 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
209 |
// break; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
210 |
} else { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
211 |
if (buffer[count - 1] == EOF) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
212 |
buffer[count - 1] = '\0'; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
213 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
214 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
215 |
std::list<TString> output = Helpers::StringToArray(buffer); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
216 |
FOutput.splice(FOutput.end(), output, output.begin(), output.end()); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
217 |
result = true; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
218 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
219 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
220 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
221 |
return false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
222 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
223 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
224 |
bool PosixProcess::IsRunning() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
225 |
bool result = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
226 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
227 |
if (kill(FChildPID, 0) == 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
228 |
result = true; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
229 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
230 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
231 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
232 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
233 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
234 |
bool PosixProcess::Terminate() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
235 |
bool result = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
236 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
237 |
if (IsRunning() == true && FRunning == true) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
238 |
FRunning = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
239 |
Cleanup(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
240 |
int status = kill(FChildPID, SIGTERM); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
241 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
242 |
if (status == 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
243 |
result = true; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
244 |
} else { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
245 |
#ifdef DEBUG |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
246 |
if (errno == EINVAL) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
247 |
printf("Kill error: The value of the sig argument is an invalid or unsupported signal number."); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
248 |
} else if (errno == EPERM) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
249 |
printf("Kill error: The process does not have permission to send the signal to any receiving process."); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
250 |
} else if (errno == ESRCH) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
251 |
printf("Kill error: No process or process group can be found corresponding to that specified by pid."); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
252 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
253 |
#endif // DEBUG |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
254 |
if (IsRunning() == true) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
255 |
status = kill(FChildPID, SIGKILL); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
256 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
257 |
if (status == 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
258 |
result = true; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
259 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
260 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
261 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
262 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
263 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
264 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
265 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
266 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
267 |
bool PosixProcess::Wait() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
268 |
bool result = false; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
269 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
270 |
int status = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
271 |
pid_t wpid = 0; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
272 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
273 |
wpid = wait(&status); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
274 |
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
275 |
if (errno != EINTR) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
276 |
status = -1; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
277 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
278 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
279 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
280 |
#ifdef DEBUG |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
281 |
if (WIFEXITED(status)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
282 |
printf("child exited, status=%d\n", WEXITSTATUS(status)); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
283 |
} else if (WIFSIGNALED(status)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
284 |
printf("child killed (signal %d)\n", WTERMSIG(status)); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
285 |
} else if (WIFSTOPPED(status)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
286 |
printf("child stopped (signal %d)\n", WSTOPSIG(status)); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
287 |
#ifdef WIFCONTINUED // Not all implementations support this |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
288 |
} else if (WIFCONTINUED(status)) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
289 |
printf("child continued\n"); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
290 |
#endif // WIFCONTINUED |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
291 |
} else { // Non-standard case -- may never happen |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
292 |
printf("Unexpected status (0x%x)\n", status); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
293 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
294 |
#endif // DEBUG |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
295 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
296 |
if (wpid != -1) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
297 |
result = true; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
298 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
299 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
300 |
return result; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
301 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
302 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
303 |
TProcessID PosixProcess::GetProcessID() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
304 |
return FChildPID; |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
305 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
306 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
307 |
void PosixProcess::SetInput(TString Value) { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
308 |
if (FInputHandle != 0) { |
57531
d24019d561da
8228402: chdir() and write() errors are not handled in jpackage
herrick
parents:
57194
diff
changeset
|
309 |
if (write(FInputHandle, Value.data(), Value.size()) < 0) { |
d24019d561da
8228402: chdir() and write() errors are not handled in jpackage
herrick
parents:
57194
diff
changeset
|
310 |
throw Exception(_T("Internal Error - write failed")); |
d24019d561da
8228402: chdir() and write() errors are not handled in jpackage
herrick
parents:
57194
diff
changeset
|
311 |
} |
57194
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
312 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
313 |
} |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
314 |
|
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
315 |
std::list<TString> PosixProcess::GetOutput() { |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
316 |
ReadOutput(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
317 |
return Process::GetOutput(); |
9d5fccd97421
8212091: Move jpackage native code under platform specific folders and files
herrick
parents:
diff
changeset
|
318 |
} |