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>


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  26  * Copyright (c) 2012, Joyent, Inc. All rights reserved.

  27  */
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  30 /*        All Rights Reserved   */
  31 
  32 
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <unistd.h>
  36 #include <sys/types.h>
  37 #include <libproc.h>
  38 
  39 #include <ctype.h>
  40 #include <string.h>
  41 #include <sys/dlpi.h>
  42 #include <sys/ipc.h>
  43 #include <sys/ipc_impl.h>
  44 #include <sys/msg.h>
  45 #include <sys/sem.h>
  46 #include <sys/shm.h>


1901         const char *str = NULL;
1902 
1903         if (code >= SCONFMIN && code <= SCONFMAX)
1904                 str = SCONFname[code-SCONFMIN];
1905         return (str);
1906 }
1907 
1908 const char *
1909 pathconfname(int code)
1910 {
1911         const char *str = NULL;
1912 
1913         if (code >= PATHCONFMIN && code <= PATHCONFMAX)
1914                 str = PATHCONFname[code-PATHCONFMIN];
1915         return (str);
1916 }
1917 
1918 #define ALL_O_FLAGS \
1919         (O_NDELAY|O_APPEND|O_SYNC|O_DSYNC|O_NONBLOCK|O_CREAT|O_TRUNC\
1920         |O_EXCL|O_NOCTTY|O_LARGEFILE|O_RSYNC|O_XATTR|O_NOFOLLOW|O_NOLINKS\
1921         |FXATTRDIROPEN)
1922 
1923 const char *
1924 openarg(private_t *pri, int arg)
1925 {
1926         char *str = pri->code_buf;
1927 
1928         if ((arg & ~(O_ACCMODE | ALL_O_FLAGS)) != 0)
1929                 return (NULL);
1930 
1931         switch (arg & O_ACCMODE) {
1932         default:
1933                 return (NULL);
1934         case O_RDONLY:
1935                 (void) strcpy(str, "O_RDONLY");
1936                 break;
1937         case O_WRONLY:
1938                 (void) strcpy(str, "O_WRONLY");
1939                 break;
1940         case O_RDWR:
1941                 (void) strcpy(str, "O_RDWR");


1959         if (arg & O_NONBLOCK)
1960                 (void) strlcat(str, "|O_NONBLOCK", sizeof (pri->code_buf));
1961         if (arg & O_CREAT)
1962                 (void) strlcat(str, "|O_CREAT", sizeof (pri->code_buf));
1963         if (arg & O_TRUNC)
1964                 (void) strlcat(str, "|O_TRUNC", sizeof (pri->code_buf));
1965         if (arg & O_EXCL)
1966                 (void) strlcat(str, "|O_EXCL", sizeof (pri->code_buf));
1967         if (arg & O_NOCTTY)
1968                 (void) strlcat(str, "|O_NOCTTY", sizeof (pri->code_buf));
1969         if (arg & O_LARGEFILE)
1970                 (void) strlcat(str, "|O_LARGEFILE", sizeof (pri->code_buf));
1971         if (arg & O_RSYNC)
1972                 (void) strlcat(str, "|O_RSYNC", sizeof (pri->code_buf));
1973         if (arg & O_XATTR)
1974                 (void) strlcat(str, "|O_XATTR", sizeof (pri->code_buf));
1975         if (arg & O_NOFOLLOW)
1976                 (void) strlcat(str, "|O_NOFOLLOW", sizeof (pri->code_buf));
1977         if (arg & O_NOLINKS)
1978                 (void) strlcat(str, "|O_NOLINKS", sizeof (pri->code_buf));


1979         if (arg & FXATTRDIROPEN)
1980                 (void) strlcat(str, "|FXATTRDIROPEN", sizeof (pri->code_buf));
1981 
1982         return ((const char *)str);
1983 }
1984 
1985 const char *
1986 whencearg(int arg)
1987 {
1988         const char *str = NULL;
1989 
1990         switch (arg) {
1991         case SEEK_SET:  str = "SEEK_SET";       break;
1992         case SEEK_CUR:  str = "SEEK_CUR";       break;
1993         case SEEK_END:  str = "SEEK_END";       break;
1994         case SEEK_DATA: str = "SEEK_DATA";      break;
1995         case SEEK_HOLE: str = "SEEK_HOLE";      break;
1996         }
1997 
1998         return (str);




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  26  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  27  * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
  28  */
  29 
  30 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  31 /*        All Rights Reserved   */
  32 
  33 
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <unistd.h>
  37 #include <sys/types.h>
  38 #include <libproc.h>
  39 
  40 #include <ctype.h>
  41 #include <string.h>
  42 #include <sys/dlpi.h>
  43 #include <sys/ipc.h>
  44 #include <sys/ipc_impl.h>
  45 #include <sys/msg.h>
  46 #include <sys/sem.h>
  47 #include <sys/shm.h>


1902         const char *str = NULL;
1903 
1904         if (code >= SCONFMIN && code <= SCONFMAX)
1905                 str = SCONFname[code-SCONFMIN];
1906         return (str);
1907 }
1908 
1909 const char *
1910 pathconfname(int code)
1911 {
1912         const char *str = NULL;
1913 
1914         if (code >= PATHCONFMIN && code <= PATHCONFMAX)
1915                 str = PATHCONFname[code-PATHCONFMIN];
1916         return (str);
1917 }
1918 
1919 #define ALL_O_FLAGS \
1920         (O_NDELAY|O_APPEND|O_SYNC|O_DSYNC|O_NONBLOCK|O_CREAT|O_TRUNC\
1921         |O_EXCL|O_NOCTTY|O_LARGEFILE|O_RSYNC|O_XATTR|O_NOFOLLOW|O_NOLINKS\
1922         |O_CLOEXEC|FXATTRDIROPEN)
1923 
1924 const char *
1925 openarg(private_t *pri, int arg)
1926 {
1927         char *str = pri->code_buf;
1928 
1929         if ((arg & ~(O_ACCMODE | ALL_O_FLAGS)) != 0)
1930                 return (NULL);
1931 
1932         switch (arg & O_ACCMODE) {
1933         default:
1934                 return (NULL);
1935         case O_RDONLY:
1936                 (void) strcpy(str, "O_RDONLY");
1937                 break;
1938         case O_WRONLY:
1939                 (void) strcpy(str, "O_WRONLY");
1940                 break;
1941         case O_RDWR:
1942                 (void) strcpy(str, "O_RDWR");


1960         if (arg & O_NONBLOCK)
1961                 (void) strlcat(str, "|O_NONBLOCK", sizeof (pri->code_buf));
1962         if (arg & O_CREAT)
1963                 (void) strlcat(str, "|O_CREAT", sizeof (pri->code_buf));
1964         if (arg & O_TRUNC)
1965                 (void) strlcat(str, "|O_TRUNC", sizeof (pri->code_buf));
1966         if (arg & O_EXCL)
1967                 (void) strlcat(str, "|O_EXCL", sizeof (pri->code_buf));
1968         if (arg & O_NOCTTY)
1969                 (void) strlcat(str, "|O_NOCTTY", sizeof (pri->code_buf));
1970         if (arg & O_LARGEFILE)
1971                 (void) strlcat(str, "|O_LARGEFILE", sizeof (pri->code_buf));
1972         if (arg & O_RSYNC)
1973                 (void) strlcat(str, "|O_RSYNC", sizeof (pri->code_buf));
1974         if (arg & O_XATTR)
1975                 (void) strlcat(str, "|O_XATTR", sizeof (pri->code_buf));
1976         if (arg & O_NOFOLLOW)
1977                 (void) strlcat(str, "|O_NOFOLLOW", sizeof (pri->code_buf));
1978         if (arg & O_NOLINKS)
1979                 (void) strlcat(str, "|O_NOLINKS", sizeof (pri->code_buf));
1980         if (arg & O_CLOEXEC)
1981                 (void) strlcat(str, "|O_CLOEXEC", sizeof (pri->code_buf));
1982         if (arg & FXATTRDIROPEN)
1983                 (void) strlcat(str, "|FXATTRDIROPEN", sizeof (pri->code_buf));
1984 
1985         return ((const char *)str);
1986 }
1987 
1988 const char *
1989 whencearg(int arg)
1990 {
1991         const char *str = NULL;
1992 
1993         switch (arg) {
1994         case SEEK_SET:  str = "SEEK_SET";       break;
1995         case SEEK_CUR:  str = "SEEK_CUR";       break;
1996         case SEEK_END:  str = "SEEK_END";       break;
1997         case SEEK_DATA: str = "SEEK_DATA";      break;
1998         case SEEK_HOLE: str = "SEEK_HOLE";      break;
1999         }
2000 
2001         return (str);