return string(_(" Global options:")) + '\n'
+ _("\t--quiet, -q\t\t\tSuppress normal output.") + '\n'
+ _("\t--verbose, -v\t\t\tIncrease verbosity.") + '\n'
+ + _("\t--debug\t\t\t\tTurn on debugging.") + '\n'
+ _("\t--utc\t\t\t\tDisplay dates and times in UTC.") + '\n'
+ _("\t--iso\t\t\t\tDisplay dates and times in ISO format.") + '\n'
+ _("\t--table-style, -t <style>\tTable style (integer).") + '\n'
const vector<Option> options = {
Option("quiet", no_argument, 'q'),
Option("verbose", no_argument, 'v'),
+ Option("debug", no_argument),
Option("utc", no_argument),
Option("iso", no_argument),
Option("table-style", required_argument, 't'),
_quiet = opts.has_option("quiet");
_verbose = opts.has_option("verbose");
+ _debug = opts.has_option("debug");
_utc = opts.has_option("utc");
_iso = opts.has_option("iso");
_no_dbus = opts.has_option("no-dbus");
bool quiet() const { return _quiet; }
bool verbose() const { return _verbose; }
+ bool debug() const { return _debug; }
bool utc() const { return _utc; }
bool iso() const { return _iso; }
bool no_dbus() const { return _no_dbus; }
bool _quiet;
bool _verbose;
+ bool _debug;
bool _utc;
bool _iso;
bool _no_dbus;
/*
* Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2020] SUSE LLC
+ * Copyright (c) [2016-2023] SUSE LLC
*
* All Rights Reserved.
*
};
+static bool log_debug = false;
+
+
void
log_do(LogLevel level, const string& component, const char* file, const int line, const char* func,
const string& text)
bool
log_query(LogLevel level, const string& component)
{
- return level == ERROR;
+ return log_debug || level == ERROR;
}
GlobalOptions global_options(get_opts);
+ if (global_options.debug())
+ {
+ log_debug = true;
+ }
+
if (global_options.version())
{
cout << "snapper " << Snapper::compileVersion() << endl;
try
{
+ y2mil("constructing ProxySnapper object");
+
ProxySnappers snappers(global_options.no_dbus() ? ProxySnappers::createLib(global_options.root()) :
ProxySnappers::createDbus());
+ y2mil("executing command");
+
if (cmd->needs_snapper)
(*cmd->cmd_func)(global_options, get_opts, &snappers, snappers.getSnapper(global_options.config()));
else
#include <unistd.h>
-#include <stdlib.h>
+#include <cstdlib>
#include <sys/types.h>
#include <pwd.h>
#include "DBusConnection.h"
+
namespace DBus
{
if (dbus_error_is_set(&err))
{
dbus_error_free(&err);
- throw FatalException();
+ SN_THROW(FatalException());
}
if (!conn)
{
- throw FatalException();
+ SN_THROW(FatalException());
}
}
if (dbus_error_is_set(&err))
{
dbus_error_free(&err);
- throw FatalException();
+ SN_THROW(FatalException());
}
if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
- throw FatalException();
+ SN_THROW(FatalException());
}
}
if (!dbus_connection_send(conn, m.get_message(), NULL))
{
- throw FatalException();
+ SN_THROW(FatalException());
}
}
0x7fffffff, &err);
if (dbus_error_is_set(&err))
{
- throw ErrorException(err);
+ SN_THROW(ErrorException(err));
}
return Message(tmp, false);
if (dbus_error_is_set(&err))
{
dbus_error_free(&err);
- throw FatalException();
+ SN_THROW(FatalException());
}
}
if (dbus_error_is_set(&err))
{
dbus_error_free(&err);
- throw FatalException();
+ SN_THROW(FatalException());
}
}
string sender = m.get_sender();
if (sender.empty())
{
- throw FatalException();
+ SN_THROW(FatalException());
}
DBusError err;
if (dbus_error_is_set(&err))
{
dbus_error_free(&err);
- throw FatalException();
+ SN_THROW(FatalException());
}
return uid;
: Connection(type), idle_timeout(-1)
{
if (pipe(wakeup_pipe) != 0)
- throw FatalException();
+ SN_THROW(FatalException());
if (!dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggled_watch,
this, NULL))
- throw FatalException();
+ SN_THROW(FatalException());
if (!dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout,
toggled_timeout, this, NULL))
- throw FatalException();
+ SN_THROW(FatalException());
dbus_connection_set_wakeup_main_function(conn, wakeup_main, this, NULL);
}
int r = poll(&pollfds[0], pollfds.size(), timeout.count());
if (r == -1)
- throw FatalException();
+ SN_THROW(FatalException());
periodic();
if (it->dbus_watch == dbus_watch)
return it;
- throw FatalException();
+ SN_THROW(FatalException());
}
if (it->dbus_timeout == dbus_timeout)
return it;
- throw FatalException();
+ SN_THROW(FatalException());
}
*/
-#include <assert.h>
-#include <stdlib.h>
+#include <cassert>
+#include <cstdlib>
#include "DBusMessage.h"
{
iters.push_back(new DBusMessageIter());
if (!dbus_message_iter_init(msg.get_message(), top()))
- throw FatalException();
+ SN_THROW(FatalException());
}
{
DBusMessageIter* iter2 = new DBusMessageIter();
if (!dbus_message_iter_open_container(top(), DBUS_TYPE_STRUCT, NULL, iter2))
- throw FatalException();
+ SN_THROW(FatalException());
iters.push_back(iter2);
}
DBusMessageIter* iter2 = top();
iters.pop_back();
if (!dbus_message_iter_close_container(top(), iter2))
- throw FatalException();
+ SN_THROW(FatalException());
delete iter2;
}
{
DBusMessageIter* iter2 = new DBusMessageIter();
if (!dbus_message_iter_open_container(top(), DBUS_TYPE_ARRAY, signature, iter2))
- throw FatalException();
+ SN_THROW(FatalException());
iters.push_back(iter2);
}
DBusMessageIter* iter2 = top();
iters.pop_back();
if (!dbus_message_iter_close_container(top(), iter2))
- throw FatalException();
+ SN_THROW(FatalException());
delete iter2;
}
{
DBusMessageIter* iter2 = new DBusMessageIter();
if (!dbus_message_iter_open_container(top(), DBUS_TYPE_DICT_ENTRY, 0, iter2))
- throw FatalException();
+ SN_THROW(FatalException());
iters.push_back(iter2);
}
DBusMessageIter* iter2 = top();
iters.pop_back();
if (!dbus_message_iter_close_container(top(), iter2))
- throw FatalException();
+ SN_THROW(FatalException());
delete iter2;
}
operator>>(Unmarshaller& unmarshaller, bool& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_BOOLEAN)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
dbus_bool_t tmp;
dbus_message_iter_get_basic(unmarshaller.top(), &tmp);
{
dbus_bool_t tmp = data;
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_BOOLEAN, &tmp))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator>>(Unmarshaller& unmarshaller, dbus_uint16_t& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_UINT16)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
dbus_message_iter_get_basic(unmarshaller.top(), &data);
dbus_message_iter_next(unmarshaller.top());
operator<<(Marshaller& marshaller, dbus_uint16_t data)
{
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_UINT16, &data))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator>>(Unmarshaller& unmarshaller, dbus_uint32_t& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_UINT32)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
dbus_message_iter_get_basic(unmarshaller.top(), &data);
dbus_message_iter_next(unmarshaller.top());
operator<<(Marshaller& marshaller, dbus_uint32_t data)
{
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_UINT32, &data))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator>>(Unmarshaller& unmarshaller, dbus_uint64_t& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_UINT64)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
dbus_message_iter_get_basic(unmarshaller.top(), &data);
dbus_message_iter_next(unmarshaller.top());
operator<<(Marshaller& marshaller, dbus_uint64_t data)
{
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_UINT64, &data))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator>>(Unmarshaller& unmarshaller, time_t& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_INT64)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
dbus_uint64_t tmp;
dbus_message_iter_get_basic(unmarshaller.top(), &tmp);
{
dbus_uint64_t tmp = data;
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_INT64, &tmp))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator<<(Marshaller& marshaller, const char* data)
{
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_STRING, &data))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
if (*it == '\\')
{
if (++it == in.end())
- throw MarshallingException();
+ SN_THROW(MarshallingException());
if (*it == '\\')
{
for (int i = 0; i < 2; ++i)
{
if (++it == in.end() || !isxdigit(*it))
- throw MarshallingException();
+ SN_THROW(MarshallingException());
t1 += *it;
}
}
else
{
- throw MarshallingException();
+ SN_THROW(MarshallingException());
}
}
else
operator>>(Unmarshaller& unmarshaller, string& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_STRING)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
const char* p = NULL;
dbus_message_iter_get_basic(unmarshaller.top(), &p);
string tmp = marshaller.escape(data);
const char* p = tmp.c_str();
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_STRING, &p))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
operator>>(Unmarshaller& unmarshaller, map<string, string>& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_ARRAY)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
unmarshaller.open_recurse();
while (unmarshaller.get_type() != DBUS_TYPE_INVALID)
{
if (unmarshaller.get_signature() != "{ss}")
- throw MarshallingException();
+ SN_THROW(MarshallingException());
unmarshaller.open_recurse();
#include "snapper/Exception.h"
+using namespace snapper;
+
+
namespace DBus
{
using std::string;
{
explicit ErrorException(const DBusError err)
: Exception("dbus error exception"), err(err) {}
- virtual ~ErrorException() throw() { dbus_error_free(&err); }
- virtual const char* name() const throw() { return err.name; }
- virtual const char* message() const throw() { return err.message; }
+ virtual ~ErrorException() { dbus_error_free(&err); }
+ virtual const char* name() const { return err.name; }
+ virtual const char* message() const { return err.message; }
DBusError err;
};
: Message(dbus_message_new_method_return(m.get_message()), false)
{
if (m.get_type() != DBUS_MESSAGE_TYPE_METHOD_CALL)
- throw FatalException();
+ SN_THROW(FatalException());
}
};
: Message(dbus_message_new_error(m.get_message(), error_msg, error_code), false)
{
if (m.get_type() != DBUS_MESSAGE_TYPE_METHOD_CALL)
- throw FatalException();
+ SN_THROW(FatalException());
}
};
Unmarshaller& operator>>(Unmarshaller& unmarshaller, vector<Type>& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_ARRAY)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
unmarshaller.open_recurse();
while (unmarshaller.get_type() != DBUS_TYPE_INVALID)
{
if (unmarshaller.get_signature() != TypeInfo<Type>::signature)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
Type tmp;
unmarshaller >> tmp;
operator>>(Unmarshaller& unmarshaller, FileDescriptor& data)
{
if (unmarshaller.get_type() != DBUS_TYPE_UNIX_FD)
- throw MarshallingException();
+ SN_THROW(MarshallingException());
int fd;
dbus_message_iter_get_basic(unmarshaller.top(), &fd);
{
const int fd = data.get_fd();
if (!dbus_message_iter_append_basic(marshaller.top(), DBUS_TYPE_UNIX_FD, &fd))
- throw FatalException();
+ SN_THROW(FatalException());
return marshaller;
}
int pipefd[2];
if (pipe2(pipefd, O_CLOEXEC) != 0)
- throw PipeException();
+ SN_THROW(PipeException());
_read_end.set_fd(pipefd[0]);
_write_end.set_fd(pipefd[1]);
<para>Increase verbosity.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--debug</option></term>
+ <listitem>
+ <para>Turn on debugging.</para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><option>--utc</option></term>
<listitem>
return it;
}
- throw NoComparison();
+ SN_THROW(NoComparison());
}
if (uid == 0)
return;
- throw Permissions();
+ SN_THROW(Permissions());
}
return;
}
- throw Permissions();
+ SN_THROW(Permissions());
}
continue;
if (it->has_lock(config_name))
- throw Lock();
+ SN_THROW(Lock());
}
}
Client::check_config_in_use(const MetaSnapper& meta_snapper) const
{
if (meta_snapper.use_count() != 0)
- throw ConfigInUse();
+ SN_THROW(ConfigInUse());
}
it1->mounts.find(make_pair(meta_snapper.configName(), number));
if (it2 != it1->mounts.end())
- throw SnapshotInUse();
+ SN_THROW(SnapshotInUse());
}
}
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
DBus::MessageMethodReturn reply(msg);
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
snapper->modifySnapshot(snap, smd);
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
bool read_only = snap->isReadOnly();
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
snap->setReadOnly(read_only);
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
uint64_t used_space = snap->getUsedSpace();
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
snap->mountFilesystemSnapshot(user_request);
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
snap->umountFilesystemSnapshot(user_request);
Snapshots& snapshots = snapper->getSnapshots();
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
- throw IllegalSnapshotException();
+ SN_THROW(IllegalSnapshotException());
string mount_point = snap->snapshotDir();
if (it->configName() == config_name)
return it;
- throw UnknownConfig();
+ SN_THROW(UnknownConfig());
}