Modernize selinux stub

This commit is contained in:
topjohnwu 2018-11-20 03:49:44 -05:00
parent 2ab999f4ca
commit baae1fc84f

View File

@ -13,14 +13,14 @@
// Stub implementations // Stub implementations
static void v_s(char *) {} static void v_s(char *s) { delete[] s; }
static int i_s(const char *) { return 0; } static int i_s(const char *) { return 0; }
static int i_ss(const char *, const char *) { return 0; } static int i_ss(const char *, const char *) { return 0; }
static int i_ssp(const char *, char ** sp) { static int i_ssp(const char *, char ** sp) {
*sp = (char *) xcalloc(1, 1); *sp = new char[1]();
return 0; return 0;
} }
@ -35,7 +35,7 @@ int (*lsetfilecon)(const char *, const char *) = i_ss;
void dload_selinux() { void dload_selinux() {
void *handle = dlopen("libselinux.so", RTLD_LAZY); void *handle = dlopen("libselinux.so", RTLD_LAZY);
if (handle == NULL) if (handle == nullptr)
return; return;
*(void **) &freecon = dlsym(handle, "freecon"); *(void **) &freecon = dlsym(handle, "freecon");
*(void **) &setcon = dlsym(handle, "setcon"); *(void **) &setcon = dlsym(handle, "setcon");
@ -119,4 +119,4 @@ void restorecon() {
fd = xopen(DATABIN, O_RDONLY | O_CLOEXEC); fd = xopen(DATABIN, O_RDONLY | O_CLOEXEC);
restore_magiskcon(fd); restore_magiskcon(fd);
close(fd); close(fd);
} }