From: Ton Voon Date: Tue, 11 Jul 2006 12:38:09 +0000 (+0000) Subject: Extra files from coreutils required for getloadavg.c to compile X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=df23fd75267c830f85a74cfde3020981c37e82a5;p=nagiosplug.git Extra files from coreutils required for getloadavg.c to compile on Tru64 (Ciro Iriarte - 1520331) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1446 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/lib/creat-safer.c b/lib/creat-safer.c new file mode 100644 index 0000000..4588de3 --- /dev/null +++ b/lib/creat-safer.c @@ -0,0 +1,33 @@ +/* Invoke creat, but avoid some glitches. + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Jim Meyering. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fcntl-safer.h" + +#include +#include "unistd-safer.h" + +int +creat_safer (char const *file, mode_t mode) +{ + return fd_safer (creat (file, mode)); +} diff --git a/lib/dup-safer.c b/lib/dup-safer.c new file mode 100644 index 0000000..8cbee70 --- /dev/null +++ b/lib/dup-safer.c @@ -0,0 +1,46 @@ +/* Invoke dup, but avoid some glitches. + Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "unistd-safer.h" + +#include + +#include +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or + STDERR_FILENO. */ + +int +dup_safer (int fd) +{ +#ifdef F_DUPFD + return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); +#else + /* fd_safer calls us back, but eventually the recursion unwinds and + does the right thing. */ + return fd_safer (dup (fd)); +#endif +} diff --git a/lib/fcntl--.h b/lib/fcntl--.h new file mode 100644 index 0000000..51b869e --- /dev/null +++ b/lib/fcntl--.h @@ -0,0 +1,28 @@ +/* Like fcntl.h, but redefine some names to avoid glitches. + + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#include +#include "fcntl-safer.h" + +#undef open +#define open open_safer + +#undef creat +#define creat creat_safer diff --git a/lib/fcntl-safer.h b/lib/fcntl-safer.h new file mode 100644 index 0000000..cab6aab --- /dev/null +++ b/lib/fcntl-safer.h @@ -0,0 +1,24 @@ +/* Invoke fcntl-like functions, but avoid some glitches. + + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#include + +int open_safer (char const *, int, ...); +int creat_safer (char const *, mode_t); diff --git a/lib/fd-safer.c b/lib/fd-safer.c new file mode 100644 index 0000000..5933bcb --- /dev/null +++ b/lib/fd-safer.c @@ -0,0 +1,59 @@ +/* Return a safer copy of a file descriptor. + + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "unistd-safer.h" + +#include + +#include +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +/* Return FD, unless FD would be a copy of standard input, output, or + error; in that case, return a duplicate of FD, closing FD. On + failure to duplicate, close FD, set errno, and return -1. Preserve + errno if FD is negative, so that the caller can always inspect + errno when the returned value is negative. + + This function is usefully wrapped around functions that return file + descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */ + +int +fd_safer (int fd) +{ + if (STDIN_FILENO <= fd && fd <= STDERR_FILENO) + { + int f = dup_safer (fd); + int e = errno; + close (fd); + errno = e; + fd = f; + } + + return fd; +} diff --git a/lib/open-safer.c b/lib/open-safer.c new file mode 100644 index 0000000..d3ba894 --- /dev/null +++ b/lib/open-safer.c @@ -0,0 +1,51 @@ +/* Invoke open, but avoid some glitches. + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "fcntl-safer.h" + +#include +#include +#include "unistd-safer.h" + +int +open_safer (char const *file, int flags, ...) +{ + mode_t mode = 0; + + if (flags & O_CREAT) + { + va_list ap; + va_start (ap, flags); + + /* Assume mode_t promotes to int if and only if it is smaller. + This assumption isn't guaranteed by the C standard, but we + don't know of any real-world counterexamples. */ + mode = (sizeof (mode_t) < sizeof (int) + ? va_arg (ap, int) + : va_arg (ap, mode_t)); + + va_end (ap); + } + + return fd_safer (open (file, flags, mode)); +} diff --git a/lib/pipe-safer.c b/lib/pipe-safer.c new file mode 100644 index 0000000..fb02d72 --- /dev/null +++ b/lib/pipe-safer.c @@ -0,0 +1,50 @@ +/* Invoke pipe, but avoid some glitches. + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Jim Meyering. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "unistd-safer.h" + +#include + +/* Like pipe, but ensure that neither of the file descriptors is + STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ + +int +pipe_safer (int fd[2]) +{ + int fail = pipe (fd); + if (fail) + return fail; + + { + int i; + for (i = 0; i < 2; i++) + { + int f = fd_safer (fd[i]); + if (f < 0) + return -1; + fd[i] = f; + } + } + + return 0; +} diff --git a/lib/unistd--.h b/lib/unistd--.h new file mode 100644 index 0000000..1fe6ce8 --- /dev/null +++ b/lib/unistd--.h @@ -0,0 +1,28 @@ +/* Like unistd.h, but redefine some names to avoid glitches. + + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#include +#include "unistd-safer.h" + +#undef dup +#define dup dup_safer + +#undef pipe +#define pipe pipe_safer diff --git a/lib/unistd-safer.h b/lib/unistd-safer.h new file mode 100644 index 0000000..f95999d --- /dev/null +++ b/lib/unistd-safer.h @@ -0,0 +1,23 @@ +/* Invoke unistd-like functions, but avoid some glitches. + + Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. + + 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +int dup_safer (int); +int fd_safer (int); +int pipe_safer (int[2]); diff --git a/m4/fcntl-safer.m4 b/m4/fcntl-safer.m4 new file mode 100644 index 0000000..be210f9 --- /dev/null +++ b/m4/fcntl-safer.m4 @@ -0,0 +1,12 @@ +#serial 2 +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FCNTL_SAFER], +[ + AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h]) + AC_LIBOBJ([open-safer]) + AC_LIBOBJ([creat-safer]) +]) diff --git a/m4/np_coreutils.m4 b/m4/np_coreutils.m4 index 23d55e4..5360bbd 100644 --- a/m4/np_coreutils.m4 +++ b/m4/np_coreutils.m4 @@ -13,11 +13,13 @@ AC_DEFUN([np_COREUTILS], AC_REQUIRE([AM_STDBOOL_H]) AC_REQUIRE([gl_C_STRTOLD]) AC_REQUIRE([gl_EXITFAIL]) + AC_REQUIRE([gl_FCNTL_SAFER]) AC_REQUIRE([gl_FSUSAGE]) AC_REQUIRE([gl_FUNC_ALLOCA]) AC_REQUIRE([gl_GETOPT]) AC_REQUIRE([gl_MOUNTLIST]) AC_REQUIRE([gl_REGEX]) + AC_REQUIRE([gl_UNISTD_SAFER]) AC_REQUIRE([gl_XALLOC]) AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) diff --git a/m4/unistd-safer.m4 b/m4/unistd-safer.m4 new file mode 100644 index 0000000..6fbe4c6 --- /dev/null +++ b/m4/unistd-safer.m4 @@ -0,0 +1,13 @@ +#serial 7 +dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_UNISTD_SAFER], +[ + AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h]) + AC_LIBOBJ([dup-safer]) + AC_LIBOBJ([fd-safer]) + AC_LIBOBJ([pipe-safer]) +])