diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2017-02-08 04:31:15 +0000 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2017-02-08 04:31:15 +0000 |
commit | 2b58008b911d9dc8354b9001e22b594fa6456dd1 (patch) | |
tree | 6085b8decdb0374505937a03e2b02fb6096c3af4 | |
parent | a45db08b92bac87d83890767c2216a8cbdf0a3f7 (diff) | |
download | gcompat-2b58008b911d9dc8354b9001e22b594fa6456dd1.tar.gz gcompat-2b58008b911d9dc8354b9001e22b594fa6456dd1.tar.bz2 gcompat-2b58008b911d9dc8354b9001e22b594fa6456dd1.tar.xz gcompat-2b58008b911d9dc8354b9001e22b594fa6456dd1.zip |
resource: new setrlimit stub for broken glibc2.2 compat
-rw-r--r-- | resource.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/resource.c b/resource.c new file mode 100644 index 0000000..029b31e --- /dev/null +++ b/resource.c @@ -0,0 +1,37 @@ +#include <sys/resource.h> /* setrlimit, struct rlimit */ +#include <assert.h> /* assert */ +#include <dlfcn.h> /* dlsym, RTLD_NEXT */ +#include <stdlib.h> /* NULL */ +#include <string.h> /* memcpy */ + +/* Sigh. + * Valve compiled Steam against the glibc2.2 version of setrlimit. + * This broken version aliased 0 to RLIM_INFINITY. + * + * So, what you have to do is: if you want to run steam with this gcompat, + * ensure you compile *without* defining NO_BROKEN_SHADOW_SETRLIMIT. + * If you do *not* want to run steam with this gcompat, define it. + * + * The only problem with enabling this all the time is that if a binary + * really does need a ulimit to be 0 for any reason (such as coredumps), it + * very obviously won't work here. + */ +#ifndef NO_BROKEN_SHADOW_SETRLIMIT +int (*real_rlimit)(int, const struct rlimit *); + +int setrlimit(int resource, const struct rlimit *rlim) +{ + struct rlimit my_rlim; + real_rlimit = dlsym(RTLD_NEXT, "setrlimit"); + assert(real_rlimit != NULL); + + memcpy(&my_rlim, rlim, sizeof(struct rlimit)); + + if(my_rlim.rlim_cur == 0) + { + my_rlim.rlim_cur = my_rlim.rlim_max; + } + + return real_rlimit(resource, &my_rlim); +} +#endif |