Skip to content

Commit 2a2ecc9

Browse files
committedSep 27, 2024
8339475: Clean up return code handling for pthread calls in library coding
Reviewed-by: clanger, jwaters
1 parent 85dba47 commit 2a2ecc9

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed
 

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static void ParkEventLoop() {
297297
static void MacOSXStartup(int argc, char *argv[]) {
298298
// Thread already started?
299299
static jboolean started = false;
300+
int rc;
300301
if (started) {
301302
return;
302303
}
@@ -309,12 +310,14 @@ static void MacOSXStartup(int argc, char *argv[]) {
309310

310311
// Fire up the main thread
311312
pthread_t main_thr;
312-
if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
313-
JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
313+
rc = pthread_create(&main_thr, NULL, &apple_main, &args);
314+
if (rc != 0) {
315+
JLI_ReportErrorMessageSys("Could not create main thread, return code: %s\n", rc);
314316
exit(1);
315317
}
316-
if (pthread_detach(main_thr)) {
317-
JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
318+
rc = pthread_detach(main_thr);
319+
if (rc != 0) {
320+
JLI_ReportErrorMessage("pthread_detach() failed, return code: %s\n", rc);
318321
exit(1);
319322
}
320323

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,7 @@ JLI_ReportErrorMessage(const char* fmt, ...) {
243243
JNIEXPORT void JNICALL
244244
JLI_ReportErrorMessageSys(const char* fmt, ...) {
245245
va_list vl;
246-
char *emsg;
247-
248-
/*
249-
* TODO: its safer to use strerror_r but is not available on
250-
* Solaris 8. Until then....
251-
*/
252-
emsg = strerror(errno);
246+
char *emsg = strerror(errno);
253247
if (emsg != NULL) {
254248
fprintf(stderr, "%s\n", emsg);
255249
}

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

+4-2
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,10 @@ SplashCreateThread(Splash * splash) {
741741

742742
int rslt = pthread_attr_init(&attr);
743743
if (rslt != 0) return;
744-
pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
744+
rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
745+
if (rslt != 0) {
746+
fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt);
747+
}
745748
pthread_attr_destroy(&attr);
746749
}
747750

0 commit comments

Comments
 (0)
Please sign in to comment.