Improve compatibility and remove unnecessary fork

This commit is contained in:
topjohnwu 2017-02-04 17:36:45 +08:00
parent 0cf13f6393
commit f269695d4a

33
su.c
View File

@ -621,7 +621,10 @@ int su_main(int argc, char *argv[]) {
int su_main_nodaemon(int argc, char **argv) { int su_main_nodaemon(int argc, char **argv) {
int ppid = getppid(); int ppid = getppid();
fork_for_samsung();
// Only fork when not running in daemon mode (already forked from daemon)
if (! is_daemon)
fork_for_samsung();
// Sanitize all secure environment variables (from linker_environ.c in AOSP linker). // Sanitize all secure environment variables (from linker_environ.c in AOSP linker).
/* The same list than GLibc at this point */ /* The same list than GLibc at this point */
@ -665,14 +668,12 @@ int su_main_nodaemon(int argc, char **argv) {
LOGD("su invoked."); LOGD("su invoked.");
//Chainfire compatibility // Replace -cn with z, for CF compatibility
if(argc >= 3 && ( for (int i = 0; i < argc; ++i) {
strcmp(argv[1], "-cn") == 0 || if (strcmp(argv[i], "-cn") == 0) {
strcmp(argv[1], "--context") == 0 strcpy(argv[i], "-z");
break;
)) { }
argc-=2;
argv+=2;
} }
struct su_context ctx = { struct su_context ctx = {
@ -705,13 +706,13 @@ int su_main_nodaemon(int argc, char **argv) {
char buf[64], *result; char buf[64], *result;
policy_t dballow; policy_t dballow;
struct option long_opts[] = { struct option long_opts[] = {
{ "command", required_argument, NULL, 'c' }, { "command", required_argument, NULL, 'c' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "login", no_argument, NULL, 'l' }, { "login", no_argument, NULL, 'l' },
{ "preserve-environment", no_argument, NULL, 'p' }, { "preserve-environment", no_argument, NULL, 'p' },
{ "shell", required_argument, NULL, 's' }, { "shell", required_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ "context", required_argument, NULL, 'z' }, { "context", required_argument, NULL, 'z' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };