tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

diff: exit crash(8) on ^D



Hello, tech-kern@!

Subj, it really annoys to have the last command
executed on ^D.

Index: crash.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/crash/crash.c,v
retrieving revision 1.2
diff -u -p -r1.2 crash.c
--- crash.c     16 Apr 2009 06:52:08 -0000      1.2
+++ crash.c     6 Apr 2011 11:59:34 -0000
@@ -73,6 +73,18 @@ static struct nlist nl[] = {
        { .n_name = NULL },
 };
 
+static void
+cleanup(void)
+{
+       if (ofp != stdout) {
+               (void)fflush(ofp);
+               (void)pclose(ofp);
+               ofp = stdout;
+       }
+       el_end(elptr);
+       history_end(hist);
+}
+
 void
 db_vprintf(const char *fmt, va_list ap)
 {
@@ -231,9 +243,9 @@ db_readline(char *lstart, int lsize)
 
        /* Read next command. */
        el = el_gets(elptr, &cnt);
-       if (el == NULL) {
-               *lstart = '\0';
-               return 0;
+       if (el == NULL) {       /* EOF */
+               cleanup();
+               exit(EXIT_SUCCESS);
        }
 
        /* Save to history, and copy to caller's buffer. */
@@ -455,15 +467,9 @@ main(int argc, char **argv)
        db_command_loop();
 
        /*
-        * Clean up and exit.
+        * Finish.
         */
-       if (ofp != stdout) {
-               (void)fflush(ofp);
-               (void)pclose(ofp);
-               ofp = stdout;
-       }
-       el_end(elptr);
-       history_end(hist);
+       cleanup();
        exit(EXIT_SUCCESS);
        /* NOTREACHED */
 }


Home | Main Index | Thread Index | Old Index