[systemd-commits] 2 commits - src/hwdb src/import

Tom Gundersen tomegun at kemper.freedesktop.org
Thu Dec 18 18:04:13 PST 2014


 src/hwdb/hwdb.c         |   83 ++++++------------------------------------------
 src/import/import-dck.c |    2 -
 2 files changed, 12 insertions(+), 73 deletions(-)

New commits:
commit caa8dab28f65a28bf410f6abdb8a9a14ee2a7a70
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Dec 19 03:01:27 2014 +0100

    systemd-hwdb: port to new verbs helper

diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index 9f8cbf6..4fce30d 100644
--- a/src/hwdb/hwdb.c
+++ b/src/hwdb/hwdb.c
@@ -29,6 +29,7 @@
 #include "strv.h"
 #include "mkdir.h"
 #include "fileio.h"
+#include "verbs.h"
 
 #include "hwdb-internal.h"
 #include "hwdb-util.h"
@@ -567,16 +568,16 @@ static int import_file(struct trie *trie, const char *filename) {
         return 0;
 }
 
-static int hwdb_query(char **args, unsigned n) {
+static int hwdb_query(int argc, char *argv[], void *userdata) {
         _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
         const char *key, *value;
         const char *modalias;
         int r;
 
-        assert(args);
-        assert(n == 2);
+        assert(argc >= 2);
+        assert(argv);
 
-        modalias = args[1];
+        modalias = argv[1];
 
         r = sd_hwdb_new(&hwdb);
         if (r < 0)
@@ -588,7 +589,7 @@ static int hwdb_query(char **args, unsigned n) {
         return 0;
 }
 
-static int hwdb_update(char **args, unsigned n) {
+static int hwdb_update(int argc, char *argv[], void *userdata) {
         _cleanup_free_ char *hwdb_bin = NULL;
         _cleanup_(trie_freep) struct trie *trie = NULL;
         char **files, **f;
@@ -699,75 +700,13 @@ static int parse_argv(int argc, char *argv[]) {
 }
 
 static int hwdb_main(int argc, char *argv[]) {
-        static const struct {
-                const char *verb;
-                const enum {
-                        MORE,
-                        LESS,
-                        EQUAL,
-                } argc_cmp;
-                const int argc;
-                int (*const dispatch)(char **args, unsigned n);
-        } verbs[] = {
-                { "update", EQUAL, 1, hwdb_update },
-                { "query", EQUAL, 2, hwdb_query },
+        const Verb verbs[] = {
+                { "update", 1, 1, 0, hwdb_update },
+                { "query", 2, 2, 0, hwdb_query },
+                {},
         };
 
-        int left;
-        unsigned i;
-
-        assert(argc >= 0);
-        assert(argv);
-
-        left = argc - optind;
-
-        if (left <= 0) {
-                log_error("Missing command.");
-                help();
-                return -EINVAL;
-        }
-
-        for (i = 0; i < ELEMENTSOF(verbs); i++)
-                if (streq(argv[optind], verbs[i].verb))
-                        break;
-
-        if (i >= ELEMENTSOF(verbs)) {
-                log_error("Unknown command %s.", argv[optind]);
-                help();
-                return -EINVAL;
-        }
-
-        switch (verbs[i].argc_cmp) {
-        case EQUAL:
-                if (left != verbs[i].argc) {
-                        log_error("Invalid number of arguments.");
-                        help();
-                        return -EINVAL;
-                }
-
-                break;
-
-        case MORE:
-                if (left < verbs[i].argc) {
-                        log_error("Too few arguments.");
-                        help();
-                        return -EINVAL;
-                }
-
-                break;
-        case LESS:
-                if (left > verbs[i].argc) {
-                        log_error("Too many arguments.");
-                        help();
-                        return -EINVAL;
-                }
-
-                break;
-        default:
-                assert_not_reached("Unknown comparison operator.");
-        }
-
-        return verbs[i].dispatch(argv + optind, left);
+        return dispatch_verb(argc, argv, verbs, NULL);
 }
 
 int main (int argc, char *argv[]) {

commit eac8e8c6de6347999f6b2115f9c38df31f8d35b1
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Dec 19 03:00:56 2014 +0100

    import: dck - fix curl error handling

diff --git a/src/import/import-dck.c b/src/import/import-dck.c
index 7c83ff7..adb0c90 100644
--- a/src/import/import-dck.c
+++ b/src/import/import-dck.c
@@ -715,7 +715,7 @@ static void dck_import_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result
         job->done = true;
 
         if (result != CURLE_OK) {
-                log_error("Transfer failed: %s", curl_easy_strerror(code));
+                log_error("Transfer failed: %s", curl_easy_strerror(result));
                 r = -EIO;
                 goto fail;
         }



More information about the systemd-commits mailing list