Skip to content

Commit

Permalink
- make some binary paths used in snbk configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Dec 17, 2024
1 parent 1c87238 commit ab65f09
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion client/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ get_filesystem(const ProxyConfig& config, const string& target_root)


Differ::Differ()
: command(DIFFBIN " --new-file --unified")
: command(DIFF_BIN " --new-file --unified")
{
}

Expand Down
3 changes: 2 additions & 1 deletion client/snbk/BackupConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#define SNAPPER_BACKUP_CONFIG_H


#include "config.h"

#include <string>
#include <vector>

#include <snapper/Enum.h>
#include <snapper/SnapperDefines.h>

#include "Shell.h"

Expand Down
2 changes: 2 additions & 0 deletions client/snbk/TheBigThing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/


#include "config.h"

#include <iostream>
#include <regex>
#include <boost/algorithm/string/predicate.hpp>
Expand Down
58 changes: 33 additions & 25 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,39 @@ AC_PREFIX_DEFAULT(/usr)

AC_PATH_PROG([XSLTPROC], [xsltproc], [/usr/bin/xsltproc])

AC_PATH_PROG([CHSNAPBIN], [chsnap], [/sbin/chsnap])
AC_PATH_PROG([CPBIN], [cp], [/bin/cp])
AC_PATH_PROG([TOUCHBIN], [touch], [/usr/bin/touch])
AC_PATH_PROG([RMBIN], [rm], [/bin/rm])
AC_PATH_PROG([DIFFBIN], [diff], [/usr/bin/diff])
AC_PATH_PROG([CHATTRBIN], [chattr], [/usr/bin/chattr])
AC_PATH_PROG([LVCREATEBIN], [lvcreate], [/sbin/lvcreate])
AC_PATH_PROG([LVREMOVEBIN], [lvremove], [/sbin/lvremove])
AC_PATH_PROG([LVSBIN], [lvs], [/sbin/lvs])
AC_PATH_PROG([LVCHANGEBIN], [lvchange], [/sbin/lvchange])
AC_PATH_PROG([LVMBIN], [lvm], [/sbin/lvm])
AC_PATH_PROG([LVRENAMEBIN], [lvrename], [/sbin/lvrename])

AC_DEFINE_UNQUOTED([CHSNAPBIN], ["$CHSNAPBIN"], [Path of chsnap program.])
AC_DEFINE_UNQUOTED([CPBIN], ["$CPBIN"], [Path of cp program.])
AC_DEFINE_UNQUOTED([TOUCHBIN], ["$TOUCHBIN"], [Path of touch program.])
AC_DEFINE_UNQUOTED([RMBIN], ["$RMBIN"], [Path of rm program.])
AC_DEFINE_UNQUOTED([DIFFBIN], ["$DIFFBIN"], [Path of diff program.])
AC_DEFINE_UNQUOTED([CHATTRBIN], ["$CHATTRBIN"], [Path of chattr program.])
AC_DEFINE_UNQUOTED([LVCREATEBIN], ["$LVCREATEBIN"], [Path of lvcreate program.])
AC_DEFINE_UNQUOTED([LVREMOVEBIN], ["$LVREMOVEBIN"], [Path of lvremove program.])
AC_DEFINE_UNQUOTED([LVSBIN], ["$LVSBIN"], [Path of lvs program.])
AC_DEFINE_UNQUOTED([LVCHANGEBIN], ["$LVCHANGEBIN"], [Path of lvchange program.])
AC_DEFINE_UNQUOTED([LVMBIN], ["$LVMBIN"], [Path of lvm program.])
AC_DEFINE_UNQUOTED([LVRENAMEBIN], ["$LVRENAMEBIN"], [Path of lvrename program.])
AC_PATH_PROG([BTRFS_BIN], [btrfs], [/usr/sbin/btrfs])
AC_PATH_PROG([CHATTR_BIN], [chattr], [/usr/bin/chattr])
AC_PATH_PROG([CHSNAP_BIN], [chsnap], [/sbin/chsnap])
AC_PATH_PROG([CP_BIN], [cp], [/bin/cp])
AC_PATH_PROG([DIFF_BIN], [diff], [/usr/bin/diff])
AC_PATH_PROG([FINDMNT_BIN], [findmnt], [/usr/bin/findmnt])
AC_PATH_PROG([LVCHANGE_BIN], [lvchange], [/sbin/lvchange])
AC_PATH_PROG([LVCREATE_BIN], [lvcreate], [/sbin/lvcreate])
AC_PATH_PROG([LVM_BIN], [lvm], [/sbin/lvm])
AC_PATH_PROG([LVREMOVE_BIN], [lvremove], [/sbin/lvremove])
AC_PATH_PROG([LVRENAME_BIN], [lvrename], [/sbin/lvrename])
AC_PATH_PROG([LVS_BIN], [lvs], [/sbin/lvs])
AC_PATH_PROG([REALPATH_BIN], [realpath], [/usr/bin/realpath])
AC_PATH_PROG([RM_BIN], [rm], [/bin/rm])
AC_PATH_PROG([RMDIR_BIN], [rmdir], [/bin/rmdir])
AC_PATH_PROG([TOUCH_BIN], [touch], [/usr/bin/touch])

AC_DEFINE_UNQUOTED([BTRFS_BIN], ["$BTRFS_BIN"], [Path of btrfs program.])
AC_DEFINE_UNQUOTED([CHATTR_BIN], ["$CHATTR_BIN"], [Path of chattr program.])
AC_DEFINE_UNQUOTED([CHSNAP_BIN], ["$CHSNAP_BIN"], [Path of chsnap program.])
AC_DEFINE_UNQUOTED([CP_BIN], ["$CP_BIN"], [Path of cp program.])
AC_DEFINE_UNQUOTED([DIFF_BIN], ["$DIFF_BIN"], [Path of diff program.])
AC_DEFINE_UNQUOTED([FINDMNT_BIN], ["$FINDMNT_BIN"], [Path of findmnt program.])
AC_DEFINE_UNQUOTED([LVCHANGE_BIN], ["$LVCHANGE_BIN"], [Path of lvchange program.])
AC_DEFINE_UNQUOTED([LVCREATE_BIN], ["$LVCREATE_BIN"], [Path of lvcreate program.])
AC_DEFINE_UNQUOTED([LVM_BIN], ["$LVM_BIN"], [Path of lvm program.])
AC_DEFINE_UNQUOTED([LVREMOVE_BIN], ["$LVREMOVE_BIN"], [Path of lvremove program.])
AC_DEFINE_UNQUOTED([LVRENAME_BIN], ["$LVRENAME_BIN"], [Path of lvrename program.])
AC_DEFINE_UNQUOTED([LVS_BIN], ["$LVS_BIN"], [Path of lvs program.])
AC_DEFINE_UNQUOTED([REALPATH_BIN], ["$REALPATH_BIN"], [Path of realpath program.])
AC_DEFINE_UNQUOTED([RM_BIN], ["$RM_BIN"], [Path of rm program.])
AC_DEFINE_UNQUOTED([RMDIR_BIN], ["$RMDIR_BIN"], [Path of rmdir program.])
AC_DEFINE_UNQUOTED([TOUCH_BIN], ["$TOUCH_BIN"], [Path of touch program.])

CFLAGS="${CFLAGS} -std=c99 -Wall -Wextra -Wformat -Wmissing-prototypes -Wno-unused-parameter"
CXXFLAGS="${CXXFLAGS} -std=c++11 -Wall -Wextra -Wformat -Wnon-virtual-dtor -Wno-unused-parameter -Wsuggest-override"
Expand Down
14 changes: 7 additions & 7 deletions snapper/Lvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ namespace snapper
: Filesystem(subvolume, root_prefix), mount_type(mount_type),
cache(LvmCache::get_lvm_cache())
{
if (access(LVCREATEBIN, X_OK) != 0)
if (access(LVCREATE_BIN, X_OK) != 0)
{
SN_THROW(ProgramNotInstalledException(LVCREATEBIN " not installed"));
SN_THROW(ProgramNotInstalledException(LVCREATE_BIN " not installed"));
}

if (access(LVSBIN, X_OK) != 0)
if (access(LVS_BIN, X_OK) != 0)
{
SN_THROW(ProgramNotInstalledException(LVSBIN " not installed"));
SN_THROW(ProgramNotInstalledException(LVS_BIN " not installed"));
}

if (access(LVCHANGEBIN, X_OK) != 0)
if (access(LVCHANGE_BIN, X_OK) != 0)
{
SN_THROW(ProgramNotInstalledException(LVCHANGEBIN " not installed"));
SN_THROW(ProgramNotInstalledException(LVCHANGE_BIN " not installed"));
}

bool found = false;
Expand Down Expand Up @@ -483,7 +483,7 @@ namespace snapper

LvmCapabilities::LvmCapabilities()
{
SystemCmd cmd({ LVMBIN, "version" });
SystemCmd cmd({ LVM_BIN, "version" });

if (cmd.retcode() != 0 || cmd.get_stdout().empty())
{
Expand Down
16 changes: 8 additions & 8 deletions snapper/LvmCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace snapper
{
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upg_lock);

SystemCmd::Args cmd_args = { LVCHANGEBIN };
SystemCmd::Args cmd_args = { LVCHANGE_BIN };
if (!caps->get_ignoreactivationskip().empty())
cmd_args << caps->get_ignoreactivationskip();
cmd_args << "--activate" << "y" << full_name();
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace snapper
{
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upg_lock);

SystemCmd cmd({ LVCHANGEBIN, "--activate", "n", full_name() });
SystemCmd cmd({ LVCHANGE_BIN, "--activate", "n", full_name() });
if (cmd.retcode() != 0)
{
y2err("lvm cache: " << full_name() << " deactivation failed!");
Expand All @@ -144,7 +144,7 @@ namespace snapper
{
boost::unique_lock<boost::shared_mutex> unique_lock(lv_mutex);

SystemCmd cmd({ LVSBIN, "--noheadings", "--options", "lv_attr,segtype", full_name() });
SystemCmd cmd({ LVS_BIN, "--noheadings", "--options", "lv_attr,segtype", full_name() });
if (cmd.retcode() != 0 || cmd.get_stdout().empty())
{
y2err("lvm cache: failed to get info about " << full_name());
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace snapper
{
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upg_lock);

SystemCmd cmd({ LVCHANGEBIN, "--permission", read_only ? "r" : "rw", full_name() });
SystemCmd cmd({ LVCHANGE_BIN, "--permission", read_only ? "r" : "rw", full_name() });
if (cmd.retcode() != 0)
{
y2err("lvm cache: " << full_name() << " setting permission failed!");
Expand Down Expand Up @@ -339,7 +339,7 @@ namespace snapper

boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upg_lock);

SystemCmd cmd({ LVCREATEBIN, "--permission", read_only ? "r" : "rw", "--snapshot",
SystemCmd cmd({ LVCREATE_BIN, "--permission", read_only ? "r" : "rw", "--snapshot",
"--name", lv_snapshot_name, full_name(lv_origin_name) });

if (cmd.retcode() != 0)
Expand All @@ -363,7 +363,7 @@ namespace snapper
}
else
{
SystemCmd cmd({ LVSBIN, "--noheadings", "--options", "lv_attr,segtype", full_name(lv_name) });
SystemCmd cmd({ LVS_BIN, "--noheadings", "--options", "lv_attr,segtype", full_name(lv_name) });
if (cmd.retcode() != 0 || cmd.get_stdout().empty())
{
y2err("lvm cache: failed to get info about " << full_name(lv_name));
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace snapper
// wait for all individual lv cache operations under shared vg lock to finish
boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upg_lock);

SystemCmd cmd({ LVREMOVEBIN, "--force", full_name(lv_name) });
SystemCmd cmd({ LVREMOVE_BIN, "--force", full_name(lv_name) });
if (cmd.retcode() != 0)
throw LvmCacheException();

Expand Down Expand Up @@ -552,7 +552,7 @@ namespace snapper
void
LvmCache::add_vg(const string& vg_name, const string& include_lv_name)
{
SystemCmd cmd({ LVSBIN, "--noheadings", "--options", "lv_name,lv_attr,segtype", vg_name });
SystemCmd cmd({ LVS_BIN, "--noheadings", "--options", "lv_name,lv_attr,segtype", vg_name });
if (cmd.retcode() != 0)
{
y2err("lvm cache: failed to get info about VG " << vg_name);
Expand Down
4 changes: 2 additions & 2 deletions snapper/Snapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ namespace snapper

sysconfig.save();

SystemCmd cmd({ RMBIN, "--", CONFIGS_DIR "/" + config_name });
SystemCmd cmd({ RM_BIN, "--", CONFIGS_DIR "/" + config_name });

SN_RETHROW(e);
}
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace snapper
SN_THROW(DeleteConfigFailedException("deleting snapshot failed"));
}

SystemCmd cmd1({ RMBIN, "--", CONFIGS_DIR "/" + config_name });
SystemCmd cmd1({ RM_BIN, "--", CONFIGS_DIR "/" + config_name });
if (cmd1.retcode() != 0)
{
SN_THROW(DeleteConfigFailedException("deleting config-file failed"));
Expand Down
11 changes: 1 addition & 10 deletions snapper/SnapperDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,16 @@
#define SNAPSHOT_NAME "snapshot"


// commands
// commands - more in configure.ac

#define SH_BIN "/bin/sh"
#define SSH_BIN "/usr/bin/ssh"

#define BTRFS_BIN "/usr/sbin/btrfs"

#define SYSTEMCTL_BIN "/usr/bin/systemctl"

#define FINDMNT_BIN "/usr/bin/findmnt"
#define REALPATH_BIN "/usr/bin/realpath"

#define CP_BIN "/usr/bin/cp"
#define SCP_BIN "/usr/bin/scp"
#define MKDIR_BIN "/usr/bin/mkdir"

#define RM_BIN "/usr/bin/rm"
#define RMDIR_BIN "/usr/bin/rmdir"


// keys from the config files

Expand Down

0 comments on commit ab65f09

Please sign in to comment.