8339475: Clean up return code handling for pthread calls in library coding

Reviewed-by: clanger, jwaters
This commit is contained in:
Matthias Baesken 2024-09-27 07:27:29 +00:00
parent 85dba47925
commit 2a2ecc994e
4 changed files with 16 additions and 14 deletions
src
java.base
macosx/native/libjli
unix/native/libjli
java.desktop
macosx/native/libsplashscreen
unix/native/libsplashscreen

@ -297,6 +297,7 @@ static void ParkEventLoop() {
static void MacOSXStartup(int argc, char *argv[]) {
// Thread already started?
static jboolean started = false;
int rc;
if (started) {
return;
}
@ -309,12 +310,14 @@ static void MacOSXStartup(int argc, char *argv[]) {
// Fire up the main thread
pthread_t main_thr;
if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
rc = pthread_create(&main_thr, NULL, &apple_main, &args);
if (rc != 0) {
JLI_ReportErrorMessageSys("Could not create main thread, return code: %s\n", rc);
exit(1);
}
if (pthread_detach(main_thr)) {
JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
rc = pthread_detach(main_thr);
if (rc != 0) {
JLI_ReportErrorMessage("pthread_detach() failed, return code: %s\n", rc);
exit(1);
}

@ -243,13 +243,7 @@ JLI_ReportErrorMessage(const char* fmt, ...) {
JNIEXPORT void JNICALL
JLI_ReportErrorMessageSys(const char* fmt, ...) {
va_list vl;
char *emsg;
/*
* TODO: its safer to use strerror_r but is not available on
* Solaris 8. Until then....
*/
emsg = strerror(errno);
char *emsg = strerror(errno);
if (emsg != NULL) {
fprintf(stderr, "%s\n", emsg);
}

@ -271,11 +271,13 @@ void
SplashCreateThread(Splash * splash) {
pthread_t thr;
pthread_attr_t attr;
int rc;
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
if (rslt != 0) {
fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt);
}
pthread_attr_destroy(&attr);
}

@ -741,7 +741,10 @@ SplashCreateThread(Splash * splash) {
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
if (rslt != 0) {
fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt);
}
pthread_attr_destroy(&attr);
}