From 6bb4a026e56438d2a3ddf298c4f13c38b604ffbd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 9 Apr 2020 18:40:02 +0300 Subject: Use butl::readsymlink() instead of POSIX readlink() in agent --- bbot/agent/agent.cxx | 32 +++++++++++++------------------- 1 file 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 // PATH_MAX #include // signal() #include // rand_r() -#include // sleep(), realink(), getuid(), fsync(), [f]stat() +#include // sleep(), getuid(), fsync(), [f]stat() #include // stat #include // [f]stat() #include // flock() @@ -21,11 +21,12 @@ #include #include #include +#include // generic_category() #include #include #include -#include // dir_iterator, try_rmfile() +#include // dir_iterator, try_rmfile(), readsymlink() #include @@ -572,29 +573,22 @@ try // Resolve the link to subvolume path. // dir_path sp; // -

. + try { - char b [PATH_MAX + 1]; - ssize_t r (readlink (lp.string ().c_str (), b, sizeof (b))); + sp = path_cast (readsymlink (lp)); - if (r == -1) - { - if (errno != ENOENT) - throw_generic_error (errno); - } - else if (static_cast (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 (); -- cgit v1.1