< prev index next >
src/java.base/unix/native/libjava/TimeZone_md.c
Print this page
@@ -42,10 +42,16 @@
#include "jvm.h"
#include "TimeZone_md.h"
#define SKIP_SPACE(p) while (*p == ' ' || *p == '\t') p++;
+#define RESTARTABLE(_cmd, _result) do { \
+ do { \
+ _result = _cmd; \
+ } while((_result == -1) && (errno == EINTR)); \
+} while(0)
+
#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
#define readdir64_r readdir_r
#endif
@@ -119,10 +125,11 @@
struct dirent64 *entry = NULL;
char *pathname = NULL;
int fd = -1;
char *dbuf = NULL;
char *tz = NULL;
+ int res;
dirp = opendir(dir);
if (dirp == NULL) {
return NULL;
}
@@ -159,11 +166,12 @@
pathname = getPathName(dir, dp->d_name);
if (pathname == NULL) {
break;
}
- if (stat(pathname, &statbuf) == -1) {
+ RESTARTABLE(stat(pathname, &statbuf), res);
+ if (res == -1) {
break;
}
if (S_ISDIR(statbuf.st_mode)) {
tz = findZoneinfoFile(buf, size, pathname);
@@ -173,14 +181,16 @@
} else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
dbuf = (char *) malloc(size);
if (dbuf == NULL) {
break;
}
- if ((fd = open(pathname, O_RDONLY)) == -1) {
+ RESTARTABLE(open(pathname, O_RDONLY), fd);
+ if (fd == -1) {
break;
}
- if (read(fd, dbuf, size) != (ssize_t) size) {
+ RESTARTABLE(read(fd, dbuf, size), res);
+ if (res != (ssize_t) size) {
break;
}
if (memcmp(buf, dbuf, size) == 0) {
tz = getZoneName(pathname);
if (tz != NULL) {
@@ -228,10 +238,11 @@
char *tz = NULL;
FILE *fp;
int fd;
char *buf;
size_t size;
+ int res;
#if defined(__linux__)
/*
* Try reading the /etc/timezone file for Debian distros. There's
* no spec of the file format available. This parsing assumes that
@@ -258,11 +269,12 @@
#endif /* defined(__linux__) */
/*
* Next, try /etc/localtime to find the zone ID.
*/
- if (lstat(DEFAULT_ZONEINFO_FILE, &statbuf) == -1) {
+ RESTARTABLE(lstat(DEFAULT_ZONEINFO_FILE, &statbuf), res);
+ if (res == -1) {
return NULL;
}
/*
* If it's a symlink, get the link name and its zone ID part. (The
@@ -292,25 +304,29 @@
* If it's a regular file, we need to find out the same zoneinfo file
* that has been copied as /etc/localtime.
* If initial symbolic link resolution failed, we should treat target
* file as a regular file.
*/
- if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
+ RESTARTABLE(open(DEFAULT_ZONEINFO_FILE, O_RDONLY), fd);
+ if (fd == -1) {
return NULL;
}
- if (fstat(fd, &statbuf) == -1) {
+
+ RESTARTABLE(fstat(fd, &statbuf), res);
+ if (res == -1) {
(void) close(fd);
return NULL;
}
size = (size_t) statbuf.st_size;
buf = (char *) malloc(size);
if (buf == NULL) {
(void) close(fd);
return NULL;
}
- if (read(fd, buf, size) != (ssize_t) size) {
+ RESTARTABLE(read(fd, buf, size), res);
+ if (res != (ssize_t) size) {
(void) close(fd);
free((void *) buf);
return NULL;
}
(void) close(fd);
@@ -370,11 +386,12 @@
}
/*
* It assumes read open.
*/
- if ((fd = open(fname, O_RDONLY)) == -1) {
+ RESTARTABLE(open(fname, O_RDONLY), fd);
+ if (fd == -1) {
return NULL;
}
/*
* Allocate struct iobuffer and its buffer
@@ -418,11 +435,12 @@
char c;
if (iop->ptr == iop->endptr) {
ssize_t len;
- if ((len = read(iop->fd, (void *)iop->buffer, BUFFER_SIZE)) == -1) {
+ RESTARTABLE(read(iop->fd, (void *)iop->buffer, BUFFER_SIZE), len);
+ if (len == -1) {
return NULL;
}
if (len == 0) {
*p = 0;
if (s == p) {
@@ -556,10 +574,11 @@
char *tz = NULL;
struct stat statbuf;
size_t size;
char *buf;
int fd;
+ int res;
/* scf specific variables */
scf_handle_t *h = NULL;
scf_snapshot_t *snap = NULL;
scf_instance_t *inst = NULL;
scf_propertygroup_t *pg = NULL;
@@ -591,24 +610,27 @@
}
}
}
cleanupScf(h, snap, inst, pg, prop, val, tz);
- if (stat(DEFAULT_ZONEINFO_FILE, &statbuf) == -1) {
+ RESTARTABLE(stat(DEFAULT_ZONEINFO_FILE, &statbuf), res);
+ if (res == -1) {
return NULL;
}
size = (size_t) statbuf.st_size;
buf = malloc(size);
if (buf == NULL) {
return NULL;
}
- if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
+ RESTARTABLE(open(DEFAULT_ZONEINFO_FILE, O_RDONLY), fd);
+ if (fd == -1) {
free((void *) buf);
return NULL;
}
- if (read(fd, buf, size) != (ssize_t) size) {
+ RESTARTABLE(read(fd, buf, size), res);
+ if (res != (ssize_t) size) {
(void) close(fd);
free((void *) buf);
return NULL;
}
(void) close(fd);
< prev index next >