Don't HANDLE_EINTR(close). Either IGNORE_EINTR(close) or just close.
It is incorrect to wrap close in HANDLE_EINTR on Linux. Correctness is
generally undefined on Mac, but as of r223369, it is incorrect in Chrome on
Mac.
To avoid new offenders, a PRESUBMIT check ensures that HANDLE_EINTR is not
used with close, and that IGNORE_EINTR is only used with close. Unnecessary
#includes of eintr_wrapper.h are also removed.
base/posix/einter_wrapper.h, PRESUBMIT.py, and ppapi/tests/test_broker.cc
contain non-mechanical changes. Variable naming within the latter is updated
per r178174. Missing #includes for <errno.h> in
content/zygote/zygote_main_linux.cc and tools/android/common/daemon.cc were
manually added. Mechanical changes were generated by running:
sed -E -i '' \
-e 's/((=|if|return|CHECK|EXPECT|ASSERT).*)HANDLE(_EINTR\(.*close)/\1IGNORE\3/' \
-e 's/(ignore_result|void ?)\(HANDLE_EINTR\((.*close\(.*)\)\)/\2/' \
-e 's/(\(void\) ?)?HANDLE_EINTR\((.*close\(.*)\)/\2/' \
$(git grep -El 'HANDLE_EINTR.*close')
sed -E -i '' -e '/#include.*eintr_wrapper\.h"/d' \
$(grep -EL '(HANDLE|IGNORE)_EINTR' \
$(git grep -El '#include.*eintr_wrapper\.h"'))
BUG=269623
[email protected], [email protected]
TBR=OWNERS
Review URL: https://codereview.chromium.org/100253002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238390 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 414cee8..f0e77e90 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -202,6 +202,30 @@
True,
(),
),
+ (
+ r'/HANDLE_EINTR\(.*close',
+ (
+ 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
+ 'descriptor will be closed, and it is incorrect to retry the close.',
+ 'Either call close directly and ignore its return value, or wrap close',
+ 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
+ ),
+ True,
+ (),
+ ),
+ (
+ r'/IGNORE_EINTR\((?!.*close)',
+ (
+ 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
+ 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
+ ),
+ True,
+ (
+ # Files that #define IGNORE_EINTR.
+ r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
+ r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
+ ),
+ ),
)
@@ -375,7 +399,14 @@
return False
if IsBlacklisted(f, excluded_paths):
continue
- if func_name in line:
+ matched = False
+ if func_name[0:1] == '/':
+ regex = func_name[1:]
+ if input_api.re.search(regex, line):
+ matched = True
+ elif func_name in line:
+ matched = True
+ if matched:
problems = warnings;
if error:
problems = errors;