summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2015-07-31 19:40:57 +0200
committerDaniel Mack <github@zonque.org>2015-07-31 19:40:57 +0200
commitc474a4ecfa74d90d02822d24efa310197a5c3298 (patch)
treeb03788434fd764ac3fc5a8cd8edd45c1e92a223e
parent6ba32d1c2f04f3f01cea6ba1a082028412b5c474 (diff)
parentcbfa6a41317b72553433f4ebe250dd0d34bf058f (diff)
Merge pull request #811 from namhyung/busctl-misc-v2
busctl: Misc cleanups and a fix (v2)
-rw-r--r--src/basic/util.c20
-rw-r--r--src/basic/util.h1
-rw-r--r--src/libsystemd/sd-bus/busctl.c24
-rw-r--r--src/test/test-util.c13
4 files changed, 33 insertions, 25 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index 1c15fbc172..a968e2156d 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -115,17 +115,23 @@ size_t page_size(void) {
return pgsz;
}
-bool streq_ptr(const char *a, const char *b) {
-
- /* Like streq(), but tries to make sense of NULL pointers */
+int strcmp_ptr(const char *a, const char *b) {
+ /* Like strcmp(), but tries to make sense of NULL pointers */
if (a && b)
- return streq(a, b);
+ return strcmp(a, b);
- if (!a && !b)
- return true;
+ if (!a && b)
+ return -1;
- return false;
+ if (a && !b)
+ return 1;
+
+ return 0;
+}
+
+bool streq_ptr(const char *a, const char *b) {
+ return strcmp_ptr(a, b) == 0;
}
char* endswith(const char *s, const char *postfix) {
diff --git a/src/basic/util.h b/src/basic/util.h
index c2e5cc610b..05ddf14780 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -71,6 +71,7 @@ size_t page_size(void) _pure_;
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
bool streq_ptr(const char *a, const char *b) _pure_;
+int strcmp_ptr(const char *a, const char *b) _pure_;
#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c
index 6aaaf0e5ec..1724292bbb 100644
--- a/src/libsystemd/sd-bus/busctl.c
+++ b/src/libsystemd/sd-bus/busctl.c
@@ -656,28 +656,15 @@ static int member_compare_func(const void *a, const void *b) {
assert(x->type);
assert(y->type);
- if (!x->interface && y->interface)
- return -1;
- if (x->interface && !y->interface)
- return 1;
- if (x->interface && y->interface) {
- d = strcmp(x->interface, y->interface);
- if (d != 0)
- return d;
- }
+ d = strcmp_ptr(x->interface, y->interface);
+ if (d != 0)
+ return d;
d = strcmp(x->type, y->type);
if (d != 0)
return d;
- if (!x->name && y->name)
- return -1;
- if (x->name && !y->name)
- return 1;
- if (x->name && y->name)
- return strcmp(x->name, y->name);
-
- return 0;
+ return strcmp_ptr(x->name, y->name);
}
static int member_compare_funcp(const void *a, const void *b) {
@@ -1697,6 +1684,7 @@ static int help(void) {
" --acquired Only show acquired names\n"
" --activatable Only show activatable names\n"
" --match=MATCH Only show matching messages\n"
+ " --size=SIZE Maximum length of captured packet\n"
" --list Don't show tree, but simple object path list\n"
" --quiet Don't show method call reply\n"
" --verbose Show result values in long format\n"
@@ -1837,7 +1825,7 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_SIZE: {
off_t o;
- r = parse_size(optarg, 0, &o);
+ r = parse_size(optarg, 1024, &o);
if (r < 0) {
log_error("Failed to parse size: %s", optarg);
return r;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index f43433baa1..7a1a4b6df2 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -2083,6 +2083,18 @@ static void test_tempfn(void) {
free(ret);
}
+static void test_strcmp_ptr(void) {
+ assert_se(strcmp_ptr(NULL, NULL) == 0);
+ assert_se(strcmp_ptr("", NULL) > 0);
+ assert_se(strcmp_ptr("foo", NULL) > 0);
+ assert_se(strcmp_ptr(NULL, "") < 0);
+ assert_se(strcmp_ptr(NULL, "bar") < 0);
+ assert_se(strcmp_ptr("foo", "bar") > 0);
+ assert_se(strcmp_ptr("bar", "baz") < 0);
+ assert_se(strcmp_ptr("foo", "foo") == 0);
+ assert_se(strcmp_ptr("", "") == 0);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -2169,6 +2181,7 @@ int main(int argc, char *argv[]) {
test_shell_maybe_quote();
test_parse_mode();
test_tempfn();
+ test_strcmp_ptr();
return 0;
}