feat: init
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
nyyu 2024-04-30 09:12:09 +02:00
commit 853378b46d
4 changed files with 59 additions and 0 deletions

15
.woodpecker.yml Normal file
View File

@ -0,0 +1,15 @@
steps:
docker:
image: docker-public.nyyu.dev/nyyu/plugin-kaniko
pull: true
settings:
username:
from_secret: registry_username
password:
from_secret: registry_password
repo: ${CI_REPO_OWNER}/numcpu_override
registry: ${DOCKER_REGISTRY}
tags: alpine
when:
branch: ${CI_REPO_DEFAULT_BRANCH}
event: [push, manual, tag]

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM alpine:3.18
COPY . .
RUN apk add --no-cache gcc musl-dev && \
gcc -shared -fPIC -Wall -Wextra -Werror numcpu_override.c -o numcpu_override.so -ldl
FROM alpine:3.18
COPY /copy.sh /
COPY --from=0 numcpu_override.so /
ENTRYPOINT ["/copy.sh"]

3
copy.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "copy '$(ls *.so)' to /_libs/"
cp -f *.so /_libs/

32
numcpu_override.c Normal file
View File

@ -0,0 +1,32 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
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;
}