From: Joshua Kwan Date: Sun, 25 Jan 2004 22:34:35 +0000 (+0000) Subject: Cleanups - globals, extraneous #defines, #include order, etc. X-Git-Tag: v1.6.1-roc-dev~537 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=c4932ed44bb5ae5f866cbd302a391e5712ae0f9a;p=dgamelaunch Cleanups - globals, extraneous #defines, #include order, etc. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@161 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- diff --git a/dgamelaunch.c b/dgamelaunch.c index 2e808ed..7872861 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -1,7 +1,7 @@ /* dgamelaunch.c * - * (c)2001-3 M. Drew Streib - * also parts (c) 2003 Joshua Kwan , + * (c)2001-4 M. Drew Streib + * also parts (c) 2003-4 Joshua Kwan , * Brett Carrington , * Jilles Tjoelker * @@ -26,12 +26,6 @@ * This is a little wrapper for nethack (and soon other programs) that * will allow them to be run from a telnetd session, chroot, shed privs, * make a simple login, then play the game. - * - * By default, this thing is also statically compiled, and can thus be - * run inside of a chroot jail itself if necessary. - * - * Yes, I know it is all global variables. Deal with it. The program - * is very small. */ #define _GNU_SOURCE @@ -48,12 +42,14 @@ /* program stuff */ -#include -#include #include -#include /* for flock() */ #include #include +#include /* ttyrec */ +#include + +#include +#include #ifndef __FreeBSD__ # include @@ -73,12 +69,9 @@ #include #include #include -#include -#include /* ttyrec */ #include #include #include -#include #include #include #include @@ -89,11 +82,12 @@ extern FILE* yyin; extern int yyparse (); +extern pid_t child; /* nethack process */ + extern int ee_main (int argc, char **argv); extern int ttyplay_main (char *ttyfile, int mode, int rstripgfx); -extern int ttyrec_main (char *); -extern int master; -extern int slave; +extern int ttyrec_main (char *username, char* ttyrec_filename); +extern int master, slave; extern struct termios tt; extern struct winsize win; @@ -103,23 +97,21 @@ struct dg_config *myconfig = NULL; char* config = NULL; struct dg_config defconfig = { - "/var/lib/dgamelaunch/", - "/bin/nethack", - "/dgldir/", - "/dgl-lock", - "/dgl-login", - "/dgl-banner", - "/dgl-default-rcfile", - "/var/mail/", - "games", "games", - 5, 60, /* games:games in Debian */ - 64000 + .chroot = "/var/lib/dgamelaunch/", + .nethack = "/bin/nethack", + .dglroot = "/dgldir/", + .lockfile = "/dgl-lock", + .passwd = "/dgl-login", + .banner = "/dgl-banner", + .rcfile = "/dgl-default-rcfile", + .spool = "/var/mail/", + .shed_user = "games", .shed_group = "games", + .shed_uid = 5, .shed_gid = 60, /* games:games in Debian */ + .max = 64000 }; -int pid_game = 0; int loggedin = 0; char rcfilename[80]; -char ttyrec_filename[100]; char *chosen_name; int f_num = 0; @@ -225,11 +217,12 @@ ttyrec_getmaster () /* ************************************************************* */ -void +char* gen_ttyrec_filename () { time_t rawtime; struct tm *ptm; + char *ttyrec_filename = calloc(100, sizeof(char)); /* append time to filename */ time (&rawtime); @@ -237,12 +230,13 @@ gen_ttyrec_filename () snprintf (ttyrec_filename, 100, "%04i-%02i-%02i.%02i:%02i:%02i.ttyrec", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); + return ttyrec_filename; } /* ************************************************************* */ void -gen_inprogress_lock (pid_t pid) +gen_inprogress_lock (pid_t pid, char* ttyrec_filename) { char lockfile[130], pidbuf[16]; int fd; @@ -270,10 +264,10 @@ gen_inprogress_lock (pid_t pid) void catch_sighup (int signum) { - if (pid_game) + if (child) { sleep (10); - kill (pid_game, SIGHUP); + kill (child, SIGHUP); sleep (5); } graceful_exit (2); @@ -1520,11 +1514,8 @@ main (int argc, char** argv) free (spool); - /* lock */ - gen_ttyrec_filename (); - /* launch program */ - ttyrec_main (me->username); + ttyrec_main (me->username, gen_ttyrec_filename()); /* NOW we can safely kill this */ freefile (); diff --git a/dgamelaunch.h b/dgamelaunch.h index f8189ad..0f7a135 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -56,13 +56,12 @@ struct dg_config extern char* config; /* file path */ extern struct dg_config *myconfig; -extern struct dg_config defconfig; /* dgamelaunch.c function prototypes */ extern void create_config (void); extern void ttyrec_getmaster (void); -extern void gen_ttyrec_filename (void); -extern void gen_inprogress_lock (pid_t pid); +extern char* gen_ttyrec_filename (void); +extern void gen_inprogress_lock (pid_t pid, char* ttyrec_filename); extern void catch_sighup (int signum); extern void loadbanner (struct dg_banner *ban); extern void drawbanner (unsigned int start_line, unsigned int howmany); diff --git a/ttyplay.c b/ttyplay.c index b2ba4c6..d57d8a1 100644 --- a/ttyplay.c +++ b/ttyplay.c @@ -31,14 +31,15 @@ * SUCH DAMAGE. */ +#include +#include +#include + #include #include #include #include #include -#include -#include -#include #include #include #include "ttyrec.h" diff --git a/ttyrec.c b/ttyrec.c index d7bcb08..007e512 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -45,10 +45,13 @@ #include "dgamelaunch.h" #include #include -#include #include -#include #include +#include +#include + +#include +#include #include #include #include @@ -59,7 +62,6 @@ #include #include -#include #include "ttyrec.h" #include "io.h" @@ -67,19 +69,6 @@ # define XCASE 0 #endif -#define HAVE_inet_aton -#define HAVE_scsi_h -#define HAVE_kd_h - -#define _(FOO) FOO - -#ifdef HAVE_openpty -#include -#endif - -extern char ttyrec_filename[100]; -extern int pid_game; - void done (void); void fail (void); void fixtty (void); @@ -91,8 +80,7 @@ void doshell (char *); FILE *fscript; int master; int slave; -int child; -int subchild; +pid_t child, subchild; struct termios tt; struct winsize win; @@ -102,7 +90,7 @@ int aflg; int uflg; int -ttyrec_main (char *username) +ttyrec_main (char *username, char* ttyrec_filename) { void finish (); char dirname[100]; @@ -142,8 +130,7 @@ ttyrec_main (char *username) if (child) { close (slave); - pid_game = child; - gen_inprogress_lock (pid_game); + gen_inprogress_lock (child, ttyrec_filename); dooutput (); } else @@ -166,8 +153,6 @@ doinput () done (); } -#include - void finish () {