From 755f16a948d822f3cd86bb79d07e91d060e6d6ab Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:42:37 +0100 Subject: [PATCH 1/9] crucible: Allow setting a relative path option for name_fd() This commit adds an option to store a relative path in prepartion for more human-friendly log output. Signed-off-by: Kai Krakow --- include/crucible/fd.h | 4 ++++ lib/fd.cc | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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()); } From 52997936d5e8204e50b36678e3b6af68fb1b1cc2 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:46:41 +0100 Subject: [PATCH 2/9] getopt: Add logic to set relative path from $CWD This commit adds a new option to set relative path output for name_fd(). Signed-off-by: Kai Krakow --- src/bees.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bees.cc b/src/bees.cc index 9458c91..d5dc9c5 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; @@ -607,10 +611,12 @@ bees_main(int argc, char *argv[]) static struct option long_options[] = { { "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); 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) { From 0c6a4d00c84f36e829f3ad8252a7efa336d3b143 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:49:34 +0100 Subject: [PATCH 3/9] Remove filter path logic from frontend script Now with relative path filtering in place, we can now give sub spawning subshells in the frontend script. Signed-off-by: Kai Krakow --- scripts/beesd.conf.sample | 2 +- scripts/beesd.in | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/scripts/beesd.conf.sample b/scripts/beesd.conf.sample index 53060fa..1d8d26e 100644 --- a/scripts/beesd.conf.sample +++ b/scripts/beesd.conf.sample @@ -16,7 +16,7 @@ UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # BEESSTATUS="$WORK_DIR/$UUID.status" ## Make path shorter in logs -# LOG_SHORT_PATH=N +# OPTIONS="--relative-paths" ## Remove timestamp from bees output # LOG_FILTER_TIME=N diff --git a/scripts/beesd.in b/scripts/beesd.in index 044fc98..fc0a2ea 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,6 @@ 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 +cd $MNT_DIR && @LIBEXEC_PREFIX@/bees ${ARGUMENTS[@]} $OPTIONS "$MNT_DIR" 3>&1 2>&1 exit 0 From 21212cd3e365dbe0eb6aa4186e75fc168232d650 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:53:00 +0100 Subject: [PATCH 4/9] Fix example config for timestamp logging --- scripts/beesd.conf.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/beesd.conf.sample b/scripts/beesd.conf.sample index 1d8d26e..79512d7 100644 --- a/scripts/beesd.conf.sample +++ b/scripts/beesd.conf.sample @@ -19,7 +19,7 @@ UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # OPTIONS="--relative-paths" ## Remove timestamp from bees output -# LOG_FILTER_TIME=N +# OPTIONS="--notimestamps" ## Bees DB size # Hash Table Sizing From f7320baa56aa32f11714be1c3b5d1ccf766ae255 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:53:25 +0100 Subject: [PATCH 5/9] Fix indentation/alignment after integration --- src/bees.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bees.cc b/src/bees.cc index d5dc9c5..415d590 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -609,11 +609,11 @@ 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' }, + { "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' } + { "help", no_argument, NULL, 'h' } }; c = getopt_long(argc, argv, "TtPph", long_options, &option_index); From d9301364841b0f77ed77aa6ab313ea498ba0a8ec Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 12 Nov 2017 15:55:02 +0100 Subject: [PATCH 6/9] Remove process forking from frontend script Now with the patches integrated to filter logging output, we can finally remove forking a subprocess and stop redirecting file descriptors. We instead use exec to replace the process with the final daemon. Signed-off-by: Kai Krakow --- scripts/beesd.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/beesd.in b/scripts/beesd.in index fc0a2ea..b4c466b 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -115,6 +115,4 @@ fi MNT_DIR="${MNT_DIR//\/\//\/}" -cd $MNT_DIR && @LIBEXEC_PREFIX@/bees ${ARGUMENTS[@]} $OPTIONS "$MNT_DIR" 3>&1 2>&1 - -exit 0 +cd $MNT_DIR && exec @LIBEXEC_PREFIX@/bees ${ARGUMENTS[@]} $OPTIONS "$MNT_DIR" From 93ba0f48de280f46ad70386378dfed69ebdd350b Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Mon, 13 Nov 2017 01:04:56 +0100 Subject: [PATCH 7/9] Make clear that options must be supplied in one variable Previously, expectations may fail when just uncommenting both lines. --- scripts/beesd.conf.sample | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/beesd.conf.sample b/scripts/beesd.conf.sample index 79512d7..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 -# OPTIONS="--relative-paths" - -## Remove timestamp from bees output -# OPTIONS="--notimestamps" +## Default options to apply, see --help for details +# OPTIONS="--relative-paths --notimestamps" ## Bees DB size # Hash Table Sizing From 270a91cf17783813edaa75fb9766858dcf8e1689 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 14 Nov 2017 06:53:48 +0100 Subject: [PATCH 8/9] Fix a fallthrough error in GCC 7+ GCC 7 and higher turn a previous warning into an error for implicit fallthrough. Let's hint the compiler that this is intentional here. Signed-off-by: Kai Krakow --- src/bees.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bees.cc b/src/bees.cc index 415d590..ea3e10c 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -635,7 +635,7 @@ bees_main(int argc, char *argv[]) crucible::set_relative_path(""); break; case 'h': - do_cmd_help(argv); + do_cmd_help(argv); // fallthrough default: return 2; } From 3024e4335552613d197cab1f139a4bfa8b8d05c4 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 14 Nov 2017 06:53:48 +0100 Subject: [PATCH 9/9] Fix a fallthrough error in GCC 7+ GCC 7 and higher turn a previous warning into an error for implicit fallthrough. Let's hint the compiler that this is intentional here. Signed-off-by: Kai Krakow --- src/bees.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bees.cc b/src/bees.cc index d5dc9c5..daceeb8 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -635,7 +635,7 @@ bees_main(int argc, char *argv[]) crucible::set_relative_path(""); break; case 'h': - do_cmd_help(argv); + do_cmd_help(argv); // fallthrough default: return 2; }