thr_fcntl.c revision 259065
1238384Sjkim/* 2238384Sjkim * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 3238384Sjkim * All rights reserved. 4238384Sjkim * 5238384Sjkim * Redistribution and use in source and binary forms, with or without 6238384Sjkim * modification, are permitted provided that the following conditions 7238384Sjkim * are met: 8238384Sjkim * 1. Redistributions of source code must retain the above copyright 9238384Sjkim * notice, this list of conditions and the following disclaimer. 10238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright 11238384Sjkim * notice, this list of conditions and the following disclaimer in the 12238384Sjkim * documentation and/or other materials provided with the distribution. 13238384Sjkim * 3. Neither the name of the author nor the names of any co-contributors 14238384Sjkim * may be used to endorse or promote products derived from this software 15238384Sjkim * without specific prior written permission. 16238384Sjkim * 17238384Sjkim * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 18238384Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20238384Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21238384Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22238384Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23238384Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25238384Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26238384Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27238384Sjkim * SUCH DAMAGE. 28238384Sjkim * 29238384Sjkim * $FreeBSD: releng/10.0/lib/libkse/thread/thr_fcntl.c 179434 2008-05-30 14:47:42Z dfr $ 30238384Sjkim */ 31238384Sjkim 32238384Sjkim#include "namespace.h" 33238384Sjkim#include <stdarg.h> 34238384Sjkim#include <fcntl.h> 35238384Sjkim#include <pthread.h> 36238384Sjkim#include "un-namespace.h" 37238384Sjkim#include "thr_private.h" 38238384Sjkim 39238384Sjkimint __fcntl(int fd, int cmd,...); 40238384Sjkimextern int __fcntl_compat(int fd, int cmd,...); 41238384Sjkim 42238384Sjkim__weak_reference(__fcntl, fcntl); 43264331Sjkim 44238384Sjkimint 45238384Sjkim__fcntl(int fd, int cmd,...) 46238384Sjkim{ 47238384Sjkim struct pthread *curthread = _get_curthread(); 48238384Sjkim int ret, check = 1; 49238384Sjkim va_list ap; 50238384Sjkim 51238384Sjkim _thr_cancel_enter(curthread); 52238384Sjkim 53238384Sjkim va_start(ap, cmd); 54238384Sjkim switch (cmd) { 55238384Sjkim case F_DUPFD: 56238384Sjkim ret = __sys_fcntl(fd, cmd, va_arg(ap, int)); 57238384Sjkim /* 58238384Sjkim * To avoid possible file handle leak, 59238384Sjkim * only check cancellation point if it is failure 60238384Sjkim */ 61238384Sjkim check = (ret == -1); 62238384Sjkim break; 63238384Sjkim case F_SETFD: 64238384Sjkim case F_SETFL: 65238384Sjkim ret = __sys_fcntl(fd, cmd, va_arg(ap, int)); 66238384Sjkim break; 67238384Sjkim case F_GETFD: 68238384Sjkim case F_GETFL: 69238384Sjkim ret = __sys_fcntl(fd, cmd); 70238384Sjkim break; 71238384Sjkim default: 72238384Sjkim ret = __fcntl_compat(fd, cmd, va_arg(ap, void *)); 73238384Sjkim } 74238384Sjkim va_end(ap); 75238384Sjkim 76238384Sjkim _thr_cancel_leave(curthread, check); 77238384Sjkim 78238384Sjkim return (ret); 79238384Sjkim} 80238384Sjkim