diff --git a/.clang-format b/.clang-format index bb9ed90..faa0d55 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,7 @@ BasedOnStyle: Google Standard: Cpp11 SortIncludes: false +SortUsingDeclarations: false AccessModifierOffset: -4 PointerBindsToType: false DerivePointerBinding: false diff --git a/README.md b/README.md index 80611b6..15709d0 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ options: -h show this message and exit -c configuration.yaml use configuration.yaml as configuration -/etc/interception/udevmon.d/*.yaml is read if -c is not provided +/etc/interception/udevmon.d/*.yaml is also read if present ``` ### intercept diff --git a/udevmon.cpp b/udevmon.cpp index 03e5c3b..9fc83af 100644 --- a/udevmon.cpp +++ b/udevmon.cpp @@ -38,7 +38,7 @@ void print_usage(std::FILE *stream, const char *program) { " -h show this message and exit\n" " -c configuration.yaml use configuration.yaml as configuration\n" "\n" - "/etc/interception/udevmon.d/*.yaml is read if -c is not provided\n", + "/etc/interception/udevmon.d/*.yaml is also read if present\n", program); // clang-format on } @@ -231,7 +231,7 @@ private: std::strerror(errno)); break; case 0: { - char *command[] = {(char *)"sh", (char *)"-c", + char *command[] = {(char *)"sh", (char *)"-c", (char *)job.c_str(), nullptr}; std::string variables = "DEVNODE=" + devnode; char *environment[] = {(char *)variables.c_str(), nullptr}; @@ -294,12 +294,18 @@ void kill_zombies(int /*signum*/) { while (waitpid(-1, &status, WNOHANG) > 0) ; } -} +} // namespace int main(int argc, char *argv[]) try { using std::perror; - std::vector configs; + std::vector configs = + scan_config("/etc/interception/udevmon.d"); + + if (configs.size() > 0) + printf( + "%zu configuration files read from /etc/interception/udevmon.d\n", + configs.size()); int opt; while ((opt = getopt(argc, argv, "hc:")) != -1) { @@ -307,7 +313,11 @@ int main(int argc, char *argv[]) try { case 'h': return print_usage(stdout, argv[0]), EXIT_SUCCESS; case 'c': - configs.push_back(YAML::LoadFile(optarg)); + try { + configs.push_back(YAML::LoadFile(optarg)); + } catch (const YAML::Exception &e) { + printf("ignoring %s, reason: %s\n", optarg, e.msg.c_str()); + } continue; } @@ -315,10 +325,7 @@ int main(int argc, char *argv[]) try { } if (configs.empty()) - configs = scan_config("/etc/interception/udevmon.d"); - - if (configs.empty()) - return print_usage(stderr, argv[0]), EXIT_FAILURE; + return perror("couldn't read any configuration"), EXIT_FAILURE; jobs_launcher launch_jobs_for_devnode(configs);