From 5606045299518fc57a59cffd3d34f1aa2037ca2b Mon Sep 17 00:00:00 2001 From: pelya Date: Sun, 10 Nov 2013 22:32:12 +0200 Subject: [PATCH] Xserver: fixes for fakechroot --- .../commandergenius/commandergenius | 2 +- project/jni/application/xserver/gfx.c | 10 +-- project/jni/application/xserver/main.c | 66 +++++++++++++++++-- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/project/jni/application/commandergenius/commandergenius b/project/jni/application/commandergenius/commandergenius index 13252e15d..1bcbadd1e 160000 --- a/project/jni/application/commandergenius/commandergenius +++ b/project/jni/application/commandergenius/commandergenius @@ -1 +1 @@ -Subproject commit 13252e15db578ccfcde859212cff9fab7c1aa5eb +Subproject commit 1bcbadd1eadd735235288463239c348f5b58f845 diff --git a/project/jni/application/xserver/gfx.c b/project/jni/application/xserver/gfx.c index eed64dbaa..c64ddc249 100644 --- a/project/jni/application/xserver/gfx.c +++ b/project/jni/application/xserver/gfx.c @@ -140,7 +140,7 @@ void * unpackFilesThread(void * unused) __android_log_print(ANDROID_LOG_INFO, "XSDL", "Running postinstall scipt"); - fo = popen(fname, "w"); + fo = popen(fname, "r"); if( !fo ) { __android_log_print(ANDROID_LOG_INFO, "XSDL", "ERROR: Cannot launch postinstall scipt"); @@ -192,7 +192,7 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i SDL_Event event; int res = -1, dpi = -1; char native[32] = "0x0"; - float dpiScale = 1.0f; + //float dpiScale = 1.0f; const char * resStr[] = { native, "1920x1080", "1280x960", "1280x720", @@ -248,7 +248,7 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i SDL_Delay(200); SDL_Flip(SDL_GetVideoSurface()); } - dpiScale = (float)resVal[res][0] / (float)*resolutionW; + //dpiScale = (float)resVal[res][0] / (float)*resolutionW; *resolutionW = resVal[res][0]; *resolutionH = resVal[res][1]; while ( dpi < 0 ) @@ -281,8 +281,8 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i SDL_Delay(200); SDL_Flip(SDL_GetVideoSurface()); } - *displayW = *displayW * (dpiScale / fontsVal[dpi]); - *displayH = *displayH * (dpiScale / fontsVal[dpi]); + *displayW = *displayW / fontsVal[dpi]; + *displayH = *displayH / fontsVal[dpi]; } void XSDL_generateBackground(const char * port, int showHelp) diff --git a/project/jni/application/xserver/main.c b/project/jni/application/xserver/main.c index ba76adaec..30dcbae05 100644 --- a/project/jni/application/xserver/main.c +++ b/project/jni/application/xserver/main.c @@ -1,9 +1,13 @@ #include #include #include +#include #include +#include #include #include +#include +#include #include #include @@ -11,6 +15,8 @@ extern int android_main( int argc, char *argv[], char *envp[] ); +static void setupEnv(void); + int main( int argc, char* argv[] ) { int i; @@ -38,6 +44,7 @@ int main( int argc, char* argv[] ) int displayH = atoi(getenv("DISPLAY_HEIGHT_MM")); __android_log_print(ANDROID_LOG_INFO, "XSDL", "Actual video resolution %d/%dx%d/%d", resolutionW, displayW, resolutionH, displayH); + setupEnv(); XSDL_initSDL(); @@ -45,22 +52,51 @@ int main( int argc, char* argv[] ) XSDL_showConfigMenu(&resolutionW, &displayW, &resolutionH, &displayH); - int s = socket(AF_INET, SOCK_STREAM, 0); - if( s >= 0 ) + for(i = 0; i < 1024; i++) { - for(i = 0; i < 1024; i++) + int s = socket(AF_INET, SOCK_STREAM, 0); + if( s >= 0 ) { struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(6000 + i); - if( bind (s, (struct sockaddr *) &addr, sizeof(addr) ) < 0 ) + if( bind (s, (struct sockaddr *) &addr, sizeof(addr) ) != 0 ) + { + __android_log_print(ANDROID_LOG_INFO, "XSDL", "TCP port %d already used, trying next one: %s", 6000 + i, strerror(errno)); + close(s); continue; - sprintf( port, ":%d", i ); + } + close(s); } - close(s); + + // Cannot create socket with non-existing path, but Xserver code somehow does that + /* + s = socket(AF_UNIX, SOCK_STREAM, 0); + if( s >= 0 ) + { + struct sockaddr_un addr; + + memset(&addr, 0, sizeof(addr)); + + addr.sun_family = AF_UNIX; + sprintf(addr.sun_path, "/tmp/.X11-unix/X%d", i); + if( bind(s, (struct sockaddr *) &addr, strlen(addr.sun_path) + sizeof(addr.sun_family)) != 0 ) + { + __android_log_print(ANDROID_LOG_INFO, "XSDL", "UNIX path %s already used, trying next one: %s", addr.sun_path, strerror(errno)); + close(s); + continue; + } + close(s); + } + */ + + sprintf( port, ":%d", i ); + break; } if( argc > 1 && strcmp(argv[1], "-nohelp") == 0 ) @@ -97,3 +133,21 @@ int main( int argc, char* argv[] ) return android_main( ARGNUM, args, envp ); } + +void setupEnv(void) +{ + uid_t uid = geteuid(); + struct passwd * pwd; + char buf[32]; + errno = 0; + pwd = getpwuid(uid); + if( !pwd ) + { + __android_log_print(ANDROID_LOG_INFO, "XSDL", "Cannot determine user name for ID %d: %s", uid, strerror(errno)); + return; + } + sprintf( buf, "%d", uid ); + __android_log_print(ANDROID_LOG_INFO, "XSDL", "User %s ID %s", pwd->pw_name, buf); + setenv("USER_ID", buf, 1); + setenv("USER", pwd->pw_name, 1); +}