diff options
Diffstat (limited to 'bbot/agent/agent.cxx')
-rw-r--r-- | bbot/agent/agent.cxx | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx index 2c4e03e..6c2e0d9 100644 --- a/bbot/agent/agent.cxx +++ b/bbot/agent/agent.cxx @@ -7,7 +7,7 @@ #include <limits.h> // PATH_MAX #include <signal.h> // signal() #include <stdlib.h> // rand_r() -#include <unistd.h> // sleep(), realink(), getuid(), fsync(), [f]stat() +#include <unistd.h> // sleep(), getuid(), fsync(), [f]stat() #include <sys/types.h> // stat #include <sys/stat.h> // [f]stat() #include <sys/file.h> // flock() @@ -21,11 +21,12 @@ #include <chrono> #include <random> #include <iostream> +#include <system_error> // generic_category() #include <libbutl/pager.mxx> #include <libbutl/sha256.mxx> #include <libbutl/openssl.mxx> -#include <libbutl/filesystem.mxx> // dir_iterator, try_rmfile() +#include <libbutl/filesystem.mxx> // dir_iterator, try_rmfile(), readsymlink() #include <libbbot/manifest.hxx> @@ -572,29 +573,22 @@ try // Resolve the link to subvolume path. // dir_path sp; // <name>-<P>.<R> + try { - char b [PATH_MAX + 1]; - ssize_t r (readlink (lp.string ().c_str (), b, sizeof (b))); + sp = path_cast<dir_path> (readsymlink (lp)); - if (r == -1) - { - if (errno != ENOENT) - throw_generic_error (errno); - } - else if (static_cast<size_t> (r) >= sizeof (b)) - throw_generic_error (EINVAL); - else - { - b[r] = '\0'; - sp = dir_path (b); - if (sp.relative ()) - sp = md / sp; - } + if (sp.relative ()) + sp = md / sp; } catch (const system_error& e) { - fail << "unable to read subvolume link " << lp << ": " << e; + // Leave the subvolume path empty if the subvolume link doesn't + // exist and fail on any other error. + // + if (e.code ().category () != std::generic_category () || + e.code ().value () != ENOENT) + fail << "unable to read subvolume link " << lp << ": " << e; } none = none && sp.empty (); |