Skip to content

Commit 2f47c39

Browse files
author
Brian Burkhalter
committed
8259943: FileDescriptor.close0 does not handle EINTR
Reviewed-by: naoto, alanb
1 parent a8073ef commit 2f47c39

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/java.base/unix/native/libjava/io_util_md.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -162,8 +162,17 @@ fileDescriptorClose(JNIEnv *env, jobject this)
162162
dup2(devnull, fd);
163163
close(devnull);
164164
}
165-
} else if (close(fd) == -1) {
166-
JNU_ThrowIOExceptionWithLastError(env, "close failed");
165+
} else {
166+
int result;
167+
#if defined(_AIX)
168+
/* AIX allows close to be restarted after EINTR */
169+
RESTARTABLE(close(fd), result);
170+
#else
171+
result = close(fd);
172+
#endif
173+
if (result == -1 && errno != EINTR) {
174+
JNU_ThrowIOExceptionWithLastError(env, "close failed");
175+
}
167176
}
168177
}
169178

@@ -234,7 +243,9 @@ jlong
234243
handleGetLength(FD fd)
235244
{
236245
struct stat64 sb;
237-
if (fstat64(fd, &sb) == 0) {
246+
int result;
247+
RESTARTABLE(fstat64(fd, &sb), result);
248+
if (result == 0) {
238249
return sb.st_size;
239250
} else {
240251
return -1;

0 commit comments

Comments
 (0)