From cdca2bcdcde7c0decf5f0553d37a811a677a4aa8 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 31 Oct 2018 16:42:46 -0400 Subject: [PATCH] main: single BeesContext instance per process After weeks of testing I copied part of a change to main without copying the rest of the change, leading to an immediate segfault on startup. So here is the rest of the change: limit the number of BeesContexts per process to 1. This change was discussed at https://github.com/Zygo/bees/issues/54#issuecomment-360332529 but there are more reasons to do it now: the candidates to replace the current hash table format are less forgiving of sharing hash tables, and it may even become necessary to have more than one hash table per BeesContext instance (e.g. to keep datasum and nodatasum data separate). Signed-off-by: Zygo Blaxell --- src/bees.cc | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/bees.cc b/src/bees.cc index 5367de8..c51b897 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -32,7 +32,7 @@ using namespace std; int bees_log_level = 8; -int +void do_cmd_help(char *argv[]) { // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 @@ -73,7 +73,6 @@ do_cmd_help(char *argv[]) "\n" // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 << endl; - return 0; } // tracing ---------------------------------------- @@ -655,11 +654,11 @@ bees_main(int argc, char *argv[]) BeesNote::set_name("bees"); BEESNOTE("main"); - list> all_contexts; - shared_ptr bc; - THROW_CHECK1(invalid_argument, argc, argc >= 0); + // Create a context so we can apply configuration to it + shared_ptr bc = make_shared(); + string cwd(readlink_or_die("/proc/self/cwd")); // Defaults @@ -705,7 +704,7 @@ bees_main(int argc, char *argv[]) // Parse options int c; - while (1) { + while (true) { int option_index = 0; c = getopt_long(argc, argv, getopt_list.c_str(), long_options, &option_index); @@ -756,12 +755,17 @@ bees_main(int argc, char *argv[]) break; case 'h': - do_cmd_help(argv); // fallthrough default: - return 2; + do_cmd_help(argv); + return EXIT_FAILURE; } } + if (optind + 1 != argc) { + BEESLOGERR("Only one filesystem path per bees process"); + return EXIT_FAILURE; + } + Chatter::enable_timestamp(chatter_prefix_timestamp); if (!relative_path().empty()) { @@ -807,18 +811,7 @@ bees_main(int argc, char *argv[]) bc->roots()->set_workaround_btrfs_send(workaround_btrfs_send); // Create a context and start crawlers - bool did_subscription = false; - while (optind < argc) { - catch_all([&]() { - bc = make_shared(bc); - bc->set_root_path(argv[optind++]); - did_subscription = true; - }); - } - - if (!did_subscription) { - BEESLOGWARN("WARNING: no filesystems added"); - } + bc->set_root_path(argv[optind++]); BeesThread status_thread("status", [&]() { bc->dump_status(); @@ -828,7 +821,7 @@ bees_main(int argc, char *argv[]) bc->show_progress(); // That is all. - return 0; + return EXIT_SUCCESS; } int @@ -838,7 +831,7 @@ main(int argc, char *argv[]) if (argc < 2) { do_cmd_help(argv); - return 2; + return EXIT_FAILURE; } int rv = 1;