From eef8cac28e01333939f97524ed6346c503b6a6f0 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 20 Dec 2017 09:53:02 +0000 Subject: [PATCH] osxlaunch: bodge to let me test-build on Linux. By default, the program still builds on Linux to a stub that just prints 'nothing to see here'. But if you compile with -DTEST_COMPILE_ON_LINUX, it compiles to a program that still doesn't do anything _actually_ useful, but goes through all the same motions that real osxlaunch would go through, until the final execv(2) fails because of course it's not _really_ living in an application bundle directory of the right shape. That allows me to run all the setup code under the debugging tools I'm most used to, in my preferred environment. (Same rationale as having puttyapp / ptermapp build for Linux too.) --- unix/osxlaunch.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/unix/osxlaunch.c b/unix/osxlaunch.c index 8082f2de..3d10c7d8 100644 --- a/unix/osxlaunch.c +++ b/unix/osxlaunch.c @@ -48,7 +48,7 @@ #include #include -#ifndef __APPLE__ +#if !defined __APPLE__ && !defined TEST_COMPILE_ON_LINUX /* When we're not compiling for OS X, it's easier to just turn this * program into a trivial hello-world by ifdef in the source than it * is to remove it in the makefile edifice. */ @@ -61,7 +61,24 @@ int main(int argc, char **argv) #include #include + +#ifdef __APPLE__ #include +#else +/* For Linux, a bodge to let as much of this code still run as + * possible, so that you can run it under friendly debugging tools + * like valgrind. */ +int _NSGetExecutablePath(char *out, uint32_t *outlen) +{ + static const char toret[] = "/proc/self/exe"; + if (out != NULL && *outlen < sizeof(toret)) + return -1; + *outlen = sizeof(toret); + if (out) + memcpy(out, toret, sizeof(toret)); + return 0; +} +#endif /* ---------------------------------------------------------------------- * Find an alphabetic prefix unused by any environment variable name.