diff --git a/include/crucible/fd.h b/include/crucible/fd.h index f905812..6890417 100644 --- a/include/crucible/fd.h +++ b/include/crucible/fd.h @@ -57,6 +57,10 @@ namespace crucible { typedef ResourceHandle Fd; + static string __relative_path; + void set_relative_path(string path); + string relative_path(); + // Functions named "foo_or_die" throw exceptions on failure. // Attempt to open the file with the given mode diff --git a/lib/fd.cc b/lib/fd.cc index be6177b..257ed56 100644 --- a/lib/fd.cc +++ b/lib/fd.cc @@ -527,6 +527,22 @@ namespace crucible { THROW_ERROR(runtime_error, "readlink: maximum buffer size exceeded"); } + string + relative_path() + { + return __relative_path; + } + + void + set_relative_path(string path) + { + path = path + "/"; + for (string::size_type i = path.find("//"); i != string::npos; i = path.find("//")) { + path.erase(i, 1); + } + __relative_path = path; + } + // Turn a FD into a human-recognizable filename OR an error message. string name_fd(int fd) @@ -534,7 +550,12 @@ namespace crucible { try { ostringstream oss; oss << "/proc/self/fd/" << fd; - return readlink_or_die(oss.str()); + string path = readlink_or_die(oss.str()); + if (!__relative_path.empty() && 0 == path.find(__relative_path)) + { + path.erase(0, __relative_path.length()); + } + return path; } catch (exception &e) { return string(e.what()); } diff --git a/scripts/beesd.conf.sample b/scripts/beesd.conf.sample index 53060fa..ee1413a 100644 --- a/scripts/beesd.conf.sample +++ b/scripts/beesd.conf.sample @@ -15,11 +15,8 @@ UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # BEESHOME="$MNT_DIR/.beeshome" # BEESSTATUS="$WORK_DIR/$UUID.status" -## Make path shorter in logs -# LOG_SHORT_PATH=N - -## Remove timestamp from bees output -# LOG_FILTER_TIME=N +## Default options to apply, see --help for details +# OPTIONS="--relative-paths --notimestamps" ## Bees DB size # Hash Table Sizing diff --git a/scripts/beesd.in b/scripts/beesd.in index 044fc98..b4c466b 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -64,7 +64,6 @@ MNT_DIR="${MNT_DIR:-$WORK_DIR/mnt/$UUID}" BEESHOME="${BEESHOME:-$MNT_DIR/.beeshome}" BEESSTATUS="${BEESSTATUS:-$WORK_DIR/$UUID.status}" DB_SIZE="${DB_SIZE:-$((64*AL16M))}" -LOG_SHORT_PATH="${LOG_SHORT_PATH:-N}" INFO "Check: Disk exists" if [ ! -b "/dev/disk/by-uuid/$UUID" ]; then @@ -116,14 +115,4 @@ fi MNT_DIR="${MNT_DIR//\/\//\/}" -filter_path(){ - if YN $LOG_SHORT_PATH; then - sed -e "s#$MNT_DIR##g" - else - cat - fi -} - -@LIBEXEC_PREFIX@/bees ${ARGUMENTS[@]} $OPTIONS "$MNT_DIR" 3>&1 2>&1 | filter_path - -exit 0 +cd $MNT_DIR && exec @LIBEXEC_PREFIX@/bees ${ARGUMENTS[@]} $OPTIONS "$MNT_DIR" diff --git a/src/bees.cc b/src/bees.cc index 63a39db..ea3e10c 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -37,6 +37,8 @@ do_cmd_help(char *argv[]) "\t-h, --help\t\tShow this help\n" "\t-t, --timestamps\tShow timestamps in log output (default)\n" "\t-T, --notimestamps\tOmit timestamps in log output\n" + "\t-p, --absolute-paths\tShow absolute paths (default)\n" + "\t-P, --relative-paths\tShow paths relative to $CWD\n" "\n" "Optional environment variables:\n" "\tBEESHOME\tPath to hash table and configuration files\n" @@ -597,6 +599,8 @@ bees_main(int argc, char *argv[]) THROW_CHECK1(invalid_argument, argc, argc >= 0); + string cwd(readlink_or_die("/proc/self/cwd")); + // Defaults bool chatter_prefix_timestamp = true; @@ -605,12 +609,14 @@ bees_main(int argc, char *argv[]) while (1) { int option_index = 0; static struct option long_options[] = { - { "timestamps", no_argument, NULL, 't' }, - { "notimestamps", no_argument, NULL, 'T' }, - { "help", no_argument, NULL, 'h' } + { "timestamps", no_argument, NULL, 't' }, + { "notimestamps", no_argument, NULL, 'T' }, + { "absolute-paths", no_argument, NULL, 'p' }, + { "relative-paths", no_argument, NULL, 'P' }, + { "help", no_argument, NULL, 'h' } }; - c = getopt_long(argc, argv, "Tth", long_options, &option_index); + c = getopt_long(argc, argv, "TtPph", long_options, &option_index); if (-1 == c) { break; } @@ -622,6 +628,12 @@ bees_main(int argc, char *argv[]) case 't': chatter_prefix_timestamp = true; break; + case 'P': + crucible::set_relative_path(cwd); + break; + case 'p': + crucible::set_relative_path(""); + break; case 'h': do_cmd_help(argv); // fallthrough default: @@ -631,6 +643,10 @@ bees_main(int argc, char *argv[]) Chatter::enable_timestamp(chatter_prefix_timestamp); + if (!relative_path().empty()) { + BEESLOG("using relative path " << relative_path() << "\n"); + } + // Create a context and start crawlers bool did_subscription = false; while (optind < argc) {