]> git.hungrycats.org Git - bees/commitdiff
main: the base directory for `--strip-paths` should be root_fd, not cwd
authorZygo Blaxell <bees@furryterror.org>
Mon, 27 Jan 2025 16:39:36 +0000 (11:39 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 7 Feb 2025 03:42:15 +0000 (22:42 -0500)
The cwd is where core dumps and various profiling and verification
libraries want to write their data, whereas root_fd is the root of the
target filesystem.  These are often intentionally different.  When
they are different, `--strip-paths` sets the wrong prefix to strip
from paths.

Once the root fd has been established, we can set the path prefix to
the string prefix that we'll get from future calls to `name_fd`.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees.cc

index e4a96abf445e456c2ea85f7944fdede271efd615..7d51651eb114603265b6f41ec5596e1e2e4cd522 100644 (file)
@@ -703,9 +703,8 @@ bees_main(int argc, char *argv[])
        shared_ptr<BeesContext> bc = make_shared<BeesContext>();
        BEESLOGDEBUG("context constructed");
 
-       string cwd(readlink_or_die("/proc/self/cwd"));
-
        // Defaults
+       bool use_relative_paths = false;
        bool chatter_prefix_timestamp = true;
        double thread_factor = 0;
        unsigned thread_count = 0;
@@ -777,7 +776,7 @@ bees_main(int argc, char *argv[])
                                thread_min = stoul(optarg);
                                break;
                        case 'P':
-                               crucible::set_relative_path(cwd);
+                               use_relative_paths = true;
                                break;
                        case 'T':
                                chatter_prefix_timestamp = false;
@@ -795,7 +794,7 @@ bees_main(int argc, char *argv[])
                                root_scan_mode = static_cast<BeesRoots::ScanMode>(stoul(optarg));
                                break;
                        case 'p':
-                               crucible::set_relative_path("");
+                               use_relative_paths = false;
                                break;
                        case 't':
                                chatter_prefix_timestamp = true;
@@ -865,6 +864,11 @@ bees_main(int argc, char *argv[])
        BEESLOGNOTICE("setting root path to '" << root_path << "'");
        bc->set_root_path(root_path);
 
+       // Set path prefix
+       if (use_relative_paths) {
+               crucible::set_relative_path(name_fd(bc->root_fd()));
+       }
+
        // Workaround for btrfs send
        bc->roots()->set_workaround_btrfs_send(workaround_btrfs_send);