25
25
#include "criuhelpers.h"
26
26
27
27
#if defined(J9VM_OPT_CRAC_SUPPORT )
28
+
29
+ #include "java.h"
30
+ #include <ctype.h>
31
+ #include <sys/wait.h>
32
+
28
33
/**
29
34
* Get the value of a command line option in the array of command line arguments.
30
35
* @param[in] optionName The name of the command line option to search for
@@ -37,7 +42,7 @@ static const char *
37
42
getCommandLineOptionValue (const char * optionName , int argc , char * * argv , int * error )
38
43
{
39
44
const char * value = NULL ;
40
- int i = argc - 1 ;
45
+ int i = 0 ;
41
46
size_t optionNameLength = strlen (optionName );
42
47
* error = -1 ;
43
48
for (i = argc - 1 ; i >= 0 ; i -- ) {
@@ -85,6 +90,7 @@ getCheckpointDirectory(int argc, char **argv, int *error)
85
90
86
91
/**
87
92
* Get the log level specified in the command line arguments.
93
+ * Valid log levels are from 0 to 4, inclusive; the default is 2.
88
94
* @param[in] argc The number of command line arguments
89
95
* @param[in] argv The array of command line arguments
90
96
* @param[in/out] error A pointer to an integer for the error code
@@ -94,8 +100,7 @@ static int
94
100
getLogLevel (int argc , char * * argv , int * error )
95
101
{
96
102
int logLevelValue = 2 ; /* default */
97
- const char * logLevelPropertyValue = NULL ;
98
- logLevelPropertyValue = getCommandLineOptionValue ("-Dopenj9.internal.criu.logLevel" , argc , argv , error );
103
+ const char * logLevelPropertyValue = getCommandLineOptionValue ("-Dopenj9.internal.criu.logLevel" , argc , argv , error );
99
104
if (0 == * error ) {
100
105
const char * c = logLevelPropertyValue ;
101
106
if (NULL == c ) {
@@ -116,7 +121,9 @@ getLogLevel(int argc, char **argv, int *error)
116
121
goto done ;
117
122
}
118
123
setLogLevelOptionValueNotValidError :
119
- JLI_ReportErrorMessage ("The value of the command line option is not valid, option=-Dopenj9.internal.criu.logLevel, value=%s." , logLevelPropertyValue );
124
+ JLI_ReportErrorMessage (
125
+ "The option '-Dopenj9.internal.criu.logLevel=%s' is not valid." ,
126
+ logLevelPropertyValue );
120
127
* error = -2 ;
121
128
done :
122
129
return logLevelValue ;
@@ -138,7 +145,9 @@ isUnprivilegedModeOn(int argc, char **argv, int *error)
138
145
if (NULL == unprivilegedModePropertyValue ) {
139
146
isUnprivilegedModeOn = JNI_TRUE ;
140
147
} else {
141
- JLI_ReportErrorMessage ("The value of the command line option is not expected, option=-Dopenj9.internal.criu.unprivilegedMode, value=%s." , unprivilegedModePropertyValue );
148
+ JLI_ReportErrorMessage (
149
+ "The option '-Dopenj9.internal.criu.unprivilegedMode=%s' does not accept a value." ,
150
+ unprivilegedModePropertyValue );
142
151
* error = -2 ;
143
152
}
144
153
}
@@ -161,7 +170,7 @@ getLogFile(int argc, char **argv, int *error)
161
170
if (NULL != logFilePropertyValue ) {
162
171
logFile = logFilePropertyValue ;
163
172
} else {
164
- JLI_ReportErrorMessage ("The value of the command line option -Dopenj9.internal.criu.logFile was not found ." );
173
+ JLI_ReportErrorMessage ("The option -Dopenj9.internal.criu.logFile requires a value ." );
165
174
* error = -2 ;
166
175
}
167
176
}
@@ -179,7 +188,6 @@ getLogFile(int argc, char **argv, int *error)
179
188
static int
180
189
restoreFromCheckpoint (const char * checkpointDirectory , int logLevel , jboolean unprivilegedModeOn , const char * logFile )
181
190
{
182
- int restoreStatus = 0 ;
183
191
int length = -1 ;
184
192
char logLevelOption [4 ] = { 0 };
185
193
char * logFileOption = NULL ;
@@ -189,48 +197,34 @@ restoreFromCheckpoint(const char *checkpointDirectory, int logLevel, jboolean un
189
197
argv [argc ++ ] = "restore" ;
190
198
argv [argc ++ ] = "-D" ;
191
199
argv [argc ++ ] = checkpointDirectory ;
192
- length = snprintf (NULL , 0 , "-v%d" , logLevel );
193
- if (length < 0 ) {
194
- JLI_ReportErrorMessage ("Failed to calculate the length of option '-v%d'." , logLevel );
195
- restoreStatus = -1 ;
196
- goto done ;
197
- }
198
- if (snprintf (logLevelOption , sizeof (logLevelOption ), "-v%d" , logLevel ) < 0 ) {
199
- JLI_ReportErrorMessage ("Failed to format the log level option '-v%d'." , logLevel );
200
- restoreStatus = -1 ;
201
- goto done ;
202
- }
200
+ /* The log level is a single digit. */
201
+ snprintf (logLevelOption , sizeof (logLevelOption ), "-v%d" , logLevel );
203
202
argv [argc ++ ] = logLevelOption ;
204
203
argv [argc ++ ] = "--shell-job" ;
205
204
if (unprivilegedModeOn ) {
206
205
argv [argc ++ ] = "--unprivileged" ;
207
206
}
208
207
if (NULL != logFile ) {
209
208
length = strlen (logFile ) + sizeof ("--log-file=%s" ) - 1 ;
210
- logFileOption = (char * )JLI_MemAlloc (length - 1 );
209
+ logFileOption = (char * )JLI_MemAlloc (length + 1 );
211
210
if (NULL == logFileOption ) {
212
211
JLI_ReportErrorMessage ("Failed to allocate memory for option '--log-file=%s'." , logFile );
213
- restoreStatus = -1 ;
214
- goto done ;
212
+ goto fail ;
215
213
}
216
- if (snprintf (logFileOption , length - 1 , "--log-file=%s" , logFile ) < 0 ) {
214
+ if (snprintf (logFileOption , length + 1 , "--log-file=%s" , logFile ) < 0 ) {
217
215
JLI_ReportErrorMessage ("Failed to format option '--log-file=%s'." , logFile );
218
- restoreStatus = -1 ;
219
- goto done ;
216
+ goto fail ;
220
217
}
221
218
argv [argc ++ ] = logFileOption ;
222
219
}
223
220
argv [argc ] = NULL ;
224
221
execvp (argv [0 ], (char * const * )argv );
225
222
/* If execvp returns, there was an error. */
226
- restoreStatus = -1 ;
227
- freeLogFileOption :
223
+ fail :
228
224
if (NULL != logFileOption ) {
229
225
JLI_MemFree ((void * )logFileOption );
230
- logFileOption = NULL ;
231
226
}
232
- done :
233
- return restoreStatus ;
227
+ return -1 ;
234
228
}
235
229
236
230
/**
@@ -252,12 +246,12 @@ handleCRaCRestore(int argc, char **argv)
252
246
int childProcessPidStatus = 0 ;
253
247
int childProcessPidExitStatus = 0 ;
254
248
checkpointDirectory = getCheckpointDirectory (argc , argv , & error );
255
- /* We ignore restore if the restore option -XX:CRaCRestoreFrom is not specified. */
256
249
if (-1 == error ) {
250
+ /* Option -XX:CRaCRestoreFrom not specified. */
257
251
return ;
258
252
}
259
253
if (-2 == error ) {
260
- JLI_ReportErrorMessage ("Failed to get the CRIU checkpoint directory, error=%d." , error );
254
+ JLI_ReportErrorMessage ("Failed to get the CRIU checkpoint directory." );
261
255
parentProcessExitStatus = EXIT_FAILURE ;
262
256
goto doneParentProcess ;
263
257
}
@@ -269,19 +263,19 @@ handleCRaCRestore(int argc, char **argv)
269
263
if (0 == childProcessPid ) {
270
264
logLevel = getLogLevel (argc , argv , & error );
271
265
if (-2 == error ) {
272
- JLI_ReportErrorMessage ("Failed to get the CRIU log level, error=%d." , error );
266
+ JLI_ReportErrorMessage ("Failed to get the CRIU log level." );
273
267
childProcessExitStatus = EXIT_FAILURE ;
274
268
goto doneChildProcess ;
275
269
}
276
270
unprivilegedModeOn = isUnprivilegedModeOn (argc , argv , & error );
277
271
if (-2 == error ) {
278
- JLI_ReportErrorMessage ("Failed to get the CRIU unprivileged mode, error=%d." , error );
272
+ JLI_ReportErrorMessage ("Failed to get the CRIU unprivileged mode." );
279
273
childProcessExitStatus = EXIT_FAILURE ;
280
274
goto doneChildProcess ;
281
275
}
282
276
logFile = getLogFile (argc , argv , & error );
283
277
if (-2 == error ) {
284
- JLI_ReportErrorMessage ("Failed to get the CRIU log file, error=%d." , error );
278
+ JLI_ReportErrorMessage ("Failed to get the CRIU log file." );
285
279
childProcessExitStatus = EXIT_FAILURE ;
286
280
goto doneChildProcess ;
287
281
}
0 commit comments