#define _GNU_SOURCE #include #include #include #include #include typedef long (*orig_sysconf_f_type)(int name); long sysconf(int name) { orig_sysconf_f_type orig; orig = (orig_sysconf_f_type)dlsym(RTLD_NEXT, "sysconf"); if (name != _SC_NPROCESSORS_CONF && name != _SC_NPROCESSORS_ONLN) { return orig(name); } printf("Overriding call sysconf %d\n", name); long numcpus = 0; char *env = getenv("NUMCPUS"); printf("Env NUMCPUS %s\n", env); if (env != NULL && strlen(env) > 0) { numcpus = strtol(env, NULL, 10); } if (numcpus == 0) { numcpus = orig(name); } printf("Return %ld\n", numcpus); fflush(stdout); return numcpus; }