summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-21 16:13:43 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-21 17:24:21 +0200
commit5ed1227238724959f020169f5332086439709b55 (patch)
tree2cdf61c9f05958a0994110c9afa46a9b7da47fd4 /src
parenta9f85faf43ae2289e19ba9105c36496aefe66072 (diff)
util: make asynchronous_close() really work like an asynchronous version of safe_close()
Save/restore errno, like we do in safe_close(). And don't fork a thread if the parameter is already negative.
Diffstat (limited to 'src')
-rw-r--r--src/shared/async.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/shared/async.c b/src/shared/async.c
index 3876deda70..115901e637 100644
--- a/src/shared/async.c
+++ b/src/shared/async.c
@@ -73,7 +73,7 @@ int asynchronous_sync(void) {
}
static void *close_thread(void *p) {
- safe_close(PTR_TO_INT(p));
+ assert_se(close_nointr(PTR_TO_INT(p)) != -EBADF);
return NULL;
}
@@ -86,9 +86,13 @@ int asynchronous_close(int fd) {
* but it doesn't, so we work around it, and hide this as a
* far away as we can. */
- r = asynchronous_job(close_thread, INT_TO_PTR(fd));
- if (r < 0)
- safe_close(fd);
+ if (fd >= 0) {
+ PROTECT_ERRNO;
+
+ r = asynchronous_job(close_thread, INT_TO_PTR(fd));
+ if (r < 0)
+ assert_se(close_nointr(fd) != -EBADF);
+ }
return -1;
}