1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rodney Ruddock of the University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)edhup.c 8.1 (Berkeley) 05/31/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <limits.h> 18 #include <regex.h> 19 #include <setjmp.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 #include <unistd.h> 24 25 #ifdef DBI 26 #include <db.h> 27 #endif 28 29 #include "ed.h" 30 #include "extern.h" 31 32 /* 33 * If a SIGHUP is received then user contact is severed. Try, if possible, 34 * to save the buffer. But be nice and don't save over remembered filename 35 * (you can figure out why, can't you?). The buffer is saved in a file 36 * named "ed.hup" in the directory that ed was started-up in. If a write 37 * cannot be made to that directory (say because it is read-only) then try 38 * writting "ed.hup" in the user's $HOME directory. Then exit. 39 */ 40 __dead void 41 do_hup() 42 { 43 char l_filename[FILENAME_LEN], *l_temp; 44 FILE *l_fp; 45 46 sigspecial++; 47 if (change_flag == 0) 48 exit(exit_code+2); /* No need to save buffer contents. */ 49 if ((l_fp = fopen("ed.hup", "w")) == NULL) { 50 /* Try writting ed.hup to the $HOME directory instead. */ 51 l_temp = getenv("HOME"); 52 if ((l_temp == NULL) || ((strlen(l_temp) + 7) > FILENAME_LEN)) 53 exit(exit_code+2); 54 strcpy(l_filename, l_temp); 55 strcat(l_filename, "/ed.hup"); 56 if ((l_fp = fopen(l_filename, "w")) == NULL) 57 exit(exit_code+2); /* We tried... */ 58 } 59 edwrite(l_fp, top, bottom); 60 fclose(l_fp); 61 #ifdef STDIO 62 fclose(fhtmp); 63 unlink(template); 64 #endif 65 #ifdef DBI 66 (dbhtmp->close) (dbhtmp); 67 unlink(template); 68 #endif 69 exit(exit_code+2); /* Hangup */ 70 } 71