From a3a5b4691add1821dafbcb65981025fa2cbe5aa2 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 24 Jan 2018 23:04:21 +0300 Subject: [PATCH] Use skip_eintr in all filesystem system calls. GitOrigin-RevId: 044a430e7bb1dd77d71751737f8edb585b1d74c5 --- tdutils/td/utils/port/path.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 74d4a10f2..cf89fe67e 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -74,7 +74,8 @@ Status mkdir(CSlice dir, int32 mode) { } Status rename(CSlice from, CSlice to) { - if (::rename(from.c_str(), to.c_str()) < 0) { + int rename_res = skip_eintr([&] { return ::rename(from.c_str(), to.c_str()); }); + if (rename_res < 0) { return OS_ERROR(PSLICE() << "Can't rename \"" << from << "\" to \"" << to << '\"'); } return Status::OK(); @@ -82,7 +83,7 @@ Status rename(CSlice from, CSlice to) { Result realpath(CSlice slice) { char full_path[PATH_MAX + 1]; - char *err = ::realpath(slice.c_str(), full_path); + char *err = skip_eintr([&] { return ::realpath(slice.c_str(), full_path); }); if (err != full_path) { return OS_ERROR(PSLICE() << "Realpath failed for \"" << slice << '"'); } @@ -99,21 +100,24 @@ Result realpath(CSlice slice) { } Status chdir(CSlice dir) { - if (::chdir(dir.c_str())) { + int chdir_res = skip_eintr([&] { return ::chdir(dir.c_str()); }); + if (chdir_res) { return OS_ERROR(PSLICE() << "Can't change directory to \"" << dir << '"'); } return Status::OK(); } Status rmdir(CSlice dir) { - if (::rmdir(dir.c_str())) { + int rmdir_res = skip_eintr([&] { return ::rmdir(dir.c_str()); }); + if (rmdir_res) { return OS_ERROR(PSLICE() << "Can't delete directory \"" << dir << '"'); } return Status::OK(); } Status unlink(CSlice path) { - if (::unlink(path.c_str())) { + int unlink_res = skip_eintr([&] { return ::unlink(path.c_str()); }); + if (unlink_res) { return OS_ERROR(PSLICE() << "Can't unlink \"" << path << '"'); } return Status::OK(); @@ -159,7 +163,7 @@ Result> mkstemp(CSlice dir) { } file_pattern += "tmpXXXXXXXXXX"; - int fd = ::mkstemp(&file_pattern[0]); + int fd = skip_eintr([&] { return ::mkstemp(&file_pattern[0]); }); if (fd == -1) { return OS_ERROR(PSLICE() << "Can't create temporary file \"" << file_pattern << '"'); } @@ -191,7 +195,7 @@ Result mkdtemp(CSlice dir, Slice prefix) { dir_pattern.append(prefix.begin(), prefix.size()); dir_pattern += "XXXXXX"; - char *result = ::mkdtemp(&dir_pattern[0]); + char *result = skip_eintr([&] { return ::mkdtemp(&dir_pattern[0]); }); if (result == nullptr) { return OS_ERROR(PSLICE() << "Can't create temporary directory \"" << dir_pattern << '"'); }