mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
tree-wide: make more code use safe_close()
Replace this: close(fd); fd = -1; write this: fd = safe_close(fd);
This commit is contained in:
parent
a1e58e8ee1
commit
66e405837b
18
coccinelle/safe_close.cocci
Normal file
18
coccinelle/safe_close.cocci
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
@@
|
||||||
|
expression fd;
|
||||||
|
@@
|
||||||
|
- close(fd);
|
||||||
|
- fd = -1;
|
||||||
|
+ fd = safe_close(fd);
|
||||||
|
@@
|
||||||
|
expression fd;
|
||||||
|
@@
|
||||||
|
- close_nointr(fd);
|
||||||
|
- fd = -1;
|
||||||
|
+ fd = safe_close(fd);
|
||||||
|
@@
|
||||||
|
expression fd;
|
||||||
|
@@
|
||||||
|
- safe_close(fd);
|
||||||
|
- fd = -1;
|
||||||
|
+ fd = safe_close(fd);
|
@ -240,8 +240,7 @@ int button_open(Button *b) {
|
|||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
if (b->fd >= 0) {
|
if (b->fd >= 0) {
|
||||||
close(b->fd);
|
b->fd = safe_close(b->fd);
|
||||||
b->fd = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = strjoina("/dev/input/", b->name);
|
p = strjoina("/dev/input/", b->name);
|
||||||
@ -267,8 +266,7 @@ int button_open(Button *b) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close(b->fd);
|
b->fd = safe_close(b->fd);
|
||||||
b->fd = -1;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,12 +754,10 @@ int udev_event_spawn(struct udev_event *event,
|
|||||||
|
|
||||||
/* child closes parent's ends of pipes */
|
/* child closes parent's ends of pipes */
|
||||||
if (outpipe[READ_END] >= 0) {
|
if (outpipe[READ_END] >= 0) {
|
||||||
close(outpipe[READ_END]);
|
outpipe[READ_END] = safe_close(outpipe[READ_END]);
|
||||||
outpipe[READ_END] = -1;
|
|
||||||
}
|
}
|
||||||
if (errpipe[READ_END] >= 0) {
|
if (errpipe[READ_END] >= 0) {
|
||||||
close(errpipe[READ_END]);
|
errpipe[READ_END] = safe_close(errpipe[READ_END]);
|
||||||
errpipe[READ_END] = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strscpy(arg, sizeof(arg), cmd);
|
strscpy(arg, sizeof(arg), cmd);
|
||||||
@ -785,12 +783,10 @@ int udev_event_spawn(struct udev_event *event,
|
|||||||
default:
|
default:
|
||||||
/* parent closed child's ends of pipes */
|
/* parent closed child's ends of pipes */
|
||||||
if (outpipe[WRITE_END] >= 0) {
|
if (outpipe[WRITE_END] >= 0) {
|
||||||
close(outpipe[WRITE_END]);
|
outpipe[WRITE_END] = safe_close(outpipe[WRITE_END]);
|
||||||
outpipe[WRITE_END] = -1;
|
|
||||||
}
|
}
|
||||||
if (errpipe[WRITE_END] >= 0) {
|
if (errpipe[WRITE_END] >= 0) {
|
||||||
close(errpipe[WRITE_END]);
|
errpipe[WRITE_END] = safe_close(errpipe[WRITE_END]);
|
||||||
errpipe[WRITE_END] = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_read(event,
|
spawn_read(event,
|
||||||
|
Loading…
Reference in New Issue
Block a user