pax_global_header00006660000000000000000000000064116051037060014511gustar00rootroot0000000000000052 comment=cf6e95482d6433464e6d022384a7896a4bb29026 libfixposix-20110706.gitcf6e954/000077500000000000000000000000001160510370600161035ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/.gitignore000066400000000000000000000003511160510370600200720ustar00rootroot00000000000000Makefile Makefile.in aclocal.m4 autom4te.cache/ build/ .build-aux/ config.* configure libtool m4/l*.m4 src/.* *.lo *.o *.la src/signalfd_test .deps/ .dirstamp .libs/ src/lib/libfixposix.h src/tests/signalfd_test src/tests/spawn_test libfixposix-20110706.gitcf6e954/LICENCE000066400000000000000000000024001160510370600170640ustar00rootroot00000000000000Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libfixposix-20110706.gitcf6e954/Makefile.am000066400000000000000000000071761160510370600201520ustar00rootroot00000000000000# -*- makefile-automake -*- ######################################################################## # # # Global Automake variables # # # ######################################################################## ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = $(LFP_CPPFLAGS) AM_CFLAGS = $(LFP_CFLAGS) INCLUDES = -I$(top_builddir)/src/include -I$(top_srcdir)/src/include ######################################################################## # # # PKG-CONFIG # # # ######################################################################## pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libfixposix.pc ######################################################################## # # # libfixposix.so # # # ######################################################################## lib_LTLIBRARIES = src/lib/libfixposix.la # Private headers, used only for internal definitions # The only purpose of this definition it to ensure that # «make dist» knows about them noinst_HEADERS = src/lib/utils.h src/lib/spawn.h include_HEADERS = src/include/lfp.h include_lfpdir = $(includedir)/lfp include_lfp_HEADERS = \ src/include/lfp/aux.h \ src/include/lfp/stdlib.h \ src/include/lfp/string.h \ src/include/lfp/errno.h \ src/include/lfp/fcntl.h \ src/include/lfp/stat.h \ src/include/lfp/unistd.h \ src/include/lfp/mman.h \ src/include/lfp/select.h \ src/include/lfp/socket.h \ src/include/lfp/wait.h \ src/include/lfp/signal.h \ src/include/lfp/spawn.h \ src/include/lfp/dirent.h \ src/include/lfp/time.h \ src/include/lfp/resource.h \ src/include/lfp/sendfile.h \ src/include/lfp/syslog.h # src/include/lfp/signalfd.h src_lib_libfixposix_la_SOURCES = \ src/lib/stdlib.c \ src/lib/string.c \ src/lib/errno.c \ src/lib/fcntl.c \ src/lib/stat.c \ src/lib/unistd.c \ src/lib/mman.c \ src/lib/select.c \ src/lib/socket.c \ src/lib/wait.c \ src/lib/signal.c \ src/lib/spawnattr.c \ src/lib/spawn_file_actions.c \ src/lib/spawn.c \ src/lib/dirent.c \ src/lib/time.c \ src/lib/resource.c \ src/lib/sendfile.c \ src/lib/syslog.c # src/lib/install_signalfd.c src_lib_libfixposix_la_DEPENDENCIES = \ src/lib/libfixposix.libtool src_lib_libfixposix_la_LIBADD = $(LFP_LDFLAGS) src_lib_libfixposix_la_LDFLAGS = -no-undefined \ -version-info `@AWK@ '/^Version:/ { print $$2 }' $(top_srcdir)/src/lib/libfixposix.libtool` ######################################################################## # # # TESTS # # # ######################################################################## check_PROGRAMS = src/tests/spawn src/tests/select check_SCRIPTS = TESTS = ${check_PROGRAMS} ${check_SCRIPTS} XFAIL_TESTS = # src_tests_signalfd_SOURCES = src/tests/signalfd.c # src_tests_signalfd_LDADD = src/lib/libfixposix.la src_tests_spawn_SOURCES = src/tests/spawn.c src_tests_spawn_LDADD = src/lib/libfixposix.la src_tests_select_SOURCES = src/tests/select.c src_tests_select_LDADD = src/lib/libfixposix.la libfixposix-20110706.gitcf6e954/README000066400000000000000000000013421160510370600167630ustar00rootroot00000000000000-*- outline -*- The purpose of libfixposix is to offer replacements for parts of POSIX whose behaviour is inconsistent across *NIX flavours. * Compilation If you've downloaded this library through git, you'll first need to generate the ./configure script; in order to do that you need to have at least autoconf-2.67, automake-1.10 and libtool-2.2.6b and run this inside the top directory: > autoreconf -i For best results use a dedicated build directory instead of running the configure script directly in the source tree: > mkdir build ; cd build > ../libfixposix/configure > make > make install On Linux, you might need to run «ldconfig» as superuser after installing, otherwise the *nix linker won't be able to find the library libfixposix-20110706.gitcf6e954/configure.ac000066400000000000000000000044541160510370600204000ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. dnl dnl This file is free software; as a special exception the author gives dnl unlimited permission to copy and/or distribute it, with or without dnl modifications, as long as this notice is preserved. dnl dnl This program is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. dnl Minimum Autoconf version required. AC_INIT([LibFixPOSIX], [0.1], [iolib-devel@common-lisp.net], [libfixposix], [http://common-lisp.net/project/iolib/]) AC_PREREQ([2.67]) AC_CONFIG_HEADERS([config.h]) dnl Where to generate output; srcdir location. AC_CONFIG_SRCDIR([src/lib/spawn.c]) dnl Auxiliary M4 macros AC_CONFIG_MACRO_DIR([m4]) dnl Must come before AM_INIT_AUTOMAKE. AC_CONFIG_AUX_DIR([.build-aux]) AM_INIT_AUTOMAKE([1.10 foreign silent-rules subdir-objects color-tests parallel-tests]) dnl Have Kbuild-like build output AM_SILENT_RULES([yes]) dnl Contains replacement functions # AC_CONFIG_LIBOBJ_DIR([lib]) dnl Checks for programs. # We need a C compiler. AC_PROG_CC_C99 AC_PROG_AWK # And we need libtool for building the shared library LT_INIT([pic-only disable-static disable-fast-install]) LT_PREREQ([2.4]) LFP_FLAGS_INIT dnl Checks for programs AC_CHECK_PROG([GETCONF], [getconf], [yes]) if test "x$ac_cv_prog_GETCONF" != xyes then AC_MSG_FAILURE([Program getconf not found]) fi dnl Set compiler & linker flags LFP_SYS_PLATFORM_SPECIFIC_DEFINITIONS AX_PTHREAD LFP_SYS_LARGEFILE LFP_CPPFLAGS+=" $LFS_CFLAGS" LFP_CFLAGS+=" $PTHREAD_CFLAGS" LFP_LDFLAGS+=" $PTHREAD_LIBS $LFS_LDFLAGS $LFS_LIBS" dnl Checks for C99 & POSIX headers AC_HEADER_ASSERT LFP_REQUIRE_HEADERS([stdlib.h stdio.h string.h errno.h time.h]) LFP_REQUIRE_HEADERS([sys/types.h unistd.h fcntl.h signal.h]) AC_CHECK_HEADER([sys/signalfd.h]) dnl Checks for declarations LFP_REQUIRE_DECLS([NSIG], [signal.h]) dnl Checks for functions AC_CHECK_FUNCS([__xpg_strerror_r strnlen strndup]) AC_CHECK_FUNCS([accept4 pipe2 sendfile]) LFP_REQUIRE_FUNCS([pselect vsyslog]) LFP_CHECK_POSIX_MONOTONIC_CLOCK dnl Checks for types dnl Configuration switches # LFP_ARG_ENABLE_EMULATED_SIGNALFD AC_CONFIG_FILES([Makefile libfixposix.pc]) AC_OUTPUT libfixposix-20110706.gitcf6e954/libfixposix.pc.in000066400000000000000000000005161160510370600213760ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Thin wrapper over POSIX functions Version: @PACKAGE_VERSION@ URL: @PACKAGE_URL@ Cflags: -I${includedir} @LFP_CFLAGS@ @LFP_CPPFLAGS@ Libs: -L${libdir} -lfixposix @PTHREAD_LIBS@ Libs.private: -L${libdir} @LFP_LDFLAGS@ libfixposix-20110706.gitcf6e954/m4/000077500000000000000000000000001160510370600164235ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/m4/ax_pthread.m4000066400000000000000000000260621160510370600210120ustar00rootroot00000000000000# =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_pthread.html # =========================================================================== # # SYNOPSIS # # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) # # DESCRIPTION # # This macro figures out how to build C programs using POSIX threads. It # sets the PTHREAD_LIBS output variable to the threads library and linker # flags, and the PTHREAD_CFLAGS output variable to any special C compiler # flags that are needed. (The user can also force certain compiler # flags/libs to be tested by setting these environment variables.) # # Also sets PTHREAD_CC to any special C compiler that is needed for # multi-threaded programs (defaults to the value of CC otherwise). (This # is necessary on AIX to use the special cc_r compiler alias.) # # NOTE: You are assumed to not only compile your program with these flags, # but also link it with them as well. e.g. you should link with # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS # # If you are only building threads programs, you may wish to use these # variables in your default LIBS, CFLAGS, and CC: # # LIBS="$PTHREAD_LIBS $LIBS" # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # CC="$PTHREAD_CC" # # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name # (e.g. PTHREAD_CREATE_UNDETACHED on AIX). # # ACTION-IF-FOUND is a list of shell commands to run if a threads library # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it # is not found. If ACTION-IF-FOUND is not specified, the default action # will define HAVE_PTHREAD. # # Please let the authors know if this macro fails on any platform, or if # you have any other suggestions or comments. This macro was based on work # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by # Alejandro Forero Cuervo to the autoconf macro repository. We are also # grateful for the helpful feedback of numerous users. # # LICENSE # # Copyright (c) 2008 Steven G. Johnson # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure # scripts that are the output of Autoconf when processing the Macro. You # need not follow the terms of the GNU General Public License when using # or distributing such scripts, even though portions of the text of the # Macro appear in them. The GNU General Public License (GPL) does govern # all other use of the material that constitutes the Autoconf Macro. # # This special exception to the GPL applies to versions of the Autoconf # Macro released by the Autoconf Archive. When you make and distribute a # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. #serial 11 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ AC_REQUIRE([AC_CANONICAL_HOST]) AC_LANG_SAVE AC_LANG_C ax_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h # requires special compiler flags (e.g. on True64 or Sequent). # It gets checked for in the link test anyway. # First of all, check if the user has set any of the PTHREAD_LIBS, # etcetera environment variables, and if threads linking works using # them: if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) AC_MSG_RESULT($ax_pthread_ok) if test x"$ax_pthread_ok" = xno; then PTHREAD_LIBS="" PTHREAD_CFLAGS="" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" fi # We must check for the threads library under a number of different # names; the ordering is very important because some systems # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). # Create a list of thread flags to try. Items starting with a "-" are # C compiler flags, and other items are library names, except for "none" # which indicates that we try without any flags at all, and "pthread-config" # which is a program returning the flags for the Pth emulation library. ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" # The ordering *is* (sometimes) important. Some notes on the # individual items follow: # pthreads: AIX (must check this before -lpthread) # none: in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) # -pthreads: Solaris/gcc # -mthreads: Mingw32/gcc, Lynx/gcc # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it # doesn't hurt to check since this sometimes defines pthreads too; # also defines -D_REENTRANT) # ... -mt is also the pthreads flag for HP/aCC # pthread: Linux, etcetera # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) case "${host_cpu}-${host_os}" in *solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based # tests will erroneously succeed. (We need to link with -pthreads/-mt/ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather # a function called by this macro, so we could check for that, but # who knows whether they'll stub that too in a future libc.) So, # we'll just look for -pthreads and -lpthread first: ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" ;; *-darwin*) ax_pthread_flags="-pthread $ax_pthread_flags" ;; esac if test x"$ax_pthread_ok" = xno; then for flag in $ax_pthread_flags; do case $flag in none) AC_MSG_CHECKING([whether pthreads work without any flags]) ;; -*) AC_MSG_CHECKING([whether pthreads work with $flag]) PTHREAD_CFLAGS="$flag" ;; pthread-config) AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) if test x"$ax_pthread_config" = xno; then continue; fi PTHREAD_CFLAGS="`pthread-config --cflags`" PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" ;; *) AC_MSG_CHECKING([for the pthreads library -l$flag]) PTHREAD_LIBS="-l$flag" ;; esac save_LIBS="$LIBS" save_CFLAGS="$CFLAGS" LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we # need a special flag -Kthread to make this header compile.) # We check for pthread_join because it is in -lpthread on IRIX # while pthread_create is in libc. We check for pthread_attr_init # due to DEC craziness with -lpthreads. We check for # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. AC_TRY_LINK([#include static void routine(void* a) {a=0;} static void* start_routine(void* a) {return a;}], [pthread_t th; pthread_attr_t attr; pthread_create(&th,0,start_routine,0); pthread_join(th, 0); pthread_attr_init(&attr); pthread_cleanup_push(routine, 0); pthread_cleanup_pop(0); ], [ax_pthread_ok=yes]) LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" AC_MSG_RESULT($ax_pthread_ok) if test "x$ax_pthread_ok" = xyes; then break; fi PTHREAD_LIBS="" PTHREAD_CFLAGS="" done fi # Various other checks: if test "x$ax_pthread_ok" = xyes; then save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. AC_MSG_CHECKING([for joinable pthread attribute]) attr_name=unknown for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do AC_TRY_LINK([#include ], [int attr=$attr; return attr;], [attr_name=$attr; break]) done AC_MSG_RESULT($attr_name) if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, [Define to necessary symbol if this constant uses a non-standard name on your system.]) fi AC_MSG_CHECKING([if more special flags are required for pthreads]) flag=no case "${host_cpu}-${host_os}" in *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; esac AC_MSG_RESULT(${flag}) if test "x$flag" != xno; then PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" fi LIBS="$save_LIBS" CFLAGS="$save_CFLAGS" # More AIX lossage: must compile with xlc_r or cc_r if test x"$GCC" != xyes; then AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) else PTHREAD_CC=$CC fi else PTHREAD_CC="$CC" fi AC_SUBST(PTHREAD_LIBS) AC_SUBST(PTHREAD_CFLAGS) AC_SUBST(PTHREAD_CC) # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: if test x"$ax_pthread_ok" = xyes; then ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) : else ax_pthread_ok=no $2 fi AC_LANG_RESTORE ])dnl AX_PTHREAD libfixposix-20110706.gitcf6e954/m4/custom_checks.m4000066400000000000000000000051011160510370600215140ustar00rootroot00000000000000# -*- Autoconf -*- AC_DEFUN([LFP_FLAGS_INIT], [ LFP_CPPFLAGS="-D_XOPEN_SOURCE" LFP_CFLAGS="" LFP_LDFLAGS="" AC_SUBST(LFP_CPPFLAGS) AC_SUBST(LFP_CFLAGS) AC_SUBST(LFP_LDFLAGS) ]) AC_DEFUN([LFP_SYS_PLATFORM_SPECIFIC_DEFINITIONS], [ case "$host" in *-*-linux*) LFP_CPPFLAGS+=" -D_GNU_SOURCE=1" LFP_LDFLAGS+=" -lrt" ;; *-*-freebsd*) LFP_CPPFLAGS+=" -D__BSD_VISIBLE" ;; *-apple-darwin*) LFP_CPPFLAGS+=" -D_DARWIN_C_SOURCE" ;; *-sunos*|*-solaris*) LFP_CPPFLAGS+=" -D__EXTENSIONS__ -D_XPG4 -D_XPG4_2" ;; esac ]) AC_DEFUN([LFP_SYS_LARGEFILE], [ LFP_GETCONF_UNDEF([LFS_CFLAGS], [LFS_CFLAGS]) LFP_GETCONF_UNDEF([LFS_LDFLAGS], [LFS_LDFLAGS]) LFP_GETCONF_UNDEF([LFS_LIBS], [LFS_LIBS]) ]) AC_DEFUN([LFP_CHECK_SIZEOF_CLOCKID_T], [ AC_CHECK_TYPE([clockid_t], [AC_CHECK_SIZEOF([clockid_t], [], [[#include ]]) if test "$ac_cv_sizeof_clockid_t" -gt 4 ; then AC_MSG_FAILURE([Type clockid_t is larger than 32 bits]) fi], [case "$host" in *-apple-darwin*) : ;; *) AC_MSG_FAILURE([Type clockid_t not found]) ;; esac], [[#include ]]) ]) AC_DEFUN([LFP_CHECK_POSIX_MONOTONIC_CLOCK], [ LFP_GETCONF_UNDEF([POSIX_MONOTONIC_CLOCK], [_POSIX_MONOTONIC_CLOCK], [LFP_CHECK_SIZEOF_CLOCKID_T], [case "$host" in *-apple-darwin*) : ;; *) AC_MSG_FAILURE([Type clockid_t not found]) ;; esac]) ]) AC_DEFUN([LFP_ARG_ENABLE_EMULATED_SIGNALFD], [ AC_ARG_ENABLE([emulated-signalfd], [AS_HELP_STRING([--enable-emulated-signalfd={yes|no|check}], [Use emulated signalfd @<:@default=check@:>@])], [], [enable_emulated_signalfd=check]) AS_CASE($enable_emulated_signalfd, [yes], [AC_DEFINE(HAVE_EMULATED_SIGNALFD, 1, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 1) ], [check], [if test x"$ac_cv_header_sys_signalfd_h" = xyes ; then AC_DEFINE(HAVE_EMULATED_SIGNALFD, 0, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 0) else AC_DEFINE(HAVE_EMULATED_SIGNALFD, 1, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 1) fi], [no], [if test x"$ac_cv_header_sys_signalfd_h" = xyes ; then AC_DEFINE(HAVE_EMULATED_SIGNALFD, 0, [Whether to use signalfd emulation]) AC_SUBST(HAVE_EMULATED_SIGNALFD, 0) else AC_MSG_FAILURE([signalfd emulation was disabled although is absent]) fi], [AC_MSG_FAILURE( [--enable-emulated-signalfd was given an illegal value: "$enable_emulated_signalfd"])]) ]) libfixposix-20110706.gitcf6e954/m4/utils.m4000066400000000000000000000024001160510370600200210ustar00rootroot00000000000000# -*- Autoconf -*- # Check for some headers and print an error if not found AC_DEFUN([LFP_REQUIRE_HEADERS], [AC_CHECK_HEADERS($1,,AC_MSG_FAILURE([Cannot find header(s) $1]))]) # Check for a function and print an error if not found AC_DEFUN([LFP_REQUIRE_FUNCS], [AC_CHECK_FUNCS($1,,AC_MSG_FAILURE([Cannot find function(s) $1]))]) # Check for a type and print an error if not found AC_DEFUN([LFP_REQUIRE_TYPE], [AC_CHECK_TYPE($1,,AC_MSG_FAILURE([Cannot find type $1 in $2]), [[#include <$2>]])]) # Check for a declaration and print an error if not found AC_DEFUN([LFP_REQUIRE_DECLS], [AC_CHECK_DECLS($1,,AC_MSG_FAILURE([Cannot find $1 in $2]), [[#include <$2>]])]) # Check for a declaration and print an error if not found # Syntax: LFP_GETCONF(VARIABLE, SYSTEM_VAR, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) AC_DEFUN([LFP_GETCONF], [ $1=`(getconf $2) 2>/dev/null` AC_SUBST($1) if test $? -eq 0 ; then : ; $3 else : ; $4 fi ]) # Check for a declaration and print an error if not found or is undefined # Syntax: LFP_GETCONF(VARIABLE, SYSTEM_VAR, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) AC_DEFUN([LFP_GETCONF_UNDEF], [ $1=`(getconf $2) 2>/dev/null` AC_SUBST($1) if test $? -eq 0 && test x"$$1" != xundefined ; then : ; $3 else : ; $4 fi ]) libfixposix-20110706.gitcf6e954/src/000077500000000000000000000000001160510370600166725ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/src/include/000077500000000000000000000000001160510370600203155ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/src/include/lfp.h000066400000000000000000000045241160510370600212540ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_H_) # define _LFP_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* _LFP_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/000077500000000000000000000000001160510370600210765ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/src/include/lfp/aux.h000066400000000000000000000043051160510370600220460ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_AUX_H_) # define _LFP_AUX_H_ #if defined(__cplusplus) # define CPLUSPLUS_GUARD extern "C" { # define END_CPLUSPLUS_GUARD } #else # define CPLUSPLUS_GUARD # define END_CPLUSPLUS_GUARD #endif #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L // only C99 has restricted pointers # define restrict #endif #endif /* _LFP_AUX_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/dirent.h000066400000000000000000000041151160510370600225350ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_DIRENT_H_) # define _LFP_DIRENT_H_ #include CPLUSPLUS_GUARD #include int lfp_readdir(DIR *dirp, struct dirent *entry, struct dirent **result); END_CPLUSPLUS_GUARD #endif /* _LFP_DIRENT_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/errno.h000066400000000000000000000041071160510370600223760ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LPF_ERRNO_H_) # define _LPF_ERRNO_H_ #include CPLUSPLUS_GUARD #include #define EBUG 10000 int lfp_errno(void); int lfp_set_errno(int value); END_CPLUSPLUS_GUARD #endif /* _LPF_ERRNO_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/fcntl.h000066400000000000000000000051771160510370600223670ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_FCNTL_H_) # define _LFP_FCNTL_H_ #include CPLUSPLUS_GUARD #include #include #include extern char **environ; #if !defined(O_CLOEXEC) // Syscalls use "int" for passing flags, and since // *nix systems use the LP64 data model, "int" is 32 bits // which means that we can allocate unsupported flags in the // upper part of an uint64_t value # define O_CLOEXEC ( 1ULL << 32 ) #endif int lfp_open(const char *pathname, uint64_t flags, ...); int lfp_openpt(uint64_t flags); int lfp_creat(const char *pathname, mode_t mode); int lfp_is_fd_cloexec(int fd); int lfp_set_fd_cloexec(int fd, bool enabled); int lfp_is_fd_nonblock(int fd); int lfp_set_fd_nonblock(int fd, bool enabled); END_CPLUSPLUS_GUARD #endif /* _LFP_FCNTL_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/mman.h000066400000000000000000000042201160510370600221750ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_MMAN_H_) # define _LFP_MMAN_H_ #include CPLUSPLUS_GUARD #include void *lfp_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); int lfp_munmap(void *addr, size_t length); END_CPLUSPLUS_GUARD #endif /* _LFP_MMAN_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/resource.h000066400000000000000000000042021160510370600230740ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LPF_RESOURCE_H_) # define _LPF_RESOURCE_H_ #include CPLUSPLUS_GUARD #include int lfp_getrlimit(int resource, struct rlimit *rlim); int lfp_setrlimit(int resource, const struct rlimit *rlim); END_CPLUSPLUS_GUARD #endif /* _LPF_RESOURCE_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/select.h000066400000000000000000000044631160510370600225350ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SELECT_H_) # define _LFP_SELECT_H_ #include CPLUSPLUS_GUARD #include #include int lfp_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout); void lfp_fd_clr(int fd, fd_set *set); bool lfp_fd_isset(int fd, fd_set *set); void lfp_fd_set(int fd, fd_set *set); void lfp_fd_zero(fd_set *set); END_CPLUSPLUS_GUARD #endif /* _LFP_SELECT_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/sendfile.h000066400000000000000000000041261160510370600230430ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SENDFILE_H_) # define _LFP_SENDFILE_H_ #include CPLUSPLUS_GUARD #include ssize_t lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes); END_CPLUSPLUS_GUARD #endif /* _LFP_SENDFILE_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/signal.h000066400000000000000000000043621160510370600225310ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SIGNAL_H_) # define _LFP_SIGNAL_H_ #include CPLUSPLUS_GUARD #include typedef void (*lfp_sighandler_t) (int); lfp_sighandler_t lfp_sig_dfl(void); lfp_sighandler_t lfp_sig_err(void); lfp_sighandler_t lfp_sig_hold(void); lfp_sighandler_t lfp_sig_ign(void); int lfp_sigrtmin(void); int lfp_sigrtmax(void); END_CPLUSPLUS_GUARD #endif /* _LFP_SIGNAL_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/signalfd.h000066400000000000000000000045211160510370600230400ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SIGNALFD_H_) # define _LFP_SIGNALFD_H_ #include CPLUSPLUS_GUARD #include #include #if defined(__linux__) # if @HAVE_EMULATED_SIGNALFD@ // HAVE_EMULATED_SIGNALFD struct signalfd_siginfo { unsigned int ssi_signo; }; # else # include # endif #endif int lfp_install_signalfd(int signum, int sa_flags, bool* blockp); int lfp_uninstall_signalfd(int signum, bool block); END_CPLUSPLUS_GUARD #endif /* _LFP_SIGNALFD_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/socket.h000066400000000000000000000047761160510370600225550ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SOCKET_H_) # define _LFP_SOCKET_H_ #include CPLUSPLUS_GUARD #include #include int lfp_socket(int domain, int type, int protocol, uint64_t flags); int lfp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t flags); struct cmsghdr* lfp_cmsg_firsthdr(struct msghdr* msgh); struct cmsghdr* lfp_cmsg_nxthdr(struct msghdr* msgh, struct cmsghdr* cmsg); size_t lfp_cmsg_space(size_t length); size_t lfp_cmsg_len(size_t length); void* lfp_cmsg_data(struct cmsghdr* cmsg); END_CPLUSPLUS_GUARD #endif /* _LFP_SOCKET_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/spawn.h000066400000000000000000000131021160510370600223740ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SPAWN_H_) # define _LFP_SPAWN_H_ #include CPLUSPLUS_GUARD #include #include #include #include typedef struct { int initialized; int allocated; struct lfp_spawn_action *actions; } lfp_spawn_file_actions_t; int lfp_spawn_file_actions_init(lfp_spawn_file_actions_t *file_actions); int lfp_spawn_file_actions_destroy(lfp_spawn_file_actions_t *file_actions); int lfp_spawn_file_actions_addopen(lfp_spawn_file_actions_t *file_actions, int fd, const char *path, uint64_t oflags, mode_t mode); int lfp_spawn_file_actions_addclose(lfp_spawn_file_actions_t *file_actions, int fd); int lfp_spawn_file_actions_adddup2(lfp_spawn_file_actions_t *file_actions, int fd, int newfd); typedef struct { uint32_t flags; sigset_t sigdefault; sigset_t sigmask; pid_t pgroup; uid_t uid; gid_t gid; char *chdir_path; char *pts_path; } lfp_spawnattr_t; typedef enum { LFP_SPAWN_SETSIGMASK = 1 << 0, #define LFP_SPAWN_SETSIGMASK ( 1 << 0 ) LFP_SPAWN_SETSIGDEFAULT = 1 << 1, #define LFP_SPAWN_SETSIGDEFAULT ( 1 << 1 ) LFP_SPAWN_SETPGROUP = 1 << 2, #define LFP_SPAWN_SETPGROUP ( 1 << 2 ) LFP_SPAWN_RESETIDS = 1 << 3, #define LFP_SPAWN_RESETIDS ( 1 << 3 ) LFP_SPAWN_SETUID = 1 << 4, #define LFP_SPAWN_SETUID ( 1 << 4 ) LFP_SPAWN_SETGID = 1 << 5, #define LFP_SPAWN_SETGID ( 1 << 5 ) LFP_SPAWN_SETCWD = 1 << 6, #define LFP_SPAWN_SETCWD ( 1 << 6 ) LFP_SPAWN_SETSID = 1 << 7, #define LFP_SPAWN_SETSID ( 1 << 7 ) LFP_SPAWN_SETCTTY = 1 << 8, #define LFP_SPAWN_SETCTTY ( 1 << 8 ) } lfp_spawnattr_flags; int lfp_spawnattr_init(lfp_spawnattr_t *attr); int lfp_spawnattr_destroy(lfp_spawnattr_t *attr); int lfp_spawnattr_getflags(lfp_spawnattr_t *attr, uint32_t *flags); int lfp_spawnattr_setflags(lfp_spawnattr_t *attr, const uint32_t flags); int lfp_spawnattr_getsigmask(lfp_spawnattr_t *attr, sigset_t *sigmask); int lfp_spawnattr_setsigmask(lfp_spawnattr_t *attr, const sigset_t *sigmask); int lfp_spawnattr_getsigdefault(lfp_spawnattr_t *attr, sigset_t *sigdefault); int lfp_spawnattr_setsigdefault(lfp_spawnattr_t *attr, const sigset_t *sigdefault); int lfp_spawnattr_getpgroup(lfp_spawnattr_t *attr, pid_t *pgroup); int lfp_spawnattr_setpgroup(lfp_spawnattr_t *attr, const pid_t pgroup); int lfp_spawnattr_setsid(lfp_spawnattr_t *attr); int lfp_spawnattr_getctty(lfp_spawnattr_t *attr, char **path); int lfp_spawnattr_setctty(lfp_spawnattr_t *attr, const char *path); int lfp_spawnattr_getcwd(lfp_spawnattr_t *attr, char **path); int lfp_spawnattr_setcwd(lfp_spawnattr_t *attr, const char *path); int lfp_spawnattr_getuid(lfp_spawnattr_t *attr, uid_t *uid); int lfp_spawnattr_setuid(lfp_spawnattr_t *attr, const uid_t uid); int lfp_spawnattr_getgid(lfp_spawnattr_t *attr, gid_t *gid); int lfp_spawnattr_setgid(lfp_spawnattr_t *attr, const gid_t gid); int lfp_spawn(pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr); int lfp_spawnp(pid_t *restrict pid, const char *restrict file, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr); END_CPLUSPLUS_GUARD #endif /* _LFP_SPAWN_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/stat.h000066400000000000000000000046261160510370600222320ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STAT_H_) # define _LFP_STAT_H_ #include CPLUSPLUS_GUARD #include #include int lfp_stat(const char *path, struct stat *buf); int lfp_fstat(int fd, struct stat *buf); int lfp_lstat(const char *path, struct stat *buf); int lfp_is_fd_open(int fd); bool lfp_isreg(mode_t mode); bool lfp_isdir(mode_t mode); bool lfp_ischr(mode_t mode); bool lfp_isblk(mode_t mode); bool lfp_isfifo(mode_t mode); bool lfp_islnk(mode_t mode); bool lfp_issock(mode_t mode); END_CPLUSPLUS_GUARD #endif /* _LFP_STAT_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/stdlib.h000066400000000000000000000041551160510370600225350ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STDLIB_H_) # define _LFP_STDLIB_H_ #include CPLUSPLUS_GUARD #include int lfp_mkstemp(char *tmplate); char* lfp_getpath(char *const envp[]); char *lfp_ptsname(int masterfd); END_CPLUSPLUS_GUARD #endif /* _LFP_STDLIB_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/string.h000066400000000000000000000042401160510370600225550ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_STRING_H_) # define _LFP_STRING_H_ #include CPLUSPLUS_GUARD #include int lfp_strerror(int errnum, char *buf, size_t buflen); size_t lfp_strnlen(const char *s, size_t maxlen); char *lfp_strndup(const char *s, size_t maxlen); END_CPLUSPLUS_GUARD #endif /* _LFP_STRING_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/syslog.h000066400000000000000000000045141160510370600225730ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_SYSLOG_H_) # define _LFP_SYSLOG_H_ #include CPLUSPLUS_GUARD #include #include void lfp_openlog(const char *ident, int options, int facility); void lfp_syslog(int priority, const char *msg, ...); void lfp_vsyslog(int priority, const char *msg, va_list args); void lfp_closelog(void); int lfp_setlogmask(int maskpri); int lfp_log_mask(int priority); int lfp_log_upto(int priority); END_CPLUSPLUS_GUARD #endif /* _LFP_SYSLOG_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/time.h000066400000000000000000000047501160510370600222130ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_TIME_H_) # define _LFP_TIME_H_ #include CPLUSPLUS_GUARD #include #include #include typedef uint64_t lfp_clockid_t; #if !defined(_POSIX_TIMERS) || _POSIX_TIMERS < 0 # define CLOCK_REALTIME 0 # define CLOCK_MONOTONIC 1 #elif !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0 # define CLOCK_MONOTONIC (1 << 32) #endif int lfp_clock_getres(lfp_clockid_t clk_id, struct timespec *res); int lfp_clock_gettime(lfp_clockid_t clk_id, struct timespec *tp); int lfp_clock_settime(lfp_clockid_t clk_id, struct timespec *tp); END_CPLUSPLUS_GUARD #endif /* _LFP_TIME_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/unistd.h000066400000000000000000000050761160510370600225650ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_UNISTD_H_) # define _LFP_UNISTD_H_ #include CPLUSPLUS_GUARD #include #include off_t lfp_lseek(int fd, off_t offset, int whence); int lfp_pipe(int pipefd[2], uint64_t flags); ssize_t lfp_pread(int fd, void *buf, size_t count, off_t offset); ssize_t lfp_pwrite(int fd, const void *buf, size_t count, off_t offset); int lfp_truncate(const char *path, off_t length); int lfp_ftruncate(int fd, off_t length); int lfp_execve(const char *path, char *const argv[], char *const envp[]) __attribute__((nonnull (1))); int lfp_execvpe(const char *file, char *const argv[], char *const envp[]) __attribute__((nonnull (1))); END_CPLUSPLUS_GUARD #endif /* _LFP_UNISTD_H_ */ libfixposix-20110706.gitcf6e954/src/include/lfp/wait.h000066400000000000000000000044371160510370600222230ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_WAIT_H_) # define _LFP_WAIT_H_ #include CPLUSPLUS_GUARD #include #include bool lfp_wifexited(int status); int lfp_wexitstatus(int status); bool lfp_wifsignaled(int status); int lfp_wtermsig(int status); bool lfp_wcoredump(int status); bool lfp_wifstopped(int status); int lfp_wstopsig(int status); bool lfp_wifcontinued(int status); END_CPLUSPLUS_GUARD #endif /* _LFP_WAIT_H_ */ libfixposix-20110706.gitcf6e954/src/lib/000077500000000000000000000000001160510370600174405ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/src/lib/dirent.c000066400000000000000000000043241160510370600210740ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include int lfp_readdir(DIR *dirp, struct dirent *entry, struct dirent **result) { int ret = readdir_r(dirp, entry, result); if ( ret > 0 ) { lfp_set_errno(ret); return -1; } else if (*result == NULL) { return 0; } else { return 1; } } libfixposix-20110706.gitcf6e954/src/lib/errno.c000066400000000000000000000037651160510370600207440ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include int lfp_errno () { return errno; } int lfp_set_errno (int value) { errno = value; return errno; } libfixposix-20110706.gitcf6e954/src/lib/fcntl.c000066400000000000000000000077271160510370600207270ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include "utils.h" int lfp_open (const char *pathname, uint64_t flags, ...) { if (flags & O_CREAT) { va_list args; va_start(args, flags); mode_t mode = va_arg(args, int); va_end(args); return open(pathname, (int)flags & 0xFFFFFFFF, mode); } else { return open(pathname, (int)flags & 0xFFFFFFFF); } } int lfp_openpt (uint64_t flags) { bool cloexec = flags & O_CLOEXEC; flags &= ~O_CLOEXEC; int fd; SYSGUARD(fd = posix_openpt((int)flags & 0xFFFFFFFF)); if (cloexec && lfp_set_fd_cloexec(fd, true) < 0) { close(fd); return -1; } else { return fd; } } int lfp_creat (const char *pathname, mode_t mode) { return creat(pathname, mode); } int lfp_is_fd_cloexec (int fd) { int current_flags = fcntl(fd, F_GETFD); if (current_flags < 0) { return -1; } else { return (current_flags & FD_CLOEXEC) ? true : false; } } int lfp_set_fd_cloexec (int fd, bool enabled) { int current_flags = fcntl(fd, F_GETFD); if (current_flags < 0) { return -1; } else { int new_flags = enabled ? current_flags | FD_CLOEXEC \ : current_flags & ~FD_CLOEXEC; if ( new_flags != current_flags ) { return fcntl(fd, F_SETFD, new_flags); } else { return 0; } } } int lfp_is_fd_nonblock (int fd) { int current_flags = fcntl(fd, F_GETFL); if (current_flags < 0) { return -1; } else { return (current_flags & O_NONBLOCK) ? true : false; } } int lfp_set_fd_nonblock (int fd, bool enabled) { int current_flags = fcntl(fd, F_GETFL); if (current_flags < 0) { return -1; } else { int new_flags = enabled ? current_flags | O_NONBLOCK \ : current_flags & ~O_NONBLOCK; if ( new_flags != current_flags ) { return fcntl(fd, F_SETFL, new_flags); } else { return 0; } } } libfixposix-20110706.gitcf6e954/src/lib/install_signalfd.c000066400000000000000000000142351160510370600231260ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include "utils.h" static struct signalfd_params { int read_fd; int write_fd; } *(signalfd_params[NSIG]); static inline int lfp_signalfd (int fd, const sigset_t *mask, int flags) { if (HAVE_EMULATED_SIGNALFD) SYSERR(ENOSYS); else return signalfd(fd, mask, flags); } static void signalfd_emulator (int signum) { struct signalfd_siginfo ssi; struct signalfd_params *params = signalfd_params[signum]; int ret; assert (params != NULL); assert (params->write_fd != -1); memset(&ssi, 0, sizeof(ssi)); ssi.ssi_signo = signum; notify_listener: ret = write(params->write_fd, &ssi, sizeof(ssi)); if (ret == sizeof(ssi)) { return; } if (ret == -1) { switch (lfp_errno()) { case EAGAIN: /* The pipe buffer is full, therefore there's already a notification in the pipe pending reception. We can drop the redundant signal notification. Redundant signals are NEVER guaranteed not to be dropped anyway, and signals may have been dropped on our way already if the system was busy. */ return; case EINTR: /* Some other signal trumped us; try again! */ goto notify_listener; } } /* Something went deeply wrong. Abort. */ abort(); } static void warning_signal_handler (int signum) { char msg[128]; int i = snprintf(msg, sizeof(msg), "\nCaught signalfd-monitored signal %d, which should have been blocked.\n", signum); write(STDERR_FILENO, msg, i); } int lfp_install_signalfd(int signum, int sa_flags, bool* blockp) { int pipefd[2]; bool block; sigset_t sigmask; int emulate_signalfd; struct signalfd_params *params; struct sigaction sa; SYSCHECK(EINVAL, signum < 0 || signum >= NSIG); /* Setup sigaction */ memset(&sa, 0, sizeof(sa)); sa.sa_flags = (sa_flags & (SA_NOCLDSTOP | SA_NOCLDWAIT)) | SA_ONSTACK; /* Create mask with one signal */ sigemptyset(&sigmask); sigaddset(&sigmask, signum); /* Allocate parameters */ SYSCHECK(EALREADY, signalfd_params[signum]); params = malloc(sizeof(signalfd_params)); SYSCHECK(ENOMEM, params == NULL); /* Before we touch the handler, block the signal */ if (sigprocmask(SIG_BLOCK, &sigmask, NULL) < 0) return -1; /* First, try signalfd */ int sigfd = lfp_signalfd(-1, &sigmask, SFD_CLOEXEC | SFD_NONBLOCK); if (sigfd != -1) { /* success with signalfd, block signal and install warning handler */ emulate_signalfd = 0; sa.sa_handler = &warning_signal_handler; /* SIG_DFL would work but we want to catch bugs */ params->read_fd = sigfd; params->write_fd = -1; block = true; goto signalfd_sigaction; } /* no success with signalfd (probably ENOSYS), emulate! */ emulate_signalfd = 1; sa.sa_handler = &signalfd_emulator; if (lfp_pipe(pipefd, O_NONBLOCK | O_CLOEXEC) < 0) return -1; params->read_fd = pipefd[0]; params->write_fd = pipefd[1]; block = false; signalfd_sigaction: signalfd_params[signum] = params; if (sigaction(signum,&sa,NULL) < 0) return -1; if (emulate_signalfd && sigprocmask(SIG_UNBLOCK, &sigmask, NULL) < 0) return -1; if (blockp) { *blockp = block; } return params->read_fd; } int lfp_uninstall_signalfd(int signum, bool block) { sigset_t sigmask; struct signalfd_params *params; struct sigaction sa; SYSCHECK(EINVAL, signum < 0 || signum >= NSIG); /* Setup sigaction */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; /* Create mask with one signal */ sigemptyset(&sigmask); sigaddset(&sigmask, signum); /* Before we touch the handler, block the signal */ if (sigprocmask(SIG_BLOCK, &sigmask, NULL) != 0) return -1; /* Release parameters */ params = signalfd_params[signum]; if ( params == NULL) return 0; close(params->read_fd); if (params->write_fd != -1) close(params->write_fd); free(params); signalfd_params[signum] = NULL; if (sigaction(signum, &sa, NULL) < 0) return -1; if (!block && sigprocmask(SIG_UNBLOCK, &sigmask, NULL) != 0) return -1; return 0; } libfixposix-20110706.gitcf6e954/src/lib/libfixposix.libtool000066400000000000000000000001671160510370600233720ustar00rootroot00000000000000# Makes sure that the library is properly re-linked # when the version changes # # CURRENT:REVISION:AGE Version: 0:0:0 libfixposix-20110706.gitcf6e954/src/lib/mman.c000066400000000000000000000041731160510370600205410ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include void *lfp_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { return mmap(addr, length, prot, flags, fd, offset); } int lfp_munmap(void *addr, size_t length) { return munmap(addr, length); } libfixposix-20110706.gitcf6e954/src/lib/resource.c000066400000000000000000000041251160510370600214350ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include int lfp_getrlimit(int resource, struct rlimit *rlim) { return getrlimit(resource, rlim); } int lfp_setrlimit(int resource, const struct rlimit *rlim) { return setrlimit(resource, rlim); } libfixposix-20110706.gitcf6e954/src/lib/select.c000066400000000000000000000050541160510370600210670ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include "utils.h" int lfp_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout) { #if defined(HAVE_PSELECT) return pselect(nfds, readfds, writefds, exceptfds, timeout, NULL); #else struct timeval tv; _lfp_timespec_to_timeval(timeout, &tv); return select(nfds, readfds, writefds, exceptfds, timeout); #endif } void lfp_fd_clr(int fd, fd_set *set) { FD_CLR(fd, set); } bool lfp_fd_isset(int fd, fd_set *set) { return (bool) FD_ISSET(fd, set); } void lfp_fd_set(int fd, fd_set *set) { FD_SET(fd, set); } void lfp_fd_zero(fd_set *set) { FD_ZERO(set); } libfixposix-20110706.gitcf6e954/src/lib/sendfile.c000066400000000000000000000053731160510370600214050ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #if defined(HAVE_SENDFILE) # if defined(__linux__) # include # elif defined(__FreeBSD__) || defined(__APPLE__) # include # include # include # endif #endif #include "utils.h" ssize_t lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes) { #if defined(HAVE_SENDFILE) # if defined(__linux__) off_t off = offset; return (ssize_t) sendfile(out_fd, in_fd, &off, nbytes); # elif defined(__FreeBSD__) return (ssize_t) sendfile(in_fd, out_fd, offset, nbytes, NULL, SF_MNOWAIT); # elif defined(__APPLE__) off_t len = nbytes; return (ssize_t) sendfile(in_fd, out_fd, offset, &len, NULL, 0); # else # error "It appears that this OS has sendfile(), but LFP doesn't use it at the moment" # error "Please send an email to iolib-devel@common-lisp.net" # endif #else return ENOSYS; #endif } libfixposix-20110706.gitcf6e954/src/lib/signal.c000066400000000000000000000045601160510370600210660ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include "utils.h" lfp_sighandler_t lfp_sig_dfl (void) { return SIG_DFL; } lfp_sighandler_t lfp_sig_err (void) { return SIG_ERR; } lfp_sighandler_t lfp_sig_hold (void) { return SIG_HOLD; } lfp_sighandler_t lfp_sig_ign (void) { return SIG_IGN; } int lfp_sigrtmin (void) { #if defined(SIGRTMIN) return SIGRTMIN; #else SYSERR(ENOSYS); #endif // SIGRTMIN } int lfp_sigrtmax (void) { #if defined(SIGRTMAX) return SIGRTMAX; #else SYSERR(ENOSYS); #endif // SIGRTMAX } libfixposix-20110706.gitcf6e954/src/lib/socket.c000066400000000000000000000076201160510370600211010ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include int lfp_socket(int domain, int type, int protocol, uint64_t flags) { #if defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) return socket(domain, type | ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0) \ | ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0), protocol); #else int fd = socket(domain, type, protocol); if (fd < 0) { goto error_return; } if (((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(fd, true) < 0)) || \ ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(fd, true) < 0))) { goto error_close; } return fd; error_close: close(fd); error_return: return -1; #endif } int lfp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t flags) { // FIXME: This branch requires that SOCK_CLOEXEC and SOCK_NONBLOCK be // defined when accept4(2) is present. Should we add an Autoconf check ? #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) return accept4(sockfd, addr, addrlen, ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0) | \ ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0)); #else int fd = accept(sockfd, addr, addrlen); if (fd < 0) { goto error_return; } if (((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(fd, true) < 0)) || \ ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(fd, true) < 0))) { goto error_close; } return fd; error_close: close(fd); error_return: return -1; #endif } struct cmsghdr* lfp_cmsg_firsthdr (struct msghdr* msgh) { return CMSG_FIRSTHDR(msgh); } struct cmsghdr* lfp_cmsg_nxthdr (struct msghdr* msgh, struct cmsghdr* cmsg) { return CMSG_NXTHDR(msgh, cmsg); } size_t lfp_cmsg_space (size_t length) { return CMSG_SPACE(length); } size_t lfp_cmsg_len (size_t length) { return CMSG_LEN(length); } void* lfp_cmsg_data (struct cmsghdr* cmsg) { return CMSG_DATA(cmsg); } libfixposix-20110706.gitcf6e954/src/lib/spawn.c000066400000000000000000000126261160510370600207430ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include "utils.h" #include "spawn.h" typedef int (execfun)(const char*, char *const[], char *const[]); static void child_exit(int pipe, int child_errno) { int noctets = write(pipe, &child_errno, sizeof(int)); if (noctets == sizeof(int)) _exit(255); else _exit(254); } static int _lfp_spawn_apply_default_attributes(const lfp_spawnattr_t *attr) { if (attr == NULL || ! (attr->flags & LFP_SPAWN_SETSIGMASK)) { sigset_t set; sigemptyset(&set); SYSGUARD(sigprocmask(SIG_SETMASK, &set, NULL)); } return 0; } static void handle_child(execfun *execfun, const char *path, char *const argv[], char *const envp[], const lfp_spawn_file_actions_t *file_actions, const lfp_spawnattr_t *attr, int pipes[2]) { close(pipes[0]); int child_errno; if ((child_errno = _lfp_spawn_apply_default_attributes(attr)) != 0 || \ (child_errno = lfp_spawn_apply_attributes(attr)) != 0 || \ (child_errno = lfp_spawn_apply_file_actions(file_actions)) != 0) { child_exit(pipes[1], child_errno); } execfun(path, argv, envp); child_exit(pipes[1], lfp_errno()); } static int handle_parent(pid_t child_pid, int pipes[2]) { close(pipes[1]); int status, child_errno; int noctets = read(pipes[0], &child_errno, sizeof(int)); int read_errno = lfp_errno(); close(pipes[0]); switch (noctets) { case -1: SYSERR(read_errno); case 0: return 0; case 4: waitpid(child_pid, &status, WNOHANG); SYSERR(child_errno); default: // This is not suppose to happen because all 4 octets // of the child's errno should get here with one write SYSERR(EBUG); } } static int _lfp_spawn(execfun *execfun, pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { int pipes[2]; // Used for passing the error code from child to parent in case // some of the syscalls executed in the child fail if (lfp_pipe(pipes, O_CLOEXEC) < 0) return -1; *pid = fork(); switch (*pid) { case -1: return -1; case 0: handle_child(execfun, path, argv, envp, file_actions, attr, pipes); // Flow reaches this point only if child_exit() mysteriously fails SYSERR(EBUG); default: return handle_parent(*pid, pipes); } } int lfp_spawn(pid_t *restrict pid, const char *restrict path, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { SYSCHECK(EINVAL, pid == NULL); return _lfp_spawn(&lfp_execve, pid, path, argv, envp, file_actions, attr); } int lfp_spawnp(pid_t *restrict pid, const char *restrict file, char *const argv[restrict], char *const envp[restrict], const lfp_spawn_file_actions_t *restrict file_actions, const lfp_spawnattr_t *restrict attr) { SYSCHECK(EINVAL, pid == NULL); return _lfp_spawn(&lfp_execvpe, pid, file, argv, envp, file_actions, attr); } libfixposix-20110706.gitcf6e954/src/lib/spawn.h000066400000000000000000000041601160510370600207420ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_INTERNAL_SPAWN_H_) # define _LFP_INTERNAL_SPAWN_H_ #include int lfp_spawn_apply_attributes(const lfp_spawnattr_t *attr); int lfp_spawn_apply_file_actions(const lfp_spawn_file_actions_t *file_actions); #endif /* _LFP_INTERNAL_SPAWN_H_ */ libfixposix-20110706.gitcf6e954/src/lib/spawn_file_actions.c000066400000000000000000000152501160510370600234560ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include #include "utils.h" #include "spawn.h" typedef enum { LFP_SPAWN_FILE_ACTION_OPEN, LFP_SPAWN_FILE_ACTION_CLOSE, LFP_SPAWN_FILE_ACTION_DUP2 } lfp_spawn_action_type; typedef struct lfp_spawn_action { lfp_spawn_action_type type; int fd; int newfd; const char *path; uint64_t flags; mode_t mode; } lfp_spawn_action; int lfp_spawn_file_actions_init(lfp_spawn_file_actions_t *file_actions) { SYSCHECK(EINVAL, file_actions == NULL); file_actions->initialized = 0; file_actions->allocated = 0; file_actions->actions = NULL; return 0; } static void lfp_spawn_file_actions_free_paths(lfp_spawn_action *actions, int initialized) { for (int i = 0; i < initialized; i++) if (actions[i].type == LFP_SPAWN_FILE_ACTION_OPEN) free((void*)actions[i].path); } int lfp_spawn_file_actions_destroy(lfp_spawn_file_actions_t *file_actions) { SYSCHECK(EINVAL, file_actions == NULL); if (file_actions->actions) { lfp_spawn_file_actions_free_paths(file_actions->actions, file_actions->initialized); free(file_actions->actions); } // lfp_spawn_file_actions_init(file_actions); return 0; } static lfp_spawn_action* lfp_spawn_file_actions_allocate(lfp_spawn_file_actions_t *file_actions) { int index = file_actions->initialized++; int allocated = file_actions->allocated; lfp_spawn_action *actions = file_actions->actions; int new_allocated; lfp_spawn_action *new_actions; if (index >= allocated) { /* Note: this code assumes we run out of memory before we overflow. */ new_allocated = 4 + allocated * 3 / 2; new_actions = calloc(new_allocated, sizeof(lfp_spawn_action)); if (!new_actions) { return NULL; } if (actions) { memcpy(new_actions, actions, allocated * sizeof(lfp_spawn_action)); free(actions); } actions = new_actions; file_actions->actions = actions; file_actions->allocated = new_allocated; memset(actions+index, 0, (new_allocated - index) * sizeof(lfp_spawn_action)); } return actions + index; } int lfp_spawn_file_actions_addopen(lfp_spawn_file_actions_t *file_actions, int fd, const char *path, uint64_t oflags, mode_t mode) { SYSCHECK(EINVAL, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_OPEN; action->fd = fd; action->path = lfp_strndup(path, PATH_MAX); action->flags = oflags; action->mode = mode; return 0; } int lfp_spawn_file_actions_addclose(lfp_spawn_file_actions_t *file_actions, int fd) { SYSCHECK(EINVAL, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_CLOSE; action->fd = fd; return 0; } int lfp_spawn_file_actions_adddup2(lfp_spawn_file_actions_t *file_actions, int fd, int newfd) { SYSCHECK(EINVAL, file_actions == NULL); SYSCHECK(EBADF, INVALID_FD(fd) || INVALID_FD(newfd)); lfp_spawn_action *action = lfp_spawn_file_actions_allocate(file_actions); SYSCHECK(ENOMEM, !action); action->type = LFP_SPAWN_FILE_ACTION_DUP2; action->fd = fd; action->newfd = newfd; return 0; } static int lfp_spawn_apply_one_file_action(const lfp_spawn_action *action) { int err, fd; switch (action->type) { case LFP_SPAWN_FILE_ACTION_OPEN: fd = lfp_open(action->path, action->flags, action->mode); if (fd == -1) { return errno; } if (fd != action->fd) { err = dup2(fd, action->fd); if (err == -1) { return errno; } err = close(fd); if (err == -1) { return errno; } } return 0; case LFP_SPAWN_FILE_ACTION_CLOSE: err = close(action->fd); if (err == -1) { return errno; } return 0; case LFP_SPAWN_FILE_ACTION_DUP2: err = dup2(action->fd, action->newfd); if (err == -1) { return errno; } return 0; default: return EINVAL; } } int lfp_spawn_apply_file_actions(const lfp_spawn_file_actions_t *file_actions) { if (file_actions == NULL) return 0; lfp_spawn_action *action = file_actions->actions; int err; for ( int count = file_actions->initialized; count > 0; count-- ) { err = lfp_spawn_apply_one_file_action (action++); if (err) { return err; } } return 0; } libfixposix-20110706.gitcf6e954/src/lib/spawnattr.c000066400000000000000000000223611160510370600216330ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include "utils.h" #include "spawn.h" #define LFP_SPAWN_ALLATTRS ( LFP_SPAWN_SETSIGMASK | \ LFP_SPAWN_SETSIGDEFAULT | \ LFP_SPAWN_SETPGROUP | \ LFP_SPAWN_RESETIDS | \ LFP_SPAWN_SETUID | \ LFP_SPAWN_SETGID | \ LFP_SPAWN_SETCWD | \ LFP_SPAWN_SETSID | \ LFP_SPAWN_SETCTTY ) int lfp_spawnattr_init(lfp_spawnattr_t *attr) { SYSCHECK(EINVAL, attr == NULL); memset(attr, 0, sizeof(lfp_spawnattr_t)); sigemptyset(&attr->sigdefault); return 0; } int lfp_spawnattr_destroy(lfp_spawnattr_t *attr) { SYSCHECK(EINVAL, attr == NULL); if (attr->chdir_path) { free(attr->chdir_path); attr->chdir_path = NULL; } if (attr->pts_path) { free(attr->pts_path); attr->pts_path = NULL; } return 0; } int lfp_spawnattr_getflags(lfp_spawnattr_t *attr, uint32_t *flags) { SYSCHECK(EINVAL, attr == NULL || flags == NULL); *flags = attr->flags; return 0; } int lfp_spawnattr_setflags(lfp_spawnattr_t *attr, const uint32_t flags) { SYSCHECK(EINVAL, attr == NULL || (flags & ~LFP_SPAWN_ALLATTRS) != 0); attr->flags = flags; return 0; } int lfp_spawnattr_getsigmask(lfp_spawnattr_t *attr, sigset_t *sigmask) { SYSCHECK(EINVAL, attr == NULL || sigmask == NULL); memcpy(sigmask, &attr->sigmask, sizeof(sigset_t)); return 0; } int lfp_spawnattr_setsigmask(lfp_spawnattr_t *attr, const sigset_t *sigmask) { SYSCHECK(EINVAL, attr == NULL); attr->flags |= LFP_SPAWN_SETSIGMASK; memcpy(&attr->sigmask, sigmask, sizeof(sigset_t)); return 0; } int lfp_spawnattr_getsigdefault(lfp_spawnattr_t *attr, sigset_t *sigdefault) { SYSCHECK(EINVAL, attr == NULL || sigdefault == NULL); memcpy(sigdefault, &attr->sigdefault, sizeof(sigset_t)); return 0; } int lfp_spawnattr_setsigdefault(lfp_spawnattr_t *attr, const sigset_t *sigdefault) { SYSCHECK(EINVAL, attr == NULL || sigdefault == NULL); attr->flags |= LFP_SPAWN_SETSIGDEFAULT; memcpy(&attr->sigdefault, sigdefault, sizeof(sigset_t)); return 0; } int lfp_spawnattr_getpgroup(lfp_spawnattr_t *attr, pid_t *pgroup) { SYSCHECK(EINVAL, attr == NULL || pgroup == NULL); *pgroup = attr->pgroup; return 0; } int lfp_spawnattr_setpgroup(lfp_spawnattr_t *attr, const pid_t pgroup) { SYSCHECK(EINVAL, attr == NULL); attr->flags |= LFP_SPAWN_SETPGROUP; attr->pgroup = pgroup; return 0; } int lfp_spawnattr_setsid(lfp_spawnattr_t *attr) { SYSCHECK(EINVAL, attr == NULL); attr->flags |= LFP_SPAWN_SETSID; return 0; } int lfp_spawnattr_getctty(lfp_spawnattr_t *attr, char **path) { SYSCHECK(EINVAL, attr == NULL || path == NULL); *path = strdup(attr->pts_path); return 0; } int lfp_spawnattr_setctty(lfp_spawnattr_t *attr, const char *path) { SYSCHECK(EINVAL, attr == NULL || path == NULL); attr->flags |= LFP_SPAWN_SETCTTY; if (attr->pts_path) { free(attr->pts_path); } attr->pts_path = lfp_strndup(path, PATH_MAX); attr->pts_path[PATH_MAX] = 0; return 0; } int lfp_spawnattr_getcwd(lfp_spawnattr_t *attr, char **path) { SYSCHECK(EINVAL, attr == NULL || path == NULL); *path = strdup(attr->chdir_path); return 0; } int lfp_spawnattr_setcwd(lfp_spawnattr_t *attr, const char *path) { SYSCHECK(EINVAL, attr == NULL || path == NULL); attr->flags |= LFP_SPAWN_SETCWD; if (attr->chdir_path) { free(attr->chdir_path); } attr->chdir_path = lfp_strndup(path, PATH_MAX); attr->chdir_path[PATH_MAX] = 0; return 0; } int lfp_spawnattr_getuid(lfp_spawnattr_t *attr, uid_t *uid) { SYSCHECK(EINVAL, attr == NULL || uid == NULL); *uid = attr->uid; return 0; } int lfp_spawnattr_setuid(lfp_spawnattr_t *attr, const uid_t uid) { SYSCHECK(EINVAL, attr == NULL); attr->flags |= LFP_SPAWN_SETUID; attr->uid = uid; return 0; } int lfp_spawnattr_getgid(lfp_spawnattr_t *attr, gid_t *gid) { SYSCHECK(EINVAL, attr == NULL || gid == NULL); *gid = attr->gid; return 0; } int lfp_spawnattr_setgid(lfp_spawnattr_t *attr, const gid_t gid) { SYSCHECK(EINVAL, attr == NULL); attr->flags |= LFP_SPAWN_SETGID; attr->gid = gid; return 0; } int lfp_spawn_apply_attributes(const lfp_spawnattr_t *attr) { if (attr == NULL) return 0; SYSCHECK(EINVAL, (attr->flags & LFP_SPAWN_RESETIDS) && \ ((attr->flags & LFP_SPAWN_SETUID) || \ (attr->flags & LFP_SPAWN_SETGID))); if (attr->flags & LFP_SPAWN_SETSIGMASK) if (sigprocmask(SIG_SETMASK, &attr->sigmask, NULL) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSIGMASK:sigprocmask"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETSIGDEFAULT) { struct sigaction sa = { .sa_flags = 0, .sa_handler = SIG_DFL }; for (int i = 1; i <= NSIG; i++) if (sigismember(&attr->sigdefault, i)) if (sigaction(i, &sa, NULL) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSIGDEFAULT:sigaction"); #endif goto error_return; } } if (attr->flags & LFP_SPAWN_SETPGROUP) if (setpgid(0, attr->pgroup) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETPGROUP:setpgid"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETSID) if (setsid() < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETSID:setsid"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETCTTY) { int ttyfd = lfp_open(attr->pts_path, O_RDWR | O_NOCTTY); if (ttyfd < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETCTTY:lfp_open"); #endif goto error_return; } else { if (ioctl(ttyfd, TIOCSCTTY) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETCTTY:ioctl"); #endif goto error_return; } } } if (attr->flags & LFP_SPAWN_SETCWD) if (chdir(attr->chdir_path) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETCWD:chdir"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_RESETIDS) { if (seteuid(getuid()) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:RESETIDS:seteuid"); #endif goto error_return; } if (setegid(getgid()) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:RESETIDS:setegid"); #endif goto error_return; } } if (attr->flags & LFP_SPAWN_SETUID) if (seteuid(attr->uid) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETUID:seteuid"); #endif goto error_return; } if (attr->flags & LFP_SPAWN_SETGID) if (setegid(attr->gid) < 0) { #if !defined(NDEBUG) perror("LFP_SPAWN_APPLY_ATTR:SETGID:setegid"); #endif goto error_return; } return 0; error_return: return lfp_errno(); } libfixposix-20110706.gitcf6e954/src/lib/stat.c000066400000000000000000000055441160510370600205670ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include int lfp_stat(const char *path, struct stat *buf) { return stat(path, buf); } int lfp_fstat(int fd, struct stat *buf) { return fstat(fd, buf); } int lfp_lstat(const char *path, struct stat *buf) { return lstat(path, buf); } int lfp_is_fd_open(int fd) { struct stat buf; int ret = fstat(fd, &buf); if ( ret < 0 ) { if ( lfp_errno() == EBADF ) { return false; } else { return -1; } } else { return true; } } bool lfp_isreg(mode_t mode) { return (bool) S_ISREG(mode); } bool lfp_isdir(mode_t mode) { return (bool) S_ISDIR(mode); } bool lfp_ischr(mode_t mode) { return (bool) S_ISCHR(mode); } bool lfp_isblk(mode_t mode) { return (bool) S_ISBLK(mode); } bool lfp_isfifo(mode_t mode) { return (bool) S_ISFIFO(mode); } bool lfp_islnk(mode_t mode) { return (bool) S_ISLNK(mode); } bool lfp_issock(mode_t mode) { return (bool) S_ISSOCK(mode); } libfixposix-20110706.gitcf6e954/src/lib/stdlib.c000066400000000000000000000062521160510370600210720ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include int lfp_mkstemp(char *template) { return mkstemp(template); } static char* _lfp_getenv(const char *name, unsigned short len, char *const envp[]) { if (envp == NULL) return NULL; do { if (strlen(*envp) > len && strncmp(name, *envp, len) == 0) return (char*)*envp+len; } while(*(++envp) != NULL); return NULL; } // FIXME: add autoconf check that confstr(_CS_PATH) returns sane values static char* _lfp_default_path(void) { size_t default_path_size = confstr(_CS_PATH, NULL, 0); char *default_path = malloc(default_path_size); confstr(_CS_PATH, default_path, default_path_size); return default_path; } char* lfp_getpath(char *const envp[]) { char *envpath = _lfp_getenv("PATH=", sizeof("PATH=")-1, envp); if (envpath != NULL) { return strdup(envpath); } else { return _lfp_default_path(); } } static pthread_mutex_t ptsname_mutex = PTHREAD_MUTEX_INITIALIZER; char *lfp_ptsname(int masterfd) { pthread_mutex_lock(&ptsname_mutex); char *_name = ptsname(masterfd); if (_name != NULL) { _name = lfp_strndup(_name, PATH_MAX); } pthread_mutex_unlock(&ptsname_mutex); return _name; } libfixposix-20110706.gitcf6e954/src/lib/string.c000066400000000000000000000057671160510370600211310ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include "utils.h" #if defined(HAVE___XPG_STRERROR_R) int __xpg_strerror_r (int errnum, char *buf, size_t buflen); #endif int lfp_strerror (int errnum, char *buf, size_t buflen) { SYSCHECK(EINVAL, buf == NULL); #if defined(HAVE___XPG_STRERROR_R) return __xpg_strerror_r(errnum, buf, buflen); #else return strerror_r(errnum, buf, buflen); #endif // HAVE___XPG_STRERROR_R } size_t lfp_strnlen(const char *s, size_t maxlen) { #if defined(HAVE_STRNLEN) return strnlen(s, maxlen); #else for (size_t i = 0; i < maxlen; i++) { if (s[i] == '\0') { return i; } } return maxlen; #endif } char *lfp_strndup(const char *s, size_t maxlen) { #if defined(HAVE_STRNDUP) return strndup(s, maxlen); #else if (s == NULL) { return NULL; } else { size_t len = lfp_strnlen(s, maxlen); char *newstr = malloc(len + 1); if (newstr == NULL) { return NULL; } else { memcpy(newstr, s, len); newstr[len] = '\0'; return newstr; } } #endif } libfixposix-20110706.gitcf6e954/src/lib/syslog.c000066400000000000000000000064371160510370600211360ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include "utils.h" static pthread_mutex_t syslog_mutex = PTHREAD_MUTEX_INITIALIZER; static char *syslog_ident = NULL; #define SYSLOG_IDENT_SIZE 1024 static void _lfp_closelog() { closelog(); if (syslog_ident) { free(syslog_ident); syslog_ident = NULL; } } static void copy_syslog_ident(const char *ident) { if (ident) { syslog_ident = malloc(SYSLOG_IDENT_SIZE); strncpy(syslog_ident, ident, SYSLOG_IDENT_SIZE - 1); syslog_ident[SYSLOG_IDENT_SIZE - 1] = 0; } } void lfp_openlog(const char *ident, int options, int facility) { pthread_mutex_lock(&syslog_mutex); _lfp_closelog(); copy_syslog_ident(ident); openlog(syslog_ident, options, facility); pthread_mutex_unlock(&syslog_mutex); } void lfp_syslog(int priority, const char *msg, ...) { va_list args; va_start(args, msg); vsyslog(priority, msg, args); va_end(args); } void lfp_vsyslog(int priority, const char *msg, va_list args) { vsyslog(priority, msg, args); } void lfp_closelog(void) { pthread_mutex_lock(&syslog_mutex); _lfp_closelog(); pthread_mutex_unlock(&syslog_mutex); } int lfp_setlogmask(int maskpri) { return setlogmask(maskpri); } int lfp_log_mask(int priority) { return LOG_MASK(priority); } int lfp_log_upto(int priority) { return LOG_UPTO(priority); } libfixposix-20110706.gitcf6e954/src/lib/time.c000066400000000000000000000102651160510370600205460ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #if defined(__APPLE__) # include # include #endif #include "utils.h" int lfp_clock_getres(lfp_clockid_t clk_id, struct timespec *res) { #if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 return clock_getres((clockid_t)clk_id & 0xFFFFFFFF, res); #else switch (clk_id) { case CLOCK_REALTIME: case CLOCK_MONOTONIC: // FIXME: it's probably safe to assume that it's 10ms // or lower(OS scheduler running at 100Hz or more) res->tv_sec = 0; res->tv_nsec = 10^7; return 0; default: SYSERR(EINVAL); } #endif } #if !defined(_POSIX_TIMERS) || _POSIX_TIMERS < 0 static inline int _lfp_clock_gettime_realtime(struct timespec *tp) { struct timeval tv; if (gettimeofday(&tv, NULL) < 0) { return -1; } else { _lfp_timeval_to_timespec(&tv, tp); return 0; } } #endif #if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0 static inline int _lfp_clock_gettime_monotonic(struct timespec *tp) { # if defined(__APPLE__) clock_serv_t clk_serv; mach_timespec_t mtp; _lfp_timespec_to_mach_timespec_t(tp, &mtp); SYSGUARD(host_get_clock_service(mach_host_self(), 0, &clk_serv)); SYSGUARD(clock_get_time(clk_serv, &mtp)); return 0; # else SYSERR(EINVAL); # endif } #endif int lfp_clock_gettime(lfp_clockid_t clk_id, struct timespec *tp) { #if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 return clock_gettime((clockid_t)clk_id & 0xFFFFFFFF, tp); #else switch (clk_id) { case CLOCK_REALTIME: return _lfp_clock_gettime_realtime(tp); case CLOCK_MONOTONIC: return _lfp_clock_gettime_monotonic(tp); default: SYSERR(EINVAL); } #endif } int lfp_clock_settime(lfp_clockid_t clk_id, struct timespec *tp) { #if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 return clock_settime((clockid_t)clk_id & 0xFFFFFFFF, tp); #else int ret; struct timeval tv; _lfp_timespec_to_timeval(tp, &tv); switch (clk_id) { case CLOCK_REALTIME: ret = settimeofday(&tv, NULL); if (ret < 0) { return -1; } return 0; case CLOCK_MONOTONIC: SYSERR(EPERM); default: SYSERR(EINVAL); } #endif } libfixposix-20110706.gitcf6e954/src/lib/unistd.c000066400000000000000000000112221160510370600211100ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include #include #include #include #include #include #include #include "utils.h" off_t lfp_lseek(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); } int lfp_pipe (int pipefd[2], uint64_t flags) { #if defined(HAVE_PIPE2) // We assume that if pipe2() is defined then O_CLOEXEC too // exists, which means that it's in the lower part of "flags" return pipe2(pipefd, (int)flags & 0xFFFFFFFF); #else if (pipe(pipefd) < 0) { goto error_return; } if ((flags & O_CLOEXEC) && (lfp_set_fd_cloexec(pipefd[0], true) < 0 || lfp_set_fd_cloexec(pipefd[1], true) < 0)) { goto error_close; } if ((flags & O_NONBLOCK) && (lfp_set_fd_nonblock(pipefd[0], true) < 0 || lfp_set_fd_nonblock(pipefd[1], true) < 0)) { goto error_close; } return 0; error_close: close(pipefd[0]); close(pipefd[1]); error_return: return -1; #endif // HAVE_PIPE2 } ssize_t lfp_pread(int fd, void *buf, size_t count, off_t offset) { return pread(fd, buf, count, offset); } ssize_t lfp_pwrite(int fd, const void *buf, size_t count, off_t offset) { return pwrite(fd, buf, count, offset); } int lfp_truncate(const char *path, off_t length) { return truncate(path, length); } int lfp_ftruncate(int fd, off_t length) { return ftruncate(fd, length); } int lfp_execve(const char *path, char *const argv[], char *const envp[]) { SYSCHECK(EINVAL, path == NULL); SYSCHECK(ENOENT, path[0] == '\0'); return execve(path, argv, envp); } int lfp_execvpe(const char *file, char *const argv[], char *const envp[]) { SYSCHECK(EINVAL, file == NULL); SYSCHECK(ENOENT, file[0] == '\0'); if (strchr(file, '/')) return execve(file, argv, envp); size_t name_max = (size_t) pathconf(file, _PC_NAME_MAX); size_t filelen = lfp_strnlen(file, name_max); SYSCHECK(ENAMETOOLONG, filelen >= name_max); char path[PATH_MAX], *searchpath=NULL, *tmpath=NULL, *bindir=NULL; tmpath = searchpath = lfp_getpath(envp); while ((bindir = strsep(&tmpath, ":")) != NULL) if ( bindir[0] != '\0' ) { size_t dirlen = lfp_strnlen(bindir, PATH_MAX); // directory + / + file size_t pathlen = dirlen + 1 + filelen; // if pathlen == PATH_MAX there's no room for the final \0 SYSCHECK(ENAMETOOLONG, pathlen >= PATH_MAX); snprintf(path, PATH_MAX, "%s/%s", bindir, file); path[pathlen] = '\0'; lfp_execve(path, argv, envp); if ( errno == E2BIG || errno == ENOEXEC || errno == ENOMEM || errno == ETXTBSY ) break; } free(searchpath); return -1; } libfixposix-20110706.gitcf6e954/src/lib/utils.h000066400000000000000000000055631160510370600207620ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #if !defined(_LFP_INTERNAL_UTILS_H_) # define _LFP_INTERNAL_UTILS_H_ #include #include #include #if defined(__APPLE__) # include #endif static inline void _lfp_timespec_to_timeval(struct timespec *ts, struct timeval *tv) { tv->tv_sec = ts->tv_sec; tv->tv_usec = ts->tv_nsec / 1000; } static inline void _lfp_timeval_to_timespec(struct timeval *tv, struct timespec *ts) { ts->tv_sec = tv->tv_sec; ts->tv_nsec = tv->tv_usec * 1000; } #if defined(__APPLE__) static inline void _lfp_timespec_to_mach_timespec_t(struct timespec *ts, mach_timespec_t *mts) { mts->tv_sec = ts->tv_sec; mts->tv_nsec = ts->tv_nsec; } #endif #define SYSERR(errcode) do { errno = errcode; return -1; } while(0) #define SYSCHECK(errcode,expr) do { if(expr) SYSERR(errcode); } while(0) #define SYSGUARD(expr) do { if((expr) < 0) return(-1); } while(0) /* not checking for OPEN_MAX, which might not be valid, on Linux */ #define INVALID_FD(fd) ( fd < 0 ) #endif /* _LFP_INTERNAL_UTILS_H_ */ libfixposix-20110706.gitcf6e954/src/lib/wait.c000066400000000000000000000047111160510370600205530ustar00rootroot00000000000000/*******************************************************************************/ /* Permission is hereby granted, free of charge, to any person or organization */ /* obtaining a copy of the software and accompanying documentation covered by */ /* this license (the "Software") to use, reproduce, display, distribute, */ /* execute, and transmit the Software, and to prepare derivative works of the */ /* Software, and to permit third-parties to whom the Software is furnished to */ /* do so, all subject to the following: */ /* */ /* The copyright notices in the Software and this entire statement, including */ /* the above license grant, this restriction and the following disclaimer, */ /* must be included in all copies of the Software, in whole or in part, and */ /* all derivative works of the Software, unless such copies or derivative */ /* works are solely in the form of machine-executable object code generated by */ /* a source language processor. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */ /* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT */ /* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE */ /* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, */ /* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */ /* DEALINGS IN THE SOFTWARE. */ /*******************************************************************************/ #include #include bool lfp_wifexited (int status) { return WIFEXITED(status); } int lfp_wexitstatus (int status) { return WEXITSTATUS(status); } bool lfp_wifsignaled (int status) { return WIFSIGNALED(status); } int lfp_wtermsig (int status) { return WTERMSIG(status); } bool lfp_wcoredump (int status) { #ifdef WCOREDUMP return WCOREDUMP(status); #else return false; #endif } bool lfp_wifstopped (int status) { return WIFSTOPPED(status); } int lfp_wstopsig (int status) { return WSTOPSIG(status); } bool lfp_wifcontinued (int status) { return WIFCONTINUED(status); } libfixposix-20110706.gitcf6e954/src/tests/000077500000000000000000000000001160510370600200345ustar00rootroot00000000000000libfixposix-20110706.gitcf6e954/src/tests/select.c000066400000000000000000000004551160510370600214630ustar00rootroot00000000000000#include #include int main() { fd_set rset, wset, eset; lfp_fd_zero(&rset); lfp_fd_zero(&wset); lfp_fd_zero(&eset); for(unsigned i = 0; i < FD_SETSIZE; i++) { if(lfp_fd_isset(i, &rset)) { printf("%d ", i); } } return 0; } libfixposix-20110706.gitcf6e954/src/tests/signalfd.c000066400000000000000000000023521160510370600217710ustar00rootroot00000000000000#include #include #include #include #include #include #include static void error_abort (const char* msg, int perrorp) { if (perrorp) { perror(msg); } else { fprintf(stderr,"%s\n",msg); } abort(); } static ssize_t do_read(int fd, void *buf, size_t count) { ssize_t s; fd_set readfds; lfp_fd_zero(&readfds); do_try_read: lfp_fd_set(fd,&readfds); lfp_select(fd+1, &readfds, NULL, NULL, NULL, NULL); s = read(fd, buf, count); if (s != -1) { return s; } switch (errno) { case EAGAIN: case ERESTART: case EINTR: goto do_try_read; } return -1; } int main () { struct signalfd_siginfo fdsi; int sfd = lfp_install_signalfd(SIGINT, 0, NULL); size_t s = do_read(sfd, &fdsi, sizeof(struct signalfd_siginfo)); if (s != sizeof(struct signalfd_siginfo)) { error_abort("read", 1); } if (fdsi.ssi_signo == SIGINT) { printf("\nGot SIGINT\n"); } else { error_abort("unexpected signal", 0); } lfp_uninstall_signalfd(SIGINT, 0); lfp_install_signalfd(SIGINT, 0, NULL); lfp_uninstall_signalfd(SIGINT, 0); return 0; } libfixposix-20110706.gitcf6e954/src/tests/spawn.c000066400000000000000000000064741160510370600213430ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include static void error_abort (const char* msg, int perrorp) { if (perrorp) { perror(msg); } else { fprintf(stderr,"%s\n",msg); } abort(); } int main () { // Not implemented yet pid_t pid; char *path = "/bin/sh"; char *myargv[] = {"/bin/sh","-c","echo foo ; echo bar >&2 ; cat",NULL}; lfp_spawn_file_actions_t file_actions; lfp_spawnattr_t attr; int err, status; char tempnam1[] = {"/tmp/lfp_spawn_test_1_XXXXXX"}; char tempnam2[] = {"/tmp/lfp_spawn_test_2_XXXXXX"}; int tempfd1, tempfd2; char buf[256]; char expected[] = {"foo\nbar\nquux\n"}; if ( (tempfd1 = mkstemp(tempnam1)) == -1 ) { error_abort("failed to create temp file 1", true); } if ( (tempfd2 = mkstemp(tempnam2)) == -1 ) { error_abort("failed to create temp file 2", true); } if (write(tempfd1,"quux\n",5)!=5) { error_abort("failed to initialize temp file 1", true); } if (close(tempfd1) == -1) { error_abort("failed to close temp file 1", true); } if (close(tempfd2) == -1) { error_abort("failed to close temp file 2", true); } err = lfp_spawn_file_actions_init(&file_actions); if (err) { error_abort("failed to init file actions", true); } err = lfp_spawnattr_init(&attr); if (err) { error_abort("failed to init attr", true); } err = lfp_spawn_file_actions_addopen(&file_actions,10,tempnam1,O_EXCL|O_RDONLY,0); err = lfp_spawn_file_actions_adddup2(&file_actions,10,0); err = lfp_spawn_file_actions_addclose(&file_actions,10); err = lfp_spawn_file_actions_addopen(&file_actions,1,tempnam2,O_WRONLY|O_APPEND,0); err = lfp_spawn_file_actions_adddup2(&file_actions,1,2); err = lfp_spawn(&pid,path,myargv,environ,&file_actions,&attr); if (err) { error_abort("failed to spawn", true); } fprintf(stderr,"spawned child %d\n",pid); err = lfp_spawn_file_actions_destroy(&file_actions); if (err) { error_abort("failed to init file actions", true); } err = lfp_spawnattr_destroy(&attr); if (err) { error_abort("failed to init attr", true); } err = waitpid(pid,&status,0); if (err == -1) { error_abort("failed to wait for child", true); } if (!WIFEXITED(status)) { error_abort("child didn't exit properly", false); } if (WEXITSTATUS(status)) { error_abort("child didn't exited with status 0", false); } tempfd2 = open(tempnam2, O_RDONLY); if (tempfd2==-1) { error_abort("failed to open the output file", true); } err = read(tempfd2,buf,sizeof(buf)); if (err == -1) { error_abort("failed to read the output file", true); } if (err != (sizeof(expected)-1)) { fprintf(stderr,"expected %zu bytes, got %d\n", sizeof(expected)-1, err); error_abort("found the wrong number of bytes", false); } err = strncmp(expected,buf,err); if (err) { error_abort("output doesn't match expectation", false); } err = unlink(tempnam1); if (err == -1) { error_abort("failed to remove the input file", true); } unlink(tempnam2); if (err == -1) { error_abort("failed to remove the output file", true); } fprintf(stderr,"spawn test successful\n"); exit(0); }