xref: /freebsd/contrib/kyua/m4/fs.m4 (revision a96ef4501919d7ac08e94e98dc34b0bdd744802b)
1dnl Copyright 2011 The Kyua Authors.
2dnl All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that the following conditions are
6dnl met:
7dnl
8dnl * Redistributions of source code must retain the above copyright
9dnl   notice, this list of conditions and the following disclaimer.
10dnl * Redistributions in binary form must reproduce the above copyright
11dnl   notice, this list of conditions and the following disclaimer in the
12dnl   documentation and/or other materials provided with the distribution.
13dnl * Neither the name of Google Inc. nor the names of its contributors
14dnl   may be used to endorse or promote products derived from this software
15dnl   without specific prior written permission.
16dnl
17dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29dnl \file m4/fs.m4
30dnl File system related checks.
31dnl
32dnl The macros in this file check for features required in the utils/fs
33dnl module.  The global KYUA_FS_MODULE macro will call all checks required
34dnl for the library.
35
36
37dnl KYUA_FS_GETCWD_DYN
38dnl
39dnl Checks whether getcwd(NULL, 0) works; i.e. if getcwd(3) can dynamically
40dnl allocate the output buffer to fit the whole current path.
41AC_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
61dnl KYUA_FS_LCHMOD
62dnl
63dnl Checks whether lchmod(3) exists and if it works.  Some systems, such as
64dnl Ubuntu 10.04.1 LTS, provide a lchmod(3) stub that is not implemented yet
65dnl allows programs to compile cleanly (albeit for a warning).  It would be
66dnl nice to detect if lchmod(3) works at run time to prevent side-effects of
67dnl this test but doing so means we will keep receiving a noisy compiler
68dnl warning.
69AC_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
98dnl KYUA_FS_UNMOUNT
99dnl
100dnl Detect the correct method to unmount a file system.
101AC_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
116dnl KYUA_FS_MODULE
117dnl
118dnl Performs all checks needed by the utils/fs library.
119AC_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])
126