Created
June 22, 2017 20:28
-
-
Save anonymous/9290a2ad5058dd6f9e22292b08bfa1c2 to your computer and use it in GitHub Desktop.
Fixes Poly Bridge not starting on Linux when you have e.g. Google Chrome open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <dlfcn.h> | |
// compile: gcc polybridge_fix.c -o polybridge_fix.so -ldl -shared -fPIC | |
// use: set launch command in steam to | |
// LD_PRELOAD=/path/to/polybridge_fix.so %command% | |
static FILE* (*real_fopen64)(const char *name, const char *mode); | |
FILE* fopen64(const char *name, const char *mode) | |
{ | |
FILE* f = real_fopen64(name, mode); | |
if(f && strncmp(name, "/proc", 5) == 0 && strstr(name, "/cmdline")) { | |
char tmp[32]; | |
fread(tmp, sizeof(tmp), 1, f); | |
if(strcmp("/proc/self/exe", tmp) == 0) { // this confuses Unity3D | |
fclose(f); f = real_fopen64("/dev/null", "r"); | |
} else { | |
fseek(f, 0, SEEK_SET); | |
} | |
} | |
return f; | |
} | |
__attribute__((constructor)) | |
static void init() { | |
real_fopen64 = (FILE* (*)()) dlsym(RTLD_NEXT, "fopen64"); | |
assert(real_fopen64); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment