diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-07-11 12:38:09 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-07-11 12:38:09 (GMT) |
commit | df23fd75267c830f85a74cfde3020981c37e82a5 (patch) | |
tree | d7db53794b2765c29eb4710c7e40fda2a06b11a2 | |
parent | 6267f1036777d505bd6a1e8c2a5d9f76690f9db0 (diff) | |
download | monitoring-plugins-df23fd75267c830f85a74cfde3020981c37e82a5.tar.gz |
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
-rw-r--r-- | lib/creat-safer.c | 33 | ||||
-rw-r--r-- | lib/dup-safer.c | 46 | ||||
-rw-r--r-- | lib/fcntl--.h | 28 | ||||
-rw-r--r-- | lib/fcntl-safer.h | 24 | ||||
-rw-r--r-- | lib/fd-safer.c | 59 | ||||
-rw-r--r-- | lib/open-safer.c | 51 | ||||
-rw-r--r-- | lib/pipe-safer.c | 50 | ||||
-rw-r--r-- | lib/unistd--.h | 28 | ||||
-rw-r--r-- | lib/unistd-safer.h | 23 | ||||
-rw-r--r-- | m4/fcntl-safer.m4 | 12 | ||||
-rw-r--r-- | m4/np_coreutils.m4 | 2 | ||||
-rw-r--r-- | m4/unistd-safer.m4 | 13 |
12 files changed, 369 insertions, 0 deletions
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 @@ | |||
1 | /* Invoke creat, but avoid some glitches. | ||
2 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Written by Jim Meyering. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "fcntl-safer.h" | ||
25 | |||
26 | #include <fcntl.h> | ||
27 | #include "unistd-safer.h" | ||
28 | |||
29 | int | ||
30 | creat_safer (char const *file, mode_t mode) | ||
31 | { | ||
32 | return fd_safer (creat (file, mode)); | ||
33 | } | ||
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 @@ | |||
1 | /* Invoke dup, but avoid some glitches. | ||
2 | Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Written by Paul Eggert. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "unistd-safer.h" | ||
25 | |||
26 | #include <fcntl.h> | ||
27 | |||
28 | #include <unistd.h> | ||
29 | #ifndef STDERR_FILENO | ||
30 | # define STDERR_FILENO 2 | ||
31 | #endif | ||
32 | |||
33 | /* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or | ||
34 | STDERR_FILENO. */ | ||
35 | |||
36 | int | ||
37 | dup_safer (int fd) | ||
38 | { | ||
39 | #ifdef F_DUPFD | ||
40 | return fcntl (fd, F_DUPFD, STDERR_FILENO + 1); | ||
41 | #else | ||
42 | /* fd_safer calls us back, but eventually the recursion unwinds and | ||
43 | does the right thing. */ | ||
44 | return fd_safer (dup (fd)); | ||
45 | #endif | ||
46 | } | ||
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 @@ | |||
1 | /* Like fcntl.h, but redefine some names to avoid glitches. | ||
2 | |||
3 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | #include <fcntl.h> | ||
22 | #include "fcntl-safer.h" | ||
23 | |||
24 | #undef open | ||
25 | #define open open_safer | ||
26 | |||
27 | #undef creat | ||
28 | #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 @@ | |||
1 | /* Invoke fcntl-like functions, but avoid some glitches. | ||
2 | |||
3 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | int open_safer (char const *, int, ...); | ||
24 | 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 @@ | |||
1 | /* Return a safer copy of a file descriptor. | ||
2 | |||
3 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | #ifdef HAVE_CONFIG_H | ||
22 | # include <config.h> | ||
23 | #endif | ||
24 | |||
25 | #include "unistd-safer.h" | ||
26 | |||
27 | #include <errno.h> | ||
28 | |||
29 | #include <unistd.h> | ||
30 | #ifndef STDIN_FILENO | ||
31 | # define STDIN_FILENO 0 | ||
32 | #endif | ||
33 | #ifndef STDERR_FILENO | ||
34 | # define STDERR_FILENO 2 | ||
35 | #endif | ||
36 | |||
37 | /* Return FD, unless FD would be a copy of standard input, output, or | ||
38 | error; in that case, return a duplicate of FD, closing FD. On | ||
39 | failure to duplicate, close FD, set errno, and return -1. Preserve | ||
40 | errno if FD is negative, so that the caller can always inspect | ||
41 | errno when the returned value is negative. | ||
42 | |||
43 | This function is usefully wrapped around functions that return file | ||
44 | descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */ | ||
45 | |||
46 | int | ||
47 | fd_safer (int fd) | ||
48 | { | ||
49 | if (STDIN_FILENO <= fd && fd <= STDERR_FILENO) | ||
50 | { | ||
51 | int f = dup_safer (fd); | ||
52 | int e = errno; | ||
53 | close (fd); | ||
54 | errno = e; | ||
55 | fd = f; | ||
56 | } | ||
57 | |||
58 | return fd; | ||
59 | } | ||
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 @@ | |||
1 | /* Invoke open, but avoid some glitches. | ||
2 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Written by Paul Eggert. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "fcntl-safer.h" | ||
25 | |||
26 | #include <fcntl.h> | ||
27 | #include <stdarg.h> | ||
28 | #include "unistd-safer.h" | ||
29 | |||
30 | int | ||
31 | open_safer (char const *file, int flags, ...) | ||
32 | { | ||
33 | mode_t mode = 0; | ||
34 | |||
35 | if (flags & O_CREAT) | ||
36 | { | ||
37 | va_list ap; | ||
38 | va_start (ap, flags); | ||
39 | |||
40 | /* Assume mode_t promotes to int if and only if it is smaller. | ||
41 | This assumption isn't guaranteed by the C standard, but we | ||
42 | don't know of any real-world counterexamples. */ | ||
43 | mode = (sizeof (mode_t) < sizeof (int) | ||
44 | ? va_arg (ap, int) | ||
45 | : va_arg (ap, mode_t)); | ||
46 | |||
47 | va_end (ap); | ||
48 | } | ||
49 | |||
50 | return fd_safer (open (file, flags, mode)); | ||
51 | } | ||
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 @@ | |||
1 | /* Invoke pipe, but avoid some glitches. | ||
2 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
17 | |||
18 | /* Written by Jim Meyering. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "unistd-safer.h" | ||
25 | |||
26 | #include <unistd.h> | ||
27 | |||
28 | /* Like pipe, but ensure that neither of the file descriptors is | ||
29 | STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ | ||
30 | |||
31 | int | ||
32 | pipe_safer (int fd[2]) | ||
33 | { | ||
34 | int fail = pipe (fd); | ||
35 | if (fail) | ||
36 | return fail; | ||
37 | |||
38 | { | ||
39 | int i; | ||
40 | for (i = 0; i < 2; i++) | ||
41 | { | ||
42 | int f = fd_safer (fd[i]); | ||
43 | if (f < 0) | ||
44 | return -1; | ||
45 | fd[i] = f; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | return 0; | ||
50 | } | ||
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 @@ | |||
1 | /* Like unistd.h, but redefine some names to avoid glitches. | ||
2 | |||
3 | Copyright (C) 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | #include <unistd.h> | ||
22 | #include "unistd-safer.h" | ||
23 | |||
24 | #undef dup | ||
25 | #define dup dup_safer | ||
26 | |||
27 | #undef pipe | ||
28 | #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 @@ | |||
1 | /* Invoke unistd-like functions, but avoid some glitches. | ||
2 | |||
3 | Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | /* Written by Paul Eggert. */ | ||
20 | |||
21 | int dup_safer (int); | ||
22 | int fd_safer (int); | ||
23 | 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 @@ | |||
1 | #serial 2 | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_FCNTL_SAFER], | ||
8 | [ | ||
9 | AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h]) | ||
10 | AC_LIBOBJ([open-safer]) | ||
11 | AC_LIBOBJ([creat-safer]) | ||
12 | ]) | ||
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], | |||
13 | AC_REQUIRE([AM_STDBOOL_H]) | 13 | AC_REQUIRE([AM_STDBOOL_H]) |
14 | AC_REQUIRE([gl_C_STRTOLD]) | 14 | AC_REQUIRE([gl_C_STRTOLD]) |
15 | AC_REQUIRE([gl_EXITFAIL]) | 15 | AC_REQUIRE([gl_EXITFAIL]) |
16 | AC_REQUIRE([gl_FCNTL_SAFER]) | ||
16 | AC_REQUIRE([gl_FSUSAGE]) | 17 | AC_REQUIRE([gl_FSUSAGE]) |
17 | AC_REQUIRE([gl_FUNC_ALLOCA]) | 18 | AC_REQUIRE([gl_FUNC_ALLOCA]) |
18 | AC_REQUIRE([gl_GETOPT]) | 19 | AC_REQUIRE([gl_GETOPT]) |
19 | AC_REQUIRE([gl_MOUNTLIST]) | 20 | AC_REQUIRE([gl_MOUNTLIST]) |
20 | AC_REQUIRE([gl_REGEX]) | 21 | AC_REQUIRE([gl_REGEX]) |
22 | AC_REQUIRE([gl_UNISTD_SAFER]) | ||
21 | AC_REQUIRE([gl_XALLOC]) | 23 | AC_REQUIRE([gl_XALLOC]) |
22 | AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) | 24 | AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) |
23 | 25 | ||
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 @@ | |||
1 | #serial 7 | ||
2 | dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_UNISTD_SAFER], | ||
8 | [ | ||
9 | AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h]) | ||
10 | AC_LIBOBJ([dup-safer]) | ||
11 | AC_LIBOBJ([fd-safer]) | ||
12 | AC_LIBOBJ([pipe-safer]) | ||
13 | ]) | ||