aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2015-07-06 21:14:24 +0200
committerErlang/OTP <[email protected]>2015-07-06 21:14:24 +0200
commit86d29105143b86bb011634a8e3c84e7f78886463 (patch)
treea130e89cae6aa1d3cc9f13571aa6de59bfee5bcc /lib
parent41bfee8dbc7127417c8d28e5189f33179908ea46 (diff)
parent9c2d22a6ceff4aa49de6a4e14973ac7b8994261c (diff)
downloadotp-86d29105143b86bb011634a8e3c84e7f78886463.tar.gz
otp-86d29105143b86bb011634a8e3c84e7f78886463.tar.bz2
otp-86d29105143b86bb011634a8e3c84e7f78886463.zip
Merge branch 'rickard/trace-file-eintr-bug/OTP-12890' into maint-17
* rickard/trace-file-eintr-bug/OTP-12890: Handle EINTR in trace_file_drv
Diffstat (limited to 'lib')
-rw-r--r--lib/runtime_tools/c_src/trace_file_drv.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/runtime_tools/c_src/trace_file_drv.c b/lib/runtime_tools/c_src/trace_file_drv.c
index 08bace80ef..f5980b4a57 100644
--- a/lib/runtime_tools/c_src/trace_file_drv.c
+++ b/lib/runtime_tools/c_src/trace_file_drv.c
@@ -326,9 +326,11 @@ static ErlDrvData trace_file_start(ErlDrvPort port, char *buff)
| O_BINARY
#endif
, 0777)) < 0) {
+ int saved_errno = errno;
if (wrap)
driver_free(wrap);
driver_free(data);
+ errno = saved_errno;
return ERL_DRV_ERROR_ERRNO;
}
@@ -524,14 +526,19 @@ static void *my_alloc(size_t size)
** A write wrapper that regards it as an error if not all data was written.
*/
static int do_write(FILETYPE fd, unsigned char *buff, int siz) {
- int w = write(fd, buff, siz);
- if (w != siz) {
- if (w >= 0) {
- errno = ENOSPC;
+ int w;
+ while (1) {
+ w = write(fd, buff, siz);
+ if (w < 0 && errno == EINTR)
+ continue;
+ else if (w != siz) {
+ if (w >= 0) {
+ errno = ENOSPC;
+ }
+ return -1;
}
- return -1;
+ return siz;
}
- return siz;
}
/*
@@ -626,8 +633,10 @@ static void close_unlink_port(TraceFileData *data)
*/
static int wrap_file(TraceFileData *data) {
if (my_flush(data) < 0) {
+ int saved_errno = errno;
close(data->fd);
data->fd = -1;
+ errno = saved_errno;
return -1;
}
close(data->fd);
@@ -643,12 +652,15 @@ static int wrap_file(TraceFileData *data) {
next_name(&data->wrap->del);
}
next_name(&data->wrap->cur);
+try_open:
data->fd = open(data->wrap->cur.name, O_WRONLY | O_TRUNC | O_CREAT
#ifdef O_BINARY
| O_BINARY
#endif
, 0777);
if (data->fd < 0) {
+ if (errno == EINTR)
+ goto try_open;
data->fd = -1;
return -1;
}