From fdeea3f4f1c0f78f1014582135d047265098fb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2019 10:17:16 +0200 Subject: Add fopen_unlocked() wrapper --- coccinelle/fopen-unlocked.cocci | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 coccinelle/fopen-unlocked.cocci (limited to 'coccinelle') diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci new file mode 100644 index 0000000000..93b993dd55 --- /dev/null +++ b/coccinelle/fopen-unlocked.cocci @@ -0,0 +1,37 @@ +@@ +expression f, path, options; +@@ +- f = fopen(path, options); +- if (!f) +- return -errno; +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); ++ r = fopen_unlocked(path, options, &f); ++ if (r < 0) ++ return r; +@@ +expression f, path, options; +@@ +- f = fopen(path, options); +- if (!f) { +- if (errno == ENOENT) +- return -ESRCH; +- return -errno; +- } +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); ++ r = fopen_unlocked(path, options, &f); ++ if (r == -ENOENT) ++ return -ESRCH; ++ if (r < 0) ++ return r; +@@ +expression f, path, options; +@@ +- f = fopen(path, options); +- if (!f) +- return errno == ENOENT ? -ESRCH : -errno; +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); ++ r = fopen_unlocked(path, options, &f); ++ if (r == -ENOENT) ++ return -ESRCH; ++ if (r < 0) ++ return r; -- cgit v1.2.1 From 41f6e627d7cfdf1ea50d5adbd7e118589dbcf8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2019 11:02:11 +0200 Subject: Make fopen_temporary and fopen_temporary_label unlocked This is partially a refactoring, but also makes many more places use unlocked operations implicitly, i.e. all users of fopen_temporary(). AFAICT, the uses are always for short-lived files which are not shared externally, and are just used within the same context. Locking is not necessary. --- coccinelle/fopen-unlocked.cocci | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'coccinelle') diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci index 93b993dd55..e6f2bc5681 100644 --- a/coccinelle/fopen-unlocked.cocci +++ b/coccinelle/fopen-unlocked.cocci @@ -35,3 +35,17 @@ expression f, path, options; + return -ESRCH; + if (r < 0) + return r; +@@ +expression f, path, p; +@@ + r = fopen_temporary(path, &f, &p); + if (r < 0) + return ...; +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); +@@ +expression f, g, path, p; +@@ + r = fopen_temporary_label(path, g, &f, &p); + if (r < 0) + return ...; +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); -- cgit v1.2.1 From 02e23d1a1a8c3baf73d82da5abbab3a4eeb1cbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2019 11:27:08 +0200 Subject: Add fdopen_unlocked() wrapper --- coccinelle/fopen-unlocked.cocci | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'coccinelle') diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci index e6f2bc5681..bbd70a6338 100644 --- a/coccinelle/fopen-unlocked.cocci +++ b/coccinelle/fopen-unlocked.cocci @@ -49,3 +49,15 @@ expression f, g, path, p; if (r < 0) return ...; - (void) __fsetlocking(f, FSETLOCKING_BYCALLER); +@@ +expression f, fd, options; +@@ +- f = fdopen(fd, options); ++ r = fdopen_unlocked(fd, options, &f); ++ if (r < 0) { +- if (!f) { + ... +- return -errno; ++ return r; + } +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); -- cgit v1.2.1 From 2fe21124a6560fcf1ce3b0a3004baa9bb45d1e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2019 11:46:44 +0200 Subject: Add open_memstream_unlocked() wrapper --- coccinelle/fopen-unlocked.cocci | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'coccinelle') diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci index bbd70a6338..7870f8ccea 100644 --- a/coccinelle/fopen-unlocked.cocci +++ b/coccinelle/fopen-unlocked.cocci @@ -61,3 +61,11 @@ expression f, fd, options; + return r; } - (void) __fsetlocking(f, FSETLOCKING_BYCALLER); +@@ +expression f, buf, sz; +@@ +- f = open_memstream(&buf, &sz); ++ f = open_memstream_unlocked(&buf, &sz); + if (!f) + return ...; +- (void) __fsetlocking(f, FSETLOCKING_BYCALLER); -- cgit v1.2.1