From 83de87968d5ffc6a755e88129e382ee51acba0b8 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 12 Jan 2008 23:47:45 +0000 Subject: [PATCH] Add a configuration command to execute an arbitrary file. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@409 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- config.l | 1 + dgamelaunch.h | 1 + dgl-common.c | 25 +++++++++++++++++++++++++ examples/dgamelaunch.conf | 1 + 4 files changed, 28 insertions(+) diff --git a/config.l b/config.l index 103f2cc..09e10da 100644 --- a/config.l +++ b/config.l @@ -88,6 +88,7 @@ chdir { yylval.i = DGLCMD_CHDIR; return TYPE_DGLCMD1; } cp { yylval.i = DGLCMD_CP; return TYPE_DGLCMD2; } unlink { yylval.i = DGLCMD_UNLINK; return TYPE_DGLCMD1; } setenv { yylval.i = DGLCMD_SETENV; return TYPE_DGLCMD2; } +exec { yylval.i = DGLCMD_EXEC; return TYPE_DGLCMD2; } DEFINE { return TYPE_DEFINE_GAME; } diff --git a/dgamelaunch.h b/dgamelaunch.h index 33df470..fedfd0a 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -101,6 +101,7 @@ typedef enum DGLCMD_CHDIR, /* chdir foo */ DGLCMD_CP, /* cp foo bar */ DGLCMD_UNLINK, /* unlink foo */ + DGLCMD_EXEC, /* exec foo bar */ DGLCMD_SETENV /* setenv foo bar */ } dglcmd_actions; diff --git a/dgl-common.c b/dgl-common.c index 68e44ef..69ceedc 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -2,6 +2,8 @@ #include "dgamelaunch.h" #include +#include +#include #include #include #include @@ -11,6 +13,7 @@ #include #include #include +#include extern FILE* yyin; extern int yyparse (); @@ -162,6 +165,28 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me) fclose (newfile); } break; + case DGLCMD_EXEC: + if (p1 && p2) { + pid_t child; + char *myargv[3]; + + myargv[0] = p1; + myargv[1] = p2; + myargv[2] = 0; + + endwin(); + child = fork(); + if (child == -1) { + perror("fork"); + graceful_exit(114); + } else if (child == 0) { + execvp(p1, myargv); + exit(0); + } else + waitpid(child, NULL, 0); + refresh(); + } + break; case DGLCMD_SETENV: if (p1 && p2) mysetenv(p1, p2, 1); break; diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index a2c728d..530d2b9 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -73,6 +73,7 @@ lockfile = "/dgl-lock" # cp "foo" "bar" = copies file "foo" to "bar", overwriting previous "bar" # unlink "foo" = deletes file "foo" # setenv "foo "bar" = sets environment variable "foo" to "bar" +# exec "foo" "bar" = execute "foo" with "bar" as it's param # # The commands will be done inside the chroot and with the uid and gid # defined above.