From 45afd54ca0eb36f5bff9694829bb41199a9a792f Mon Sep 17 00:00:00 2001 From: Brett Carrington Date: Sun, 4 Jan 2004 01:45:21 +0000 Subject: [PATCH] graceful_exit, does nothing but please deprecate exit(). git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@63 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- dgamelaunch.c | 83 ++++++++++++++++++++++++++++++++------------------- dgamelaunch.h | 1 + ttyplay.c | 6 ++-- ttyrec.c | 2 +- virus.c | 2 +- 5 files changed, 58 insertions(+), 36 deletions(-) diff --git a/dgamelaunch.c b/dgamelaunch.c index 5cc1fb2..3995884 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -112,7 +112,7 @@ ttyrec_getmaster () #else if ((master = open ("/dev/ptmx", O_RDWR)) < 0) #endif - exit (62); + graceful_exit (62); } /* ************************************************************* */ @@ -150,7 +150,7 @@ gen_inprogress_lock () fd = open (lockfile, O_WRONLY | O_CREAT, 0644); if (fcntl (fd, F_SETLKW, &fl) == -1) - exit (68); + graceful_exit (68); } /* ************************************************************* */ @@ -164,7 +164,7 @@ catch_sighup (int signum) kill (pid_game, SIGHUP); sleep (5); } - exit (2); + graceful_exit (2); } /* ************************************************************* */ @@ -277,7 +277,7 @@ populate_games (int *l) len = 0; if (!(pdir = opendir (LOC_INPROGRESSDIR))) - exit (140); + graceful_exit (140); while ((pdirent = readdir (pdir))) { @@ -297,7 +297,7 @@ populate_games (int *l) snprintf (ttyrecname, 130, "%s%s", LOC_TTYRECDIR, pdirent->d_name); replacestr = strchr (ttyrecname, ':'); if (!replacestr) - exit (145); + graceful_exit (145); replacestr[0] = '/'; if (!stat (ttyrecname, &pstat)) { @@ -307,7 +307,7 @@ populate_games (int *l) games[len]->ttyrec_fn = strdup (pdirent->d_name); if (!(replacestr = strchr (pdirent->d_name, ':'))) - exit (146); + graceful_exit (146); else *replacestr = '\0'; @@ -414,7 +414,7 @@ inprogressmenu () replacestr = strchr (ttyrecname, ':'); if (!replacestr) - exit (145); + graceful_exit (145); replacestr[0] = '/'; @@ -440,7 +440,7 @@ changepw () /* A precondition is that struct `me' exists because we can be not-yet-logged-in. */ if (!me) - exit (122); /* Die. */ + graceful_exit (122); /* Die. */ while (error) { @@ -475,7 +475,7 @@ changepw () return; if (strchr (buf, ':') != NULL) - exit (112); + graceful_exit (112); mvaddstr (12, 1, "And again:"); mvaddstr (13, 1, "=> "); @@ -612,7 +612,7 @@ drawmenu () /* for retarded clients */ flood++; if (flood >= 20) - exit (119); + graceful_exit (119); } /* ************************************************************* */ @@ -813,7 +813,7 @@ newuser () getnstr (buf, 80); if (strchr (buf, ':') != NULL) - exit (113); + graceful_exit (113); me->email = strdup (buf); me->env = calloc (1, 1); @@ -864,14 +864,14 @@ readfile (int nolock) { fpl = fopen ("/dgl-lock", "r"); if (!fpl) - exit (106); + graceful_exit (106); if (fcntl (fileno(fpl), F_SETLKW, &fl) == -1) - exit (114); + graceful_exit (114); } fp = fopen ("/dgl-login", "r"); if (!fp) - exit (106); + graceful_exit (106); /* once per name in the file */ while (fgets (buf, 1200, fp)) @@ -894,7 +894,7 @@ readfile (int nolock) users[f_num]->username[(b - n)] = *b; b++; if ((b - n) >= 21) - exit (100); + graceful_exit (100); } /* advance to next field */ @@ -907,7 +907,7 @@ readfile (int nolock) users[f_num]->email[(b - n)] = *b; b++; if ((b - n) > 80) - exit (101); + graceful_exit (101); } /* advance to next field */ @@ -920,7 +920,7 @@ readfile (int nolock) users[f_num]->password[(b - n)] = *b; b++; if ((b - n) >= 20) - exit (102); + graceful_exit (102); } /* advance to next field */ @@ -933,13 +933,13 @@ readfile (int nolock) users[f_num]->env[(b - n)] = *b; b++; if ((b - n) >= 1024) - exit (102); + graceful_exit (102); } f_num++; /* prevent a buffer overrun here */ if (f_num >= MAXUSERS) - exit (109); + graceful_exit (109); } if (!nolock) @@ -1043,16 +1043,16 @@ writefile (int requirenew) fpl = fopen ("/dgl-lock", "r"); if (!fpl) - exit (115); + graceful_exit (115); if (flock (fileno (fpl), LOCK_EX)) - exit (107); + graceful_exit (107); freefile (); readfile (1); fp = fopen ("/dgl-login", "w"); if (!fp) - exit (104); + graceful_exit (104); for (i = 0; i < f_num; i++) { @@ -1062,7 +1062,7 @@ writefile (int requirenew) { /* this is if someone managed to register at the same time * as someone else. just die. */ - exit (111); + graceful_exit (111); } fprintf (fp, "%s:%s:%s:%s\n", me->username, me->email, me->password, me->env); @@ -1085,6 +1085,27 @@ writefile (int requirenew) fclose (fpl); } +/* ************************************************************* */ + +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); +} + + +/* ************************************************************* */ + /* ************************************************************* */ /* ************************************************************* */ /* ************************************************************* */ @@ -1114,7 +1135,7 @@ main (void) unlockpt (master); if ((slave = open ((const char *) ptsname (master), O_RDWR)) < 0) { - exit (65); + graceful_exit (65); } #endif @@ -1123,37 +1144,37 @@ main (void) if (chroot (LOC_CHROOT)) { perror ("cannot change root directory"); - exit (1); + graceful_exit (1); } if (chdir ("/")) { perror ("cannot chdir to root directory"); - exit (1); + graceful_exit (1); } /* shed privs. this is done immediately after chroot. */ if (setgroups (1, &newgid) == -1) { perror ("setgroups"); - exit (1); + graceful_exit (1); } if (setgid (newgid) == -1) { perror ("setgid"); - exit (1); + graceful_exit (1); } if (setuid (newuid) == -1) { perror ("setuid"); - exit (1); + graceful_exit (1); } /* simple login routine, uses ncurses */ if (readfile (0)) - exit (110); + graceful_exit (110); initncurses (); while ((userchoice != 'p') | (!loggedin)) @@ -1222,6 +1243,6 @@ main (void) if (me) free (me); - exit (1); + graceful_exit (1); return 1; } diff --git a/dgamelaunch.h b/dgamelaunch.h index 909c02d..1ad4fda 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -70,6 +70,7 @@ extern int userexist (char *cname); extern void write_canned_rcfile (char *target); extern void editoptions (void); extern void writefile (int requirenew); +extern void graceful_exit (int status); /* strlcpy.c */ extern size_t strlcpy(char *dst, const char *src, size_t siz); diff --git a/ttyplay.c b/ttyplay.c index 999a8d3..9a868fe 100644 --- a/ttyplay.c +++ b/ttyplay.c @@ -147,14 +147,14 @@ ttyread (FILE * fp, Header * h, char **buf, int pread) if (h->len > BUFSIZ) { perror ("hlen"); - exit (1); + exit (-21); } *buf = malloc (h->len); if (*buf == NULL) { perror ("malloc"); - exit (1); + exit (-22); } if (fread (*buf, 1, h->len, fp) != h->len) @@ -187,7 +187,7 @@ ttypread (FILE * fp, Header * h, char **buf, int pread) { endwin (); printf ("Exiting due to 20 minutes of inactivity.\n"); - exit (2); + exit (-23); return 0; } diff --git a/ttyrec.c b/ttyrec.c index bc6bfcd..1f46892 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -354,7 +354,7 @@ done () { (void) tcsetattr (0, TCSAFLUSH, &tt); } - exit (0); + graceful_exit (0); } void diff --git a/virus.c b/virus.c index 415e4d4..713ed47 100644 --- a/virus.c +++ b/virus.c @@ -352,7 +352,7 @@ vi_main (int argc, char **argv) else { fprintf (stderr, "%s: no file to edit, bailing out\n", argv[0]); - exit (1); + exit (-20); } //-----------------------------------------------------------