feat: add language selection for build;feat: file and line number for debug messages;fix:add error handling for chdir call

This commit is contained in:
dragonmuffin 2024-08-25 20:26:45 +05:00
parent 157eafc58b
commit 858b2e7fd7
7 changed files with 18 additions and 31 deletions

View file

@ -11,16 +11,10 @@ static void procfs_prepare()
#define hostname "runner"
#define put_old "oldfs"
//#define shared_folder "../shared"
//#define shared_mountpoint "shared"
void mnt_prepare(char* rootfs, char* shared_mountpoint) {
//char* shared_folder = malloc(strlen(shared_mountpoint)+4);
//strcpy(shared_folder,"../");
//strcat(shared_folder,shared_mountpoint);
char* shared_folder=NULL;
asprintf(&shared_folder,"../%s",shared_mountpoint);
if (mount(rootfs,rootfs,"ext4",MS_BIND,"")) die("failed to mount %s: %m", rootfs);
//if (mount(shared_mountpoint,shared_mountpoint,"ext4",MS_BIND,"")) die("failed to mount %s: %m",shared_mountpoint);
if (chdir(rootfs)) die("falied to cd:%m");
//if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m");
//if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m");
@ -58,15 +52,15 @@ static int nsrun(void* arg) {
await_setup(params->fd[0]);
char cwd[PATH_MAX];
if(getcwd(cwd,sizeof(cwd))==NULL) die("getcwd error: %m");
if(chdir(params->shared_folder)) die("failed to chdir: %m");
if(chdir(params->shared_folder)) die("failed to chdir to shared folder: %m")
int out_fd=open("out",O_WRONLY|O_CREAT,0666);
if(out_fd==-1) die("unable to open output file:%m");
if(out_fd==-1) die("unable to open output file:%m")
else dup2(out_fd,STDOUT_FILENO);
int in_fd=open("in",O_RDONLY|O_CREAT,0666);
if(in_fd==-1) die("unable to open input file:%m");
if(in_fd==-1) die("unable to open input file:%m")
else dup2(in_fd,STDIN_FILENO);
int err_fd=open("err",O_WRONLY|O_CREAT,0666);
if(err_fd==-1) die("unable to open error file:%m");
if(err_fd==-1) die("unable to open error file:%m")
else dup2(err_fd,STDERR_FILENO);
if(chdir(cwd)) die("failed to chdir: %m");
mnt_prepare("minrootfs",params->shared_folder);

View file

@ -141,7 +141,7 @@ int main(int argc,char** argv) {
if (waitpid(nsrun_pid, NULL, 0) == -1) die("Failed to wait pid %d: %m\n", nsrun_pid);
kill(kill_pid,SIGKILL);//kill killer
int time = getmstime()-time_start;
chdir(params.shared_folder);
if(chdir(params.shared_folder)) die("Failed to chdir to shared folder:%m");
if(time>=limits.time) {
write_file("time", "-1");
}

View file

@ -1,10 +1,12 @@
#define die(...) {fprintf(stderr,"file %s,line %d\n",__FILE__,__LINE__);die_func(__VA_ARGS__);}
void remove_cgroup();
static void die(const char *fmt, ...)
static void die_func(const char *fmt, ...)
{
va_list params;
va_start(params, fmt);
vfprintf(stderr, fmt, params);
puts("\n");
va_end(params);
remove_cgroup();
exit(1);