set file descriptors to be close-on-exec; block signals while
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 15 Feb 1991 10:25:42 +0000 (02:25 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 15 Feb 1991 10:25:42 +0000 (02:25 -0800)
unlinking the temporary file so we don't get caught

SCCS-vsn: lib/libc/db/hash/hash.c 5.2
SCCS-vsn: lib/libc/db/hash/hash_page.c 5.2

usr/src/lib/libc/db/hash/hash.c
usr/src/lib/libc/db/hash/hash_page.c

index 81780ef..43cf205 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash.c     5.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
@@ -135,6 +135,7 @@ HASHINFO    *info;          /* Special directives for create */
     if ( file && ((hashp->fp = open ( file, flags, mode )) == -1)) {
        RETURN_ERROR (errno, error0);
     }
     if ( file && ((hashp->fp = open ( file, flags, mode )) == -1)) {
        RETURN_ERROR (errno, error0);
     }
+    (void)fcntl(hashp->fp, F_SETFD, 1);
 
     if ( new_table ) {
        if ( !(hashp = init_hash( info )) ) {
 
     if ( new_table ) {
        if ( !(hashp = init_hash( info )) ) {
index b13c4c7..778d158 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)hash_page.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)hash_page.c        5.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /******************************************************************************
 #endif /* LIBC_SCCS and not lint */
 
 /******************************************************************************
@@ -29,6 +29,7 @@ ROUTINES:
 
 #include <sys/param.h>
 #include <sys/file.h>
 
 #include <sys/param.h>
 #include <sys/file.h>
+#include <signal.h>
 #include <assert.h>
 #include <errno.h>
 #include <db.h>
 #include <assert.h>
 #include <errno.h>
 #include <db.h>
@@ -764,13 +765,22 @@ BUFHEAD   *obufp;
 static int
 open_temp()
 {
 static int
 open_temp()
 {
-    char        *namestr = "_hashXXXXXX";
-
-    if ((hashp->fp = mkstemp ( namestr )) == -1){
-       return (-1);
+    sigset_t   set, oset;
+    char       *namestr = "_hashXXXXXX";
+
+    /* Block signals; make sure file goes away at process exit. */
+    sigemptyset(&set);
+    sigaddset(&set, SIGHUP);
+    sigaddset(&set, SIGINT);
+    sigaddset(&set, SIGQUIT);
+    sigaddset(&set, SIGTERM);
+    (void)sigprocmask(SIG_BLOCK, &set, &oset);
+    if ((hashp->fp = mkstemp ( namestr )) != -1) {
+       (void)unlink(namestr);
+       (void)fcntl(hashp->fp, F_SETFD, 1);
     }
     }
-    unlink(namestr);    /* Make sure file goes away at process exit*/
-    return(0);
+    (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL);
+    return(hashp->fp != -1 ? 0 : -1);
 }
 
 /* 
 }
 
 /*