Better nice name
This commit is contained in:
parent
8b84039f1f
commit
a19c7215d2
@ -6,17 +6,15 @@
|
||||
|
||||
#include <magisk.h>
|
||||
#include <selinux.h>
|
||||
#include <utils.h>
|
||||
|
||||
static int (*applet_main[]) (int, char *[]) =
|
||||
{ magisk_main, su_client_main, resetprop_main, magiskhide_main, nullptr };
|
||||
|
||||
char *argv0;
|
||||
|
||||
__attribute__((noreturn)) static void call_applets(int argc, char *argv[]) {
|
||||
// Applets
|
||||
for (int i = 0; applet_names[i]; ++i) {
|
||||
if (strcmp(basename(argv[0]), applet_names[i]) == 0) {
|
||||
strcpy(argv0, basename(argv[0]));
|
||||
exit((*applet_main[i])(argc, argv));
|
||||
}
|
||||
}
|
||||
@ -26,11 +24,11 @@ __attribute__((noreturn)) static void call_applets(int argc, char *argv[]) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
umask(0);
|
||||
argv0 = argv[0];
|
||||
dload_selinux();
|
||||
cmdline_logging();
|
||||
init_argv0(argc, argv);
|
||||
|
||||
if (strcmp(basename(argv0), "magisk.bin") == 0 ||
|
||||
if (strcmp(basename(argv[0]), "magisk.bin") == 0 ||
|
||||
(strcmp(basename(argv[0]), "magisk") == 0
|
||||
&& argc > 1 && argv[1][0] != '-')) {
|
||||
--argc;
|
||||
|
@ -132,7 +132,7 @@ static void main_daemon() {
|
||||
xlisten(fd, 10);
|
||||
|
||||
// Change process name
|
||||
strcpy(argv0, "magiskd");
|
||||
set_nice_name("magiskd");
|
||||
|
||||
// Block all signals
|
||||
sigset_t block_set;
|
||||
|
@ -39,7 +39,6 @@
|
||||
#define SEPOL_PROC_DOMAIN "magisk"
|
||||
#define SEPOL_FILE_DOMAIN "magisk_file"
|
||||
|
||||
extern char *argv0; /* For changing process name */
|
||||
extern int SDK_INT;
|
||||
|
||||
#define applet_names ((const char *[]) { "magisk", "su", "resetprop", "magiskhide", nullptr })
|
||||
|
@ -85,6 +85,8 @@ int fork_dont_care();
|
||||
int fork_no_zombie();
|
||||
void gen_rand_str(char *buf, int len);
|
||||
int strend(const char *s1, const char *s2);
|
||||
void init_argv0(int argc, char **argv);
|
||||
void set_nice_name(const char *name);
|
||||
|
||||
#define getline __getline
|
||||
#define getdelim __getdelim
|
||||
|
@ -224,3 +224,15 @@ int new_daemon_thread(void *(*start_routine) (void *), void *arg, const pthread_
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *argv0;
|
||||
static size_t name_len;
|
||||
void init_argv0(int argc, char **argv) {
|
||||
argv0 = argv[0];
|
||||
name_len = (argv[argc - 1] - argv[0]) + strlen(argv[argc - 1]) + 1;
|
||||
}
|
||||
|
||||
void set_nice_name(const char *name) {
|
||||
memset(argv0, 0, name_len);
|
||||
strlcpy(argv0, name, name_len);
|
||||
prctl(PR_SET_NAME, name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user