Add a configuration command to execute an arbitrary file.
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@409 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
b13a65584a
commit
83de87968d
1
config.l
1
config.l
|
@ -88,6 +88,7 @@ chdir { yylval.i = DGLCMD_CHDIR; return TYPE_DGLCMD1; }
|
||||||
cp { yylval.i = DGLCMD_CP; return TYPE_DGLCMD2; }
|
cp { yylval.i = DGLCMD_CP; return TYPE_DGLCMD2; }
|
||||||
unlink { yylval.i = DGLCMD_UNLINK; return TYPE_DGLCMD1; }
|
unlink { yylval.i = DGLCMD_UNLINK; return TYPE_DGLCMD1; }
|
||||||
setenv { yylval.i = DGLCMD_SETENV; return TYPE_DGLCMD2; }
|
setenv { yylval.i = DGLCMD_SETENV; return TYPE_DGLCMD2; }
|
||||||
|
exec { yylval.i = DGLCMD_EXEC; return TYPE_DGLCMD2; }
|
||||||
DEFINE { return TYPE_DEFINE_GAME; }
|
DEFINE { return TYPE_DEFINE_GAME; }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ typedef enum
|
||||||
DGLCMD_CHDIR, /* chdir foo */
|
DGLCMD_CHDIR, /* chdir foo */
|
||||||
DGLCMD_CP, /* cp foo bar */
|
DGLCMD_CP, /* cp foo bar */
|
||||||
DGLCMD_UNLINK, /* unlink foo */
|
DGLCMD_UNLINK, /* unlink foo */
|
||||||
|
DGLCMD_EXEC, /* exec foo bar */
|
||||||
DGLCMD_SETENV /* setenv foo bar */
|
DGLCMD_SETENV /* setenv foo bar */
|
||||||
} dglcmd_actions;
|
} dglcmd_actions;
|
||||||
|
|
||||||
|
|
25
dgl-common.c
25
dgl-common.c
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "dgamelaunch.h"
|
#include "dgamelaunch.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -11,6 +13,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
extern FILE* yyin;
|
extern FILE* yyin;
|
||||||
extern int yyparse ();
|
extern int yyparse ();
|
||||||
|
@ -162,6 +165,28 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me)
|
||||||
fclose (newfile);
|
fclose (newfile);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case DGLCMD_SETENV:
|
||||||
if (p1 && p2) mysetenv(p1, p2, 1);
|
if (p1 && p2) mysetenv(p1, p2, 1);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -73,6 +73,7 @@ lockfile = "/dgl-lock"
|
||||||
# cp "foo" "bar" = copies file "foo" to "bar", overwriting previous "bar"
|
# cp "foo" "bar" = copies file "foo" to "bar", overwriting previous "bar"
|
||||||
# unlink "foo" = deletes file "foo"
|
# unlink "foo" = deletes file "foo"
|
||||||
# setenv "foo "bar" = sets environment variable "foo" to "bar"
|
# 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
|
# The commands will be done inside the chroot and with the uid and gid
|
||||||
# defined above.
|
# defined above.
|
||||||
|
|
Loading…
Reference in New Issue