From 8eb2a01c2841aa8f070d4962be43ab57624cb57f Mon Sep 17 00:00:00 2001 From: Carsten Leonhardt Date: Tue, 12 Jan 2016 17:37:26 +0100 Subject: [PATCH] Apply Carsten's patch that fixes bug #2192 builds on kfreebsd --- bacula/autoconf/acconfig.h | 1 + bacula/autoconf/bacula-macros/os.m4 | 8 ++++ bacula/autoconf/config.h.in | 1 + bacula/src/findlib/fstype.c | 69 +++++++++++++++-------------- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/bacula/autoconf/acconfig.h b/bacula/autoconf/acconfig.h index 3a694a0fce..310c77f72c 100644 --- a/bacula/autoconf/acconfig.h +++ b/bacula/autoconf/acconfig.h @@ -137,6 +137,7 @@ /* OSes */ #undef HAVE_LINUX_OS #undef HAVE_FREEBSD_OS +#undef HAVE_KFREEBSD_OS #undef HAVE_NETBSD_OS #undef HAVE_OPENBSD_OS #undef HAVE_BSDI_OS diff --git a/bacula/autoconf/bacula-macros/os.m4 b/bacula/autoconf/bacula-macros/os.m4 index eb249a6e4f..b82deed532 100644 --- a/bacula/autoconf/bacula-macros/os.m4 +++ b/bacula/autoconf/bacula-macros/os.m4 @@ -160,6 +160,14 @@ then else AM_CONDITIONAL(HAVE_DARWIN_OS, $FALSEPRG) fi + +if test $HAVE_UNAME=yes -a x`uname -s` = xGNU/kFreeBSD +then + AM_CONDITIONAL(HAVE_KFREEBSD_OS, $TRUEPRG) + AC_DEFINE(HAVE_KFREEBSD_OS) +else + AM_CONDITIONAL(HAVE_KFREEBSD_OS, $FALSEPRG) +fi ]) AC_DEFUN([BA_CHECK_OPSYS_DISTNAME], diff --git a/bacula/autoconf/config.h.in b/bacula/autoconf/config.h.in index 5cc08b80ad..f9f1bd9fd7 100644 --- a/bacula/autoconf/config.h.in +++ b/bacula/autoconf/config.h.in @@ -137,6 +137,7 @@ /* OSes */ #undef HAVE_LINUX_OS #undef HAVE_FREEBSD_OS +#undef HAVE_KFREEBSD_OS #undef HAVE_NETBSD_OS #undef HAVE_OPENBSD_OS #undef HAVE_BSDI_OS diff --git a/bacula/src/findlib/fstype.c b/bacula/src/findlib/fstype.c index dc4f65d0ff..ab3b20616e 100644 --- a/bacula/src/findlib/fstype.c +++ b/bacula/src/findlib/fstype.c @@ -337,7 +337,41 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen) /* Read mtab entries */ bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx) { -#ifdef HAVE_GETMNTENT +/* Debian stretch GNU/KFreeBSD has both getmntinfo and getmntent, but + only the first seems to work, so ordering is important here */ +#ifdef HAVE_GETMNTINFO + struct stat st; +#if defined(ST_NOWAIT) + int flags = ST_NOWAIT; +#elif defined(MNT_NOWAIT) + int flags = MNT_NOWAIT; +#else + int flags = 0; +#endif +#if defined(HAVE_NETBSD_OS) + struct statvfs *mntinfo; +#else + struct statfs *mntinfo; +#endif + int nument; + + P(mutex); + if ((nument = getmntinfo(&mntinfo, flags)) > 0) { + while (nument-- > 0) { + if (is_rootfs(mntinfo->f_fstypename)) { + continue; + } + if (stat(mntinfo->f_mntonname, &st) < 0) { + continue; + } + mtab_handler(user_ctx, &st, mntinfo->f_mntfromname, + mntinfo->f_mntonname, mntinfo->f_fstypename, NULL); + mntinfo++; + } + } + V(mutex); +/* HAVE_GETMNTINFO */ +#elif defined(HAVE_GETMNTENT) FILE *mntfp; struct stat st; @@ -389,39 +423,6 @@ bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx) #endif #endif /* HAVE_GETMNTENT */ - -#ifdef HAVE_GETMNTINFO - struct stat st; -#if defined(ST_NOWAIT) - int flags = ST_NOWAIT; -#elif defined(MNT_NOWAIT) - int flags = MNT_NOWAIT; -#else - int flags = 0; -#endif -#if defined(HAVE_NETBSD_OS) - struct statvfs *mntinfo; -#else - struct statfs *mntinfo; -#endif - int nument; - - P(mutex); - if ((nument = getmntinfo(&mntinfo, flags)) > 0) { - while (nument-- > 0) { - if (is_rootfs(mntinfo->f_fstypename)) { - continue; - } - if (stat(mntinfo->f_mntonname, &st) < 0) { - continue; - } - mtab_handler(user_ctx, &st, mntinfo->f_mntfromname, - mntinfo->f_mntonname, mntinfo->f_fstypename, NULL); - mntinfo++; - } - } - V(mutex); -#endif /* HAVE_GETMNTINFO */ return true; } -- 2.39.5