mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 06:21:54 +00:00
Cleanup file descriptors
This commit is contained in:
@@ -221,6 +221,8 @@ int run_command(int *fd, const char *path, char *const argv[]) {
|
||||
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv) == -1)
|
||||
return -1;
|
||||
// We use sv[0], give them sv[1] for communication
|
||||
if (fcntl(sv[1], F_SETFD, FD_CLOEXEC))
|
||||
PLOGE("fcntl FD_CLOEXEC");
|
||||
*fd = sv[1];
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ extern int quit_signals[];
|
||||
// xwrap.c
|
||||
|
||||
FILE *xfopen(const char *pathname, const char *mode);
|
||||
FILE *xfdopen(int fd, const char *mode);
|
||||
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
|
||||
#define xopen(...) GET_MACRO(__VA_ARGS__, xopen3, xopen2)(__VA_ARGS__)
|
||||
int xopen2(const char *pathname, int flags);
|
||||
|
||||
@@ -32,6 +32,14 @@ FILE *xfopen(const char *pathname, const char *mode) {
|
||||
return fp;
|
||||
}
|
||||
|
||||
FILE *xfdopen(int fd, const char *mode) {
|
||||
FILE *fp = fdopen(fd, mode);
|
||||
if (fp == NULL) {
|
||||
PLOGE("fopen");
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
int xopen2(const char *pathname, int flags) {
|
||||
int fd = open(pathname, flags);
|
||||
if (fd < 0) {
|
||||
|
||||
Reference in New Issue
Block a user