This is also needed in order to make the requested number of CPUs
appear. For now we don't reroute to the original sysconf() call so
we return -1,EINVAL for all other info.
#define _GNU_SOURCE
+#include <errno.h>
#include <limits.h>
#include <sched.h>
#include <stdio.h>
static char prog_full_path[PATH_MAX];
+long sysconf(int name)
+{
+ if (name == _SC_NPROCESSORS_ONLN ||
+ name == _SC_NPROCESSORS_CONF) {
+ const char *ncpu = getenv("NCPU");
+ int n;
+
+ n = ncpu ? atoi(ncpu) : CPU_SETSIZE;
+ if (n < 0 || n > CPU_SETSIZE)
+ n = CPU_SETSIZE;
+ return n;
+ }
+ errno = EINVAL;
+ return -1;
+}
+
/* return a cpu_set having the first $NCPU set */
int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask)
{