Skip to content

Commit

Permalink
Start Xposed logcat daemon after Xposed services
Browse files Browse the repository at this point in the history
Allows us to read settings from /data via the services a bit earlier.
There's only a small chance that errors will occur while the services
start, which would now no longer be visible in the error.log (still in
the logcat though). However, even writing the logfile requires some
similar mechanisms as the services (e.g. SELinux context switches), so
the overall impact is very small.
  • Loading branch information
rovo89 committed May 18, 2016
1 parent cc0d213 commit 894ccc1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
16 changes: 13 additions & 3 deletions xposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool initialize(bool zygote, bool startSystemServer, const char* className, int
#endif // XPOSED_WITH_SELINUX

if (startSystemServer) {
xposed::logcat::start();
xposed::logcat::printStartupMarker();
} else if (zygote) {
// TODO Find a better solution for this
// Give the primary Zygote process a little time to start first.
Expand All @@ -109,15 +109,25 @@ bool initialize(bool zygote, bool startSystemServer, const char* className, int
printRomInfo();

if (startSystemServer) {
if (!xposed::service::startAll())
if (!xposed::service::startAll()) {
return false;
}
xposed::logcat::start();
#if XPOSED_WITH_SELINUX
} else if (xposed->isSELinuxEnabled) {
if (!xposed::service::startMembased())
if (!xposed::service::startMembased()) {
return false;
}
#endif // XPOSED_WITH_SELINUX
}

#if XPOSED_WITH_SELINUX
// Don't let any further forks access the Zygote service
if (xposed->isSELinuxEnabled) {
xposed::service::membased::restrictMemoryInheritance();
}
#endif // XPOSED_WITH_SELINUX

// FIXME Zygote has no access to input devices, this would need to be check in system_server context
if (zygote && !isSafemodeDisabled() && detectSafemodeTrigger(shouldSkipSafemodeDelay()))
disableXposed();
Expand Down
4 changes: 3 additions & 1 deletion xposed_logcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ static void runDaemon(int pipefd) {
exit(EXIT_FAILURE);
}

void start() {
void printStartupMarker() {
sprintf(marker, "Current time: %d, PID: %d", (int) time(NULL), getpid());
ALOG(LOG_DEBUG, "XposedStartupMarker", marker, NULL);
}

void start() {
// Fork to create a daemon
pid_t pid;
if ((pid = fork()) < 0) {
Expand Down
1 change: 1 addition & 0 deletions xposed_logcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace xposed {
namespace logcat {

void printStartupMarker();
void start();

} // namespace logcat
Expand Down
7 changes: 2 additions & 5 deletions xposed_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static bool init() {
return true;
}

static void restrictMemoryInheritance() {
void restrictMemoryInheritance() {
madvise(shared, sizeof(MemBasedState), MADV_DONTFORK);
canAlwaysAccessService = false;
}
Expand Down Expand Up @@ -884,12 +884,9 @@ static void appService(bool useSingleProcess) {
}

bool checkMembasedRunning() {
// Don't let any further forks inherit this mapping
membased::restrictMemoryInheritance();

// Ensure that the memory based service is running
if (!membased::waitForRunning(5)) {
ALOGE("Zygote service is not running, Xposed cannot work without it");
ALOGE("Xposed's Zygote service is not running, cannot work without it");
return false;
}

Expand Down
1 change: 1 addition & 0 deletions xposed_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace service {
int accessFile(const char* path, int mode);
int statFile(const char* path, struct stat* stat);
char* readFile(const char* path, int* bytesRead);
void restrictMemoryInheritance();
} // namespace membased
#endif // XPOSED_WITH_SELINUX

Expand Down

0 comments on commit 894ccc1

Please sign in to comment.