{"record":{"id":"8aafabae44abbf0b","repo":"MuntashirAkon/AppManager","slug":"warning-chown-failed-s-n","errorCode":null,"errorMessage":"Warning: chown failed: %s\\n","messagePattern":"Warning: chown failed: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/src/main/cpp/run_server.c","lineNumber":163,"sourceCode":"    uid_t uid = getuid();\n    gid_t gid = getgid();\n    printf(\"Starting %s as %d:%d...\\n\", SERVER_NAME, uid, gid);\n\n    // Copy am.jar as /data/local/tmp/am.jar\n    const char *resolved_am_jar_path = NULL;\n    for (int i = 0; i < 4; i++) {\n        if (copy_file(am_jar_fallbacks[i], exec_jar_path) == 0) {\n            resolved_am_jar_path = am_jar_fallbacks[i];\n            break;\n        }\n    }\n    if (resolved_am_jar_path == NULL) {\n        fprintf(stderr, \"Error! %s could not be found or copied.\\n\", am_jar_name);\n        return 1;\n    }\n    // Fix ownership\n    if (chown(exec_jar_path, uid, gid) != 0) {\n        fprintf(stderr, \"Warning: chown failed: %s\\n\", strerror(errno));\n        // Although it failed, still proceed\n    }\n\n    // Copy main.jar as /data/local/tmp/main.jar\n    const char *resolved_main_jar_path = NULL;\n    for (int i = 0; i < 4; i++) {\n        if (copy_file(main_jar_fallbacks[i], main_jar_path) == 0) {\n            resolved_main_jar_path = main_jar_fallbacks[i];\n            break;\n        }\n    }\n    if (resolved_main_jar_path == NULL) {\n        fprintf(stderr, \"Error! %s could not be found or copied.\\n\", main_jar_name);\n        return 1;\n    }\n    // Fix ownership\n    if (chown(main_jar_path, uid, gid) != 0) {\n        fprintf(stderr, \"Warning: chown failed: %s\\n\", strerror(errno));","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/cpp/run_server.c#L145-L181","documentation":"After resolving am.jar, chown(exec_jar_path, uid, gid) failed, so the copied jar could not be given the app user's ownership. This is non-fatal — the binary prints a warning and continues, but the app process may later fail to read/execute the jar.","triggerScenarios":"The process running run_server lacks permission (not root / wrong uid) to chown the file at /data/local/tmp/<am_jar_name>, or the file lives on a filesystem that does not support chown (some emulated/FUSE mounts).","commonSituations":"Running without root on a non-rooted device; SELinux policy blocking chown on /data/local/tmp; FUSE-backed sdcard paths not supporting ownership changes.","solutions":["Run the binary as root (su) so chown succeeds","Manually verify/fix ownership with adb: chown <uid>:<gid> /data/local/tmp/am.jar","Confirm the jar is readable by the target app uid even without chown (chmod 644)","Ignore if execution still works — this is a warning, not fatal"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"Process p = Runtime.getRuntime().exec(new String[]{\"su\",\"-c\", cmd});\nString err = readStream(p.getErrorStream());\nif (err.contains(\"chown failed\")) {\n    // proceed, but ensure jar is world-readable instead\n    exec(\"chmod 644 \" + jarPath);\n}","preventionTips":["Run the binary as root so chown succeeds","chmod 644 staged jars so app uid can read them regardless of ownership","Confirm SELinux policy permits chown on /data/local/tmp","Treat as benign when execution succeeds"],"tags":["permissions","chown","filesystem"],"backgroundTag":"permission-denied","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}