summaryrefslogtreecommitdiff
path: root/bin/bbackupd/BackupDaemon.cpp
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-12-07 16:34:47 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-12-07 16:34:47 +0000
commit81d8eda2419e7a23088a98cdfc52a305c9ceac0d (patch)
tree27143d7b539a8bf2e23cc18e2f598804fa8d784d /bin/bbackupd/BackupDaemon.cpp
parent065dc6f8cd168e3ee6e71ddfb06f42a92abfabbd (diff)
Merged martin/autoconf at r35 to trunk
Diffstat (limited to 'bin/bbackupd/BackupDaemon.cpp')
-rwxr-xr-xbin/bbackupd/BackupDaemon.cpp94
1 files changed, 48 insertions, 46 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index bc07ee21..f22de591 100755
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -12,15 +12,16 @@
#include <unistd.h>
#include <syslog.h>
#include <sys/param.h>
-#include <sys/mount.h>
#include <signal.h>
-#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
- #ifdef PLATFORM_SUNOS
- #include <cstdio>
- #include <sys/mnttab.h>
- #else
- #include <mntent.h>
- #endif
+#ifdef HAVE_SYS_MOUNT_H
+ #include <sys/mount.h>
+#endif
+#ifdef HAVE_MNTENT_H
+ #include <mntent.h>
+#endif
+#ifdef HAVE_SYS_MNTTAB_H
+ #include <cstdio>
+ #include <sys/mnttab.h>
#endif
#include <sys/wait.h>
@@ -894,7 +895,7 @@ void BackupDaemon::SendSyncStartOrFinish(bool SendStart)
-#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
+#ifndef HAVE_STRUCT_STATFS_F_MNTONNAME
// string comparison ordering for when mount points are handled
// by code, rather than the OS.
typedef struct
@@ -957,16 +958,21 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
std::map<std::string, int> mounts;
int numIDMaps = 0;
-#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
+#ifndef HAVE_STRUCT_STATFS_F_MNTONNAME
// Linux and others can't tell you where a directory is mounted. So we
// have to read the mount entries from /etc/mtab! Bizarre that the OS
// itself can't tell you, but there you go.
std::set<std::string, mntLenCompare> mountPoints;
// BLOCK
FILE *mountPointsFile = 0;
-#ifdef PLATFORM_SUNOS
+
+#ifdef HAVE_STRUCT_MNTENT_MNT_DIR
// Open mounts file
- mountPointsFile = ::fopen("/etc/mnttab", "r");
+ mountPointsFile = ::setmntent("/proc/mounts", "r");
+ if(mountPointsFile == 0)
+ {
+ mountPointsFile = ::setmntent("/etc/mtab", "r");
+ }
if(mountPointsFile == 0)
{
THROW_EXCEPTION(CommonException, OSFileError);
@@ -974,51 +980,47 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
try
{
-
// Read all the entries, and put them in the set
- struct mnttab entry;
- while(getmntent(mountPointsFile, &entry) == 0)
+ struct mntent *entry = 0;
+ while((entry = ::getmntent(mountPointsFile)) != 0)
{
- TRACE1("Found mount point at %s\n", entry.mnt_mountp);
- mountPoints.insert(std::string(entry.mnt_mountp));
+ TRACE1("Found mount point at %s\n", entry->mnt_dir);
+ mountPoints.insert(std::string(entry->mnt_dir));
}
// Close mounts file
- ::fclose(mountPointsFile);
+ ::endmntent(mountPointsFile);
}
catch(...)
{
- ::fclose(mountPointsFile);
+ ::endmntent(mountPointsFile);
throw;
}
#else
- // Open mounts file
- mountPointsFile = ::setmntent("/proc/mounts", "r");
+ // Open mounts file
+ mountPointsFile = ::fopen("/etc/mnttab", "r");
if(mountPointsFile == 0)
{
- mountPointsFile = ::setmntent("/etc/mtab", "r");
+ THROW_EXCEPTION(CommonException, OSFileError);
}
- if(mountPointsFile == 0)
- {
- THROW_EXCEPTION(CommonException, OSFileError);
- }
-
+
try
{
+
// Read all the entries, and put them in the set
- struct mntent *entry = 0;
- while((entry = ::getmntent(mountPointsFile)) != 0)
+ struct mnttab entry;
+ while(getmntent(mountPointsFile, &entry) == 0)
{
- TRACE1("Found mount point at %s\n", entry->mnt_dir);
- mountPoints.insert(std::string(entry->mnt_dir));
+ TRACE1("Found mount point at %s\n", entry.mnt_mountp);
+ mountPoints.insert(std::string(entry.mnt_mountp));
}
-
+
// Close mounts file
- ::endmntent(mountPointsFile);
+ ::fclose(mountPointsFile);
}
catch(...)
{
- ::endmntent(mountPointsFile);
+ ::fclose(mountPointsFile);
throw;
}
#endif
@@ -1030,7 +1032,7 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
ASSERT(*i == "/");
}
#endif // n NDEBUG
-#endif // PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
+#endif // n HAVE_STRUCT_STATFS_F_MNTONNAME
// Then... go through each of the entries in the configuration,
// making sure there's a directory created for it.
@@ -1052,7 +1054,17 @@ TRACE0("new location\n");
// Do a fsstat on the pathname to find out which mount it's on
{
-#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
+#ifdef HAVE_STRUCT_STATFS_F_MNTONNAME
+ // BSD style statfs -- includes mount point, which is nice.
+ struct statfs s;
+ if(::statfs(ploc->mPath.c_str(), &s) != 0)
+ {
+ THROW_EXCEPTION(CommonException, OSFileError)
+ }
+
+ // Where the filesystem is mounted
+ std::string mountName(s.f_mntonname);
+#else
// Warn in logs if the directory isn't absolute
if(ploc->mPath[0] != '/')
{
@@ -1078,16 +1090,6 @@ TRACE0("new location\n");
}
TRACE2("mount point chosen for %s is %s\n", ploc->mPath.c_str(), mountName.c_str());
}
-#else
- // BSD style statfs -- includes mount point, which is nice.
- struct statfs s;
- if(::statfs(ploc->mPath.c_str(), &s) != 0)
- {
- THROW_EXCEPTION(CommonException, OSFileError)
- }
-
- // Where the filesystem is mounted
- std::string mountName(s.f_mntonname);
#endif
// Got it?