Add no-action command line option 98/135298/2
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Wed, 21 Jun 2017 16:01:40 +0000 (18:01 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 22 Jun 2017 09:44:31 +0000 (11:44 +0200)
Also adds a possibility to disable any module category.

Change-Id: I82a24f6e4594a0946ce4b796cedbb59da0b722ad
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/core/module.c
src/core/module.h
src/faultd.c

index edd970e8c838087709dc4473bbe5dcae53635d0e..e56ea99714f4a0378c64923addf91923b23ff1a1 100644 (file)
 #include "module.h"
 
 static struct list_head modules[FAULTD_MODULE_TYPE_MAX];
+static int category_disabled[FAULTD_MODULE_TYPE_MAX];
 
 static void init_heads(void)
 {
        unsigned i;
 
-       for (i = 0; i < ARRAY_SIZE(modules); ++i)
+       for (i = 0; i < ARRAY_SIZE(modules); ++i) {
                INIT_LIST_HEAD(modules + i);
+               category_disabled[i] = 0;
+       }
 }
 
 int faultd_module_register(struct faultd_module *module)
@@ -63,6 +66,11 @@ int faultd_modules_init(sd_event *event_loop)
                init_heads();
 
        for (i = 0; i < (int)(ARRAY_SIZE(modules)); ++i) {
+               if (category_disabled[i]) {
+                       log_debug("Skipping modules category %d", i);
+                       continue;
+               }
+
                log_debug("Initializing modules category %d", i);
                list_for_each_entry(module, modules + i, node) {
                        if (module->disabled)
@@ -79,6 +87,9 @@ int faultd_modules_init(sd_event *event_loop)
 
 err_cleanup:
        for (; i >= 0; --i) {
+               if (category_disabled[i])
+                       continue;
+
                log_debug("Cleaning up modules category %d", i);
                /* From first element of the list... */
                for (module_to_clean = list_first_entry(modules + i,
@@ -107,6 +118,9 @@ void faultd_modules_cleanup()
        int i;
 
        for (i = FAULTD_MODULE_TYPE_MAX - 1; i >= 0; --i) {
+               if (category_disabled[i])
+                       continue;
+
                log_debug("Cleaning up modules category %d", i);
                list_for_each_entry(module, modules + i, node) {
                        if (module->disabled)
@@ -132,3 +146,8 @@ struct faultd_module *faultd_get_module_by_name(const char *name)
 
        return NULL;
 }
+
+void faultd_disable_module_category(int category)
+{
+       category_disabled[category] = 1;
+}
index dd83951f78ff40a4534b6931a9d8c7ad141f62ac..28b07243dbfb98aea28380438b198e6ce7d02793 100644 (file)
@@ -69,6 +69,7 @@ int faultd_modules_init(sd_event *event_loop);
 void faultd_modules_cleanup(void);
 
 struct faultd_module *faultd_get_module_by_name(const char *name);
+void faultd_disable_module_category(int category);
 
 #ifndef __CONSTRUCTOR__
 #define __CONSTRUCTOR__ __attribute__((constructor))
index c22559da2e51a03d128651bcf6eb680690ebb2e4..5d92ab5c523845d8e657c608e00e7cf267d98245 100644 (file)
@@ -50,10 +50,12 @@ static int parse_argv(int ac, char *av[])
        int c, r;
        enum {
                ARG_LOG_LEVEL = 0x100,
+               ARG_NO_ACTION,
        };
        static const struct option options[] = {
                {"log-level", required_argument, NULL, ARG_LOG_LEVEL},
                {"disable-module", required_argument, NULL, 'd'},
+               {"no-action", no_argument, NULL, ARG_NO_ACTION},
                {}
        };
 
@@ -85,6 +87,11 @@ static int parse_argv(int ac, char *av[])
                        }
 
                        break;
+
+               case ARG_NO_ACTION:
+                       faultd_disable_module_category(FAULTD_MODULE_TYPE_ACTION);
+                       break;
+
                default:
                        return -EINVAL;
                }