Skip to content

Commit a01f024

Browse files
committed
8339475: Clean up return code handling for pthread calls in library coding
8341135: Incorrect format string after JDK-8339475 Reviewed-by: mdoerr Backport-of: 2a2ecc994e02049d6d84f083b8e92a51368577bf
1 parent b23b738 commit a01f024

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/java.base/macosx/native/libjli/java_md_macosx.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ static void ParkEventLoop() {
333333
static void MacOSXStartup(int argc, char *argv[]) {
334334
// Thread already started?
335335
static jboolean started = false;
336+
int rc;
336337
if (started) {
337338
return;
338339
}
@@ -345,12 +346,14 @@ static void MacOSXStartup(int argc, char *argv[]) {
345346

346347
// Fire up the main thread
347348
pthread_t main_thr;
348-
if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
349-
JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
349+
rc = pthread_create(&main_thr, NULL, &apple_main, &args);
350+
if (rc != 0) {
351+
JLI_ReportErrorMessageSys("Could not create main thread, return code: %d\n", rc);
350352
exit(1);
351353
}
352-
if (pthread_detach(main_thr)) {
353-
JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
354+
rc = pthread_detach(main_thr);
355+
if (rc != 0) {
356+
JLI_ReportErrorMessage("pthread_detach() failed, return code: %d\n", rc);
354357
exit(1);
355358
}
356359

src/java.base/unix/native/libjli/java_md_common.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,7 @@ JLI_ReportErrorMessage(const char* fmt, ...) {
200200
JNIEXPORT void JNICALL
201201
JLI_ReportErrorMessageSys(const char* fmt, ...) {
202202
va_list vl;
203-
char *emsg;
204-
205-
/*
206-
* TODO: its safer to use strerror_r but is not available on
207-
* Solaris 8. Until then....
208-
*/
209-
emsg = strerror(errno);
203+
char *emsg = strerror(errno);
210204
if (emsg != NULL) {
211205
fprintf(stderr, "%s\n", emsg);
212206
}

src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ static int isInAquaSession() {
271271
SplashCreateThread(Splash * splash) {
272272
pthread_t thr;
273273
pthread_attr_t attr;
274-
int rc;
275274

276275
int rslt = pthread_attr_init(&attr);
277276
if (rslt != 0) return;
278-
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
277+
rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
278+
if (rslt != 0) {
279+
fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt);
280+
}
279281
pthread_attr_destroy(&attr);
280282
}
281283

src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,13 @@ void
771771
SplashCreateThread(Splash * splash) {
772772
pthread_t thr;
773773
pthread_attr_t attr;
774-
int rc;
775774

776775
int rslt = pthread_attr_init(&attr);
777776
if (rslt != 0) return;
778-
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
777+
rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
778+
if (rslt != 0) {
779+
fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt);
780+
}
779781
pthread_attr_destroy(&attr);
780782
}
781783

0 commit comments

Comments
 (0)