Re: [systemd-devel] compile with clang broken

2014-08-16 Thread David Herrmann
Hi

On Fri, Aug 15, 2014 at 5:22 PM, Daniele Nicolodi dani...@grinta.net wrote:
 On 15/08/2014 16:30, David Herrmann wrote:
 Ok, took me a while, but I now figured out how to cause compilation to
 fail even in expressions that initialize types (_Static_assert is not
 allowed there):
   #define assert_const(expr)
 ((void)(__builtin_types_compatible_p(int[(expr) ? 1 : -1], int[1])))

 Btw., I like that more than our current assert_cc() fallback. But I
 leave it up to you to decide.

 Anyhow, I found a way to make CONST_MAX work:
 #define CONST_MAX(_A, _B)
 (__builtin_choose_expr(__builtin_constant_p(_A) 
 __builtin_constant_p(_B), ((_A)  (_B)) ? (_A) : (_B), (void)0))

 This will return (void) in case _A or _B is not constant. Works fine
 on LLVM, I now have to test it on gcc. If it works, I will commit it
 and fix resolvd.

 Hello,

 this may be completely stupid, but if the only use case you have for
 CONST_MAX() is for computing the size of a data structure, I find
 something like

 #define MAXSIZE(A, B) sizeof(union { __typeof(A) a; __typeof(B) b;})

 a little more clear and less magic, and I believe it has the same
 guarantees that the solution you found.

Your MAXSIZE macro might add padding:
union A {
int a;
char b[5];
};
This union has size 8, not 5 (64bit). But CONST_MAX would return 5.
Not sure whether that really matters, though. And we could probably
add __packed__ to the definition.

However, I noticed that GCC complains about using
statement-expressions to initialize static-const structure members,
even with my 'const' annotations added to MAX. *sigh*
Thus, I think I'll keep CONST_MAX, as we'd require a 3rd macro otherwise.

If you know a way to unify them all, please lemme know.

Thanks
David
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] compile with clang broken

2014-08-16 Thread Daniele Nicolodi
On 16/08/2014 12:35, David Herrmann wrote:
 On Fri, Aug 15, 2014 at 5:22 PM, Daniele Nicolodi dani...@grinta.net wrote:
 this may be completely stupid, but if the only use case you have for
 CONST_MAX() is for computing the size of a data structure, I find
 something like

 #define MAXSIZE(A, B) sizeof(union { __typeof(A) a; __typeof(B) b;})

 a little more clear and less magic, and I believe it has the same
 guarantees that the solution you found.
 
 Your MAXSIZE macro might add padding:

 This union has size 8, not 5 (64bit). But CONST_MAX would return 5.
 Not sure whether that really matters, though. And we could probably
 add __packed__ to the definition.

Indeed it does add padding. Adding the __packed__ attribute solves the
problem:

#define MAXSIZE(A, B) sizeof(   \
   union __attribute__((__packed__)) {  \
  __typeof(A) a; __typeof(B) b;})

 However, I noticed that GCC complains about using
 statement-expressions to initialize static-const structure members,
 even with my 'const' annotations added to MAX. *sigh*
 Thus, I think I'll keep CONST_MAX, as we'd require a 3rd macro otherwise.

My proposal was based on the fact that the only use of CONST_MAX there
is (was?) in the code was about array size declarations, and I find
MAXSIZE() much easier to understand.


Cheers,
Daniele

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 8/8] tests: add missing entry to test-tables

2014-08-16 Thread Ronny Chevalier
---
 src/test/test-tables.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/test/test-tables.c b/src/test/test-tables.c
index cb9185e..88e7d10 100644
--- a/src/test/test-tables.c
+++ b/src/test/test-tables.c
@@ -86,6 +86,7 @@ int main(int argc, char **argv) {
 test_table(policy_item_type, POLICY_ITEM_TYPE);
 test_table(protect_home, PROTECT_HOME);
 test_table(protect_system, PROTECT_SYSTEM);
+test_table(rlimit, RLIMIT);
 test_table(scope_result, SCOPE_RESULT);
 test_table(scope_state, SCOPE_STATE);
 test_table(service_exec_command, SERVICE_EXEC_COMMAND);
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 4/8] tests: add test for fdset_iterate

2014-08-16 Thread Ronny Chevalier
---
 src/test/test-fdset.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c
index 3b77415..91df7eb 100644
--- a/src/test/test-fdset.c
+++ b/src/test/test-fdset.c
@@ -126,12 +126,41 @@ static void test_fdset_remove(void) {
 unlink(name);
 }
 
+static void test_fdset_iterate(void) {
+int fd = -1;
+FDSet *fdset = NULL;
+char name[] = /tmp/test-fdset_iterate.XX;
+Iterator i;
+int c = 0;
+int a;
+
+fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+assert_se(fd = 0);
+
+fdset = fdset_new();
+assert_se(fdset);
+assert_se(fdset_put(fdset, fd) = 0);
+assert_se(fdset_put(fdset, fd) = 0);
+assert_se(fdset_put(fdset, fd) = 0);
+
+FDSET_FOREACH(a, fdset, i) {
+c++;
+assert_se(a == fd);
+}
+assert_se(c == 1);
+
+fdset_free(fdset);
+
+unlink(name);
+}
+
 int main(int argc, char *argv[]) {
 test_fdset_new_fill();
 test_fdset_put_dup();
 test_fdset_cloexec();
 test_fdset_close_others();
 test_fdset_remove();
+test_fdset_iterate();
 
 return 0;
 }
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 3/8] tests: add tests for fileio.c

2014-08-16 Thread Ronny Chevalier
add tests for:
- write_string_stream
- write_string_file
- sendfile_full
---
 src/test/test-fileio.c | 69 ++
 1 file changed, 69 insertions(+)

diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 1de59fa..e69706c 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -290,6 +290,72 @@ static void test_capeff(void) {
 }
 }
 
+static void test_write_string_stream(void) {
+char fn[] = /tmp/test-write_string_stream-XX;
+_cleanup_fclose_ FILE *f = NULL;
+int fd;
+char buf[64];
+
+fd = mkostemp_safe(fn, O_RDWR);
+assert_se(fd = 0);
+
+f = fdopen(fd, r);
+assert_se(f);
+assert_se(write_string_stream(f, boohoo)  0);
+
+f = fdopen(fd, r+);
+assert_se(f);
+
+assert_se(write_string_stream(f, boohoo) == 0);
+rewind(f);
+
+assert_se(fgets(buf, sizeof(buf), f));
+assert_se(streq(buf, boohoo\n));
+
+unlink(fn);
+}
+
+static void test_write_string_file(void) {
+char fn[] = /tmp/test-write_string_file-XX;
+int fd;
+char buf[64] = {0};
+
+fd = mkostemp_safe(fn, O_RDWR);
+assert_se(fd = 0);
+
+assert_se(write_string_file(fn, boohoo) == 0);
+
+assert_se(read(fd, buf, sizeof(buf)));
+assert_se(streq(buf, boohoo\n));
+
+unlink(fn);
+}
+
+static void test_sendfile_full(void) {
+char in_fn[] = /tmp/test-sendfile_full-XX;
+char out_fn[] = /tmp/test-sendfile_full-XX;
+_cleanup_close_ int in_fd = -1;
+int out_fd;
+char text[] = boohoo\nfoo\n\tbar\n;
+char buf[64] = {0};
+
+in_fd = mkostemp_safe(in_fn, O_RDWR);
+assert_se(in_fd = 0);
+out_fd = mkostemp_safe(out_fn, O_RDWR);
+assert_se(out_fd = 0);
+
+assert_se(write_string_file(in_fn, text) == 0);
+assert_se(sendfile_full(out_fd, 
/a/file/which/does/not/exist/i/guess)  0);
+assert_se(sendfile_full(out_fd, in_fn) == sizeof(text) - 1);
+assert_se(lseek(out_fd, SEEK_SET, 0) == 0);
+
+assert_se(read(out_fd, buf, sizeof(buf)) == sizeof(text) - 1);
+assert_se(streq(buf, text));
+
+unlink(in_fn);
+unlink(out_fn);
+}
+
 int main(int argc, char *argv[]) {
 log_parse_environment();
 log_open();
@@ -299,6 +365,9 @@ int main(int argc, char *argv[]) {
 test_executable_is_script();
 test_status_field();
 test_capeff();
+test_write_string_stream();
+test_write_string_file();
+test_sendfile_full();
 
 return 0;
 }
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 7/8] tests: add tests for time-util.c

2014-08-16 Thread Ronny Chevalier
add tests for:
- timezone_is_valid
- get_timezones
---
 src/test/test-time.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/src/test/test-time.c b/src/test/test-time.c
index 7c29f96..87e7ae7 100644
--- a/src/test/test-time.c
+++ b/src/test/test-time.c
@@ -20,6 +20,7 @@
 ***/
 
 #include time-util.h
+#include strv.h
 
 static void test_parse_sec(void) {
 usec_t u;
@@ -126,11 +127,33 @@ static void test_format_timespan(usec_t accuracy) {
 test_format_timespan_one(9*USEC_PER_YEAR/5 - 23, accuracy);
 }
 
+static void test_timezone_is_valid(void) {
+assert_se(timezone_is_valid(Europe/Berlin));
+assert_se(timezone_is_valid(Australia/Sydney));
+assert_se(!timezone_is_valid(Europe/Do not exist));
+}
+
+static void test_get_timezones(void) {
+_cleanup_strv_free_ char **zones = NULL;
+int r;
+char **zone;
+
+r = get_timezones(zones);
+assert_se(r == 0);
+
+STRV_FOREACH(zone, zones) {
+assert_se(timezone_is_valid(*zone));
+}
+}
+
 int main(int argc, char *argv[]) {
 test_parse_sec();
 test_parse_nsec();
 test_format_timespan(1);
 test_format_timespan(USEC_PER_MSEC);
 test_format_timespan(USEC_PER_SEC);
+test_timezone_is_valid();
+test_get_timezones();
+
 return 0;
 }
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 5/8] tests: add tests for util.c

2014-08-16 Thread Ronny Chevalier
add tests for:
- is_symlink
- pid_is_unwaited
- pid_is_alive
- search_and_fopen
- search_and_fopen_nulstr
- glob_exists
- execute_directory
---
 src/test/test-util.c | 165 +++
 1 file changed, 165 insertions(+)

diff --git a/src/test/test-util.c b/src/test/test-util.c
index a8fa48a..e876248 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -27,6 +27,7 @@
 #include errno.h
 #include signal.h
 #include math.h
+#include sys/wait.h
 
 #include util.h
 #include mkdir.h
@@ -943,6 +944,163 @@ static void test_strappenda(void) {
 assert_se(streq(actual, foobarbaz));
 }
 
+static void test_is_symlink(void) {
+char name[] = /tmp/test-is_symlink.XX;
+char name_link[] = /tmp/test-is_symlink.link;
+_cleanup_close_ int fd = -1;
+
+fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+assert_se(fd = 0);
+assert_se(symlink(name, name_link) = 0);
+
+assert_se(is_symlink(name) == 0);
+assert_se(is_symlink(name_link) == 1);
+assert_se(is_symlink(/a/file/which/does/not/exist/i/guess)  0);
+
+
+unlink(name);
+unlink(name_link);
+}
+
+static void test_pid_is_unwaited(void) {
+pid_t pid;
+
+pid = fork();
+assert_se(pid = 0);
+if (pid == 0) {
+_exit(EXIT_SUCCESS);
+} else {
+int status;
+
+waitpid(pid, status, 0);
+assert_se(!pid_is_unwaited(pid));
+}
+assert_se(pid_is_unwaited(getpid()));
+assert_se(!pid_is_unwaited(-1));
+}
+
+static void test_pid_is_alive(void) {
+pid_t pid;
+
+pid = fork();
+assert_se(pid = 0);
+if (pid == 0) {
+_exit(EXIT_SUCCESS);
+} else {
+int status;
+
+waitpid(pid, status, 0);
+assert_se(!pid_is_alive(pid));
+}
+assert_se(pid_is_alive(getpid()));
+assert_se(!pid_is_alive(-1));
+}
+
+static void test_search_and_fopen(void) {
+const char *dirs[] = {/tmp/foo/bar, /tmp, NULL};
+char name[] = /tmp/test-search_and_fopen.XX;
+int fd = -1;
+int r;
+FILE *f;
+
+fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+assert_se(fd = 0);
+close(fd);
+
+r = search_and_fopen(basename(name), r, NULL, dirs, f);
+assert_se(r = 0);
+fclose(f);
+
+r = search_and_fopen(name, r, NULL, dirs, f);
+assert_se(r = 0);
+fclose(f);
+
+r = search_and_fopen(basename(name), r, /, dirs, f);
+assert_se(r = 0);
+fclose(f);
+
+r = search_and_fopen(/a/file/which/does/not/exist/i/guess, r, 
NULL, dirs, f);
+assert_se(r  0);
+r = search_and_fopen(afilewhichdoesnotexistiguess, r, NULL, dirs, 
f);
+assert_se(r  0);
+
+r = unlink(name);
+assert_se(r == 0);
+
+r = search_and_fopen(basename(name), r, NULL, dirs, f);
+assert_se(r  0);
+}
+
+
+static void test_search_and_fopen_nulstr(void) {
+const char dirs[] = /tmp/foo/bar\0/tmp\0;
+char name[] = /tmp/test-search_and_fopen.XX;
+int fd = -1;
+int r;
+FILE *f;
+
+fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+assert_se(fd = 0);
+close(fd);
+
+r = search_and_fopen_nulstr(basename(name), r, NULL, dirs, f);
+assert_se(r = 0);
+fclose(f);
+
+r = search_and_fopen_nulstr(name, r, NULL, dirs, f);
+assert_se(r = 0);
+fclose(f);
+
+r = search_and_fopen_nulstr(/a/file/which/does/not/exist/i/guess, 
r, NULL, dirs, f);
+assert_se(r  0);
+r = search_and_fopen_nulstr(afilewhichdoesnotexistiguess, r, NULL, 
dirs, f);
+assert_se(r  0);
+
+r = unlink(name);
+assert_se(r == 0);
+
+r = search_and_fopen_nulstr(basename(name), r, NULL, dirs, f);
+assert_se(r  0);
+}
+
+static void test_glob_exists(void) {
+char name[] = /tmp/test-glob_exists.XX;
+int fd = -1;
+int r;
+
+fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+assert_se(fd = 0);
+close(fd);
+
+r = glob_exists(/tmp/test-glob_exists*);
+assert_se(r == 1);
+
+r = unlink(name);
+assert_se(r == 0);
+r = glob_exists(/tmp/test-glob_exists*);
+assert_se(r == 0);
+}
+
+static void test_execute_directory(void) {
+char name[] = /tmp/test-execute_directory/script1;
+char name2[] = /tmp/test-execute_directory/script2;
+char name3[] = /tmp/test-execute_directory/useless;
+char tempdir[] = /tmp/test-execute_directory/;
+
+assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) = 0);
+assert_se(write_string_file(name, #!/bin/sh\necho 'Executing 
'$0\ntouch /tmp/test-execute_directory/it_works) == 0);
+assert_se(write_string_file(name2, #!/bin/sh\necho 

[systemd-devel] [PATCH 6/8] tests: add test-condition-util

2014-08-16 Thread Ronny Chevalier
---
 .gitignore |   1 +
 Makefile.am|  11 -
 src/test/test-condition-util.c | 107 +
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 src/test/test-condition-util.c

diff --git a/.gitignore b/.gitignore
index 6f90524..a3d8c4e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -153,6 +153,7 @@
 /test-cgroup-util
 /test-compress
 /test-compress-benchmark
+/test-condition-util
 /test-conf-files
 /test-coredump-vacuum
 /test-daemon
diff --git a/Makefile.am b/Makefile.am
index b95ddf2..29855be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1319,7 +1319,8 @@ tests += \
test-conf-files \
test-capability \
test-async \
-   test-ratelimit
+   test-ratelimit \
+   test-condition-util
 
 EXTRA_DIST += \
test/a.service \
@@ -1458,6 +1459,14 @@ test_async_SOURCES = \
 test_async_LDADD = \
libsystemd-shared.la
 
+test_condition_util_SOURCES = \
+   src/test/test-condition-util.c
+
+test_condition_util_LDADD = \
+   libsystemd-shared.la \
+   libsystemd-internal.la
+
+
 test_fdset_SOURCES = \
src/test/test-fdset.c
 
diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
new file mode 100644
index 000..4ee5600
--- /dev/null
+++ b/src/test/test-condition-util.c
@@ -0,0 +1,107 @@
+/***
+  This file is part of systemd
+
+  Copyright 2014 Ronny Chevalier
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see http://www.gnu.org/licenses/.
+***/
+
+#include condition-util.h
+#include macro.h
+#include util.h
+#include log.h
+#include architecture.h
+#include systemd/sd-id128.h
+
+static void test_condition_test_ac_power(void) {
+Condition *condition;
+
+condition = condition_new(CONDITION_AC_POWER, true, false, false);
+assert_se(condition_test_ac_power(condition) == on_ac_power());
+condition_free(condition);
+
+condition = condition_new(CONDITION_AC_POWER, false, false, false);
+assert_se(condition_test_ac_power(condition) != on_ac_power());
+condition_free(condition);
+
+condition = condition_new(CONDITION_AC_POWER, false, false, true);
+assert_se(condition_test_ac_power(condition) == on_ac_power());
+condition_free(condition);
+}
+
+static void test_condition_test_host(void) {
+Condition *condition;
+sd_id128_t id;
+int r;
+char sid[SD_ID128_STRING_MAX];
+char *hostname;
+
+r = sd_id128_get_machine(id);
+assert_se(r = 0);
+assert_se(sd_id128_to_string(id, sid));
+
+condition = condition_new(CONDITION_HOST, sid, false, false);
+assert_se(condition_test_host(condition));
+condition_free(condition);
+
+condition = condition_new(CONDITION_HOST, garbage value 
jj, false, false);
+assert_se(!condition_test_host(condition));
+condition_free(condition);
+
+condition = condition_new(CONDITION_HOST, sid, false, true);
+assert_se(!condition_test_host(condition));
+condition_free(condition);
+
+hostname = gethostname_malloc();
+assert_se(hostname);
+
+condition = condition_new(CONDITION_HOST, hostname, false, false);
+assert_se(condition_test_host(condition));
+condition_free(condition);
+}
+
+static void test_condition_test_architecture(void) {
+Condition *condition;
+Architecture a;
+const char *sa;
+
+a = uname_architecture();
+assert_se(a = 0);
+
+sa = architecture_to_string(a);
+assert_se(sa);
+
+condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false);
+assert_se(condition_test_architecture(condition));
+condition_free(condition);
+
+condition = condition_new(CONDITION_ARCHITECTURE, garbage value, 
false, false);
+assert_se(!condition_test_architecture(condition));
+condition_free(condition);
+
+condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true);
+assert_se(!condition_test_architecture(condition));
+condition_free(condition);
+}
+
+int main(int argc, char *argv[]) {
+log_parse_environment();
+log_open();
+
+test_condition_test_ac_power();
+test_condition_test_host();
+test_condition_test_architecture();
+
+return 0;
+}

[systemd-devel] [PATCH 2/8] tests: add missing unlink

2014-08-16 Thread Ronny Chevalier
---
 src/test/test-async.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/test/test-async.c b/src/test/test-async.c
index c1c535b..401e685 100644
--- a/src/test/test-async.c
+++ b/src/test/test-async.c
@@ -46,5 +46,7 @@ int main(int argc, char *argv[]) {
 assert_se(fcntl(fd, F_GETFD) == -1);
 assert_se(test_async);
 
+unlink(name);
+
 return 0;
 }
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 1/8] tests: add tests for socket-util.c

2014-08-16 Thread Ronny Chevalier
add tests for:
- socket_address_is
- socket_address_is_netlink
- sockaddr_equal
---
 src/test/test-socket-util.c | 50 +
 1 file changed, 50 insertions(+)

diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index 4e90590..17180db 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -140,6 +140,24 @@ static void test_socket_address_get_path(void) {
 assert_se(streq(socket_address_get_path(a), /foo/bar));
 }
 
+static void test_socket_address_is(void) {
+SocketAddress a;
+
+assert_se(socket_address_parse(a, 192.168.1.1:) = 0);
+assert_se(socket_address_is(a, 192.168.1.1:, SOCK_STREAM));
+assert_se(!socket_address_is(a, route, SOCK_STREAM));
+assert_se(!socket_address_is(a, 192.168.1.1:, SOCK_RAW));
+}
+
+static void test_socket_address_is_netlink(void) {
+SocketAddress a;
+
+assert_se(socket_address_parse_netlink(a, route 10) = 0);
+assert_se(socket_address_is_netlink(a, route 10));
+assert_se(!socket_address_is_netlink(a, 192.168.1.1:));
+assert_se(!socket_address_is_netlink(a, route 1));
+}
+
 static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, 
unsigned apl, const char *b, unsigned bpl, int result) {
 union in_addr_union ua, ub;
 
@@ -265,6 +283,34 @@ static void test_nameinfo_pretty(void) {
 assert(r == 0);
 }
 
+static void test_sockaddr_equal(void) {
+union sockaddr_union a = {
+.in.sin_family = AF_INET,
+.in.sin_port = 0,
+.in.sin_addr.s_addr = htonl(INADDR_ANY),
+};
+union sockaddr_union b = {
+.in.sin_family = AF_INET,
+.in.sin_port = 0,
+.in.sin_addr.s_addr = htonl(INADDR_ANY),
+};
+union sockaddr_union c = {
+.in.sin_family = AF_INET,
+.in.sin_port = 0,
+.in.sin_addr.s_addr = htonl(1234),
+};
+union sockaddr_union d = {
+.in6.sin6_family = AF_INET6,
+.in6.sin6_port = 0,
+.in6.sin6_addr = IN6ADDR_ANY_INIT,
+};
+assert_se(sockaddr_equal(a, a));
+assert_se(sockaddr_equal(a, b));
+assert_se(sockaddr_equal(d, d));
+assert_se(!sockaddr_equal(a, c));
+assert_se(!sockaddr_equal(b, c));
+}
+
 int main(int argc, char *argv[]) {
 
 log_set_max_level(LOG_DEBUG);
@@ -273,11 +319,15 @@ int main(int argc, char *argv[]) {
 test_socket_address_parse_netlink();
 test_socket_address_equal();
 test_socket_address_get_path();
+test_socket_address_is();
+test_socket_address_is_netlink();
 
 test_in_addr_prefix_intersect();
 test_in_addr_prefix_next();
 
 test_nameinfo_pretty();
 
+test_sockaddr_equal();
+
 return 0;
 }
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bootchart: use NSEC_PER_SEC

2014-08-16 Thread Ronny Chevalier
---
 src/bootchart/store.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/bootchart/store.c b/src/bootchart/store.c
index cedcba8..d838a53 100644
--- a/src/bootchart/store.c
+++ b/src/bootchart/store.c
@@ -34,6 +34,7 @@
 #include time.h
 
 #include util.h
+#include time-util.h
 #include strxcpyx.h
 #include store.h
 #include bootchart.h
@@ -54,14 +55,14 @@ double gettime_ns(void) {
 
 clock_gettime(CLOCK_MONOTONIC, n);
 
-return (n.tv_sec + (n.tv_nsec / 10.0));
+return (n.tv_sec + (n.tv_nsec / NSEC_PER_SEC));
 }
 
 static double gettime_up(void) {
 struct timespec n;
 
 clock_gettime(CLOCK_BOOTTIME, n);
-return (n.tv_sec + (n.tv_nsec / 10.0));
+return (n.tv_sec + (n.tv_nsec / NSEC_PER_SEC));
 }
 
 void log_uptime(void) {
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] man: fix typo

2014-08-16 Thread Ronny Chevalier
---
 man/systemd-firstboot.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man/systemd-firstboot.xml b/man/systemd-firstboot.xml
index 42fd753..c3fe0ed 100644
--- a/man/systemd-firstboot.xml
+++ b/man/systemd-firstboot.xml
@@ -249,7 +249,7 @@
 
termoption--setup-machine-id/option/term
 
 paraInitialize the system's machine
-ID to a random ID. This only works
+ID to a random ID. This only works in
 combination with
 option--root=/option./para
 /varlistentry
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] condition-util: do not validate condition if paramater is garbage

2014-08-16 Thread Ronny Chevalier
To follow the same behavior that src/core/condition.c do
---
 src/shared/condition-util.c| 2 +-
 src/test/test-condition-util.c | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index ff4a8ec..f21786f 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -213,7 +213,7 @@ bool condition_test_ac_power(Condition *c) {
 
 r = parse_boolean(c-parameter);
 if (r  0)
-return !c-negate;
+return c-negate;
 
 return ((on_ac_power() != 0) == !!r) == !c-negate;
 }
diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
index 4ee5600..3de0b67 100644
--- a/src/test/test-condition-util.c
+++ b/src/test/test-condition-util.c
@@ -38,6 +38,10 @@ static void test_condition_test_ac_power(void) {
 condition = condition_new(CONDITION_AC_POWER, false, false, true);
 assert_se(condition_test_ac_power(condition) == on_ac_power());
 condition_free(condition);
+
+condition = condition_new(CONDITION_AC_POWER, garbage value, false, 
false);
+assert_se(!condition_test_ac_power(condition));
+condition_free(condition);
 }
 
 static void test_condition_test_host(void) {
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] util: do not execute files without exec permission

2014-08-16 Thread Ronny Chevalier
---
 src/shared/util.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/shared/util.c b/src/shared/util.c
index 18d40f3..3a03470 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3921,6 +3921,10 @@ void execute_directory(const char *directory, DIR *d, 
usec_t timeout, char *argv
 _exit(EXIT_FAILURE);
 }
 
+if (access(path, X_OK)  0) {
+continue;
+}
+
 pid = fork();
 if (pid  0) {
 log_error(Failed to fork: %m);
-- 
2.0.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] suspend-utils and systemd

2014-08-16 Thread Rodolfo García Peñas (kix)

Hi,

I am new on the list. Thanks for your work with systemd.

I am trying to run systemd and suspend-utils (uswsusp in Debian) and I  
don't know how to do it.


I was checking how to include support for suspend with normal packages  
(server daemons,...) but I am not sure how to implement it with  
suspend-utils.


Reading [1], it modify the systemd hibernate/supsend/hybrid scripts,  
but IMO this is not the right option to include support in  
suspend-utils and uswsusp package.


Help is welcome.

Best regards,
Rodolfo.

[1] https://wiki.archlinux.org/index.php/Uswsusp#With_systemd
--
 .''`.
: :'  : Rodolfo García Peñas (kix) k...@debian.org
`. `'`  Proud Debian Developer
 `-
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Networkd fails to activate the device on boot

2014-08-16 Thread Thomas Bächler
Hello Tom,

I am using systemd 215-4 from Arch Linux.

I have the following configuration files in /etc/systemd/network:

# 01-lan.network
[Match]
Name=enp3s0

[Network]
Address=10.23.42.4/26
Gateway=10.23.42.3

# 01-qemu.netdev
[NetDev]
MACAddress=1a:de:ad:be:ef:01
Name=qemu
Kind=tap

# 01-qemu.network
[Match]
Name=qemu

[Network]
Address=10.23.42.129/26

I have two problems with this setup:

1) The enp3s0 interface does not activate on boot. I need to restart
networkd manually to make it work.

2) The qemu interface does not have the correct MAC address. It gains a
seemingly random address that is inconsistent across reboots.

Here is an excerpt from the journal:

[2.356909] lije systemd[1]: Starting Network Service...
[2.377715] lije systemd-networkd[367]: rtnl: received address for a
nonexistent link, ignoring
[2.377862] lije systemd-networkd[367]: rtnl: received address for a
nonexistent link, ignoring
[2.377960] lije systemd-networkd[367]: qemu: link configured
[2.379489] lije systemd[1]: Started Network Service.
[   57.298036] lije systemd[1]: Stopping Network Service...
[   57.298776] lije systemd-networkd[367]: Received SIGTERM from PID 1
(systemd).
[   57.364169] lije systemd[1]: Starting Network Service...
[   57.451984] lije systemd-networkd[490]: lo  : gained carrier
[   57.452133] lije systemd[1]: Started Network Service.
[   57.492641] lije systemd-networkd[490]: qemu: link configured
[   57.492732] lije systemd-networkd[490]: enp3s0  : link configured
[   59.074472] lije systemd-networkd[490]: enp3s0  : gained carrier

Any ideas?



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus-control: Fix cgroup handling

2014-08-16 Thread Denis Kenzior
On systems without properly setup systemd, cg_get_root_path returns
-ENOENT.  This means that busctl doesn't display much information.

busctl monitor also fails whenever it intercepts messages.

This fix fakes creates a fake / root cgroup which lets busctl work
on such systems.
---
 src/libsystemd/sd-bus/bus-control.c | 4 +++-
 src/libsystemd/sd-bus/bus-kernel.c  | 5 -
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/libsystemd/sd-bus/bus-control.c 
b/src/libsystemd/sd-bus/bus-control.c
index 076bbce..8c5c669 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -497,7 +497,9 @@ static int bus_get_owner_kdbus(
 
 if (!bus-cgroup_root) {
 r = 
cg_get_root_path(bus-cgroup_root);
-if (r  0)
+if (r == -ENOENT)
+bus-cgroup_root = strdup(/);
+else if (r  0)
 goto fail;
 }
 
diff --git a/src/libsystemd/sd-bus/bus-kernel.c 
b/src/libsystemd/sd-bus/bus-kernel.c
index 8b961c3..e49298d 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -27,6 +27,7 @@
 #include malloc.h
 #include sys/mman.h
 #include sys/prctl.h
+#include string.h
 
 #include util.h
 #include strv.h
@@ -544,7 +545,9 @@ static int bus_kernel_make_message(sd_bus *bus, struct 
kdbus_msg *k) {
 
 if (!bus-cgroup_root) {
 r = cg_get_root_path(bus-cgroup_root);
-if (r  0)
+if (r == -ENOENT)
+bus-cgroup_root = strdup(/);
+else if (r  0)
 goto fail;
 }
 
-- 
1.8.5.5

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Misleading udev error messages regarding virtual interfaces

2014-08-16 Thread Leonid Isaev
Hi,

On Fri, Aug 15, 2014 at 06:20:07PM +0200, Lennart Poettering wrote:
 On Sun, 06.07.14 12:43, Leonid Isaev (lis...@umail.iu.edu) wrote:
 
  Hi,
  
  Sorry for a delayed reply.
  
  On Thu, Jul 03, 2014 at 01:46:53PM +0200, Lennart Poettering wrote:
   it would be good to know what the precise error output is you get now
   with this new change...
  
  With systemd-215 udevd still complains (and segfaults) about the virtual
  interface:
  --
  $ journalctl | grep udevd
  Jul 06 12:21:05 hermes systemd-udevd[46]: starting version 215
  Jul 06 12:21:05 hermes systemd-udevd[226]: starting version 215
  Jul 06 12:21:06 hermes systemd-udevd[234]: renamed network interface wlan0 
  to wlp1s0
  Jul 06 12:21:09 hermes systemd-udevd[226]: worker [233] terminated by 
  signal 11 (Segmentation fault)
  Jul 06 12:21:09 hermes kernel: systemd-udevd[233]: segfault at 0 ip 
  7ff524a0571a sp 7fffc8a69540 error 4 in 
  libc-2.19.so[7ff524907000+1a4000]
  Jul 06 12:21:09 hermes systemd-udevd[226]: worker [233] failed while 
  handling '/devices/virtual/net/veth7DH07K'
  --
  
  As before, things seem to work i.e. I can still see servers inside 
  containers.
  The kernel is 3.15.3.
 
 Does this still occur with current systemd git?

I haven't tested the git master yet, but with systemd 215 and kernels  3.15.5,
I did not see a single segfault...

 
 Any chance to get a backtrace for this with current git?

I'll try tomorrow.

Thanks,
-- 
Leonid Isaev
GPG fingerprints: DA92 034D B4A8 EC51 7EA6  20DF 9291 EE8A 043C B8C4
  C0DF 20D0 C075 C3F1 E1BE  775A A7AE F6CB 164B 5A6D


pgpxD_HBfNaSB.pgp
Description: PGP signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Logind error - Failed to abandon session scope: Connection reset

2014-08-16 Thread Roger Qiu

Hello Lennart,

The reason why you don't want explicit ordering is because of a slower 
boot time?


When you are referring to patching them out, would that be from upstream 
systemd/logind?


Thanks,
Roger

On 15/08/2014 7:41 PM, Lennart Poettering wrote:

On Fri, 15.08.14 15:04, Roger Qiu (roger@polycademy.com) wrote:


Hello Lennart,

Thanks for answering.

Is there any way to enforce ordering to make this error not occur?

You could order systemd-logind.service After= dbus.service. That way
dbus is started first, and logind second. And since the top order is the
reversed start order, this would result in logind being stopped first
and dbus second.

But honestly, I don't really like this, we should no add unnecessary
ordering here...


Or what's the best way to hide that warning?

We should probably just patch it out...


Or when is the ETA for kdbus?

Well, when it's ready...

Lennart



___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel