[systemd-commits] 9 commits - .gitignore Makefile.am README src/shared src/test TODO
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Oct 31 03:00:00 PDT 2014
.gitignore | 3 -
Makefile.am | 16 +++++-
README | 1
TODO | 7 --
src/shared/capability.c | 4 -
src/shared/copy.h | 3 +
src/shared/locale-util.h | 4 +
src/test/test-copy.c | 115 ++++++++++++++++++++++++++++++++++++++++++++
src/test/test-fileio.c | 63 ++++++++++++++++++++++++
src/test/test-locale-util.c | 59 ++++++++++++++++++++++
src/test/test-path-util.c | 21 ++++++++
src/test/test-strv.c | 39 ++++++++++++++
src/test/test-tables.c | 2
13 files changed, 325 insertions(+), 12 deletions(-)
New commits:
commit 641d1f99b8c4c5427a1fedcb4740586a130ac6cf
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Wed Oct 29 22:28:50 2014 +0100
tests: add test-copy
diff --git a/.gitignore b/.gitignore
index 7d5f04d..23522ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -159,6 +159,7 @@
/test-compress-benchmark
/test-condition-util
/test-conf-files
+/test-copy
/test-coredump-vacuum
/test-daemon
/test-date
diff --git a/Makefile.am b/Makefile.am
index 00465e8..3f1ace0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1360,7 +1360,8 @@ tests += \
test-condition-util \
test-uid-range \
test-bus-policy \
- test-locale-util
+ test-locale-util \
+ test-copy
EXTRA_DIST += \
test/a.service \
@@ -1510,6 +1511,12 @@ test_locale_util_SOURCES = \
test_locale_util_LDADD = \
libsystemd-shared.la
+test_copy_SOURCES = \
+ src/test/test-copy.c
+
+test_copy_LDADD = \
+ libsystemd-shared.la
+
test_condition_util_SOURCES = \
src/test/test-condition-util.c
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
new file mode 100644
index 0000000..6aa86a0
--- /dev/null
+++ b/src/test/test-copy.c
@@ -0,0 +1,115 @@
+/***
+ 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 <unistd.h>
+
+#include "copy.h"
+#include "path-util.h"
+#include "fileio.h"
+#include "mkdir.h"
+#include "strv.h"
+#include "macro.h"
+#include "util.h"
+
+static void test_copy_file(void) {
+ _cleanup_free_ char *buf = NULL;
+ char fn[] = "/tmp/test-copy_file.XXXXXX";
+ char fn_copy[] = "/tmp/test-copy_file.XXXXXX";
+ size_t sz = 0;
+ int fd;
+
+ fd = mkostemp_safe(fn, O_RDWR|O_CLOEXEC);
+ assert_se(fd >= 0);
+ close(fd);
+
+ fd = mkostemp_safe(fn_copy, O_RDWR|O_CLOEXEC);
+ assert_se(fd >= 0);
+ close(fd);
+
+ assert_se(write_string_file(fn, "foo bar bar bar foo") == 0);
+
+ assert_se(copy_file(fn, fn_copy, 0, 0644) == 0);
+
+ assert_se(read_full_file(fn_copy, &buf, &sz) == 0);
+ assert_se(streq(buf, "foo bar bar bar foo\n"));
+
+ unlink(fn);
+ unlink(fn_copy);
+}
+
+static void test_copy_tree(void) {
+ char original_dir[] = "/tmp/test-copy_tree/";
+ char copy_dir[] = "/tmp/test-copy_tree-copy/";
+ char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file");
+ char **links = STRV_MAKE("link", "file",
+ "link2", "dir1/file");
+ char **p, **link;
+
+ rm_rf_dangerous(copy_dir, false, true, false);
+ rm_rf_dangerous(original_dir, false, true, false);
+
+ STRV_FOREACH(p, files) {
+ char *f = strappenda(original_dir, *p);
+
+ assert_se(mkdir_parents(f, 0755) >= 0);
+ assert_se(write_string_file(f, "file") == 0);
+ }
+
+ STRV_FOREACH_PAIR(link, p, links) {
+ char *f = strappenda(original_dir, *p);
+ char *l = strappenda(original_dir, *link);
+
+ assert_se(mkdir_parents(l, 0755) >= 0);
+ assert_se(symlink(f, l) == 0);
+ }
+
+ assert_se(copy_tree(original_dir, copy_dir, true) == 0);
+
+ STRV_FOREACH(p, files) {
+ _cleanup_free_ char *buf = NULL;
+ size_t sz = 0;
+ char *f = strappenda(copy_dir, *p);
+
+ assert_se(access(f, F_OK) == 0);
+ assert_se(read_full_file(f, &buf, &sz) == 0);
+ assert_se(streq(buf, "file\n"));
+ }
+
+ STRV_FOREACH_PAIR(link, p, links) {
+ _cleanup_free_ char *target = NULL;
+ char *f = strappenda(original_dir, *p);
+ char *l = strappenda(copy_dir, *link);
+
+ assert_se(readlink_and_canonicalize(l, &target) == 0);
+ assert_se(path_equal(f, target));
+ }
+
+ assert_se(copy_tree(original_dir, copy_dir, false) < 0);
+ assert_se(copy_tree("/tmp/inexistent/foo/bar/fsdoi", copy_dir, false) < 0);
+
+ rm_rf_dangerous(copy_dir, false, true, false);
+ rm_rf_dangerous(original_dir, false, true, false);
+}
+
+int main(int argc, char *argv[]) {
+ test_copy_file();
+ test_copy_tree();
+
+ return 0;
+}
commit 5895b62f1da8db93677d2bc369dff34fcaa97f91
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Wed Oct 22 00:58:24 2014 +0200
tests: add tests for path_startswith
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 63d64b2..82090ce 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -242,6 +242,25 @@ static void test_strv_resolve(void) {
assert_se(rm_rf_dangerous(tmp_dir, false, true, false) == 0);
}
+static void test_path_startswith(void) {
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "////"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo//bar/////barfoo///"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo////"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar///barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo////bar/barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "////foo/bar/barfoo/"));
+ assert_se(path_startswith("/foo/bar/barfoo/", "/foo/bar/barfoo"));
+
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa/"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/foo/bar/barfooa"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", ""));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/bar/foo"));
+ assert_se(!path_startswith("/foo/bar/barfoo/", "/f/b/b/"));
+}
+
int main(int argc, char **argv) {
test_path();
test_find_binary(argv[0]);
@@ -250,5 +269,7 @@ int main(int argc, char **argv) {
test_fsck_exists();
test_make_relative();
test_strv_resolve();
+ test_path_startswith();
+
return 0;
}
commit d3774a1b15ea86f6156269e7ed813830f0c4abb8
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Thu Oct 16 23:22:06 2014 +0200
shared: fix typo
diff --git a/src/shared/capability.c b/src/shared/capability.c
index d2b9013..0226542 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -228,7 +228,7 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
* which we want to avoid. */
if (setresgid(gid, gid, gid) < 0) {
- log_error("Failed change group ID: %m");
+ log_error("Failed to change group ID: %m");
return -errno;
}
@@ -244,7 +244,7 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
r = setresuid(uid, uid, uid);
if (r < 0) {
- log_error("Failed change user ID: %m");
+ log_error("Failed to change user ID: %m");
return -errno;
}
commit 17c6bd5222c7d05cd4f577ac131a448307605b00
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Sun Oct 12 18:11:15 2014 +0200
tests: add missing entry for LocalVariable to test-tables
diff --git a/src/test/test-tables.c b/src/test/test-tables.c
index 907958e..2138442 100644
--- a/src/test/test-tables.c
+++ b/src/test/test-tables.c
@@ -48,6 +48,7 @@
#include "link-config.h"
#include "bus-policy.h"
#include "journald-server.h"
+#include "locale-util.h"
#include "test-tables.h"
@@ -116,6 +117,7 @@ int main(int argc, char **argv) {
test_table(unit_file_state, UNIT_FILE_STATE);
test_table(unit_load_state, UNIT_LOAD_STATE);
test_table(unit_type, UNIT_TYPE);
+ test_table(locale_variable, VARIABLE_LC);
test_table_sparse(object_compressed, OBJECT_COMPRESSED);
commit 2b89a960604d44ea1483c0d99bfb567dab9c3aa1
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Sun Oct 12 18:05:10 2014 +0200
tests: add test-locale-util
diff --git a/.gitignore b/.gitignore
index 14f1691..7d5f04d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -198,6 +198,7 @@
/test-libudev
/test-libudev-sym*
/test-list
+/test-locale-util
/test-log
/test-login
/test-login-shared
diff --git a/Makefile.am b/Makefile.am
index 2e4f692..00465e8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1359,7 +1359,8 @@ tests += \
test-ratelimit \
test-condition-util \
test-uid-range \
- test-bus-policy
+ test-bus-policy \
+ test-locale-util
EXTRA_DIST += \
test/a.service \
@@ -1503,6 +1504,12 @@ test_async_SOURCES = \
test_async_LDADD = \
libsystemd-shared.la
+test_locale_util_SOURCES = \
+ src/test/test-locale-util.c
+
+test_locale_util_LDADD = \
+ libsystemd-shared.la
+
test_condition_util_SOURCES = \
src/test/test-condition-util.c
diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c
new file mode 100644
index 0000000..1398a3a
--- /dev/null
+++ b/src/test/test-locale-util.c
@@ -0,0 +1,59 @@
+/***
+ 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 <unistd.h>
+
+#include "locale-util.h"
+#include "strv.h"
+#include "macro.h"
+
+static void test_get_locales(void) {
+ _cleanup_strv_free_ char **locales = NULL;
+ char **p;
+ int r;
+
+ r = get_locales(&locales);
+ assert_se(r >= 0);
+ assert_se(locales);
+
+ STRV_FOREACH(p, locales) {
+ puts(*p);
+ assert_se(locale_is_valid(*p));
+ }
+}
+
+static void test_locale_is_valid(void) {
+ assert_se(locale_is_valid("en_EN.utf8"));
+ assert_se(locale_is_valid("fr_FR.utf8"));
+ assert_se(locale_is_valid("fr_FR at euro"));
+ assert_se(locale_is_valid("fi_FI"));
+ assert_se(locale_is_valid("POSIX"));
+ assert_se(locale_is_valid("C"));
+
+ assert_se(!locale_is_valid(""));
+ assert_se(!locale_is_valid("/usr/bin/foo"));
+ assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
+}
+
+int main(int argc, char *argv[]) {
+ test_get_locales();
+ test_locale_is_valid();
+
+ return 0;
+}
commit 81a12ba6ec2f8514b7d35f0c39a96cc74bb14019
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Sun Oct 12 17:59:03 2014 +0200
shared: add missing includes
diff --git a/src/shared/copy.h b/src/shared/copy.h
index 0bf2598..6b93107 100644
--- a/src/shared/copy.h
+++ b/src/shared/copy.h
@@ -21,6 +21,9 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <stdbool.h>
+#include <sys/types.h>
+
int copy_file(const char *from, const char *to, int flags, mode_t mode);
int copy_tree(const char *from, const char *to, bool merge);
int copy_bytes(int fdf, int fdt, off_t max_bytes);
diff --git a/src/shared/locale-util.h b/src/shared/locale-util.h
index d7a3e4f..e48aa3d 100644
--- a/src/shared/locale-util.h
+++ b/src/shared/locale-util.h
@@ -21,6 +21,10 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <stdbool.h>
+
+#include "macro.h"
+
typedef enum LocaleVariable {
/* We don't list LC_ALL here on purpose. People should be
* using LANG instead. */
commit 7bd57a87aded06c9812119c4f99d4c22e35e77be
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Sun Oct 12 17:32:23 2014 +0200
tests: add tests for strv.c
add tests for:
- strv_find_startswith
- strv_push_prepend
- strv_consume_prepend
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index bbfe306..915fa46 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -113,6 +113,22 @@ static void test_strv_find_prefix(void) {
assert_se(!strv_find_prefix((char **)input_table_multiple, "onee"));
}
+static void test_strv_find_startswith(void) {
+ char *r;
+
+ r = strv_find_startswith((char **)input_table_multiple, "o");
+ assert_se(r && streq(r, "ne"));
+
+ r = strv_find_startswith((char **)input_table_multiple, "one");
+ assert_se(r && streq(r, ""));
+
+ r = strv_find_startswith((char **)input_table_multiple, "");
+ assert_se(r && streq(r, "one"));
+
+ assert_se(!strv_find_startswith((char **)input_table_multiple, "xxx"));
+ assert_se(!strv_find_startswith((char **)input_table_multiple, "onee"));
+}
+
static void test_strv_join(void) {
_cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL;
@@ -416,6 +432,27 @@ static void test_strv_from_stdarg_alloca(void) {
test_strv_from_stdarg_alloca_one(STRV_MAKE_EMPTY, NULL);
}
+static void test_strv_push_prepend(void) {
+ _cleanup_strv_free_ char **a = NULL;
+
+ a = strv_new("foo", "bar", "three", NULL);
+
+ assert_se(strv_push_prepend(&a, strdup("first")) >= 0);
+ assert_se(streq(a[0], "first"));
+ assert_se(streq(a[1], "foo"));
+ assert_se(streq(a[2], "bar"));
+ assert_se(streq(a[3], "three"));
+ assert_se(!a[4]);
+
+ assert_se(strv_consume_prepend(&a, strdup("first2")) >= 0);
+ assert_se(streq(a[0], "first2"));
+ assert_se(streq(a[1], "first"));
+ assert_se(streq(a[2], "foo"));
+ assert_se(streq(a[3], "bar"));
+ assert_se(streq(a[4], "three"));
+ assert_se(!a[5]);
+}
+
int main(int argc, char *argv[]) {
test_specifier_printf();
test_strv_foreach();
@@ -423,6 +460,7 @@ int main(int argc, char *argv[]) {
test_strv_foreach_pair();
test_strv_find();
test_strv_find_prefix();
+ test_strv_find_startswith();
test_strv_join();
test_strv_quote_unquote(input_table_multiple, "\"one\" \"two\" \"three\"");
@@ -462,6 +500,7 @@ int main(int argc, char *argv[]) {
test_strv_extend();
test_strv_extendf();
test_strv_from_stdarg_alloca();
+ test_strv_push_prepend();
return 0;
}
commit cb607ecb84b3cb7299438ca6f7fab705b0a6de45
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Thu Sep 25 22:46:37 2014 +0200
remove references of readahead
diff --git a/.gitignore b/.gitignore
index 0b71f09..14f1691 100644
--- a/.gitignore
+++ b/.gitignore
@@ -101,7 +101,6 @@
/systemd-quotacheck
/systemd-random-seed
/systemd-rc-local-generator
-/systemd-readahead
/systemd-remount-api-vfs
/systemd-remount-fs
/systemd-reply-password
diff --git a/README b/README
index 99b66a8..1440367 100644
--- a/README
+++ b/README
@@ -30,7 +30,6 @@ AUTHOR:
LICENSE:
LGPLv2.1+ for all code
- - except sd-readahead.[ch] which is MIT
- except src/shared/MurmurHash2.c which is Public Domain
- except src/shared/siphash24.c which is CC0 Public Domain
- except src/journal/lookup3.c which is Public Domain
diff --git a/TODO b/TODO
index c86d6ab..af26a5c 100644
--- a/TODO
+++ b/TODO
@@ -641,13 +641,6 @@ Features:
* and a dbus call to generate target from current state
-* readahead:
- - drop /.readahead on bigger upgrades with yum
- - move readahead files into /var (look for them with .path units?)
- - readahead: use BTRFS_IOC_DEFRAG_RANGE instead of BTRFS_IOC_DEFRAG ioctl, with START_IO
- - readahead: when bumping /sys readahead variable save mtime and compare later to detect changes
- - readahead: make use of EXT4_IOC_MOVE_EXT, as used by http://e4rat.sourceforge.net/
-
* GC unreferenced jobs (such as .device jobs)
* write blog stories about:
commit e07995a3e23cdadb8a24d47de03f1a3d319763f9
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date: Tue Sep 2 18:55:31 2014 +0200
tests: add tests for fileio.c
add tests for the following functions:
- write_string_file_no_create
- load_env_file_pairs
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 7e7b4ac..a713abd 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -331,6 +331,23 @@ static void test_write_string_file(void) {
unlink(fn);
}
+static void test_write_string_file_no_create(void) {
+ char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX";
+ _cleanup_close_ int fd;
+ char buf[64] = {0};
+
+ fd = mkostemp_safe(fn, O_RDWR);
+ assert_se(fd >= 0);
+
+ assert_se(write_string_file_no_create("/a/file/which/does/not/exists/i/guess", "boohoo") < 0);
+ assert_se(write_string_file_no_create(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-XXXXXX";
char out_fn[] = "/tmp/test-sendfile_full-XXXXXX";
@@ -355,6 +372,50 @@ static void test_sendfile_full(void) {
unlink(out_fn);
}
+static void test_load_env_file_pairs(void) {
+ char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX";
+ int fd;
+ int r;
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_strv_free_ char **l = NULL;
+ char **k, **v;
+
+ fd = mkostemp_safe(fn, O_RDWR);
+ assert_se(fd >= 0);
+
+ r = write_string_file(fn,
+ "NAME=\"Arch Linux\"\n"
+ "ID=arch\n"
+ "PRETTY_NAME=\"Arch Linux\"\n"
+ "ANSI_COLOR=\"0;36\"\n"
+ "HOME_URL=\"https://www.archlinux.org/\"\n"
+ "SUPPORT_URL=\"https://bbs.archlinux.org/\"\n"
+ "BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n"
+ );
+ assert_se(r == 0);
+
+ f = fdopen(fd, "r");
+ assert_se(f);
+
+ r = load_env_file_pairs(f, fn, NULL, &l);
+ assert_se(r >= 0);
+
+ assert_se(strv_length(l) == 14);
+ STRV_FOREACH_PAIR(k, v, l) {
+ assert_se(STR_IN_SET(*k, "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL", "SUPPORT_URL", "BUG_REPORT_URL"));
+ printf("%s=%s\n", *k, *v);
+ if (streq(*k, "NAME")) assert_se(streq(*v, "Arch Linux"));
+ if (streq(*k, "ID")) assert_se(streq(*v, "arch"));
+ if (streq(*k, "PRETTY_NAME")) assert_se(streq(*v, "Arch Linux"));
+ if (streq(*k, "ANSI_COLOR")) assert_se(streq(*v, "0;36"));
+ if (streq(*k, "HOME_URL")) assert_se(streq(*v, "https://www.archlinux.org/"));
+ if (streq(*k, "SUPPORT_URL")) assert_se(streq(*v, "https://bbs.archlinux.org/"));
+ if (streq(*k, "BUG_REPORT_URL")) assert_se(streq(*v, "https://bugs.archlinux.org/"));
+ }
+
+ unlink(fn);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -366,7 +427,9 @@ int main(int argc, char *argv[]) {
test_capeff();
test_write_string_stream();
test_write_string_file();
+ test_write_string_file_no_create();
test_sendfile_full();
+ test_load_env_file_pairs();
return 0;
}
More information about the systemd-commits
mailing list