diff --git a/srogue/command.c b/srogue/command.c index f005be9..71a3007 100644 --- a/srogue/command.c +++ b/srogue/command.c @@ -369,8 +369,10 @@ quit(int a) /* * Reset the signal in case we got here via an interrupt */ +#ifdef SIGINT if (signal(SIGINT, quit) != quit) mpos = 0; +#endif msg("Really quit? [y/n/s]"); /* ch = tolower(readchar());*/ ch = readchar(); @@ -395,7 +397,9 @@ quit(int a) } } else { +#ifdef SIGINT signal(SIGINT, quit); +#endif wmove(cw, 0, 0); wclrtoeol(cw); draw(cw); @@ -637,46 +641,15 @@ shell() /* * Fork and do a shell */ -#ifndef __DJGPP__ - while((pid = fork()) < 0) - sleep(1); - if (pid == 0) { - setuid(playuid); /* Set back to original user */ - setgid(playgid); - execl(sh == NULL ? "/bin/sh" : sh, "shell", "-i", 0); - perror("No shelly"); - byebye(-1); - } - else { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - while (wait(&ret_status) != pid) - continue; - signal(SIGINT, quit); - signal(SIGQUIT, endit); - -#else - { - char shell[PATH_MAX]; - - if (sh && *sh) - strncpy(shell,sh,PATH_MAX); - else - sprintf(shell, "%s\\bin\\sh.exe", getenv("DJDIR")); - - if (spawnl(P_WAIT,shell, "shell", "-i", 0) == -1) - msg("No shelly: %s", shell); - -#endif - printf("\n%s", retstr); - fflush(stdout); - nonl(); - noecho(); - crmode(); - in_shell = FALSE; - wait_for(cw, '\n'); - restscr(cw); - } + md_shellescape(); + printf("\n%s", retstr); + fflush(stdout); + nonl(); + noecho(); + crmode(); + in_shell = FALSE; + wait_for(cw, '\n'); + restscr(cw); } diff --git a/srogue/configure.ac b/srogue/configure.ac index ef19265..7db64e5 100644 --- a/srogue/configure.ac +++ b/srogue/configure.ac @@ -15,6 +15,7 @@ AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h pwd.h errno.h fcntl.h limits.h nlist.h stdlib.h string.h sys/ioctl.h termios.h unistd.h term.h ncurses/term.h process.h]) # Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_UID_T AC_TYPE_SIZE_T AC_STRUCT_TM # Checks for library functions. diff --git a/srogue/io.c b/srogue/io.c index fb9dab5..7caac01 100644 --- a/srogue/io.c +++ b/srogue/io.c @@ -263,7 +263,6 @@ char ch; #ifdef NEED_GETTIME #include -#include /* * gettime: diff --git a/srogue/main.c b/srogue/main.c index 9af0fb6..8494add 100644 --- a/srogue/main.c +++ b/srogue/main.c @@ -18,11 +18,8 @@ #include #include #include -#include #include #include -#include -#include #include #include #include "rogue.h" @@ -39,8 +36,6 @@ #include "rogue.ext" -struct termios terminal; - main(argc, argv, envp) char **argv; char **envp; @@ -48,8 +43,6 @@ char **envp; register char *env; register struct linked_list *item; register struct object *obj; - struct passwd *pw; - struct passwd *getpwuid(); char alldone, wpt; char *getpass(), *xcrypt(), *strrchr(); int lowtime; @@ -132,10 +125,11 @@ char **envp; if ((env = getenv("HOME")) != NULL) strcpy(home, env); - else if ((pw = getpwuid(playuid)) != NULL) - strcpy(home, pw->pw_dir); - else - home[0] = '\0'; + else { + strncpy(home, md_gethomedir(), LINLEN); + if (home[LINLEN-1] != '\0') + home[0] = '\0'; + } if (strcmp(home,"/") == 0) home[0] = '\0'; @@ -153,13 +147,7 @@ char **envp; if (!use_savedir && (env == NULL || whoami[0] == '\0')) { - if((pw = getpwuid(playuid)) == NULL) - { - printf("Say, who are you?\n"); - exit(1); - } - else - strucpy(whoami, pw->pw_name, strlen(pw->pw_name)); + strucpy(whoami, md_getusername(), strlen(md_getusername())); } if (env == NULL || fruit[0] == '\0') @@ -191,8 +179,7 @@ char **envp; seed = dnum; srand48(seed); /* init rnd number gen */ - signal(SIGINT, byebye); /* just in case */ - signal(SIGQUIT ,byebye); + md_onsignal_exit(); /* just in case */ init_everything(); @@ -397,27 +384,7 @@ int number, sides; */ setup() { - signal(SIGHUP, auto_save); - signal(SIGINT, auto_save); - signal(SIGQUIT, byebye); - signal(SIGILL, game_err); - signal(SIGTRAP, game_err); -#ifdef SIGIOT - signal(SIGIOT, game_err); -#endif -#ifdef SIGEMT - signal(SIGEMT, game_err); -#endif - signal(SIGFPE, game_err); -#ifdef SIGBUS - signal(SIGBUS, game_err); -#endif - signal(SIGSEGV, game_err); -#ifdef SIGSYS - signal(SIGSYS, game_err); -#endif - signal(SIGPIPE, game_err); - signal(SIGTERM, game_err); + md_onsignal_autosave(); nonl(); cbreak(); @@ -433,9 +400,6 @@ playit() { reg char *opts; - tcgetattr(0,&terminal); - - /* parse environment declaration of options */ if ((opts = getenv("ROGUEOPTS")) != NULL) diff --git a/srogue/mdport.c b/srogue/mdport.c index 36b35ff..6160c30 100644 --- a/srogue/mdport.c +++ b/srogue/mdport.c @@ -210,6 +210,9 @@ md_onsignal_exit(void) #ifdef SIGTERM signal(SIGTERM, exit); #endif +#ifdef SIGINT + signal(SIGINT, exit); +#endif } extern void auto_save(int sig); diff --git a/srogue/options.c b/srogue/options.c index 74a5929..199bf57 100644 --- a/srogue/options.c +++ b/srogue/options.c @@ -14,14 +14,11 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include #include #include #include "rogue.h" #include "rogue.ext" -extern struct termios terminal; - /* * description of an option and what to do with it */ @@ -137,7 +134,7 @@ WINDOW *awin; } if (c == -1) continue; - else if(c == terminal.c_cc[VERASE]) { /* process erase char */ + else if(c == md_erasechar()) { /* process erase char */ if (sp > buf) { reg int i; @@ -147,7 +144,7 @@ WINDOW *awin; } continue; } - else if (c == terminal.c_cc[VKILL]) { /* process kill character */ + else if (c == md_killchar()) { /* process kill character */ sp = buf; wmove(awin, oy, ox); continue; diff --git a/srogue/rip.c b/srogue/rip.c index b3be7dc..c1c9020 100644 --- a/srogue/rip.c +++ b/srogue/rip.c @@ -14,11 +14,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include #include #include #include -#include #include #include "rogue.h" #include "rogue.ext" @@ -127,8 +125,7 @@ int amount, aflag; reg FILE *outf; char *packend; - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); if (aflag != WINNER) { if (aflag == CHICKEN) packend = "when you chickened out"; @@ -213,8 +210,7 @@ int amount, aflag; encwrite((char *) scoreline, 100, outf); } fclose(outf); - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); clear(); refresh(); endwin(); @@ -300,12 +296,7 @@ int showname; } printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts); if (showname) { - struct passwd *pp, *getpwuid(); - - if ((pp = getpwuid(scp->sc_uid)) == NULL) - printf(" (%d)\n", scp->sc_uid); - else - printf(" (%s)\n", pp->pw_name); + printf(" (%s)\n", md_getrealname(scp->sc_uid)); } else printf("\n"); diff --git a/srogue/save.c b/srogue/save.c index 38252b9..db1400f 100644 --- a/srogue/save.c +++ b/srogue/save.c @@ -42,10 +42,7 @@ STAT sbuf; */ ignore() { - int i; - - for (i = 0; i < NSIG; i++) - signal(i, SIG_IGN); + md_ignoreallsignals(); } /* @@ -191,8 +188,7 @@ FILE *savef; msg(""); rs_save_file(savef); close(fnum); - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); wclear(cw); draw(cw); } diff --git a/srogue/wizard.c b/srogue/wizard.c index 9538c3f..5b6be50 100644 --- a/srogue/wizard.c +++ b/srogue/wizard.c @@ -15,14 +15,10 @@ */ #include -#include #include #include "rogue.h" -#include #include "rogue.ext" -extern struct termios terminal; - /* * whatis: * What a certain object is @@ -359,9 +355,9 @@ passwd() mpos = 0; sp = buf; while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE) - if (c == terminal.c_cc[VKILL]) + if (c == md_killchar()) sp = buf; - else if (c == terminal.c_cc[VERASE] && sp > buf) + else if (c == md_erasechar() && sp > buf) sp--; else *sp++ = c; diff --git a/srogue/xcrypt.c b/srogue/xcrypt.c index e0d1744..7bad484 100644 --- a/srogue/xcrypt.c +++ b/srogue/xcrypt.c @@ -51,7 +51,6 @@ #include #include -#include #include #ifdef DEBUG