Print this page
3665 Implement O_CLOEXEC as an open() flag
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/syscall/open.c
          +++ new/usr/src/uts/common/syscall/open.c
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  
  26   26  /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T     */
  27   27  /*        All Rights Reserved   */
  28   28  
  29   29  /*
       30 + * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
       31 + */
       32 +/*
  30   33   * Portions of this source code were derived from Berkeley 4.3 BSD
  31   34   * under license from the Regents of the University of California.
  32   35   */
  33   36  
  34   37  #include <sys/param.h>
  35   38  #include <sys/isa_defs.h>
  36   39  #include <sys/types.h>
  37   40  #include <sys/sysmacros.h>
  38   41  #include <sys/user.h>
  39   42  #include <sys/systm.h>
↓ open down ↓ 179 lines elided ↑ open up ↑
 219  222                                  VN_RELE(startvp);
 220  223                          if (error == 0) {
 221  224                                  if ((vp->v_flag & VDUP) == 0) {
 222  225                                          fp->f_vnode = vp;
 223  226                                          mutex_exit(&fp->f_tlock);
 224  227                                          /*
 225  228                                           * We must now fill in the slot
 226  229                                           * falloc reserved.
 227  230                                           */
 228  231                                          setf(fd, fp);
      232 +                                        if ((filemode & FCLOEXEC) != 0) {
      233 +                                                f_setfd(fd, FD_CLOEXEC);
      234 +                                        }
 229  235                                          return (fd);
 230  236                                  } else {
 231  237                                          /*
 232  238                                           * Special handling for /dev/fd.
 233  239                                           * Give up the file pointer
 234  240                                           * and dup the indicated file descriptor
 235  241                                           * (in v_rdev). This is ugly, but I've
 236  242                                           * seen worse.
 237  243                                           */
 238  244                                          unfalloc(fp);
↓ open down ↓ 6 lines elided ↑ open up ↑
 245  251                                          if (type != VCHR)
 246  252                                                  return (set_errno(EINVAL));
 247  253                                          if ((fp = getf(dupfd)) == NULL) {
 248  254                                                  setf(fd, NULL);
 249  255                                                  return (set_errno(EBADF));
 250  256                                          }
 251  257                                          mutex_enter(&fp->f_tlock);
 252  258                                          fp->f_count++;
 253  259                                          mutex_exit(&fp->f_tlock);
 254  260                                          setf(fd, fp);
      261 +                                        if ((filemode & FCLOEXEC) != 0) {
      262 +                                                f_setfd(fd, FD_CLOEXEC);
      263 +                                        }
 255  264                                          releasef(dupfd);
 256  265                                  }
 257  266                                  return (fd);
 258  267                          } else {
 259  268                                  setf(fd, NULL);
 260  269                                  unfalloc(fp);
 261  270                                  return (set_errno(error));
 262  271                          }
 263  272                  }
 264  273          } else {
↓ open down ↓ 67 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX