]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/m4/fs.m4
addr2line: fix allocation leak in error path
[FreeBSD/FreeBSD.git] / contrib / kyua / m4 / fs.m4
1 dnl Copyright 2011 The Kyua Authors.
2 dnl All rights reserved.
3 dnl
4 dnl Redistribution and use in source and binary forms, with or without
5 dnl modification, are permitted provided that the following conditions are
6 dnl met:
7 dnl
8 dnl * Redistributions of source code must retain the above copyright
9 dnl   notice, this list of conditions and the following disclaimer.
10 dnl * Redistributions in binary form must reproduce the above copyright
11 dnl   notice, this list of conditions and the following disclaimer in the
12 dnl   documentation and/or other materials provided with the distribution.
13 dnl * Neither the name of Google Inc. nor the names of its contributors
14 dnl   may be used to endorse or promote products derived from this software
15 dnl   without specific prior written permission.
16 dnl
17 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 dnl \file m4/fs.m4
30 dnl File system related checks.
31 dnl
32 dnl The macros in this file check for features required in the utils/fs
33 dnl module.  The global KYUA_FS_MODULE macro will call all checks required
34 dnl for the library.
35
36
37 dnl KYUA_FS_GETCWD_DYN
38 dnl
39 dnl Checks whether getcwd(NULL, 0) works; i.e. if getcwd(3) can dynamically
40 dnl allocate the output buffer to fit the whole current path.
41 AC_DEFUN([KYUA_FS_GETCWD_DYN], [
42     AC_CACHE_CHECK(
43         [whether getcwd(NULL, 0) works],
44         [kyua_cv_getcwd_dyn], [
45         AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h>
46 #include <unistd.h>
47 ], [
48     char *cwd = getcwd(NULL, 0);
49     return (cwd != NULL) ? EXIT_SUCCESS : EXIT_FAILURE;
50 ])],
51         [kyua_cv_getcwd_dyn=yes],
52         [kyua_cv_getcwd_dyn=no])
53     ])
54     if test "${kyua_cv_getcwd_dyn}" = yes; then
55         AC_DEFINE_UNQUOTED([HAVE_GETCWD_DYN], [1],
56                            [Define to 1 if getcwd(NULL, 0) works])
57     fi
58 ])
59
60
61 dnl KYUA_FS_LCHMOD
62 dnl
63 dnl Checks whether lchmod(3) exists and if it works.  Some systems, such as
64 dnl Ubuntu 10.04.1 LTS, provide a lchmod(3) stub that is not implemented yet
65 dnl allows programs to compile cleanly (albeit for a warning).  It would be
66 dnl nice to detect if lchmod(3) works at run time to prevent side-effects of
67 dnl this test but doing so means we will keep receiving a noisy compiler
68 dnl warning.
69 AC_DEFUN([KYUA_FS_LCHMOD], [
70     AC_CACHE_CHECK(
71         [for a working lchmod],
72         [kyua_cv_lchmod_works], [
73         AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <sys/stat.h>
74 #include <fcntl.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <unistd.h>
78 ], [
79     int fd = open("conftest.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
80     if (fd == -1) {
81         perror("creation of conftest.txt failed");
82         return EXIT_FAILURE;
83     }
84
85     return lchmod("conftest.txt", 0640) != -1 ?  EXIT_SUCCESS : EXIT_FAILURE;
86 ])],
87         [kyua_cv_lchmod_works=yes],
88         [kyua_cv_lchmod_works=no])
89     ])
90     rm -f conftest.txt
91     if test "${kyua_cv_lchmod_works}" = yes; then
92         AC_DEFINE_UNQUOTED([HAVE_WORKING_LCHMOD], [1],
93                            [Define to 1 if your lchmod works])
94     fi
95 ])
96
97
98 dnl KYUA_FS_UNMOUNT
99 dnl
100 dnl Detect the correct method to unmount a file system.
101 AC_DEFUN([KYUA_FS_UNMOUNT], [
102     AC_CHECK_FUNCS([unmount], [have_unmount2=yes], [have_unmount2=no])
103     if test "${have_unmount2}" = no; then
104         have_umount8=yes
105         AC_PATH_PROG([UMOUNT], [umount], [have_umount8=no])
106         if test "${have_umount8}" = yes; then
107             AC_DEFINE_UNQUOTED([UMOUNT], ["${UMOUNT}"],
108                                [Set to the path of umount(8)])
109         else
110             AC_MSG_ERROR([Don't know how to unmount a file system])
111         fi
112     fi
113 ])
114
115
116 dnl KYUA_FS_MODULE
117 dnl
118 dnl Performs all checks needed by the utils/fs library.
119 AC_DEFUN([KYUA_FS_MODULE], [
120     AC_CHECK_HEADERS([sys/mount.h sys/statvfs.h sys/vfs.h])
121     AC_CHECK_FUNCS([statfs statvfs])
122     KYUA_FS_GETCWD_DYN
123     KYUA_FS_LCHMOD
124     KYUA_FS_UNMOUNT
125 ])