]> skyeroc.xyz Git - dgamelaunch/commitdiff
Added dgl-wall to cvsignore, fixed build
authorJoshua Kwan <joshk@triplehelix.org>
Sun, 22 Feb 2004 09:01:03 +0000 (09:01 +0000)
committerJoshua Kwan <joshk@triplehelix.org>
Sun, 22 Feb 2004 09:01:03 +0000 (09:01 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@249 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

Changelog
dgamelaunch.c
dgl-common.c

index dabb323f9e56bdfb896728702190da4c47002daf..411784d7bb2e0b81cd62d97606dc6311ecdeb708 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,10 @@
          writing a full file all the time. (jilles)
        * Don't write rcfiles if they already exist. (i.e., lost account
          holders recreating their accounts.
+       * Allow administrator to hardcode a dgamelaunch.conf path.
+       * Include dgl-wall, which notifies all logged in users with
+         a mail message.
+       * Split common functions into dgl-common.c.
 
 1.4.1 (2004/02/13)
        * Don't explicitly unlock the lock file before fclosing it;
index 0057b6376541bf49792a1e3c28ded98166b12d4d..4e1d555ea89f55eeca2a27a88318f045b8f42a0f 100644 (file)
@@ -89,30 +89,7 @@ extern int editor_main (int argc, char **argv);
 
 /* global variables */
 
-struct dg_config *myconfig = NULL;
-char* config = NULL;
-int silent = 0;
-
-struct dg_config defconfig = {
-  /* 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 set_max = 0; /* XXX */
-int loggedin = 0;
 char rcfilename[80];
-char *chosen_name;
 
 int f_num = 0;
 struct dg_user **users = NULL;
@@ -142,82 +119,9 @@ mysetenv (const char* name, const char* value, int overwrite)
 # define mysetenv setenv
 #endif /* !linux && !bsd */
 
-void
-create_config ()
-{
-  FILE *config_file = NULL;
-
-  if (config)
-  {
-    if ((config_file = fopen(config, "r")) != NULL)
-    {
-      yyin = config_file;
-      yyparse();
-      fclose(config_file);
-      free (config);
-    }
-    else
-    {
-      fprintf(stderr, "ERROR: can't find or open %s for reading\n", config);
-      graceful_exit(104);
-      return;
-    }
-  }
-  else
-  {
-#ifdef DEFCONFIG
-    config = DEFCONFIG;
-    if ((config_file = fopen(DEFCONFIG, "r")) != NULL)
-    {
-      yyin = config_file;
-      yyparse();
-      fclose(config_file);
-    }
-#else
-    myconfig = &defconfig;
-    return;
-#endif
-  }
-
-  if (!myconfig) /* a parse error occurred */
-  {
-    myconfig = &defconfig;
-    return;
-  }
-  /* Fill the rest with defaults */
-  if (!myconfig->shed_user && myconfig->shed_uid == -1)
-  {
-    struct passwd *pw;
-    if ((pw = getpwnam(defconfig.shed_user)))
-      myconfig->shed_uid = pw->pw_uid;
-    else
-      myconfig->shed_uid = defconfig.shed_uid;
-  }
-
-  if (!myconfig->shed_group && myconfig->shed_gid == -1)
-  {
-    struct group *gr;
-    if ((gr = getgrnam(defconfig.shed_group)))
-      myconfig->shed_gid = gr->gr_gid;
-    else
-      myconfig->shed_gid = defconfig.shed_gid;
-  }
-
-  if (myconfig->max == 0 && !set_max) myconfig->max = defconfig.max;
-  if (!myconfig->banner) myconfig->banner = defconfig.banner;
-  if (!myconfig->chroot) myconfig->chroot = defconfig.chroot;
-  if (!myconfig->nethack) myconfig->nethack = defconfig.nethack;
-  if (!myconfig->dglroot) myconfig->dglroot = defconfig.dglroot;
-  if (!myconfig->rcfile) myconfig->rcfile = defconfig.rcfile;
-  if (!myconfig->spool) myconfig->spool = defconfig.spool;
-  if (!myconfig->passwd) myconfig->passwd = defconfig.passwd;
-  if (!myconfig->lockfile) myconfig->lockfile = defconfig.lockfile;
-}
-
 /* ************************************************************* */
 /* for ttyrec */
 
-
 void
 ttyrec_getpty ()
 {
@@ -398,96 +302,6 @@ drawbanner (unsigned int start_line, unsigned int howmany)
     mvaddstr (start_line + i, 1, banner.lines[i]);
 }
 
-struct dg_game **
-populate_games (int *l)
-{
-  int fd, len;
-  DIR *pdir;
-  struct dirent *pdirent;
-  struct stat pstat;
-  char fullname[130], ttyrecname[130];
-  char *replacestr, *dir;
-  struct dg_game **games = NULL;
-  struct flock fl = { 0 };
-  size_t slen;
-
-  fl.l_type = F_WRLCK;
-  fl.l_whence = SEEK_SET;
-  fl.l_start = 0;
-  fl.l_len = 0;
-
-  len = 0;
-  
-  slen = strlen(myconfig->dglroot) + ARRAY_SIZE("inprogress/") + 1;
-  dir = malloc(slen);
-  snprintf(dir, slen, "%sinprogress/", myconfig->dglroot);
-
-  if (!(pdir = opendir (dir)))
-    graceful_exit (140);
-
-  while ((pdirent = readdir (pdir)))
-    {
-      if (!strcmp (pdirent->d_name, ".") || !strcmp (pdirent->d_name, ".."))
-        continue;
-
-      snprintf (fullname, 130, "%sinprogress/%s", myconfig->dglroot, pdirent->d_name);
-
-      fd = 0;
-      /* O_RDWR here should be O_RDONLY, but we need to test for
-       * an exclusive lock */
-      fd = open (fullname, O_RDWR);
-      if ((fd > 0) && fcntl (fd, F_SETLK, &fl) == -1)
-        {
-
-          /* stat to check idle status */
-          snprintf (ttyrecname, 130, "%sttyrec/%s", myconfig->dglroot, pdirent->d_name);
-          replacestr = strchr (ttyrecname, ':');
-          if (!replacestr)
-            graceful_exit (145);
-          replacestr[0] = '/';
-          if (!stat (ttyrecname, &pstat))
-            {
-              /* now it's a valid game for sure */
-              games = realloc (games, sizeof (struct dg_game) * (len + 1));
-              games[len] = malloc (sizeof (struct dg_game));
-              games[len]->ttyrec_fn = strdup (pdirent->d_name);
-
-              if (!(replacestr = strchr (pdirent->d_name, ':')))
-                graceful_exit (146);
-              else
-                *replacestr = '\0';
-
-              games[len]->name = malloc (strlen (pdirent->d_name) + 1);
-              strlcpy (games[len]->name, pdirent->d_name,
-                       strlen (pdirent->d_name) + 1);
-
-              games[len]->date = malloc (11);
-              strlcpy (games[len]->date, replacestr + 1, 11);
-
-              games[len]->time = malloc (9);
-              strlcpy (games[len]->time, replacestr + 12, 9);
-
-              games[len]->idle_time = pstat.st_mtime;
-
-              len++;
-            }
-        }
-      else
-        {
-          /* clean dead ones */
-          unlink (fullname);
-        }
-      close (fd);
-
-      fl.l_type = F_WRLCK;
-    }
-
-  closedir (pdir);
-  *l = len;
-  return games;
-}
-
-
 void
 inprogressmenu ()
 {
@@ -1383,30 +1197,12 @@ writefile (int requirenew)
 
 /* ************************************************************* */
 
-void
-graceful_exit (int status)
-{
-  /*FILE *fp;
-     if (status != 1) 
-     { 
-     fp = fopen ("/crash.log", "a");
-     char buf[100];
-     sprintf (buf, "graceful_exit called with status %d", status);
-     fputs (buf, fp);
-     } 
-     This doesn't work. Ever.
-   */
-  exit (status);
-}
-
-
 /* ************************************************************* */
 
 /* ************************************************************* */
 /* ************************************************************* */
 /* ************************************************************* */
 
-
 /* TODO: Some of the messages here (sorry no nethack for you!) are nethack specific
  * as may be some code... don't think so though. Globalize it. */ 
 int
index 72278c6d42fc55ae5dc8808c6d31a9b0ad79520b..af70c7038d14d686c8288369b6403056aed5f73e 100644 (file)
@@ -117,13 +117,9 @@ populate_games (int *l)
           /* clean dead ones */
           unlink (fullname);
         }
-      fl.l_type = F_UNLCK;
-
-      fcntl (fd, F_SETLK, &fl);
+      close (fd);
 
       fl.l_type = F_WRLCK;
-      
-      close (fd);
     }
 
   closedir (pdir);
@@ -131,6 +127,22 @@ populate_games (int *l)
   return games;
 }
 
+  void
+graceful_exit (int status)
+{
+  /*FILE *fp;
+     if (status != 1) 
+     { 
+     fp = fopen ("/crash.log", "a");
+     char buf[100];
+     sprintf (buf, "graceful_exit called with status %d", status);
+     fputs (buf, fp);
+     } 
+     This doesn't work. Ever.
+   */
+  exit (status);
+}
+
 void
 create_config ()
 {
@@ -151,80 +163,54 @@ create_config ()
       graceful_exit(104);
       return;
     }
-
-    if (!myconfig) /* a parse error occurred */
-    {
-      myconfig = &defconfig;
-      return;
-    }
-    /* Fill the rest with defaults */
-    if (!myconfig->shed_user && myconfig->shed_uid == -1)
-    {
-      struct passwd *pw;
-      if ((pw = getpwnam(defconfig.shed_user)))
-        myconfig->shed_uid = pw->pw_uid;
-      else
-       myconfig->shed_uid = defconfig.shed_uid;
-    }
-
-    if (!myconfig->shed_group && myconfig->shed_gid == -1)
+  }
+  else
+  {
+#ifdef DEFCONFIG
+    config = DEFCONFIG;
+    if ((config_file = fopen(DEFCONFIG, "r")) != NULL)
     {
-      struct group *gr;
-      if ((gr = getgrnam(defconfig.shed_group)))
-       myconfig->shed_gid = gr->gr_gid;
-      else
-       myconfig->shed_gid = defconfig.shed_gid;
+      yyin = config_file;
+      yyparse();
+      fclose(config_file);
     }
-
-    if (myconfig->max == 0 && !set_max) myconfig->max = defconfig.max;
-    if (!myconfig->banner) myconfig->banner = defconfig.banner;
-    if (!myconfig->chroot) myconfig->chroot = defconfig.chroot;
-    if (!myconfig->nethack) myconfig->nethack = defconfig.nethack;
-    if (!myconfig->dglroot) myconfig->dglroot = defconfig.dglroot;
-    if (!myconfig->rcfile) myconfig->rcfile = defconfig.rcfile;
-    if (!myconfig->spool) myconfig->spool = defconfig.spool;
-    if (!myconfig->passwd) myconfig->passwd = defconfig.passwd;
-    if (!myconfig->lockfile) myconfig->lockfile = defconfig.lockfile;
+#else
+    myconfig = &defconfig;
+    return;
+#endif
   }
-  else
+
+  if (!myconfig) /* a parse error occurred */
   {
     myconfig = &defconfig;
+    return;
+  }
+  /* Fill the rest with defaults */
+  if (!myconfig->shed_user && myconfig->shed_uid == -1)
+  {
+    struct passwd *pw;
+    if ((pw = getpwnam(defconfig.shed_user)))
+      myconfig->shed_uid = pw->pw_uid;
+    else
+      myconfig->shed_uid = defconfig.shed_uid;
   }
-}
 
-#if !defined(BSD) && !defined(__linux__)
-int
-mysetenv (const char* name, const char* value, int overwrite)
-{
-  int retval;
-  char *buf = NULL;
-  
-  if (getenv(name) == NULL || overwrite)
+  if (!myconfig->shed_group && myconfig->shed_gid == -1)
   {
-    size_t len = strlen(name) + 1 + strlen(value) + 1; /* NAME=VALUE\0 */
-    buf = malloc(len);
-    snprintf(buf, len, "%s=%s", name, value);
-    retval = putenv(buf);
+    struct group *gr;
+    if ((gr = getgrnam(defconfig.shed_group)))
+      myconfig->shed_gid = gr->gr_gid;
+    else
+      myconfig->shed_gid = defconfig.shed_gid;
   }
-  else
-    retval = -1;
-  
-  return retval;  
-}
-#endif
 
-void
-graceful_exit (int status)
-{
-  /*FILE *fp;
-     if (status != 1) 
-     { 
-     fp = fopen ("/crash.log", "a");
-     char buf[100];
-     sprintf (buf, "graceful_exit called with status %d", status);
-     fputs (buf, fp);
-     } 
-     This doesn't work. Ever.
-   */
-  exit (status);
+  if (myconfig->max == 0 && !set_max) myconfig->max = defconfig.max;
+  if (!myconfig->banner) myconfig->banner = defconfig.banner;
+  if (!myconfig->chroot) myconfig->chroot = defconfig.chroot;
+  if (!myconfig->nethack) myconfig->nethack = defconfig.nethack;
+  if (!myconfig->dglroot) myconfig->dglroot = defconfig.dglroot;
+  if (!myconfig->rcfile) myconfig->rcfile = defconfig.rcfile;
+  if (!myconfig->spool) myconfig->spool = defconfig.spool;
+  if (!myconfig->passwd) myconfig->passwd = defconfig.passwd;
+  if (!myconfig->lockfile) myconfig->lockfile = defconfig.lockfile;
 }