/* * Luminary.app main executable. * * The bundle needs a Mach-O main executable so it can be code signed and, if a * certificate is ever bought, notarized: Apple's notary service rejects a * bundle whose CFBundleExecutable is a shell script. This shim resolves its own * path, finds Contents/Resources/launcher.sh next to it, and execs bash on it, * passing every argument through. All the actual launcher logic lives in that * script, where it can be changed without recompiling anything. */ #include #include #include #include #include #ifdef __APPLE__ #include #endif /** Write this process's executable path into buf, or return -1. */ static int executable_path(char *buf, size_t size) { #ifdef __APPLE__ uint32_t needed = (uint32_t)size; if (_NSGetExecutablePath(buf, &needed) != 0) return -1; return 0; #else /* Not used in the bundle; kept so the shim can be built and tested when * packaging is exercised from a non-Apple host. */ ssize_t length = readlink("/proc/self/exe", buf, size - 1); if (length < 0) return -1; buf[length] = '\0'; return 0; #endif } int main(int argc, char **argv) { char raw[PATH_MAX]; char exe[PATH_MAX]; char script[PATH_MAX]; if (executable_path(raw, sizeof raw) != 0) { fprintf(stderr, "luminary: cannot resolve the application path\n"); return 1; } if (realpath(raw, exe) == NULL) { fprintf(stderr, "luminary: cannot resolve %s\n", raw); return 1; } /* exe is .../Luminary.app/Contents/MacOS/Luminary */ char *slash = strrchr(exe, '/'); if (slash == NULL) { fprintf(stderr, "luminary: unexpected executable path %s\n", exe); return 1; } *slash = '\0'; if (snprintf(script, sizeof script, "%s/../Resources/launcher.sh", exe) >= (int)sizeof script) { fprintf(stderr, "luminary: application path is too long\n"); return 1; } char *args[argc + 2]; args[0] = "/bin/bash"; args[1] = script; for (int i = 1; i < argc; i++) args[i + 1] = argv[i]; args[argc + 1] = NULL; execv("/bin/bash", args); perror("luminary: could not start the launcher"); return 1; }