From 4550eebc903a839f41bc4a634be5147327e0252b Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Mon, 18 Aug 2014 23:46:17 +0200 Subject: [PATCH] Make system calls restart on signals instead of handling EINTR This leads to simpler code and probably fewer bugs. --- src/gmenu2x.cpp | 1 + src/utilities.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index b4ae4ea..84ef09f 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -140,6 +140,7 @@ static void set_handler(int signal, void (*handler)(int)) struct sigaction sig; sigaction(signal, NULL, &sig); sig.sa_handler = handler; + sig.sa_flags |= SA_RESTART; sigaction(signal, &sig, NULL); } diff --git a/src/utilities.cpp b/src/utilities.cpp index b8b8bd2..cb3f2e6 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -116,11 +116,7 @@ bool writeStringToFile(string const& filename, string const& data) { } // Close temporary file. - while (close(fd)) { - if (errno != EINTR) { - return false; - } - } + ok &= close(fd) == 0; // Replace actual output file with temporary file. if (ok) { @@ -148,11 +144,7 @@ bool syncDir(string const& dirname) bool ok = fsync(fd) == 0; - while (close(fd)) { - if (errno != EINTR) { - return false; - } - } + ok &= close(fd) == 0; return ok; }