comparison src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c @ 7401:fd940a08ec2d

8055421: (fs) bad error handling in java.base/unix/native/libnio/fs/UnixNativeDispatcher.c Reviewed-by: martin, alanb
author igerasim
date Tue, 26 Aug 2014 15:55:35 +0400
parents 37377dcd43d0
children
comparison
equal deleted inserted replaced
10:64f612cc2ddc 11:1e1c66038490
276 Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) { 276 Java_sun_nio_fs_UnixNativeDispatcher_dup(JNIEnv* env, jclass this, jint fd) {
277 277
278 int res = -1; 278 int res = -1;
279 279
280 RESTARTABLE(dup((int)fd), res); 280 RESTARTABLE(dup((int)fd), res);
281 if (fd == -1) { 281 if (res == -1) {
282 throwUnixException(env, errno); 282 throwUnixException(env, errno);
283 } 283 }
284 return (jint)res; 284 return (jint)res;
285 } 285 }
286 286
304 } 304 }
305 305
306 JNIEXPORT void JNICALL 306 JNIEXPORT void JNICALL
307 Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) 307 Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream)
308 { 308 {
309 int res;
310 FILE* fp = jlong_to_ptr(stream); 309 FILE* fp = jlong_to_ptr(stream);
311 310
312 do { 311 /* NOTE: fclose() wrapper is only used with read-only streams.
313 res = fclose(fp); 312 * If it ever is used with write streams, it might be better to add
314 } while (res == EOF && errno == EINTR); 313 * RESTARTABLE(fflush(fp)) before closing, to make sure the stream
315 if (res == EOF) { 314 * is completely written even if fclose() failed.
315 */
316 if (fclose(fp) == EOF && errno != EINTR) {
316 throwUnixException(env, errno); 317 throwUnixException(env, errno);
317 } 318 }
318 } 319 }
319 320
320 JNIEXPORT jint JNICALL 321 JNIEXPORT jint JNICALL
608 return ptr_to_jlong(dir); 609 return ptr_to_jlong(dir);
609 } 610 }
610 611
611 JNIEXPORT void JNICALL 612 JNIEXPORT void JNICALL
612 Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { 613 Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) {
613 int err;
614 DIR* dirp = jlong_to_ptr(dir); 614 DIR* dirp = jlong_to_ptr(dir);
615 615
616 RESTARTABLE(closedir(dirp), err); 616 if (closedir(dirp) == -1 && errno != EINTR) {
617 if (errno == -1) {
618 throwUnixException(env, errno); 617 throwUnixException(env, errno);
619 } 618 }
620 } 619 }
621 620
622 JNIEXPORT jbyteArray JNICALL 621 JNIEXPORT jbyteArray JNICALL