summaryrefslogtreecommitdiff
path: root/coccinelle
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-12 13:51:53 +0200
committerGitHub <noreply@github.com>2019-04-12 13:51:53 +0200
commit3661dc349ec0e0e8f19fb3a542ccbc813753ef8b (patch)
treec0043f61ec11d0af1d143fbf58328433638789e3 /coccinelle
parent15de23a0b24f6073d527c6a8c22556ad5101a160 (diff)
parent673a1e6fb9ea2b61d97be45b8f9852c70a69778c (diff)
downloadsystemd-3661dc349ec0e0e8f19fb3a542ccbc813753ef8b.tar.gz
Merge pull request #12217 from keszybz/unlocked-operations
Refactor how we do unlocked file operations
Diffstat (limited to 'coccinelle')
-rw-r--r--coccinelle/fopen-unlocked.cocci71
1 files changed, 71 insertions, 0 deletions
diff --git a/coccinelle/fopen-unlocked.cocci b/coccinelle/fopen-unlocked.cocci
new file mode 100644
index 0000000000..7870f8ccea
--- /dev/null
+++ b/coccinelle/fopen-unlocked.cocci
@@ -0,0 +1,71 @@
+@@
+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;
+@@
+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);
+@@
+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);
+@@
+expression f, buf, sz;
+@@
+- f = open_memstream(&buf, &sz);
++ f = open_memstream_unlocked(&buf, &sz);
+ if (!f)
+ return ...;
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);