[systemd-devel] [PATCH] cryptsetup: craft a unique ID with the source device
From: Harald Hoyer If cryptsetup is called with a source device as argv[3], then craft the ID for the password agent with a unique device path. If possible "/dev/block/:" is used, otherwise the original argv[3] is used. This enables password agents like petera [1] to provide a password according to the source device. The original ID did not carry enough information and was more targeted for a human readable string, which is specified in the "Message" field anyway. With this patch the ID of the ask.XXX ini file looks like this: ID=cryptsetup:/dev/block/: [1] https://github.com/npmccallum/petera --- src/cryptsetup/cryptsetup.c | 97 ++--- 1 file changed, 66 insertions(+), 31 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a5018f1..130c36e 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -238,6 +238,33 @@ static void log_glue(int level, const char *msg, void *usrptr) { log_debug("%s", msg); } +static char* disk_maj_min(const char *path) { +struct stat st, st2; +char *i = NULL; +int r; + +assert(path); + +if (stat(path, &st) < 0) +return NULL; + +if (!S_ISBLK(st.st_mode)) +return NULL; + +asprintf(&i, "/dev/block/%d:%d", major(st.st_rdev), minor(st.st_rdev)); + +if (!i) +return strdup(path); + +r = stat(i, &st2); +if ((r < 0) || (st.st_rdev != st2.st_rdev)) { +free(i); +return strdup(path); +} + +return i; +} + static char* disk_description(const char *path) { static const char name_fields[] = @@ -295,20 +322,54 @@ static char *disk_mount_point(const char *label) { return NULL; } -static int get_password(const char *name, usec_t until, bool accept_cached, char ***passwords) { -int r; +static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***passwords) { +int r = 0; char **p; _cleanup_free_ char *text = NULL; _cleanup_free_ char *escaped_name = NULL; char *id; +const char *name = NULL; +_cleanup_free_ char *description = NULL, *name_buffer = NULL, +*mount_point = NULL, *maj_min = NULL; assert(name); assert(passwords); +description = disk_description(src); +mount_point = disk_mount_point(vol); + +if (description && streq(vol, description)) { +/* If the description string is simply the + * volume name, then let's not show this + * twice */ +free(description); +description = NULL; +} + +if (mount_point && description) +r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point); +else if (mount_point) +r = asprintf(&name_buffer, "%s on %s", vol, mount_point); +else if (description) +r = asprintf(&name_buffer, "%s (%s)", description, vol); + +if (r < 0) { +log_oom(); +return r; +} +name = name_buffer ? name_buffer : vol; + if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) return log_oom(); -escaped_name = cescape(name); +if (src) +maj_min = disk_maj_min(src); + +if (maj_min) +escaped_name = maj_min; +else +escaped_name = cescape(name); + if (!escaped_name) return log_oom(); @@ -552,8 +613,7 @@ int main(int argc, char *argv[]) { unsigned tries; usec_t until; crypt_status_info status; -const char *key_file = NULL, *name = NULL; -_cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL; +const char *key_file; /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */ @@ -581,31 +641,6 @@ int main(int argc, char *argv[]) { /* A delicious drop of snake oil */ mlockall(MCL_FUTURE); -description = disk_description(argv[3]); -mount_point = disk_mount_point(argv[2]); - -if (description && streq(argv[2], description)) { -/* If the description string is simply the - * volume name, then let's not show this - * twice */ -free(description); -description = NULL; -} - -k = 0; -if (m
[systemd-devel] [PATCH V2] cryptsetup: craft a unique ID with the source device
From: Harald Hoyer If cryptsetup is called with a source device as argv[3], then craft the ID for the password agent with a unique device path. If possible "/dev/block/:" is used, otherwise the original argv[3] is used. This enables password agents like petera [1] to provide a password according to the source device. The original ID did not carry enough information and was more targeted for a human readable string, which is specified in the "Message" field anyway. With this patch the ID of the ask.XXX ini file looks like this: ID=cryptsetup:/dev/block/: [1] https://github.com/npmccallum/petera --- V2: - renamed to disk_major_minor(), return error values - removed sanity stat() for /dev/block/maj:min src/cryptsetup/cryptsetup.c | 88 + 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a5018f1..ff3325c 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -238,6 +238,24 @@ static void log_glue(int level, const char *msg, void *usrptr) { log_debug("%s", msg); } +static int disk_major_minor(const char *path, char **ret) { +struct stat st; + +assert(path); + +if (stat(path, &st) < 0) +return -errno; + +if (!S_ISBLK(st.st_mode)) +return -EINVAL; + +if(asprintf(ret, "/dev/block/%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) { +return log_oom(); +} + +return 0; +} + static char* disk_description(const char *path) { static const char name_fields[] = @@ -295,20 +313,54 @@ static char *disk_mount_point(const char *label) { return NULL; } -static int get_password(const char *name, usec_t until, bool accept_cached, char ***passwords) { -int r; +static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***passwords) { +int r = 0; char **p; _cleanup_free_ char *text = NULL; _cleanup_free_ char *escaped_name = NULL; char *id; +const char *name = NULL; +_cleanup_free_ char *description = NULL, *name_buffer = NULL, +*mount_point = NULL, *maj_min = NULL; assert(name); assert(passwords); +description = disk_description(src); +mount_point = disk_mount_point(vol); + +if (description && streq(vol, description)) { +/* If the description string is simply the + * volume name, then let's not show this + * twice */ +free(description); +description = NULL; +} + +if (mount_point && description) +r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point); +else if (mount_point) +r = asprintf(&name_buffer, "%s on %s", vol, mount_point); +else if (description) +r = asprintf(&name_buffer, "%s (%s)", description, vol); + +if (r < 0) { +log_oom(); +return r; +} +name = name_buffer ? name_buffer : vol; + if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) return log_oom(); -escaped_name = cescape(name); +if (src) +disk_major_minor(src, &maj_min); + +if (maj_min) +escaped_name = maj_min; +else +escaped_name = cescape(name); + if (!escaped_name) return log_oom(); @@ -552,8 +604,7 @@ int main(int argc, char *argv[]) { unsigned tries; usec_t until; crypt_status_info status; -const char *key_file = NULL, *name = NULL; -_cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL; +const char *key_file = NULL; /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */ @@ -581,31 +632,6 @@ int main(int argc, char *argv[]) { /* A delicious drop of snake oil */ mlockall(MCL_FUTURE); -description = disk_description(argv[3]); -mount_point = disk_mount_point(argv[2]); - -if (description && streq(argv[2], description)) { -/* If the description string is simply the - * volume name, then let's not show this - * twice */ -free(description); -description = NULL; -} - -k = 0; -if (mount_point && description) -
[systemd-devel] [PATCH V3] cryptsetup: craft a unique ID with the source device
From: Harald Hoyer If cryptsetup is called with a source device as argv[3], then craft the ID for the password agent with a unique device path. If possible "/dev/block/:" is used, otherwise the original argv[3] is used. This enables password agents like petera [1] to provide a password according to the source device. The original ID did not carry enough information and was more targeted for a human readable string, which is specified in the "Message" field anyway. With this patch the ID of the ask.XXX ini file looks like this: ID=cryptsetup:/dev/block/: [1] https://github.com/npmccallum/petera --- V2: - renamed to disk_major_minor(), return error values - removed sanity stat() for /dev/block/maj:min V3: - assert() the correct parameters src/cryptsetup/cryptsetup.c | 91 + 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a5018f1..5f64ada 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -238,6 +238,24 @@ static void log_glue(int level, const char *msg, void *usrptr) { log_debug("%s", msg); } +static int disk_major_minor(const char *path, char **ret) { +struct stat st; + +assert(path); + +if (stat(path, &st) < 0) +return -errno; + +if (!S_ISBLK(st.st_mode)) +return -EINVAL; + +if(asprintf(ret, "/dev/block/%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) { +return log_oom(); +} + +return 0; +} + static char* disk_description(const char *path) { static const char name_fields[] = @@ -295,20 +313,55 @@ static char *disk_mount_point(const char *label) { return NULL; } -static int get_password(const char *name, usec_t until, bool accept_cached, char ***passwords) { -int r; +static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***passwords) { +int r = 0; char **p; _cleanup_free_ char *text = NULL; _cleanup_free_ char *escaped_name = NULL; char *id; +const char *name = NULL; +_cleanup_free_ char *description = NULL, *name_buffer = NULL, +*mount_point = NULL, *maj_min = NULL; -assert(name); +assert(vol); +assert(src); assert(passwords); +description = disk_description(src); +mount_point = disk_mount_point(vol); + +if (description && streq(vol, description)) { +/* If the description string is simply the + * volume name, then let's not show this + * twice */ +free(description); +description = NULL; +} + +if (mount_point && description) +r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point); +else if (mount_point) +r = asprintf(&name_buffer, "%s on %s", vol, mount_point); +else if (description) +r = asprintf(&name_buffer, "%s (%s)", description, vol); + +if (r < 0) { +log_oom(); +return r; +} +name = name_buffer ? name_buffer : vol; + if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) return log_oom(); -escaped_name = cescape(name); +if (src) +disk_major_minor(src, &maj_min); + +if (maj_min) +escaped_name = maj_min; +else +escaped_name = cescape(name); + if (!escaped_name) return log_oom(); @@ -552,8 +605,7 @@ int main(int argc, char *argv[]) { unsigned tries; usec_t until; crypt_status_info status; -const char *key_file = NULL, *name = NULL; -_cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL; +const char *key_file = NULL; /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */ @@ -581,31 +633,6 @@ int main(int argc, char *argv[]) { /* A delicious drop of snake oil */ mlockall(MCL_FUTURE); -description = disk_description(argv[3]); -mount_point = disk_mount_point(argv[2]); - -if (description && streq(argv[2], description)) { -/* If the description string is simply the - * volume name, then let's not show this - * twice */ -free(description); -description = NULL; -} - -k = 0; -
[systemd-devel] [PATCHi V4] cryptsetup: craft a unique ID with the source device
From: Harald Hoyer If cryptsetup is called with a source device as argv[3], then craft the ID for the password agent with a unique device path. If possible "/dev/block/:" is used, otherwise the original argv[3] is used. This enables password agents like petera [1] to provide a password according to the source device. The original ID did not carry enough information and was more targeted for a human readable string, which is specified in the "Message" field anyway. With this patch the ID of the ask.XXX ini file looks like this: ID=cryptsetup:/dev/block/: [1] https://github.com/npmccallum/petera --- V2: - renamed to disk_major_minor(), return error values - removed sanity stat() for /dev/block/maj:min V3: - assert() the correct parameters V4: - code style cleanup - fixed maj_min _cleanup_free_ src/cryptsetup/cryptsetup.c | 91 + 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a5018f1..dd6f01c 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -238,6 +238,23 @@ static void log_glue(int level, const char *msg, void *usrptr) { log_debug("%s", msg); } +static int disk_major_minor(const char *path, char **ret) { +struct stat st; + +assert(path); + +if (stat(path, &st) < 0) +return -errno; + +if (!S_ISBLK(st.st_mode)) +return -EINVAL; + +if (asprintf(ret, "/dev/block/%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) +return -errno; + +return 0; +} + static char* disk_description(const char *path) { static const char name_fields[] = @@ -295,20 +312,56 @@ static char *disk_mount_point(const char *label) { return NULL; } -static int get_password(const char *name, usec_t until, bool accept_cached, char ***passwords) { -int r; +static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***passwords) { +int r = 0; char **p; _cleanup_free_ char *text = NULL; _cleanup_free_ char *escaped_name = NULL; char *id; +const char *name = NULL; +_cleanup_free_ char *description = NULL, *name_buffer = NULL, +*mount_point = NULL, *maj_min = NULL; -assert(name); +assert(vol); +assert(src); assert(passwords); +description = disk_description(src); +mount_point = disk_mount_point(vol); + +if (description && streq(vol, description)) { +/* If the description string is simply the + * volume name, then let's not show this + * twice */ +free(description); +description = NULL; +} + +if (mount_point && description) +r = asprintf(&name_buffer, "%s (%s) on %s", description, vol, mount_point); +else if (mount_point) +r = asprintf(&name_buffer, "%s on %s", vol, mount_point); +else if (description) +r = asprintf(&name_buffer, "%s (%s)", description, vol); + +if (r < 0) { +log_oom(); +return r; +} +name = name_buffer ? name_buffer : vol; + if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) return log_oom(); -escaped_name = cescape(name); +if (src) +disk_major_minor(src, &maj_min); + +if (maj_min) { +escaped_name = maj_min; +maj_min = NULL; +} else +escaped_name = cescape(name); + if (!escaped_name) return log_oom(); @@ -552,8 +605,7 @@ int main(int argc, char *argv[]) { unsigned tries; usec_t until; crypt_status_info status; -const char *key_file = NULL, *name = NULL; -_cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL; +const char *key_file = NULL; /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE [PASSWORD] [OPTIONS] */ @@ -581,31 +633,6 @@ int main(int argc, char *argv[]) { /* A delicious drop of snake oil */ mlockall(MCL_FUTURE); -description = disk_description(argv[3]); -mount_point = disk_mount_point(argv[2]); - -if (description && streq(argv[2], description)) { -/* If the description string is simply the - * volume name, then let's not show this - * twice */ -free(description); -
[systemd-devel] [PATCH 1/6] readahead-replay: use posix_fadvise instead of readahead
From: Harald Hoyer --- src/readahead-replay.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/readahead-replay.c b/src/readahead-replay.c index b886857..f4d252b 100644 --- a/src/readahead-replay.c +++ b/src/readahead-replay.c @@ -85,7 +85,7 @@ static int unpack_file(FILE *pack) { any = true; if (fd >= 0) -if (readahead(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE) < 0) { +if (posix_fadvise(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE, POSIX_FADV_WILLNEED) < 0) { log_warning("readahead() failed: %m"); goto finish; } @@ -96,7 +96,7 @@ static int unpack_file(FILE *pack) { * intended to mean that the whole file shall be * read */ -if (readahead(fd, 0, st.st_size) < 0) { +if (posix_fadvise(fd, 0, st.st_size, POSIX_FADV_WILLNEED) < 0) { log_warning("readahead() failed: %m"); goto finish; } -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/6] readahead-common:fs_on_ssd() stat might not get the real device name
From: Harald Hoyer btrfs returns a major(0) for its device, so try to find the mountpoint and real device. --- src/readahead-common.c | 36 ++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/readahead-common.c b/src/readahead-common.c index 8533717..1ff027d 100644 --- a/src/readahead-common.c +++ b/src/readahead-common.c @@ -51,6 +51,25 @@ int file_verify(int fd, const char *fn, struct stat *st) { return 1; } +static char *get_devname(const char *mountpoint) +{ +FILE *fp; +int maj, min; + char mp[1024], dev[1024]; + +fp = fopen("/proc/self/mountinfo", "r"); +if (fp == NULL) +return NULL; +while (fscanf(fp, "%*s %*s %i:%i %*s %1024s %*s %*s %*s %1024s %*[^\n]", &maj, &min, mp, dev) == 4) { +if (strcmp(mountpoint, mp) == 0) { + fclose(fp); +return strdup(dev); +} +} +fclose(fp); +return NULL; +} + int fs_on_ssd(const char *p) { struct stat st; struct udev *udev = NULL; @@ -66,8 +85,21 @@ int fs_on_ssd(const char *p) { if (!(udev = udev_new())) return -ENOMEM; -if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) -goto finish; + if (major(st.st_dev) == 0) { + /* special device, might be on a btrfs */ + int ret = -1; + char *devname = get_devname(p); + if (devname == NULL) + return -EINVAL; + ret = stat(devname, &st); + free(devname); + if (ret < 0) { + return -EINVAL; + } + } + + if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) + goto finish; if ((devtype = udev_device_get_property_value(udev_device, "DEVTYPE")) && streq(devtype, "partition")) -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 3/6] hashmap.h: HASHMAP_FOREACH* iterate until ITERATOR_LAST
From: Harald Hoyer --- src/hashmap.h |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hashmap.h b/src/hashmap.h index ac5a8ae..64a468d 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -77,12 +77,12 @@ void* hashmap_first(Hashmap *h); void* hashmap_last(Hashmap *h); #define HASHMAP_FOREACH(e, h, i) \ -for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), NULL); (e); (e) = hashmap_iterate((h), &(i), NULL)) +for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), NULL); (i) != ITERATOR_LAST; (e) = hashmap_iterate((h), &(i), NULL)) #define HASHMAP_FOREACH_KEY(e, k, h, i) \ -for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), (const void**) &(k)); (e); (e) = hashmap_iterate((h), &(i), (const void**) &(k))) +for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), (const void**) &(k)); (i) != ITERATOR_LAST; (e) = hashmap_iterate((h), &(i), (const void**) &(k))) #define HASHMAP_FOREACH_BACKWARDS(e, h, i) \ -for ((i) = ITERATOR_LAST, (e) = hashmap_iterate_backwards((h), &(i), NULL); (e); (e) = hashmap_iterate_backwards((h), &(i), NULL)) +for ((i) = ITERATOR_LAST, (e) = hashmap_iterate_backwards((h), &(i), NULL); (i) != ITERATOR_LAST; (e) = hashmap_iterate_backwards((h), &(i), NULL)) #endif -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 4/6] readahead-collect: check for negative return codes of fs_on_ssd()
From: Harald Hoyer --- src/readahead-collect.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/readahead-collect.c b/src/readahead-collect.c index 5ff3711..7983b31 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -326,7 +326,7 @@ static int collect(const char *root) { log_debug("Writing Pack File..."); -on_ssd = fs_on_ssd(root); +on_ssd = fs_on_ssd(root) == 0; log_debug("On SSD: %s", yes_no(on_ssd)); on_btrfs = statfs(root, &sfs) >= 0 && sfs.f_type == BTRFS_SUPER_MAGIC; -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 5/6] readahead-collect: handle btrfs FIEMAP
From: Harald Hoyer Some files on btrfs do not have a physical extent. Just return an increasing number. --- src/readahead-collect.c |9 - 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/readahead-collect.c b/src/readahead-collect.c index 7983b31..f7f0f14 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -146,6 +146,7 @@ static unsigned long fd_first_block(int fd) { struct fiemap fiemap; struct fiemap_extent extent; } data; + static unsigned long ul = 0; zero(data); data.fiemap.fm_length = ~0ULL; @@ -160,6 +161,12 @@ static unsigned long fd_first_block(int fd) { if (data.fiemap.fm_extents[0].fe_flags & FIEMAP_EXTENT_UNKNOWN) return 0; + // Some filesystems/files do not have a physical extent. + // Just return an increasing number. + if (data.fiemap.fm_extents[0].fe_flags & FIEMAP_EXTENT_MERGED + && data.fiemap.fm_extents[0].fe_physical == 0) + return ul++; + return (unsigned long) data.fiemap.fm_extents[0].fe_physical; } @@ -298,7 +305,7 @@ static int collect(const char *root) { ul = fd_first_block(m->fd); -if ((k = hashmap_put(files, p, ULONG_TO_PTR(ul))) < 0) { +if (ul && (k = hashmap_put(files, p, ULONG_TO_PTR(ul))) < 0) { if (k != -EEXIST) log_warning("set_put() failed: %s", strerror(-k)); -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 6/6] readahead-collect: typo, free the correct pointer
From: Harald Hoyer --- src/readahead-collect.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/readahead-collect.c b/src/readahead-collect.c index f7f0f14..9fb4771 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -434,7 +434,7 @@ finish: free(pack_fn); while ((p = hashmap_steal_first_key(files))) -free(q); +free(p); hashmap_free(files); -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/6] readahead-replay: use posix_fadvise instead of readahead
From: Harald Hoyer --- src/readahead-replay.c |8 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/readahead-replay.c b/src/readahead-replay.c index 1f1ec52..c93f147 100644 --- a/src/readahead-replay.c +++ b/src/readahead-replay.c @@ -85,8 +85,8 @@ static int unpack_file(FILE *pack) { any = true; if (fd >= 0) -if (readahead(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE) < 0) { -log_warning("readahead() failed: %m"); +if (posix_fadvise(fd, b * PAGE_SIZE, (c - b) * PAGE_SIZE, POSIX_FADV_WILLNEED) < 0) { +log_warning("posix_fadvise() failed: %m"); goto finish; } } @@ -96,8 +96,8 @@ static int unpack_file(FILE *pack) { * intended to mean that the whole file shall be * read */ -if (readahead(fd, 0, st.st_size) < 0) { -log_warning("readahead() failed: %m"); +if (posix_fadvise(fd, 0, st.st_size, POSIX_FADV_WILLNEED) < 0) { +log_warning("posix_fadvise() failed: %m"); goto finish; } } -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] var-run.service: create console dir needed by pam
From: Harald Hoyer --- units/var-run.service |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/units/var-run.service b/units/var-run.service index 2cb861e..16acb5a 100644 --- a/units/var-run.service +++ b/units/var-run.service @@ -17,3 +17,4 @@ Type=oneshot RemainAfterExit=yes ExecStart=/bin/touch /var/run/utmp ; /bin/chmod 0664 /var/run/utmp ; /bin/chown root:utmp /var/run/utmp ExecStart=/bin/mkdir /var/run/user ; /bin/chmod 0755 /var/run/user ; -/sbin/restorecon /var/run/user +ExecStart=/bin/mkdir /var/run/console ; /bin/chmod 0755 /var/run/console ; -/sbin/restorecon /var/run/console -- 1.7.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Spelling Corrections
From: Harald Hoyer Just some lame spelling corrections with no functionality. --- CODING_STYLE |2 +- src/automount.c |2 +- src/cgroups-agent.c |2 +- src/dbus.c |2 +- src/device.c |4 ++-- src/device.h |2 +- src/execute.c| 16 src/job.c|2 +- src/log.c|8 src/logger.c |2 +- src/main.c |4 ++-- src/manager.c|8 src/manager.h|4 ++-- src/namespace.c |4 ++-- src/sd-daemon.h |4 ++-- src/securebits.h |2 +- src/service.c|6 +++--- src/shutdown.c |2 +- src/socket.c |4 ++-- src/strv.c |6 +++--- src/swap.h |2 +- src/test-engine.c|6 +++--- src/test-job-type.c |2 +- src/tmpfiles.c |2 +- src/tty-ask-password-agent.c |4 ++-- src/unit-name.c |2 +- src/unit.c |4 ++-- src/unit.h |4 ++-- 28 files changed, 56 insertions(+), 56 deletions(-) diff --git a/CODING_STYLE b/CODING_STYLE index 93f54f6..9341b48 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -20,7 +20,7 @@ we those lookups involve synchronously talking to services that we would need to start up. -- Do not acccess any directories outside of /etc/, /dev, /lib from the +- Do not access any directories outside of /etc/, /dev, /lib from the init daemon to avoid deadlocks with the automounter. - Don't synchronously talk to any other service, due to risk of diff --git a/src/automount.c b/src/automount.c index 9447c0d..0c3c2c9 100644 --- a/src/automount.c +++ b/src/automount.c @@ -583,7 +583,7 @@ static void automount_enter_runnning(Automount *a) { /* Before we do anything, let's see if somebody is playing games with us? */ if (lstat(a->where, &st) < 0) { -log_warning("%s failed stat automount point: %m", a->meta.id); +log_warning("%s failed to stat automount point: %m", a->meta.id); goto fail; } diff --git a/src/cgroups-agent.c b/src/cgroups-agent.c index 3fd0de6..7b4fca2 100644 --- a/src/cgroups-agent.c +++ b/src/cgroups-agent.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { /* We send this event to the private D-Bus socket and then the * system instance will forward this to the system bus. We do - * this to avoid an actviation loop when we start dbus when we + * this to avoid an activation loop when we start dbus when we * are called when the dbus service is shut down. */ if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", &error))) { diff --git a/src/dbus.c b/src/dbus.c index d7b80ba..370db79 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -418,7 +418,7 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus goto oom; } -/* On success we don't do anything, the service will be spwaned now */ +/* On success we don't do anything, the service will be spawned now */ } } diff --git a/src/device.c b/src/device.c index b9d8a2b..ccf2935 100644 --- a/src/device.c +++ b/src/device.c @@ -65,7 +65,7 @@ static void device_init(Unit *u) { /* In contrast to all other unit types we timeout jobs waiting * for devices by default. This is because they otherwise wait - * indefinetely for plugged in devices, something which cannot + * indefinitely for plugged in devices, something which cannot * happen for the other units since their operations time out * anyway. */ d->meta.job_timeout = DEFAULT_TIMEOUT_USEC; @@ -542,7 +542,7 @@ void device_fd_event(Manager *m, int events) { if (!(dev = udev_monitor_receive_device(m->udev_monitor))) { /* * libudev might filter-out devices which pass the bloom filter, - * so getting NULL here is not neccessarily an error + * so getting NULL here is not necessarily an error */ return; } diff --git a/src/device.h b/src/device.h index ee50cfa..9a56a52 100644 --- a/src/device.h +++ b/src/device.h @@ -40,7 +40,7 @@ struct Device { char *sysfs; -/* In order to be able to distuingish dependencies on +/* In order to be able to distinguish dependencies on different device nodes we might end up creating multiple devices for t
[systemd-devel] [PATCH] ratelimit: removed n_printed
From: Harald Hoyer Removed n_printed and renamed n_printed to num. This is not a logging rate limiter anymore. --- src/ratelimit.c | 14 -- src/ratelimit.h |8 +++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/ratelimit.c b/src/ratelimit.c index 5adf1ae..1ddc831 100644 --- a/src/ratelimit.c +++ b/src/ratelimit.c @@ -38,25 +38,19 @@ bool ratelimit_test(RateLimit *r) { if (r->begin <= 0 || r->begin + r->interval < ts) { - -if (r->n_missed > 0) -log_warning("%u events suppressed", r->n_missed); - r->begin = ts; -/* Reset counters */ -r->n_printed = 0; -r->n_missed = 0; +/* Reset counter */ +r->num = 0; goto good; } -if (r->n_printed <= r->burst) +if (r->num <= r->burst) goto good; -r->n_missed++; return false; good: -r->n_printed++; +r->num++; return true; } diff --git a/src/ratelimit.h b/src/ratelimit.h index 2c77787..a44ef70 100644 --- a/src/ratelimit.h +++ b/src/ratelimit.h @@ -28,15 +28,14 @@ typedef struct RateLimit { usec_t interval; usec_t begin; unsigned burst; -unsigned n_printed, n_missed; +unsigned num; } RateLimit; #define RATELIMIT_DEFINE(_name, _interval, _burst) \ RateLimit _name = { \ .interval = (_interval), \ .burst = (_burst), \ -.n_printed = 0, \ -.n_missed = 0, \ +.num = 0,\ .begin = 0 \ } @@ -45,8 +44,7 @@ typedef struct RateLimit { RateLimit *_r = &(v);\ _r->interval = (_interval); \ _r->burst = (_burst);\ -_r->n_printed = 0; \ -_r->n_missed = 0;\ +_r->num = 0; \ _r->begin = 0; \ } while (false); -- 1.7.3.4 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Add support for "ROOT=" on the kernel command line
From: Harald Hoyer "ROOT=" mounts the initial ramdisk with a tmpfs filesystem. --- src/fstab-generator/fstab-generator.c | 5 + src/gpt-auto-generator/gpt-auto-generator.c | 7 +++ 2 files changed, 12 insertions(+) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index bc4c155..3d2e4dd 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -498,6 +498,11 @@ static int parse_proc_cmdline_item(const char *key, const char *value) { if (free_and_strdup(&arg_root_what, value) < 0) return log_oom(); +} else if (streq(key, "ROOT") && value) { + +if (free_and_strdup(&arg_root_what, value) < 0) +return log_oom(); + } else if (streq(key, "rootfstype") && value) { if (free_and_strdup(&arg_root_fstype, value) < 0) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 909fdda..85ceffd 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -613,6 +613,13 @@ static int parse_proc_cmdline_item(const char *key, const char *value) { arg_root_enabled = streq(value, "gpt-auto"); +} else if (streq(key, "ROOT") && value) { + +/* Disable root disk logic if there's a ROOT= value + * specified (unless it happens to be "gpt-auto") */ + +arg_root_enabled = streq(value, "gpt-auto"); + } else if (streq(key, "rw") && !value) arg_root_rw = true; else if (streq(key, "ro") && !value) -- 2.2.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] path-util.c: fix path_is_mount_point() for symlinks
From: Harald Hoyer path_is_mount_point() compares the mount_id of a directory and the mount_id of the parent directory. When following symlinks, the function to get the parent directory does not take the symlink into account. /bin -> /usr/bin with /usr being a mountpoint: mount_id of /bin with AT_SYMLINK_FOLLOW != mount_id of / --- src/shared/path-util.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/shared/path-util.c b/src/shared/path-util.c index b9db7f1..acc7569 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -485,7 +485,17 @@ int path_is_mount_point(const char *t, bool allow_symlink) { return -errno; } -r = path_get_parent(t, &parent); +if (allow_symlink) { +char *real; +real = realpath(t, NULL); +if (!real) +return -errno; +r = path_get_parent(real, &parent); +free(real); +} else { +r = path_get_parent(t, &parent); +} + if (r < 0) return r; -- 2.3.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] fstab-generator: mask systemd-fsck-root for /sysroot unit
From: Harald Hoyer If the fstab-generator generates a mount unit for /sysroot, we shall not run systemd-fsck-root in the real root. --- Makefile.am | 1 + src/fstab-generator/fstab-generator.c | 11 +++ 2 files changed, 12 insertions(+) diff --git a/Makefile.am b/Makefile.am index ba63f68..f28a984 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2427,6 +2427,7 @@ systemd_fstab_generator_SOURCES = \ src/core/mount-setup.c systemd_fstab_generator_LDADD = \ + libsystemd-units.la \ libsystemd-label.la \ libsystemd-shared.la diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 5662b5f..a5e763c 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -37,6 +37,7 @@ #include "generator.h" #include "strv.h" #include "virt.h" +#include "install.h" static const char *arg_dest = "/tmp"; static bool arg_fstab_enabled = true; @@ -388,6 +389,10 @@ static int parse_fstab(bool initrd) { static int add_root_mount(void) { _cleanup_free_ char *what = NULL; const char *opts; +int r; +const char *const files[] = { "systemd-fsck-root.service", NULL }; +UnitFileChange *changes = NULL; +unsigned n_changes = 0; if (isempty(arg_root_what)) { log_debug("Could not find a root= entry on the kernel command line."); @@ -409,6 +414,12 @@ static int add_root_mount(void) { opts = arg_root_options; log_debug("Found entry what=%s where=/sysroot type=%s", what, strna(arg_root_fstype)); + +/* mask systemd-fsck-root.service */ +r = unit_file_mask(UNIT_FILE_SYSTEM, true, NULL, (char**) files, true, &changes, &n_changes); +if (r < 0) +log_error("Failed to mask systemd-fsck-root.service: %m"); + return add_mount(what, "/sysroot", arg_root_fstype, -- 2.3.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] path-util.c: fix path_is_mount_point() for symlinks
From: Harald Hoyer path_is_mount_point() compares the mount_id of a directory and the mount_id of the parent directory. When following symlinks, the function to get the parent directory does not take the symlink into account. /bin -> /usr/bin with /usr being a mountpoint: mount_id of /bin with AT_SYMLINK_FOLLOW != mount_id of / --- src/shared/path-util.c | 32 ++-- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/shared/path-util.c b/src/shared/path-util.c index b9db7f1..0cff7b9 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -456,19 +456,26 @@ int path_is_mount_point(const char *t, bool allow_symlink) { union file_handle_union h = FILE_HANDLE_INIT; int mount_id = -1, mount_id_parent = -1; -_cleanup_free_ char *parent = NULL; struct stat a, b; int r; +int fd; bool nosupp = false; /* We are not actually interested in the file handles, but * name_to_handle_at() also passes us the mount ID, hence use * it but throw the handle away */ - if (path_equal(t, "/")) return 1; -r = name_to_handle_at(AT_FDCWD, t, &h.handle, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0); +fd = openat(AT_FDCWD, t, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|(allow_symlink ? 0 : O_PATH)); +if (fd < 0) { +if (errno == ENOENT) +return 0; + +return -errno; +} + +r = name_to_handle_at(fd, "", &h.handle, &mount_id, AT_EMPTY_PATH); if (r < 0) { if (errno == ENOSYS) /* This kernel does not support name_to_handle_at() @@ -485,12 +492,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) { return -errno; } -r = path_get_parent(t, &parent); -if (r < 0) -return r; h.handle.handle_bytes = MAX_HANDLE_SZ; -r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, AT_SYMLINK_FOLLOW); +r = name_to_handle_at(fd, "..", &h.handle, &mount_id_parent, 0); if (r < 0) if (errno == EOPNOTSUPP) if (nosupp) @@ -509,10 +513,8 @@ int path_is_mount_point(const char *t, bool allow_symlink) { return mount_id != mount_id_parent; fallback: -if (allow_symlink) -r = stat(t, &a); -else -r = lstat(t, &a); + +r = fstatat(fd, "", &a, AT_EMPTY_PATH); if (r < 0) { if (errno == ENOENT) @@ -521,14 +523,8 @@ fallback: return -errno; } -free(parent); -parent = NULL; - -r = path_get_parent(t, &parent); -if (r < 0) -return r; -r = stat(parent, &b); +r = fstatat(fd, "..", &b, 0); if (r < 0) return -errno; -- 2.3.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V3] path-util.c: fix path_is_mount_point() for symlinks
From: Harald Hoyer path_is_mount_point() compares the mount_id of a directory and the mount_id of the parent directory. When following symlinks, the function to get the parent directory does not take the symlink into account. /bin -> /usr/bin with /usr being a mountpoint: mount_id of /bin with AT_SYMLINK_FOLLOW != mount_id of / --- V2 with openat and all relative V3 with _cleanup_close_ src/shared/path-util.c | 30 +- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/shared/path-util.c b/src/shared/path-util.c index b9db7f1..5b7fed5 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -456,9 +456,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) { union file_handle_union h = FILE_HANDLE_INIT; int mount_id = -1, mount_id_parent = -1; -_cleanup_free_ char *parent = NULL; struct stat a, b; int r; +_cleanup_close_ int fd = -1; bool nosupp = false; /* We are not actually interested in the file handles, but @@ -468,7 +468,15 @@ int path_is_mount_point(const char *t, bool allow_symlink) { if (path_equal(t, "/")) return 1; -r = name_to_handle_at(AT_FDCWD, t, &h.handle, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0); +fd = openat(AT_FDCWD, t, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|(allow_symlink ? 0 : O_PATH)); +if (fd < 0) { +if (errno == ENOENT) +return 0; + +return -errno; +} + +r = name_to_handle_at(fd, "", &h.handle, &mount_id, AT_EMPTY_PATH); if (r < 0) { if (errno == ENOSYS) /* This kernel does not support name_to_handle_at() @@ -485,12 +493,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) { return -errno; } -r = path_get_parent(t, &parent); -if (r < 0) -return r; h.handle.handle_bytes = MAX_HANDLE_SZ; -r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, AT_SYMLINK_FOLLOW); +r = name_to_handle_at(fd, "..", &h.handle, &mount_id_parent, 0); if (r < 0) if (errno == EOPNOTSUPP) if (nosupp) @@ -509,10 +514,7 @@ int path_is_mount_point(const char *t, bool allow_symlink) { return mount_id != mount_id_parent; fallback: -if (allow_symlink) -r = stat(t, &a); -else -r = lstat(t, &a); +r = fstatat(fd, "", &a, AT_EMPTY_PATH); if (r < 0) { if (errno == ENOENT) @@ -521,14 +523,8 @@ fallback: return -errno; } -free(parent); -parent = NULL; - -r = path_get_parent(t, &parent); -if (r < 0) -return r; -r = stat(parent, &b); +r = fstatat(fd, "..", &b, 0); if (r < 0) return -errno; -- 2.3.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] use dolt.m4 to speedup compilation
From: Harald Hoyer The speedup is significant Original libtool $ ccache -C && make clean && time make -j4 […] real6m4.104s user13m49.234s sys7m37.864s Original libtool + dolt $ ccache -C && make clean && time make -j4 […] real2m24.869s user7m30.198s sys1m17.813s --- configure.ac | 1 + m4/dolt.m4 | 178 +++ 2 files changed, 179 insertions(+) create mode 100644 m4/dolt.m4 diff --git a/configure.ac b/configure.ac index 14518bc..bc75c31 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,7 @@ AC_CANONICAL_HOST AC_DEFINE_UNQUOTED([CANONICAL_HOST], "$host", [Canonical host string.]) LT_PREREQ(2.2) LT_INIT([disable-static]) +DOLT AS_IF([test "x$enable_static" = "xyes"], [AC_MSG_ERROR([--enable-static is not supported by systemd])]) AS_IF([test "x$enable_largefile" = "xno"], [AC_MSG_ERROR([--disable-largefile is not supported by systemd])]) diff --git a/m4/dolt.m4 b/m4/dolt.m4 new file mode 100644 index 000..af76e9d --- /dev/null +++ b/m4/dolt.m4 @@ -0,0 +1,178 @@ +dnl dolt, a replacement for libtool +dnl Copyright © 2007-2010 Josh Triplett +dnl Copying and distribution of this file, with or without modification, +dnl are permitted in any medium without royalty provided the copyright +dnl notice and this notice are preserved. +dnl +dnl To use dolt, invoke the DOLT macro immediately after the libtool macros. +dnl Optionally, copy this file into acinclude.m4, to avoid the need to have it +dnl installed when running autoconf on your project. + +AC_DEFUN([DOLT], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +# dolt, a replacement for libtool +# Josh Triplett +AC_PATH_PROG(DOLT_BASH, bash) +AC_MSG_CHECKING([if dolt supports this host]) +dolt_supported=yes +if test x$DOLT_BASH = x; then +dolt_supported=no +fi +if test x$GCC != xyes; then +dolt_supported=no +fi +case $host in +*-*-linux* \ +|amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*) +pic_options='-fPIC' +;; +i?86-apple-darwin*) +pic_options='-fno-common' +;; +*) +dolt_supported=no +;; +esac +if test x$dolt_supported = xno ; then +AC_MSG_RESULT([no, falling back to libtool]) +LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)' +LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)' +else +AC_MSG_RESULT([yes, replacing libtool]) + +dnl Start writing out doltcompile. +cat <<__DOLTCOMPILE__EOF__ >doltcompile +#!$DOLT_BASH +__DOLTCOMPILE__EOF__ +cat <<'__DOLTCOMPILE__EOF__' >>doltcompile +args=("$[]@") +for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do +if test x"${args@<:@$arg@:>@}" = x-o ; then +objarg=$((arg+1)) +break +fi +done +if test x$objarg = x ; then +echo 'Error: no -o on compiler command line' 1>&2 +exit 1 +fi +lo="${args@<:@$objarg@:>@}" +obj="${lo%.lo}" +if test x"$lo" = x"$obj" ; then +echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2 +exit 1 +fi +objbase="${obj##*/}" +__DOLTCOMPILE__EOF__ + +dnl Write out shared compilation code. +if test x$enable_shared = xyes; then +cat <<'__DOLTCOMPILE__EOF__' >>doltcompile +libobjdir="${obj%$objbase}.libs" +if test ! -d "$libobjdir" ; then +mkdir_out="$(mkdir "$libobjdir" 2>&1)" +mkdir_ret=$? +if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then + echo "$mkdir_out" 1>&2 +exit $mkdir_ret +fi +fi +pic_object="$libobjdir/$objbase.o" +args@<:@$objarg@:>@="$pic_object" +__DOLTCOMPILE__EOF__ +cat <<__DOLTCOMPILE__EOF__ >>doltcompile +"\${args@<:@@@:>@}" $pic_options -DPIC || exit \$? +__DOLTCOMPILE__EOF__ +fi + +dnl Write out static compilation code. +dnl Avoid duplicate compiler output if also building shared objects. +if test x$enable_static = xyes; then +cat <<'__DOLTCOMPILE__EOF__' >>doltcompile +non_pic_object="$obj.o" +args@<:@$objarg@:>@="$non_pic_object" +__DOLTCOMPILE__EOF__ +if test x$enable_shared = xyes; then +cat <<'__DOLTCOMPILE__EOF__' >>doltcompile +"${args@<:@@@:>@}" >/dev/null 2>&1 || exit $? +__DOLTCOMPILE__EOF__ +else +cat <<'__DOLTCOMPILE__EOF__' >>doltcompile +"${args@<:@@@:>@}" || exit $? +__DOLTCOMPILE__EOF__ +fi +fi + +dnl Write out the code to write the .lo file. +dnl The second li
[systemd-devel] [PATCH] journalctl: add "-t --identifier=STRING" option
From: Harald Hoyer This turns journalctl to the counterpart of systemd-cat. Messages sent with systemd-cat --identifier foo --prioritiy debug can now be shown with journalctl --identifier foo --prioritiy debug "--identifier" is not merged with "--unit" to make a clear distinction between syslog and systemd units. syslog identifiers can be chosen freely by anyone. --- man/journalctl.xml | 14 ++ src/journal/journalctl.c | 43 ++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/man/journalctl.xml b/man/journalctl.xml index bf18756..906ffd0 100644 --- a/man/journalctl.xml +++ b/man/journalctl.xml @@ -498,6 +498,20 @@ +-t + --identifier=SYSLOG_IDENTIFIER|PATTERN + +Show messages for the +specified syslog identifier +SYSLOG_IDENTIFIER, or +for any of the messages with a SYSLOG_IDENTIFIER +matched by PATTERN. + +This parameter can be specified +multiple times. + + + -u --unit=UNIT|PATTERN diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 5c4a71d..3037fb8 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -89,6 +89,7 @@ static bool arg_force = false; #endif static usec_t arg_since, arg_until; static bool arg_since_set = false, arg_until_set = false; +static char **arg_syslog_identifier = NULL; static char **arg_system_units = NULL; static char **arg_user_units = NULL; static const char *arg_field = NULL; @@ -180,6 +181,7 @@ static void help(void) { " -k --dmesg Show kernel message log from the current boot\n" " -u --unit=UNIT Show data only from the specified unit\n" " --user-unit=UNIT Show data only from the specified user session unit\n" + " -t --identifier=STRING Show only messages wit the specified syslog identifier\n" " -p --priority=RANGE Show only messages within the specified priority range\n" " -e --pager-end Immediately jump to end of the journal in the pager\n" " -f --follow Follow the journal\n" @@ -276,6 +278,7 @@ static int parse_argv(int argc, char *argv[]) { { "file", required_argument, NULL, ARG_FILE }, { "root", required_argument, NULL, ARG_ROOT }, { "header", no_argument, NULL, ARG_HEADER }, +{ "identifier", required_argument, NULL, 't' }, { "priority", required_argument, NULL, 'p' }, { "setup-keys", no_argument, NULL, ARG_SETUP_KEYS }, { "interval", required_argument, NULL, ARG_INTERVAL }, @@ -304,7 +307,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); -while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0) +while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:t:u:F:xrM:", options, NULL)) >= 0) switch (c) { @@ -590,6 +593,12 @@ static int parse_argv(int argc, char *argv[]) { arg_until_set = true; break; +case 't': +r = strv_extend(&arg_syslog_identifier, optarg); +if (r < 0) +return log_oom(); +break; + case 'u': r = strv_extend(&arg_system_units, optarg); if (r < 0) @@ -1212,6 +1221,32 @@ static int add_priorities(sd_journal *j) { return 0; } + +static int add_syslog_identifier(sd_journal *j) { +int r; +char **i; + +assert(j); + +STRV_FOREACH(i, arg_syslog_identifier) { +char *u; + +u = strappenda("SYSLOG_IDENTIFIER=", *i); +r = sd_journal_add_match(j, u, 0); +if (r < 0) +return r; +r = sd_journal_add_disjunction(j); +if (r < 0) +return r; +} + +r =
[systemd-devel] [PATCH] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication --- Makefile.am| 1 + src/core/main.c| 2 +- src/core/shutdown.c| 77 +- src/core/switch-root.c | 6 ++-- src/core/switch-root.h | 2 +- 5 files changed, 13 insertions(+), 75 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4028112..6401fcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1873,6 +1873,7 @@ systemd_shutdown_SOURCES = \ systemd_shutdown_LDADD = \ libsystemd-label.la \ + libsystemd-core.la \ libudev-internal.la \ libsystemd-shared.la diff --git a/src/core/main.c b/src/core/main.c index 792b316..1805128 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1842,7 +1842,7 @@ finish: broadcast_signal(SIGTERM, false, true); /* And switch root */ -r = switch_root(switch_root_dir); +r = switch_root(switch_root_dir, "/mnt", true); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..554d4da 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -132,15 +133,6 @@ static int parse_argv(int argc, char *argv[]) { } static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -150,67 +142,9 @@ static int prepare_new_root(void) { log_error("Failed to make /run/initramfs private mount: %m"); return -errno; } - -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - return 0; } -static int pivot_to_new_root(void) { - -if (chdir("/run/initramfs") < 0) { -log_error("Failed to change directory to /run/initramfs: %m"); -return -errno; -} - -/* Work-around for a kernel bug: for some reason the kernel - * refuses switching root if any file systems are mounted - * MS_SHARED. Hence remount them MS_PRIVATE here as a - * work-around. - * - * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */ -if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0) -log_warning("Failed to make \"/\" private mount: %m"); - -if (pivot_root(".", "oldroot") < 0) { -log_error("pivot failed: %m"); -/* only chroot if pivot root succeeded */ -return -errno; -} - -chroot("."); - -setsid(); -make_console_stdio(); - -log_info("Successfully changed into root pivot."); - -return 0; -} int main(int argc, char *argv[]) { bool need_umount, need_swapoff, need_loop_detach, need_dm_detach; @@ -372,12 +306,15 @@ int main(int argc, char *argv[]) { if (!in_container && !in_initrd() &&
[systemd-devel] [PATCH V2] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication --- Removed all references to "/mnt" in switch_root() and the bogus comment. Makefile.am| 1 + src/core/main.c| 2 +- src/core/shutdown.c| 77 +- src/core/switch-root.c | 14 +++-- src/core/switch-root.h | 2 +- 5 files changed, 14 insertions(+), 82 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4028112..6401fcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1873,6 +1873,7 @@ systemd_shutdown_SOURCES = \ systemd_shutdown_LDADD = \ libsystemd-label.la \ + libsystemd-core.la \ libudev-internal.la \ libsystemd-shared.la diff --git a/src/core/main.c b/src/core/main.c index 792b316..1805128 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1842,7 +1842,7 @@ finish: broadcast_signal(SIGTERM, false, true); /* And switch root */ -r = switch_root(switch_root_dir); +r = switch_root(switch_root_dir, "/mnt", true); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..554d4da 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -132,15 +133,6 @@ static int parse_argv(int argc, char *argv[]) { } static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -150,67 +142,9 @@ static int prepare_new_root(void) { log_error("Failed to make /run/initramfs private mount: %m"); return -errno; } - -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - return 0; } -static int pivot_to_new_root(void) { - -if (chdir("/run/initramfs") < 0) { -log_error("Failed to change directory to /run/initramfs: %m"); -return -errno; -} - -/* Work-around for a kernel bug: for some reason the kernel - * refuses switching root if any file systems are mounted - * MS_SHARED. Hence remount them MS_PRIVATE here as a - * work-around. - * - * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */ -if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0) -log_warning("Failed to make \"/\" private mount: %m"); - -if (pivot_root(".", "oldroot") < 0) { -log_error("pivot failed: %m"); -/* only chroot if pivot root succeeded */ -return -errno; -} - -chroot("."); - -setsid(); -make_console_stdio(); - -log_info("Successfully changed into root pivot."); - -return 0; -} int main(int argc, char *argv[]) { bool need_umount, need_swapoff, need_loop_detach, need_dm_detach; @@ -372,12 +306,15 @@ int main(i
[systemd-devel] [PATCH V3] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication also move switch-root to shared --- V2: - Removed all references to "/mnt" in switch_root() and the bogus comment. V3: - moved switch-root.[ch] to shared - added switch to mount MS_MOVE or MS_BIND the old dirs Makefile.am| 4 +- src/core/main.c| 2 +- src/core/shutdown.c| 77 -- src/{core => shared}/switch-root.c | 30 +++ src/{core => shared}/switch-root.h | 2 +- 5 files changed, 26 insertions(+), 89 deletions(-) rename src/{core => shared}/switch-root.c (84%) rename src/{core => shared}/switch-root.h (89%) diff --git a/Makefile.am b/Makefile.am index 4028112..14ba8f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -864,6 +864,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/memfd.h \ src/shared/uid-range.c \ src/shared/uid-range.h \ + src/shared/switch-root.h \ + src/shared/switch-root.c \ src/shared/nss-util.h nodist_libsystemd_shared_la_SOURCES = \ @@ -1105,8 +1107,6 @@ libsystemd_core_la_SOURCES = \ src/core/namespace.h \ src/core/build.h \ src/core/sysfs-show.h \ - src/core/switch-root.h \ - src/core/switch-root.c \ src/core/killall.h \ src/core/killall.c \ src/core/audit-fd.c \ diff --git a/src/core/main.c b/src/core/main.c index 792b316..62a038c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1842,7 +1842,7 @@ finish: broadcast_signal(SIGTERM, false, true); /* And switch root */ -r = switch_root(switch_root_dir); +r = switch_root(switch_root_dir, "/mnt", true, true); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..f0c66a1 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -132,15 +133,6 @@ static int parse_argv(int argc, char *argv[]) { } static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -150,67 +142,9 @@ static int prepare_new_root(void) { log_error("Failed to make /run/initramfs private mount: %m"); return -errno; } - -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - return 0; } -static int pivot_to_new_root(void) { - -if (chdir("/run/initramfs") < 0) { -log_error("Failed to change directory to /run/initramfs: %m"); -return -errno; -} - -/* Work-around for a kernel bug: for some reason the kernel - * refuses switching root if any file systems are mounted - * MS_SHARED. Hence remount them MS_PRIVATE here as a - * work-around. - * - * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */ -if (mount(NULL, "/", NULL, MS_REC|MS
[systemd-devel] [PATCH V4] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication also move switch-root to shared --- V2: - Removed all references to "/mnt" in switch_root() and the bogus comment. V3: - moved switch-root.[ch] to shared - added switch to mount MS_MOVE or MS_BIND the old dirs V4: - mkdir_p_label() in switch_root() Makefile.am| 4 +- src/core/main.c| 2 +- src/core/shutdown.c| 77 -- src/{core => shared}/switch-root.c | 34 - src/{core => shared}/switch-root.h | 2 +- 5 files changed, 28 insertions(+), 91 deletions(-) rename src/{core => shared}/switch-root.c (83%) rename src/{core => shared}/switch-root.h (89%) diff --git a/Makefile.am b/Makefile.am index 4028112..14ba8f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -864,6 +864,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/memfd.h \ src/shared/uid-range.c \ src/shared/uid-range.h \ + src/shared/switch-root.h \ + src/shared/switch-root.c \ src/shared/nss-util.h nodist_libsystemd_shared_la_SOURCES = \ @@ -1105,8 +1107,6 @@ libsystemd_core_la_SOURCES = \ src/core/namespace.h \ src/core/build.h \ src/core/sysfs-show.h \ - src/core/switch-root.h \ - src/core/switch-root.c \ src/core/killall.h \ src/core/killall.c \ src/core/audit-fd.c \ diff --git a/src/core/main.c b/src/core/main.c index 792b316..62a038c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1842,7 +1842,7 @@ finish: broadcast_signal(SIGTERM, false, true); /* And switch root */ -r = switch_root(switch_root_dir); +r = switch_root(switch_root_dir, "/mnt", true, true); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..f0c66a1 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -132,15 +133,6 @@ static int parse_argv(int argc, char *argv[]) { } static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -150,67 +142,9 @@ static int prepare_new_root(void) { log_error("Failed to make /run/initramfs private mount: %m"); return -errno; } - -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - return 0; } -static int pivot_to_new_root(void) { - -if (chdir("/run/initramfs") < 0) { -log_error("Failed to change directory to /run/initramfs: %m"); -return -errno; -} - -/* Work-around for a kernel bug: for some reason the kernel - * refuses switching root if any file systems are mounted - * MS_SHARED. Hence remount them MS_PRIVATE here as a - * work-around. - * - * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */ -if (mount(NULL,
[systemd-devel] [PATCH V5] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication also move switch-root to shared --- V2: - Removed all references to "/mnt" in switch_root() and the bogus comment. V3: - moved switch-root.[ch] to shared - added switch to mount MS_MOVE or MS_BIND the old dirs V4: - mkdir_p_label() in switch_root() V5: - fixed coding style - mountflags now argument of switch_root() - add comment for mountflags used Makefile.am| 4 +- src/core/main.c| 4 +- src/core/shutdown.c| 88 -- src/{core => shared}/switch-root.c | 35 --- src/{core => shared}/switch-root.h | 2 +- 5 files changed, 41 insertions(+), 92 deletions(-) rename src/{core => shared}/switch-root.c (81%) rename src/{core => shared}/switch-root.h (88%) diff --git a/Makefile.am b/Makefile.am index 4028112..14ba8f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -864,6 +864,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/memfd.h \ src/shared/uid-range.c \ src/shared/uid-range.h \ + src/shared/switch-root.h \ + src/shared/switch-root.c \ src/shared/nss-util.h nodist_libsystemd_shared_la_SOURCES = \ @@ -1105,8 +1107,6 @@ libsystemd_core_la_SOURCES = \ src/core/namespace.h \ src/core/build.h \ src/core/sysfs-show.h \ - src/core/switch-root.h \ - src/core/switch-root.c \ src/core/killall.h \ src/core/killall.c \ src/core/audit-fd.c \ diff --git a/src/core/main.c b/src/core/main.c index 792b316..3807e73 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1841,8 +1841,8 @@ finish: * deserializing. */ broadcast_signal(SIGTERM, false, true); -/* And switch root */ -r = switch_root(switch_root_dir); +/* And switch root with MS_MOVE, because we remove the old directory afterwards and detach it. */ +r = switch_root(switch_root_dir, "/mnt", true, MS_MOVE); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..8026f59 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -131,15 +132,8 @@ static int parse_argv(int argc, char *argv[]) { return 0; } -static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; +static int switch_root_initramfs(void) { +int r; if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); @@ -151,66 +145,19 @@ static int prepare_new_root(void) { return -errno; } -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; +/* switch_root with MS_BIND, because there might still be processes lurking around, which have open file desriptors. + * /run/initramfs/shutdown will take care of these. + * Also do not detach the old root, because /run/initramfs/shutdown needs to access it. + */ +r = switch_root("/run/initramfs", "/ol
[systemd-devel] [PATCH] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication also move switch-root to shared --- V2: - Removed all references to "/mnt" in switch_root() and the bogus comment. V3: - moved switch-root.[ch] to shared - added switch to mount MS_MOVE or MS_BIND the old dirs V4: - mkdir_p_label() in switch_root() V5: - fixed coding style - mountflags now argument of switch_root() - add comment for mountflags used V6: - removed double error message, if switch_root_initramfs() failed Makefile.am| 4 +- src/core/main.c| 4 +- src/core/shutdown.c| 88 +++--- src/{core => shared}/switch-root.c | 35 --- src/{core => shared}/switch-root.h | 2 +- 5 files changed, 37 insertions(+), 96 deletions(-) rename src/{core => shared}/switch-root.c (81%) rename src/{core => shared}/switch-root.h (88%) diff --git a/Makefile.am b/Makefile.am index 4028112..14ba8f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -864,6 +864,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/memfd.h \ src/shared/uid-range.c \ src/shared/uid-range.h \ + src/shared/switch-root.h \ + src/shared/switch-root.c \ src/shared/nss-util.h nodist_libsystemd_shared_la_SOURCES = \ @@ -1105,8 +1107,6 @@ libsystemd_core_la_SOURCES = \ src/core/namespace.h \ src/core/build.h \ src/core/sysfs-show.h \ - src/core/switch-root.h \ - src/core/switch-root.c \ src/core/killall.h \ src/core/killall.c \ src/core/audit-fd.c \ diff --git a/src/core/main.c b/src/core/main.c index 792b316..3807e73 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1841,8 +1841,8 @@ finish: * deserializing. */ broadcast_signal(SIGTERM, false, true); -/* And switch root */ -r = switch_root(switch_root_dir); +/* And switch root with MS_MOVE, because we remove the old directory afterwards and detach it. */ +r = switch_root(switch_root_dir, "/mnt", true, MS_MOVE); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..db6407f 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -131,16 +132,7 @@ static int parse_argv(int argc, char *argv[]) { return 0; } -static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - +static int switch_root_initramfs(void) { if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -151,66 +143,13 @@ static int prepare_new_root(void) { return -errno; } -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - -return 0; +/* switch_root with MS_BIND, because there might still be processes lurking around, which have open file desriptors. + * /run/initramfs/shutdown will take care of these. + * Also do not detach the old root, because /run
[systemd-devel] [PATCH V7] use the switch_root function in shutdown
From: Harald Hoyer removes code duplication also move switch-root to shared --- V2: - Removed all references to "/mnt" in switch_root() and the bogus comment. V3: - moved switch-root.[ch] to shared - added switch to mount MS_MOVE or MS_BIND the old dirs V4: - mkdir_p_label() in switch_root() V5: - fixed coding style - mountflags now argument of switch_root() - add comment for mountflags used V6: - removed double error message, if switch_root_initramfs() failed V7: - use return value of switch_root_initramfs() with strerror() Makefile.am| 4 +- src/core/main.c| 4 +- src/core/shutdown.c| 90 +++--- src/{core => shared}/switch-root.c | 35 +++ src/{core => shared}/switch-root.h | 2 +- 5 files changed, 39 insertions(+), 96 deletions(-) rename src/{core => shared}/switch-root.c (81%) rename src/{core => shared}/switch-root.h (88%) diff --git a/Makefile.am b/Makefile.am index 4028112..14ba8f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -864,6 +864,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/memfd.h \ src/shared/uid-range.c \ src/shared/uid-range.h \ + src/shared/switch-root.h \ + src/shared/switch-root.c \ src/shared/nss-util.h nodist_libsystemd_shared_la_SOURCES = \ @@ -1105,8 +1107,6 @@ libsystemd_core_la_SOURCES = \ src/core/namespace.h \ src/core/build.h \ src/core/sysfs-show.h \ - src/core/switch-root.h \ - src/core/switch-root.c \ src/core/killall.h \ src/core/killall.c \ src/core/audit-fd.c \ diff --git a/src/core/main.c b/src/core/main.c index 792b316..3807e73 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1841,8 +1841,8 @@ finish: * deserializing. */ broadcast_signal(SIGTERM, false, true); -/* And switch root */ -r = switch_root(switch_root_dir); +/* And switch root with MS_MOVE, because we remove the old directory afterwards and detach it. */ +r = switch_root(switch_root_dir, "/mnt", true, MS_MOVE); if (r < 0) log_error("Failed to switch root, ignoring: %s", strerror(-r)); } diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140..e23f3c6 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -48,6 +48,7 @@ #include "killall.h" #include "cgroup-util.h" #include "def.h" +#include "switch-root.h" #define FINALIZE_ATTEMPTS 50 @@ -131,16 +132,7 @@ static int parse_argv(int argc, char *argv[]) { return 0; } -static int prepare_new_root(void) { -static const char dirs[] = -"/run/initramfs/oldroot\0" -"/run/initramfs/proc\0" -"/run/initramfs/sys\0" -"/run/initramfs/dev\0" -"/run/initramfs/run\0"; - -const char *dir; - +static int switch_root_initramfs(void) { if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) { log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m"); return -errno; @@ -151,66 +143,13 @@ static int prepare_new_root(void) { return -errno; } -NULSTR_FOREACH(dir, dirs) -if (mkdir_p_label(dir, 0755) < 0 && errno != EEXIST) { -log_error("Failed to mkdir %s: %m", dir); -return -errno; -} - -if (mount("/sys", "/run/initramfs/sys", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /sys on /run/initramfs/sys: %m"); -return -errno; -} - -if (mount("/proc", "/run/initramfs/proc", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /proc on /run/initramfs/proc: %m"); -return -errno; -} - -if (mount("/dev", "/run/initramfs/dev", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /dev on /run/initramfs/dev: %m"); -return -errno; -} - -if (mount("/run", "/run/initramfs/run", NULL, MS_BIND, NULL) < 0) { -log_error("Failed to mount bind /run on /run/initramfs/run: %m"); -return -errno; -} - -return 0; +/* switch_root with MS_BIND, because there might still be processes lurking around, which have open file desriptors. + * /run/initramfs/shutdown will take care o
[systemd-devel] [PATCH] switch_root: do not fail, if base_filesystem_create() failed
From: Harald Hoyer Not all switch roots are like base_filesystem_create() wants them to look like. They might even boot, if they are RO and don't have the FS layout. Just output the error and switch_root nevertheless. --- src/shared/switch-root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 5f075e6..fcd3420 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -107,7 +107,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, r = base_filesystem_create(new_root); if (r < 0) { log_error("Failed to create the base filesystem: %s", strerror(-r)); -return r; +r = 0; } if (chdir(new_root) < 0) { -- 2.1.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] switch_root: do not fail, if base_filesystem_create() failed
From: Harald Hoyer Not all switch roots are like base_filesystem_create() wants them to look like. They might even boot, if they are RO and don't have the FS layout. Just ignore the error and switch_root nevertheless. base_filesystem_create() should have logged, what went wrong. --- src/shared/switch-root.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index bac0e5c..673f8a7 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -103,11 +103,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, } } -r = base_filesystem_create(new_root); -if (r < 0) { -log_error("Failed to create the base filesystem: %s", strerror(-r)); -return r; -} +base_filesystem_create(new_root); if (chdir(new_root) < 0) { log_error("Failed to change directory to %s: %m", new_root); -- 2.1.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] s/commandline/command line/g
From: Harald Hoyer --- TODO | 2 +- m4/attributes.m4 | 2 +- man/systemd-bootchart.xml | 4 ++-- man/systemd-delta.xml | 2 +- man/systemd-run.xml| 2 +- man/systemd.link.xml | 2 +- man/udev.conf.xml | 2 +- src/core/shutdown.c| 2 +- src/cryptsetup/cryptsetup-generator.c | 4 ++-- src/fstab-generator/fstab-generator.c | 2 +- src/journal/coredump.c | 2 +- src/network/networkd-wait-online-manager.c | 2 +- src/shared/condition-util.c| 2 +- src/udev/collect/collect.c | 2 +- src/udev/net/link-config.c | 2 +- src/udev/udevd.c | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index b54aa61..8d3ef11 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,7 @@ Bugfixes: Environment=ONE='one' "TWO='two two' too" THREE= ExecStart=/bin/python3 -c 'import sys;print(sys.argv)' $ONE $TWO $THREE -* MEMORY return code is overloaded for syntax errors in the commandline. +* MEMORY return code is overloaded for syntax errors in the command line. str_split_quoted() should return a real return code, so spawn_child can report the failure properly. diff --git a/m4/attributes.m4 b/m4/attributes.m4 index 7bd5ad8..ac3c662 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -89,7 +89,7 @@ AC_DEFUN([CC_NOUNDEFINED], [ *-freebsd* | *-openbsd*) ;; *) dnl First of all check for the --no-undefined variant of GNU ld. This allows -dnl for a much more readable commandline, so that people can understand what +dnl for a much more readable command line, so that people can understand what dnl it does without going to look for what the heck -z defs does. for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) diff --git a/man/systemd-bootchart.xml b/man/systemd-bootchart.xml index 150ca48..0068e92 100644 --- a/man/systemd-bootchart.xml +++ b/man/systemd-bootchart.xml @@ -64,7 +64,7 @@ as an SVG graph. Normally, systemd-bootchart is invoked by the kernel by passing init=/usr/lib/systemd/systemd-bootchart -on the kernel commandline. systemd-bootchart will then +on the kernel command line. systemd-bootchart will then fork the real init off to resume normal system startup, while monitoring and logging startup information in the background. @@ -125,7 +125,7 @@ One can execute systemd-bootchart as normal application from the -commandline. In this mode it is highly +command line. In this mode it is highly recommended to pass the -r flag in order to not graph the time elapsed since boot diff --git a/man/systemd-delta.xml b/man/systemd-delta.xml index 9117773..2175f96 100644 --- a/man/systemd-delta.xml +++ b/man/systemd-delta.xml @@ -97,7 +97,7 @@ only configuration files in this subdirectory (across all configuration paths) will be analyzed. Otherwise, all configuration files will be analyzed. If the -commandline argument is not given at all, all +command line argument is not given at all, all configuration files will be analyzed. See below for some examples. diff --git a/man/systemd-run.xml b/man/systemd-run.xml index 0c9d13d..6ccfd71 100644 --- a/man/systemd-run.xml +++ b/man/systemd-run.xml @@ -215,7 +215,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. All command-line arguments after the first non-option -argument become part of the commandline of the launched +argument become part of the command line of the launched process. If a command is run as service unit, its first argument needs to be an absolute binary path. diff --git a/man/systemd.link.xml b/man/systemd.link.xml index 6075b39..6c74b42 100644 --- a/man/systemd.link.xml +++ b/man/systemd.link.xml @@ -231,7 +231,7 @@ be set. NamePolicy may be disabled by specifying net.ifnames=0 on the kernel -
[systemd-devel] [PATCH] 60-persistent-storage.rules: ignore partitions with ID_FS_TYPE of parent
From: Harald Hoyer If ID_FS_TYPE of a parent is already set, then it's something like "linux_raid_member" or "mpath_member" and the disk is already in use, so don't handle the partitions --- rules/60-persistent-storage.rules | 5 + 1 file changed, 5 insertions(+) diff --git a/rules/60-persistent-storage.rules b/rules/60-persistent-storage.rules index 475b151..836e053 100644 --- a/rules/60-persistent-storage.rules +++ b/rules/60-persistent-storage.rules @@ -22,6 +22,11 @@ TEST=="whole_disk", GOTO="persistent_storage_end" # for partitions import parent information ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*" +# If ID_FS_TYPE of a parent is already set, +# then it's something like "linux_raid_member" or "mpath_member" +# and the disk is already in use, so don't handle the partitions +ENV{ID_FS_TYPE}=="?*", GOTO="persistent_storage_end" + # virtio-blk KERNEL=="vd*[!0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/virtio-$env{ID_SERIAL}" KERNEL=="vd*[0-9]", ATTRS{serial}=="?*", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="disk/by-id/virtio-$env{ID_SERIAL}-part%n" -- 2.1.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] hwdb: Logitech MX 518
From: Harald Hoyer --- hwdb/70-mouse.hwdb | 4 1 file changed, 4 insertions(+) diff --git a/hwdb/70-mouse.hwdb b/hwdb/70-mouse.hwdb index 36778d5..06b5338 100644 --- a/hwdb/70-mouse.hwdb +++ b/hwdb/70-mouse.hwdb @@ -168,6 +168,10 @@ mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4026: mouse:bluetooth:v046dpb00d:name:Ultrathin Touch Mouse: MOUSE_DPI=1000@1000 +# Logitech MX 518 +mouse:usb:v046dpc01e:name:Logitech USB-PS/2 Optical Mouse: + MOUSE_DPI=400@125 *800@125 1600@125 + ## # Microsoft ## -- 2.2.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] nss-myhostname: also recognize "gateway."
From: Harald Hoyer "gateway." skips adding the domain search path and saves some queries to the nameserver. --- src/nss-myhostname/nss-myhostname.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index aa92cc9..2f76860 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -78,7 +78,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r( canonical = "localhost"; local_address_ipv4 = htonl(INADDR_LOOPBACK); -} else if (streq(name, "gateway")) { +} else if (streq(name, "gateway") || streq(name, "gateway.")) { n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses); if (n_addresses <= 0) { @@ -348,7 +348,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r( canonical = "localhost"; local_address_ipv4 = htonl(INADDR_LOOPBACK); -} else if (streq(name, "gateway")) { +} else if (streq(name, "gateway") || streq(name, "gateway.")) { n_addresses = local_gateways(NULL, 0, af, &addresses); if (n_addresses <= 0) { -- 2.2.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 0/2] systemd serialization on switch-root
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. Harald Hoyer (2): util: add files_same() helper function systemctl: for switch-root check, if we switch to a systemd init src/shared/util.c | 20 +--- src/shared/util.h | 2 ++ src/systemctl/systemctl.c | 11 +++ 3 files changed, 26 insertions(+), 7 deletions(-) -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/2] util: add files_same() helper function
From: Harald Hoyer files_same() returns 1, if the files are the same 0, if the files have different inode/dev numbers errno, for any stat error --- src/shared/util.c | 20 +--- src/shared/util.h | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index 8c7cfbd..b1341ad 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3198,19 +3198,25 @@ bool on_tty(void) { return cached_on_tty; } -int running_in_chroot(void) { +int files_same(const char *filea, const char *fileb) { struct stat a = {}, b = {}; -/* Only works as root */ -if (stat("/proc/1/root", &a) < 0) +if (stat(filea, &a) < 0) return -errno; -if (stat("/", &b) < 0) +if (stat(fileb, &b) < 0) return -errno; -return -a.st_dev != b.st_dev || -a.st_ino != b.st_ino; +return (a.st_dev == b.st_dev && a.st_ino == b.st_ino); +} + +int running_in_chroot(void) { +int ret = files_same("/proc/1/root", "/"); + +if (ret < 0) +return ret; + +return (ret == 0); } static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) { diff --git a/src/shared/util.h b/src/shared/util.h index e430071..eab8cfd 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -451,6 +451,8 @@ static inline const char *ansi_highlight_off(void) { return on_tty() ? ANSI_HIGHLIGHT_OFF : ""; } +int files_same(const char *filea, const char *fileb); + int running_in_chroot(void); char *ellipsize(const char *s, size_t length, unsigned percent); -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] systemctl: for switch-root check, if we switch to a systemd init
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. --- src/systemctl/systemctl.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f395265..18dbcc0 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4283,6 +4283,7 @@ static int show_environment(sd_bus *bus, char **args) { static int switch_root(sd_bus *bus, char **args) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *init = NULL; +_cleanup_free_ char *root_systemd_path = NULL; const char *root; unsigned l; int r; @@ -4309,6 +4310,16 @@ static int switch_root(sd_bus *bus, char **args) { if (!init) return log_oom(); +root_systemd_path = strjoin(root, "/", SYSTEMD_BINARY_PATH, NULL); +if (!root_systemd_path) +return log_oom(); + +if (files_same(init, root_systemd_path) > 0) { +char *t = init; +init = strdup(""); +free(t); +} + log_debug("switching root - root: %s; init: %s", root, init); r = sd_bus_call_method( -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] [V2] systemctl: for switch-root check, if we switch to a systemd init
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. --- Version 2: now with new "root" prepended to "init" also. src/systemctl/systemctl.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f395265..cfdda43 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4283,6 +4283,8 @@ static int show_environment(sd_bus *bus, char **args) { static int switch_root(sd_bus *bus, char **args) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *init = NULL; +_cleanup_free_ char *root_init_path = NULL; +_cleanup_free_ char *root_systemd_path = NULL; const char *root; unsigned l; int r; @@ -4309,6 +4311,22 @@ static int switch_root(sd_bus *bus, char **args) { if (!init) return log_oom(); +if (init[0]) { +root_systemd_path = strjoin(root, "/", SYSTEMD_BINARY_PATH, NULL); +if (!root_systemd_path) +return log_oom(); + +root_init_path = strjoin(root, "/", init, NULL); +if (!root_init_path) +return log_oom(); + +if (files_same(root_init_path, root_systemd_path) > 0) { +char *t = init; +init = strdup(""); +free(t); +} +} + log_debug("switching root - root: %s; init: %s", root, init); r = sd_bus_call_method( -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] [V3] systemctl: switch-root check, if we switch to a systemd init
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. --- src/systemctl/systemctl.c | 27 +-- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f395265..852616d 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4295,19 +4295,34 @@ static int switch_root(sd_bus *bus, char **args) { root = args[1]; -if (l >= 3) +if (l >= 3) { init = strdup(args[2]); +if (!init) +return log_oom(); +} else { parse_env_file("/proc/cmdline", WHITESPACE, "init", &init, NULL); - -if (!init) -init = strdup(""); } -if (!init) -return log_oom(); +if (init && init[0]) { +_cleanup_free_ char *root_init_path = NULL; +_cleanup_free_ char *root_systemd_path = NULL; + +root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH); +if (!root_systemd_path) +return log_oom(); + +root_init_path = strjoin(root, "/", init, NULL); +if (!root_init_path) +return log_oom(); + +if (files_same(root_init_path, root_systemd_path) > 0) { +free(init); +init = NULL; +} +} log_debug("switching root - root: %s; init: %s", root, init); -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/2] [V3] util: add files_same() helper function
From: Harald Hoyer files_same() returns 1, if the files are the same 0, if the files have different inode/dev numbers errno, for any stat error --- src/shared/util.c | 22 +++--- src/shared/util.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index 588b1f5..3292854 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3198,19 +3198,27 @@ bool on_tty(void) { return cached_on_tty; } -int running_in_chroot(void) { +int files_same(const char *filea, const char *fileb) { struct stat a = {}, b = {}; -/* Only works as root */ -if (stat("/proc/1/root", &a) < 0) +if (stat(filea, &a) < 0) return -errno; -if (stat("/", &b) < 0) +if (stat(fileb, &b) < 0) return -errno; -return -a.st_dev != b.st_dev || -a.st_ino != b.st_ino; +return a.st_dev == b.st_dev && a.st_ino == b.st_ino; +} + +int running_in_chroot(void) { +int ret; + +ret = files_same("/proc/1/root", "/"); + +if (ret < 0) +return ret; + +return ret == 0; } static char *ascii_ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent) { diff --git a/src/shared/util.h b/src/shared/util.h index 51b1caf..c881a05 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -451,6 +451,8 @@ static inline const char *ansi_highlight_off(void) { return on_tty() ? ANSI_HIGHLIGHT_OFF : ""; } +int files_same(const char *filea, const char *fileb); + int running_in_chroot(void); char *ellipsize(const char *s, size_t length, unsigned percent); -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 0/2] [V3] systemd serialization on switch-root
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. Harald Hoyer (2): util: add files_same() helper function systemctl: for switch-root check, if we switch to a systemd init src/shared/util.c | 22 +++--- src/shared/util.h | 2 ++ src/systemctl/systemctl.c | 27 +-- 3 files changed, 38 insertions(+), 13 deletions(-) -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] [V4] systemctl: for switch-root check, if we switch to a systemd init
From: Harald Hoyer If "systemctl switch-root" is called with a specific "INIT" or /proc/cmdline contains "init=", then systemd would not serialize itsself. Let systemctl check, if the new init is in the standard systemd installation path and if so, clear the INIT parameter, to let systemd serialize itsself. --- src/systemctl/systemctl.c | 26 +++--- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f395265..e2588e5 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4295,19 +4295,31 @@ static int switch_root(sd_bus *bus, char **args) { root = args[1]; -if (l >= 3) +if (l >= 3) { init = strdup(args[2]); -else { +if (!init) +return log_oom(); +} else { parse_env_file("/proc/cmdline", WHITESPACE, "init", &init, NULL); - -if (!init) -init = strdup(""); } -if (!init) -return log_oom(); +if (!isempty(init)) { +char *root_systemd_path = NULL; +_cleanup_free_ char *root_init_path = NULL; + +root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH); + +root_init_path = strjoin(root, "/", init, NULL); +if (!root_init_path) +return log_oom(); + +if (files_same(root_init_path, root_systemd_path) > 0) { +free(init); +init = NULL; +} +} log_debug("switching root - root: %s; init: %s", root, init); -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] systemctl: refuse to do kexec, if no kernel is loaded
From: Harald Hoyer Doing a kexec with no kernel loaded would currently issue a normal reboot. This might not be wanted, if the goal of kexec is to circumvent the boot loader. Better fail to kexec, than to reboot into a maybe broken setup. --- src/systemctl/systemctl.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 5a5681b..ac99f44 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2853,6 +2853,11 @@ static int start_special(sd_bus *bus, char **args) { return -EPERM; } +if (a == ACTION_KEXEC && !kexec_loaded()) { +log_error("No kernel loaded for kexec!"); +return -EINVAL; +} + if (arg_force >= 2 && (a == ACTION_HALT || a == ACTION_POWEROFF || @@ -6711,6 +6716,12 @@ int main(int argc, char*argv[]) { goto finish; } +if (arg_action == ACTION_KEXEC && !kexec_loaded()) { +log_error("No kernel loaded for kexec!"); +r = -EINVAL; +goto finish; +} + if (!avoid_bus()) r = bus_open_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus); -- 1.8.5.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] udevadm-settle: fixed return code for empty queue
From: Harald Hoyer If the udev queue is empty and "/run/udev/queue" does not exist, "udevadm settle" would return with EXIT_FAILURE, because the inotify on "/run/udev/queue" would fail with ENOENT. This patch lets "udevadm settle" exit with EXIT_SUCCESS in this case. --- src/udev/udevadm-settle.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 65fc35f..66fd843 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -116,7 +116,11 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) } if (inotify_add_watch(pfd[0].fd, "/run/udev/queue" , IN_DELETE) < 0) { -log_debug("watching /run/udev failed"); +/* If it does not exist, we don't have to wait */ +if (errno == ENOENT) +rc = EXIT_SUCCESS; +else +log_debug("watching /run/udev/queue failed"); goto out; } -- 1.9.0 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Added arch tuple for PPC64LE
From: Harald Hoyer Thanks to Brent Baude , who checked with the debian guys, that this is correct and provided the patch. --- src/shared/architecture.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/architecture.h b/src/shared/architecture.h index 38780d1..71c79b1 100644 --- a/src/shared/architecture.h +++ b/src/shared/architecture.h @@ -87,7 +87,7 @@ Architecture uname_architecture(void); #define LIB_ARCH_TUPLE "ppc64-linux-gnu" # else #define native_architecture() ARCHITECTURE_PPC64_LE -#error "Missing LIB_ARCH_TUPLE for PPC64LE" +#define LIB_ARCH_TUPLE "powerpc64le-linux-gnu" # endif #elif defined(__powerpc__) # if __BYTE_ORDER == __BIG_ENDIAN -- 2.0.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Removed PPC 32 bit LE architecture
From: Harald Hoyer According to Brent Baude , who provided the patch, IBM doesn't want to support the PPC 32 bit LE architecture at all. --- src/shared/architecture.h | 5 - 1 file changed, 5 deletions(-) diff --git a/src/shared/architecture.h b/src/shared/architecture.h index 71c79b1..2bbfb8a 100644 --- a/src/shared/architecture.h +++ b/src/shared/architecture.h @@ -90,13 +90,8 @@ Architecture uname_architecture(void); #define LIB_ARCH_TUPLE "powerpc64le-linux-gnu" # endif #elif defined(__powerpc__) -# if __BYTE_ORDER == __BIG_ENDIAN #define native_architecture() ARCHITECTURE_PPC #define LIB_ARCH_TUPLE "powerpc-linux-gnu" -# else -#define native_architecture() ARCHITECTURE_PPC_LE -#error "Missing LIB_ARCH_TUPLE for PPCLE" -# endif #elif defined(__ia64__) # define native_architecture() ARCHITECTURE_IA64 # define LIB_ARCH_TUPLE "ia64-linux-gnu" -- 2.0.3 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] journal: handle multiline syslog messages
From: Harald Hoyer Since the journal can handle multiple lines just well natively, and rsyslog can be configured to handle them as well, there is no need to truncate messages from syslog() after the first newline. Reproducer: 1. Add following four lines to /etc/rsyslog.conf -- $EscapeControlCharactersOnReceive off $ActionFileDefaultTemplate RSYSLOG_SysklogdFileFormat $SpaceLFOnReceive on $DropTrailingLFOnReception off -- 3. Restart rsyslog # service rsyslog restart 4. Compile and run the following program -- #include #include int main() { syslog(LOG_INFO, "aaa%caaa", '\n'); return 0; } -- Actual results: Below message appears in /var/log/messages. -- Sep 7 19:19:39 localhost test2: aaa -- Expected results: Below message, which worked prior to systemd-journald appears in /var/log/messages. -- Sep 7 19:19:39 localhost test2: aaa aaa https://bugzilla.redhat.com/show_bug.cgi?id=855313 --- src/journal/journald-server.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 821935c..f417059 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1240,12 +1240,7 @@ int process_event(Server *s, struct epoll_event *ev) { char *e; if (n > 0 && n_fds == 0) { -e = memchr(s->buffer, '\n', n); -if (e) -*e = 0; -else -s->buffer[n] = 0; - +s->buffer[n] = 0; server_process_syslog_message(s, strstrip(s->buffer), ucred, tv, label, label_len); } else if (n_fds > 0) log_warning("Got file descriptors via syslog socket. Ignoring."); -- 1.8.3.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] 60-persistent-storage.rules: add NVMe disks and partitions
From: Harald Hoyer Although NVMe PCIe SSD are not named sd*, they can be queried with scsi_id and handled equally. --- rules/60-persistent-storage.rules | 5 + 1 file changed, 5 insertions(+) diff --git a/rules/60-persistent-storage.rules b/rules/60-persistent-storage.rules index 154ffd9..8d46f24 100644 --- a/rules/60-persistent-storage.rules +++ b/rules/60-persistent-storage.rules @@ -42,6 +42,11 @@ KERNEL=="cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}!="?*", IMPORT{program}="s KERNEL=="sd*|sr*|cciss*", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" KERNEL=="sd*|cciss*", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n" +# NVMe +KERNEL=="nvme?n?", ENV{ID_SERIAL}!="?*", IMPORT{program}="scsi_id --export --whitelisted -d $devnode", ENV{ID_BUS}="scsi" +KERNEL=="nvme?n?", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" +KERNEL=="nvme?n?*", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n" + # firewire KERNEL=="sd*[!0-9]|sr*", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}" KERNEL=="sd*[0-9]", ATTRS{ieee1394_id}=="?*", SYMLINK+="disk/by-id/ieee1394-$attr{ieee1394_id}-part%n" -- 1.8.4.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] log_error(), if inotify_add_watch() fails
From: Harald Hoyer --- src/login/sd-login.c| 3 +++ src/shared/ask-password-api.c | 1 + src/shared/util.c | 1 + src/tty-ask-password-agent/tty-ask-password-agent.c | 2 ++ 4 files changed, 7 insertions(+) diff --git a/src/login/sd-login.c b/src/login/sd-login.c index b81dddf..d204f34 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -733,6 +733,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); if (k < 0) { +log_error("Failed to watch /run/systemd/seats/: %m"); close_nointr_nofail(fd); return -errno; } @@ -743,6 +744,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "session")) { k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE); if (k < 0) { +log_error("Failed to watch /run/systemd/sessions/: %m"); close_nointr_nofail(fd); return -errno; } @@ -753,6 +755,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "uid")) { k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE); if (k < 0) { +log_error("Failed to watch /run/systemd/users/: %m"); close_nointr_nofail(fd); return -errno; } diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 8a0fb89..4f14280 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -78,6 +78,7 @@ int ask_password_tty( } if (inotify_add_watch(notify, flag_file, IN_ATTRIB /* for the link count */) < 0) { +log_error("Failed to watch %s: %m", flag_file); r = -errno; goto finish; } diff --git a/src/shared/util.c b/src/shared/util.c index d754c83..d8203dc 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2220,6 +2220,7 @@ int acquire_terminal( wd = inotify_add_watch(notify, name, IN_CLOSE); if (wd < 0) { r = -errno; +log_error("Failed to watch %s: %m", name); goto fail; } } diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 99a626c..88f5cd3 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -81,6 +81,7 @@ static int ask_password_plymouth( } if (inotify_add_watch(notify, flag_file, IN_ATTRIB /* for the link count */) < 0) { +log_error("Failed to watch %s: %m", flag_file); r = -errno; goto finish; } @@ -577,6 +578,7 @@ static int watch_passwords(void) { } if (inotify_add_watch(notify, "/run/systemd/ask-password", IN_CLOSE_WRITE|IN_MOVED_TO) < 0) { +log_error("Failed to watch /run/systemd/ask-password: %m"); r = -errno; goto finish; } -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] selinux-access:log_callback() increase buffer for audit logging
From: Harald Hoyer As per https://bugzilla.redhat.com/show_bug.cgi?id=883043#c5 we can increase the buffer used with audit_log_user_avc_message() safely to 4096 bytes. --- src/core/selinux-access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index 08a4834..363673a 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -181,7 +181,7 @@ static int log_callback(int type, const char *fmt, ...) { #ifdef HAVE_AUDIT if (get_audit_fd() >= 0) { -char buf[LINE_MAX]; +char buf[4096]; vsnprintf(buf, sizeof(buf), fmt, ap); audit_log_user_avc_message(get_audit_fd(), AUDIT_USER_AVC, buf, NULL, NULL, NULL, 0); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] run systemd-vconsole-setup.service before systemd-ask-password-console.service
From: Harald Hoyer --- units/systemd-vconsole-setup.service.in | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/units/systemd-vconsole-setup.service.in b/units/systemd-vconsole-setup.service.in index 18faa63..c6d7a96 100644 --- a/units/systemd-vconsole-setup.service.in +++ b/units/systemd-vconsole-setup.service.in @@ -11,10 +11,13 @@ Documentation=man:systemd-vconsole-setup.service(8) man:vconsole.conf(5) DefaultDependencies=no Conflicts=shutdown.target After=systemd-readahead-collect.service systemd-readahead-replay.service -Before=sysinit.target shutdown.target +Before=sysinit.target shutdown.target systemd-ask-password-console.service ConditionPathExists=/dev/tty0 [Service] Type=oneshot RemainAfterExit=yes ExecStart=@rootlibexecdir@/systemd-vconsole-setup + +[Install] +WantedBy=systemd-ask-password-console.service -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] bootchart: more fixes for bootchart in the initramfs
From: Harald Hoyer --- src/bootchart/bootchart.c | 10 +- src/bootchart/bootchart.h | 2 ++ src/bootchart/svg.c | 14 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index fb95c6b..43e8fdc 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include "bootchart.h" @@ -50,6 +52,7 @@ double interval; FILE *of = NULL; int overrun = 0; static int exiting = 0; +int sysfd=-1; /* graph defaults */ int entropy = 0; @@ -272,6 +275,9 @@ int main(int argc, char *argv[]) of = fopen(output_file, "w"); } +if (sysfd < 0) { +sysfd = open("/sys", O_RDONLY); +} /* wait for /proc to become available, discarding samples */ if (!(graph_start > 0.0)) @@ -330,7 +336,6 @@ int main(int argc, char *argv[]) if (ps->smaps) fclose(ps->smaps); } -closedir(proc); if (!of) { t = time(NULL); @@ -349,6 +354,9 @@ int main(int argc, char *argv[]) fprintf(stderr, "bootchartd: Wrote %s\n", output_file); fclose(of); +closedir(proc); +close(sysfd); + /* nitpic cleanups */ ps = ps_first; while (ps->next_ps) { diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h index 7793cfc..6b11fd8 100644 --- a/src/bootchart/bootchart.h +++ b/src/bootchart/bootchart.h @@ -117,6 +117,8 @@ extern char init_path[PATH_MAX]; extern FILE *of; extern DIR *proc; +extern int procfd; +extern int sysfd; extern double gettime_ns(void); extern void log_uptime(void); diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index 6ad7348..dc55cb3 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "bootchart.h" #include "util.h" @@ -151,10 +153,12 @@ static void svg_title(void) char *c; FILE *f; time_t t; +int fd; struct utsname uts; /* grab /proc/cmdline */ -f = fopen("/proc/cmdline", "r"); +fd = openat(procfd, "cmdline", O_RDONLY); +f = fdopen(fd, "r"); if (f) { if (!fgets(cmdline, 255, f)) sprintf(cmdline, "Unknown"); @@ -167,8 +171,9 @@ static void svg_title(void) strncpy(rootbdev, &c[10], 3); rootbdev[3] = '\0'; } -sprintf(filename, "/sys/block/%s/device/model", rootbdev); -f = fopen(filename, "r"); +sprintf(filename, "block/%s/device/model", rootbdev); +fd = openat(sysfd, filename, O_RDONLY); +f = fdopen(fd, "r"); if (f) { if (!fgets(model, 255, f)) fprintf(stderr, "Error reading disk model for %s\n", rootbdev); @@ -184,7 +189,8 @@ static void svg_title(void) strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t)); /* CPU type */ -f = fopen("/proc/cpuinfo", "r"); +fd = openat(procfd, "cpuinfo", O_RDONLY); +f = fdopen(fd, "r"); if (f) { while (fgets(buf, 255, f)) { if (strstr(buf, "model name")) { -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] bootchart: if "root=/dev" is not matched, don't try to read /sys
From: Harald Hoyer --- src/bootchart/svg.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index dc55cb3..7fdcd01 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -166,18 +166,19 @@ static void svg_title(void) } /* extract root fs so we can find disk model name in sysfs */ +/* FIXME: this works only in the simple case */ c = strstr(cmdline, "root=/dev/"); if (c) { strncpy(rootbdev, &c[10], 3); rootbdev[3] = '\0'; -} -sprintf(filename, "block/%s/device/model", rootbdev); -fd = openat(sysfd, filename, O_RDONLY); -f = fdopen(fd, "r"); -if (f) { -if (!fgets(model, 255, f)) -fprintf(stderr, "Error reading disk model for %s\n", rootbdev); -fclose(f); +sprintf(filename, "block/%s/device/model", rootbdev); +fd = openat(sysfd, filename, O_RDONLY); +f = fdopen(fd, "r"); +if (f) { +if (!fgets(model, 255, f)) +fprintf(stderr, "Error reading disk model for %s\n", rootbdev); +fclose(f); +} } /* various utsname parameters */ -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] bootchart: parse /etc/os-release rather than system-release
From: Harald Hoyer Also parse it early, so that we can get it in the initramfs. --- src/bootchart/bootchart.c | 9 - src/bootchart/bootchart.h | 2 +- src/bootchart/svg.c | 15 +++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 43e8fdc..1c14c33 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -81,6 +81,7 @@ static void signal_handler(int sig) int main(int argc, char *argv[]) { +_cleanup_free_ char *build = NULL; struct sigaction sig; struct ps_struct *ps; char output_file[PATH_MAX]; @@ -279,6 +280,12 @@ int main(int argc, char *argv[]) sysfd = open("/sys", O_RDONLY); } +if (!build) { +parse_env_file("/etc/os-release", NEWLINE, + "PRETTY_NAME", &build, + NULL); +} + /* wait for /proc to become available, discarding samples */ if (!(graph_start > 0.0)) log_uptime(); @@ -349,7 +356,7 @@ int main(int argc, char *argv[]) exit (EXIT_FAILURE); } -svg_do(); +svg_do(build); fprintf(stderr, "bootchartd: Wrote %s\n", output_file); fclose(of); diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h index 6b11fd8..84e9420 100644 --- a/src/bootchart/bootchart.h +++ b/src/bootchart/bootchart.h @@ -124,4 +124,4 @@ extern double gettime_ns(void); extern void log_uptime(void); extern void log_sample(int sample); -extern void svg_do(void); +extern void svg_do(const char *build); diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index 7fdcd01..f8a3776 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -140,7 +140,7 @@ static void svg_header(void) } -static void svg_title(void) +static void svg_title(const char *build) { char cmdline[256] = ""; char filename[PATH_MAX]; @@ -149,7 +149,6 @@ static void svg_title(void) char model[256] = "Unknown"; char date[256] = "Unknown"; char cpu[256] = "Unknown"; -char build[256] = "Unknown"; char *c; FILE *f; time_t t; @@ -202,14 +201,6 @@ static void svg_title(void) fclose(f); } -/* Build - 1st line from /etc/system-release */ -f = fopen("/etc/system-release", "r"); -if (f) { -if (fgets(buf, 255, f)) -strncpy(build, buf, 255); -fclose(f); -} - svg("Bootchart for %s - %s\n", uts.nodename, date); svg("System: %s %s %s %s\n", @@ -1054,7 +1045,7 @@ static void svg_top_ten_pss(void) } -void svg_do(void) +void svg_do(const char *build) { struct ps_struct *ps; @@ -1107,7 +1098,7 @@ void svg_do(void) svg("\n\n"); svg("\n"); -svg_title(); +svg_title(build); svg("\n\n"); svg("\n"); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] honor SELinux labels, when creating and writing config files
From: Harald Hoyer see https://bugzilla.redhat.com/show_bug.cgi?id=881577 --- Makefile.am | 2 + src/core/unit.c | 3 +- src/hostname/hostnamed.c | 7 ++-- src/locale/localed.c | 7 ++-- src/login/logind-dbus.c | 4 +- src/shared/label.c | 103 +++ src/shared/label.h | 4 ++ src/timedate/timedated.c | 5 ++- 8 files changed, 125 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 403439b..1a19b8b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2898,6 +2898,7 @@ systemd_hostnamed_CFLAGS = \ $(DBUS_CFLAGS) systemd_hostnamed_LDADD = \ + libsystemd-label.la \ libsystemd-shared.la \ libsystemd-daemon.la \ libsystemd-dbus.la @@ -3034,6 +3035,7 @@ systemd_timedated_CFLAGS = \ $(DBUS_CFLAGS) systemd_timedated_LDADD = \ + libsystemd-label.la \ libsystemd-shared.la \ libsystemd-daemon.la \ libsystemd-dbus.la diff --git a/src/core/unit.c b/src/core/unit.c index f7d00b6..52603ab 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -46,6 +46,7 @@ #include "missing.h" #include "cgroup-attr.h" #include "mkdir.h" +#include "label.h" const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { [UNIT_SERVICE] = &service_vtable, @@ -2778,7 +2779,7 @@ int unit_write_drop_in(Unit *u, bool runtime, const char *name, const char *data return -ENOMEM; mkdir_p(p, 0755); -return write_one_line_file_atomic(q, data); +return label_write_one_line_file_atomic(q, data); } int unit_remove_drop_in(Unit *u, bool runtime, const char *name) { diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index c5a8b6f..14a8376 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -33,6 +33,7 @@ #include "def.h" #include "virt.h" #include "env-util.h" +#include "label.h" #define INTERFACE \ " \n" \ @@ -287,8 +288,7 @@ static int write_data_static_hostname(void) { return 0; } - -return write_one_line_file_atomic("/etc/hostname", data[PROP_STATIC_HOSTNAME]); +return label_write_one_line_file_atomic("/etc/hostname", data[PROP_STATIC_HOSTNAME]); } static int write_data_other(void) { @@ -338,7 +338,7 @@ static int write_data_other(void) { return 0; } -r = write_env_file("/etc/machine-info", l); +r = label_write_env_file("/etc/machine-info", l); strv_free(l); return r; @@ -683,6 +683,7 @@ int main(int argc, char *argv[]) { log_open(); umask(0022); +label_init("/etc"); if (argc == 2 && streq(argv[1], "--introspect")) { fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE diff --git a/src/locale/localed.c b/src/locale/localed.c index fedcdfb..317291d 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -32,6 +32,7 @@ #include "polkit.h" #include "def.h" #include "env-util.h" +#include "label.h" #define INTERFACE \ " \n" \ @@ -390,7 +391,7 @@ static int write_data_locale(void) { return 0; } -r = write_env_file("/etc/locale.conf", l); +r = label_write_env_file("/etc/locale.conf", l); strv_free(l); return r; @@ -546,7 +547,7 @@ static int write_data_vconsole(void) { return 0; } -r = write_env_file("/etc/vconsole.conf", l); +r = label_write_env_file("/etc/vconsole.conf", l); strv_free(l); return r; @@ -1364,7 +1365,7 @@ int main(int argc, char *argv[]) { log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); - +label_init("/etc"); umask(0022); if (argc == 2 && streq(argv[1], "--introspect")) { diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index f351859..fadaa25 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -33,6 +33,7 @@ #include "special.h" #include "systemd/sd-id128.h" #include "systemd/sd-messages.h" +#include "label.h" #define BUS_MANAGER_INTERFACE \ " \n"\ @@ -937,7 +938,8 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { } mkdir_p_label("/etc/udev/rules.d", 0755); -r = write_one_line_file_atomic(file, rule); +label_init("/etc"); +r = label_write_one_line_file_atomic(fi
[systemd-devel] [PATCH] run systemd-ask-password-console.service after systemd-vconsole-setup.service
From: Harald Hoyer --- units/systemd-ask-password-console.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/units/systemd-ask-password-console.service.in b/units/systemd-ask-password-console.service.in index 4bcb30b..a24fa51 100644 --- a/units/systemd-ask-password-console.service.in +++ b/units/systemd-ask-password-console.service.in @@ -10,7 +10,7 @@ Description=Dispatch Password Requests to Console Documentation=man:systemd-ask-password-console.service(8) DefaultDependencies=no Conflicts=shutdown.target -After=plymouth-start.service +After=plymouth-start.service systemd-vconsole-setup.service Before=shutdown.target ConditionPathExists=!/run/plymouth/pid -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] cryptsetup-generator: Add JobTimeoutSec=0 for all known crypt devices
From: Harald Hoyer put JobTimeoutSec=0 in .d/JobTimeoutSec0.conf files This helps with grabbing a cup of coffee while booting and not have the crypto password dialog timeout and systemd in a failed state. --- src/cryptsetup/cryptsetup-generator.c | 62 +++ 1 file changed, 62 insertions(+) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 38a7cfa..55fc4b7 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -221,6 +221,68 @@ static int create_disk( goto fail; } +if (!noauto && !nofail) { +free(p); +p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/JobTimeoutSec0.conf", NULL); +if (!p) { +r = log_oom(); +goto fail; +} + +mkdir_parents_label(p, 0755); + +if (f) +fclose(f); +f = fopen(p, "wxe"); +if (!f) { +r = -errno; +log_error("Failed to create unit file %s: %m", p); +goto fail; +} + +fprintf(f, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n" /* the binary handles timeouts anyway */ +); +fflush(f); + +if (ferror(f)) { +r = -errno; +log_error("Failed to write file %s: %m", p); +goto fail; +} + +free(p); +p = strjoin(arg_dest, "/", d, ".d/JobTimeoutSec0.conf", NULL); +if (!p) { +r = log_oom(); +goto fail; +} + +mkdir_parents_label(p, 0755); + +f = fopen(p, "wxe"); +if (!f) { +r = -errno; +log_error("Failed to create unit file %s: %m", p); +goto fail; +} + +fprintf(f, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n" /* the binary handles timeouts anyway */ +); +fflush(f); + +if (ferror(f)) { +r = -errno; +log_error("Failed to write file %s: %m", p); +goto fail; +} +} + r = 0; fail: -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] fstab-generator: If we wait indefinitely for a mount, wait also for the device
From: Harald Hoyer Write out "JobTimeoutSec=0" for the device the mountpoint (which does not timeout) waits for. This helps with grabbing a cup of coffee while booting and not have the crypto password dialog timeout and systemd in a failed state. --- src/fstab-generator/fstab-generator.c | 26 ++ 1 file changed, 26 insertions(+) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index d4470f4..026d070 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -313,6 +313,32 @@ static int add_mount(const char *what, const char *where, const char *type, cons return r; if (r > 0) { +if (wait) { +free(unit); +unit = strjoin(arg_dest, "/", device, ".d/JobTimeoutSec0.conf", NULL); + +mkdir_parents_label(unit, 0755); + +fclose(f); +f = fopen(unit, "wxe"); +if (!f) { +log_error("Failed to create unit file %s: %m", unit); +return -errno; +} + +fprintf(f, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n" +); +fflush(f); + +if (ferror(f)) { +log_error("Failed to write file %s: %m", unit); +return -errno; +} +} + free(lnk); lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL); if (!lnk) -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] fstab-generator: default to "ro"
From: Harald Hoyer If no "ro" or "rw" is specified on the kernel command line, mount root read-only on /sysroot by default --- src/fstab-generator/fstab-generator.c | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 026d070..d83e73f 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -465,9 +465,11 @@ finish: static int parse_new_root_from_proc_cmdline(void) { char *w, *state; _cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL; +char *tmp_word; int r; size_t l; bool wait = false; +bool ro_rw = false; r = read_one_line_file("/proc/cmdline", &line); if (r < 0) { @@ -482,7 +484,7 @@ static int parse_new_root_from_proc_cmdline(void) { /* root= and roofstype= may occur more than once, the last instance should take precedence. * In the case of multiple rootflags= the arguments should be concatenated */ FOREACH_WORD_QUOTED(w, l, line, state) { -char *word, *tmp_word; +char *word; word = strndup(w, l); if (!word) @@ -514,12 +516,22 @@ static int parse_new_root_from_proc_cmdline(void) { if (!opts) return log_oom(); +ro_rw = true; + } else if (streq(word, "rootwait")) wait = true; free(word); } +if (!ro_rw) { +tmp_word = opts; +opts = strjoin(opts, ",", "ro", NULL); +free(tmp_word); +if (!opts) +return log_oom(); +} + if (what) { log_debug("Found entry what=%s where=/sysroot type=%s", what, type); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/4] fstab-generator: place /sysroot* mount units in initrd-fs.target
From: Harald Hoyer --- src/fstab-generator/fstab-generator.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..fade192 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -200,8 +200,8 @@ static bool mount_in_initrd(struct mntent *me) { } static int add_mount(const char *what, const char *where, const char *type, const char *opts, - int passno, bool noauto, bool nofail, bool automount, bool isbind, bool isnetwork, - const char *source) { + int passno, bool noauto, bool nofail, bool automount, bool isbind, + bool remote_fs_target, bool initrd_fs_target, const char *source) { char _cleanup_free_ *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL, *automount_name = NULL, *automount_unit = NULL; @@ -227,9 +227,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons mount_point_ignore(where)) return 0; -if (isnetwork) { +if (remote_fs_target) { post = SPECIAL_REMOTE_FS_TARGET; pre = SPECIAL_REMOTE_FS_PRE_TARGET; +} else if (initrd_fs_target) { +post = SPECIAL_INITRD_FS_TARGET; +pre = SPECIAL_INITRD_FS_PRE_TARGET; } else { post = SPECIAL_LOCAL_FS_TARGET; pre = SPECIAL_LOCAL_FS_PRE_TARGET; @@ -432,8 +435,8 @@ static int parse_fstab(const char *prefix, bool initrd) { isnetwork = mount_is_network(me); k = add_mount(what, where, me->mnt_type, me->mnt_opts, - me->mnt_passno, noauto, nofail, automount, - isbind, isnetwork, fstab_path); + me->mnt_passno, noauto, nofail, automount, + isbind, isnetwork, initrd, fstab_path); } if (k < 0) @@ -514,7 +517,7 @@ static int parse_new_root_from_proc_cmdline(void) { log_debug("Found entry what=%s where=/sysroot type=%s", what, type); r = add_mount(what, "/sysroot", type, opts, 0, false, false, false, - false, false, "/proc/cmdline"); + false, false, true, "/proc/cmdline"); return (r < 0) ? r : 0; } -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/4] fstab-generator: skip generation, if sysroot.mount already exists
From: Harald Hoyer --- src/fstab-generator/fstab-generator.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index fade192..3b8329b 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -450,10 +450,19 @@ finish: static int parse_new_root_from_proc_cmdline(void) { char *w, *state; -_cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL; +_cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL, *mu = NULL; int r; size_t l; +/* Skip generation, if sysroot.mount already exists */ +mu = strjoin(arg_dest, "/", "sysroot.mount", NULL); +if (!mu) +return log_oom(); + +r = access(mu, R_OK); +if (r == 0) +return 0; + r = read_one_line_file("/proc/cmdline", &line); if (r < 0) { log_error("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 3/4] fstab-generator: do not overwrite already generated units
From: Harald Hoyer only checks for /run/systemd/generator/*.mount --- src/fstab-generator/fstab-generator.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 3b8329b..502f64c 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -419,6 +419,21 @@ static int parse_fstab(const char *prefix, bool initrd) { if (is_path(where)) path_kill_slashes(where); +if (initrd) { +char _cleanup_free_ *mu = NULL, *name = NULL; +/* Skip generation, if unit already exists */ +name = unit_name_from_path(where, ".mount"); +if (!name) +return log_oom(); +mu = strjoin(arg_dest, "/", name, NULL); +if (!mu) +return log_oom(); + +k = access(mu, R_OK); +if (k == 0) +continue; +} + log_debug("Found entry what=%s where=%s type=%s", what, where, me->mnt_type); if (streq(me->mnt_type, "swap")) -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] bootchart: add parameter "-C" to expand process names to the full cmdline
From: Harald Hoyer --- src/bootchart/bootchart.c | 7 ++- src/bootchart/bootchart.h | 3 ++- src/bootchart/log.c | 39 +-- src/bootchart/svg.c | 37 + 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index af573da..543037d 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -76,6 +76,7 @@ bool entropy = false; bool initcall = true; bool relative = false; bool filter = true; +bool show_cmdline = false; bool pss = false; int samples; int len = 500; /* we record len+1 (1 start sample) */ @@ -150,6 +151,7 @@ int main(int argc, char *argv[]) {"output",required_argument, NULL, 'o'}, {"init", required_argument, NULL, 'i'}, {"no-filter", no_argument,NULL, 'F'}, +{"cmdline", no_argument,NULL, 'C'}, {"help", no_argument,NULL, 'h'}, {"scale-x", required_argument, NULL, 'x'}, {"scale-y", required_argument, NULL, 'y'}, @@ -159,7 +161,7 @@ int main(int argc, char *argv[]) gind = 0; -i = getopt_long(argc, argv, "erpf:n:o:i:Fhx:y:", opts, &gind); +i = getopt_long(argc, argv, "erpf:n:o:i:FChx:y:", opts, &gind); if (i == -1) break; switch (i) { @@ -175,6 +177,9 @@ int main(int argc, char *argv[]) case 'F': filter = false; break; +case 'C': +show_cmdline = true; +break; case 'n': r = safe_atoi(optarg, &len); if (r < 0) diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h index ea26c93..c42f971 100644 --- a/src/bootchart/bootchart.h +++ b/src/bootchart/bootchart.h @@ -61,7 +61,7 @@ struct ps_struct { struct ps_struct *next; /* siblings */ /* must match - otherwise it's a new process with same PID */ -char name[16]; +char name[256]; int pid; int ppid; @@ -101,6 +101,7 @@ extern struct cpu_stat_struct cpustat[]; extern int pscount; extern bool relative; extern bool filter; +extern bool show_cmdline; extern bool pss; extern bool entropy; extern bool initcall; diff --git a/src/bootchart/log.c b/src/bootchart/log.c index cf6c3a7..460adc5 100644 --- a/src/bootchart/log.c +++ b/src/bootchart/log.c @@ -273,7 +273,25 @@ schedstat_next: if (!sscanf(buf, "%s %*s %*s", key)) continue; -strncpy(ps->name, key, 16); +strncpy(ps->name, key, 256); + +/* cmdline */ +if (show_cmdline) { +sprintf(filename, "%d/cmdline", pid); +fd = openat(procfd, filename, O_RDONLY); +if (fd >= 0) { +n = read(fd, ps->name, 255); +if (n > 0) { +int i; +for(i=0; i < n; i++) +if (ps->name[i] == '\0') +ps->name[i] = ' '; +ps->name[n] = '\0'; +} +close(fd); +} +} + /* discard line 2 */ m = bufgetline(buf); if (!m) @@ -433,7 +451,24 @@ catch_rename: if (!sscanf(buf, "%s %*s %*s", key)) continue; -strncpy(ps->name, key, 16); +strncpy(ps->name, key, 256); + +/* cmdline */ +if (show_cmdline) { +sprintf(filename, "%d/cmdline", pid); +fd = openat(procfd, filename, O_RDONLY); +if (fd >= 0) { +n = read(fd, ps->name, 255); +
[systemd-devel] [PATCH 1/3] bootchart: add parameter "-C" to expand process names to the full cmdline
From: Harald Hoyer --- src/bootchart/bootchart.c | 7 ++- src/bootchart/bootchart.h | 3 ++- src/bootchart/log.c | 33 +++-- src/bootchart/svg.c | 39 +-- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index af573da..543037d 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -76,6 +76,7 @@ bool entropy = false; bool initcall = true; bool relative = false; bool filter = true; +bool show_cmdline = false; bool pss = false; int samples; int len = 500; /* we record len+1 (1 start sample) */ @@ -150,6 +151,7 @@ int main(int argc, char *argv[]) {"output",required_argument, NULL, 'o'}, {"init", required_argument, NULL, 'i'}, {"no-filter", no_argument,NULL, 'F'}, +{"cmdline", no_argument,NULL, 'C'}, {"help", no_argument,NULL, 'h'}, {"scale-x", required_argument, NULL, 'x'}, {"scale-y", required_argument, NULL, 'y'}, @@ -159,7 +161,7 @@ int main(int argc, char *argv[]) gind = 0; -i = getopt_long(argc, argv, "erpf:n:o:i:Fhx:y:", opts, &gind); +i = getopt_long(argc, argv, "erpf:n:o:i:FChx:y:", opts, &gind); if (i == -1) break; switch (i) { @@ -175,6 +177,9 @@ int main(int argc, char *argv[]) case 'F': filter = false; break; +case 'C': +show_cmdline = true; +break; case 'n': r = safe_atoi(optarg, &len); if (r < 0) diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h index ea26c93..c42f971 100644 --- a/src/bootchart/bootchart.h +++ b/src/bootchart/bootchart.h @@ -61,7 +61,7 @@ struct ps_struct { struct ps_struct *next; /* siblings */ /* must match - otherwise it's a new process with same PID */ -char name[16]; +char name[256]; int pid; int ppid; @@ -101,6 +101,7 @@ extern struct cpu_stat_struct cpustat[]; extern int pscount; extern bool relative; extern bool filter; +extern bool show_cmdline; extern bool pss; extern bool entropy; extern bool initcall; diff --git a/src/bootchart/log.c b/src/bootchart/log.c index cf6c3a7..1e3f4a9 100644 --- a/src/bootchart/log.c +++ b/src/bootchart/log.c @@ -95,6 +95,26 @@ static char *bufgetline(char *buf) return c; } +static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) { + char filename[PATH_MAX]; + int _cleanup_close_ fd=-1; + ssize_t n; + + sprintf(filename, "%d/cmdline", pid); + fd = openat(procfd, filename, O_RDONLY); + if (fd < 0) + return -errno; + + n = read(fd, buffer, buf_len-1); +if (n > 0) { +int i; +for (i = 0; i < n; i++) +if (buffer[i] == '\0') +buffer[i] = ' '; +buffer[n] = '\0'; +} + return 0; +} void log_sample(int sample) { @@ -273,7 +293,12 @@ schedstat_next: if (!sscanf(buf, "%s %*s %*s", key)) continue; -strncpy(ps->name, key, 16); +strncpy(ps->name, key, 256); + +/* cmdline */ +if (show_cmdline) +pid_cmdline_strncpy(ps->name, pid, 256); + /* discard line 2 */ m = bufgetline(buf); if (!m) @@ -433,7 +458,11 @@ catch_rename: if (!sscanf(buf, "%s %*s %*s", key)) continue; -strncpy(ps->name, key, 16); +strncpy(ps->name, key, 256); + +/* cmdline */ +if (show_cmdline) +pid_cmdline_strncpy(ps->name, pid, 256); } } } diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index f8a3776..4c78abd 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -267,6 +267,20 @@ static void svg_graph_box(int height) } } +/* xml comments must not contain "--" */ +static char* xml_comment_enco
[systemd-devel] [PATCH 2/3] bootchart: rename global len to samples_len
From: Harald Hoyer --- src/bootchart/bootchart.c | 32 src/bootchart/bootchart.h | 2 +- src/bootchart/log.c | 2 +- src/bootchart/svg.c | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 543037d..e7c0b49 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -79,7 +79,7 @@ bool filter = true; bool show_cmdline = false; bool pss = false; int samples; -int len = 500; /* we record len+1 (1 start sample) */ +int samples_len = 500; /* we record len+1 (1 start sample) */ double hz = 25.0; /* 20 seconds log time */ double scale_x = 100.0; /* 100px = 1sec */ double scale_y = 20.0; /* 16px = 1 process bar */ @@ -112,16 +112,16 @@ int main(int argc, char *argv[]) char *init = NULL, *output = NULL; const ConfigTableItem items[] = { -{ "Bootchart", "Samples", config_parse_int,0, &len }, -{ "Bootchart", "Frequency",config_parse_double, 0, &hz }, -{ "Bootchart", "Relative", config_parse_bool, 0, &relative }, -{ "Bootchart", "Filter", config_parse_bool, 0, &filter }, -{ "Bootchart", "Output", config_parse_path, 0, &output }, -{ "Bootchart", "Init", config_parse_path, 0, &init }, -{ "Bootchart", "PlotMemoryUsage", config_parse_bool, 0, &pss }, -{ "Bootchart", "PlotEntropyGraph", config_parse_bool, 0, &entropy }, -{ "Bootchart", "ScaleX", config_parse_double, 0, &scale_x }, -{ "Bootchart", "ScaleY", config_parse_double, 0, &scale_y }, +{ "Bootchart", "Samples", config_parse_int,0, &samples_len }, +{ "Bootchart", "Frequency",config_parse_double, 0, &hz }, +{ "Bootchart", "Relative", config_parse_bool, 0, &relative}, +{ "Bootchart", "Filter", config_parse_bool, 0, &filter }, +{ "Bootchart", "Output", config_parse_path, 0, &output }, +{ "Bootchart", "Init", config_parse_path, 0, &init}, +{ "Bootchart", "PlotMemoryUsage", config_parse_bool, 0, &pss }, +{ "Bootchart", "PlotEntropyGraph", config_parse_bool, 0, &entropy }, +{ "Bootchart", "ScaleX", config_parse_double, 0, &scale_x }, +{ "Bootchart", "ScaleY", config_parse_double, 0, &scale_y }, { NULL, NULL, NULL, 0, NULL } }; @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) show_cmdline = true; break; case 'n': -r = safe_atoi(optarg, &len); +r = safe_atoi(optarg, &samples_len); if (r < 0) log_warning("failed to parse --samples/-n argument '%s': %s", optarg, strerror(-r)); @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]); fprintf(stderr, " --rel, -r Record time relative to recording\n"); fprintf(stderr, " --freq, -f fSample frequency [%f]\n", hz); -fprintf(stderr, " --samples, -n NStop sampling at [%d] samples\n", len); +fprintf(stderr, " --samples, -n NStop sampling at [%d] samples\n", samples_len); fprintf(stderr, " --scale-x, -x NScale the graph horizontally [%f] \n", scale_x); fprintf(stderr, " --scale-y, -y NScale the graph vertically [%f] \n", scale_y); fprintf(stderr, " --pss, -p Enable PSS graph (CPU intensive)\n"); @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) } } -if (len > MAXSAMPLES) { +if (samples_len > MAXSAMPLES) { fprintf(stderr, "Error: sa
[systemd-devel] [PATCH 3/3] bootchart: use _cleanup_fclose_
From: Harald Hoyer --- src/bootchart/log.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/bootchart/log.c b/src/bootchart/log.c index 43999f2..ccec03f 100644 --- a/src/bootchart/log.c +++ b/src/bootchart/log.c @@ -57,7 +57,7 @@ double gettime_ns(void) void log_uptime(void) { -FILE *f; +FILE _cleanup_fclose_ *f = NULL; char str[32]; double uptime; @@ -65,11 +65,9 @@ void log_uptime(void) if (!f) return; -if (!fscanf(f, "%s %*s", str)) { -fclose(f); +if (!fscanf(f, "%s %*s", str)) return; -} -fclose(f); + uptime = strtod(str, NULL); log_start = gettime_ns(); @@ -120,7 +118,6 @@ void log_sample(int sample) { static int vmstat; static int schedstat; -FILE *st; char buf[4095]; char key[256]; char val[256]; @@ -253,6 +250,7 @@ schedstat_next: /* end of our LL? then append a new record */ if (ps->pid != pid) { +FILE _cleanup_fclose_ *st = NULL; char t[32]; struct ps_struct *parent; @@ -320,10 +318,8 @@ schedstat_next: if (!st) continue; if (!fscanf(st, "%*s %*s %*s %i", &p)) { -fclose(st); continue; } -fclose(st); ps->ppid = p; /* -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] fstab-generator: fsck /sysroot before we mount it rw
From: Harald Hoyer --- src/fstab-generator/fstab-generator.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..b5fe0fa 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -449,6 +449,7 @@ static int parse_new_root_from_proc_cmdline(void) { char *w, *state; _cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL; int r; +int fsck_passno = 0; size_t l; r = read_one_line_file("/proc/cmdline", &line); @@ -490,7 +491,16 @@ static int parse_new_root_from_proc_cmdline(void) { if (!opts) return log_oom(); -} else if (streq(word, "ro") || streq(word, "rw")) { +} else if (streq(word, "ro")) { +fsck_passno = 0; +tmp_word = opts; +opts = strjoin(opts, ",", word, NULL); +free(tmp_word); +if (!opts) +return log_oom(); + +} else if (streq(word, "rw")) { +fsck_passno = 1; tmp_word = opts; opts = strjoin(opts, ",", word, NULL); free(tmp_word); @@ -513,7 +523,7 @@ static int parse_new_root_from_proc_cmdline(void) { } log_debug("Found entry what=%s where=/sysroot type=%s", what, type); -r = add_mount(what, "/sysroot", type, opts, 0, false, false, false, +r = add_mount(what, "/sysroot", type, opts, fsck_passno, false, false, false, false, false, "/proc/cmdline"); return (r < 0) ? r : 0; -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] cryptsetup-generator: use _cleanup_ where possible
From: Harald Hoyer --- src/cryptsetup/cryptsetup-generator.c | 209 +++--- 1 file changed, 65 insertions(+), 144 deletions(-) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 38a7cfa..0a51db8 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -34,7 +34,6 @@ static const char *arg_dest = "/tmp"; static bool arg_enabled = true; static bool arg_read_crypttab = true; -static char **arg_proc_cmdline_disks = NULL; static bool has_option(const char *haystack, const char *needle) { const char *f = haystack; @@ -71,9 +70,8 @@ static int create_disk( const char *password, const char *options) { -char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *from = NULL, *to = NULL, *e = NULL; -int r; -FILE *f = NULL; +char _cleanup_free_ *p = NULL, *n = NULL, *d = NULL, *u = NULL, *from = NULL, *to = NULL, *e = NULL; +FILE _cleanup_fclose_ *f = NULL; bool noauto, nofail; assert(name); @@ -83,34 +81,25 @@ static int create_disk( nofail = has_option(options, "nofail"); n = unit_name_from_path_instance("systemd-cryptsetup", name, ".service"); -if (!n) { -r = log_oom(); -goto fail; -} +if (!n) +return log_oom(); p = strjoin(arg_dest, "/", n, NULL); -if (!p) { -r = log_oom(); -goto fail; -} +if (!p) +return log_oom(); u = fstab_node_to_udev_node(device); -if (!u) { -r = log_oom(); -goto fail; -} +if (!u) +return log_oom(); d = unit_name_from_path(u, ".device"); -if (!d) { -r = log_oom(); -goto fail; -} +if (!d) +return log_oom(); f = fopen(p, "wxe"); if (!f) { -r = -errno; log_error("Failed to create unit file %s: %m", p); -goto fail; +return -errno; } fprintf(f, @@ -160,47 +149,39 @@ static int create_disk( fflush(f); if (ferror(f)) { -r = -errno; log_error("Failed to write file %s: %m", p); -goto fail; +return -errno; } -if (asprintf(&from, "../%s", n) < 0) { -r = log_oom(); -goto fail; -} +if (asprintf(&from, "../%s", n) < 0) +return log_oom(); if (!noauto) { to = strjoin(arg_dest, "/", d, ".wants/", n, NULL); -if (!to) { -r = log_oom(); -goto fail; -} +if (!to) +return log_oom(); mkdir_parents_label(to, 0755); if (symlink(from, to) < 0) { log_error("Failed to create symlink '%s' to '%s': %m", from, to); -r = -errno; -goto fail; +return -errno; } free(to); +to = NULL; if (!nofail) to = strjoin(arg_dest, "/cryptsetup.target.requires/", n, NULL); else to = strjoin(arg_dest, "/cryptsetup.target.wants/", n, NULL); -if (!to) { -r = log_oom(); -goto fail; -} +if (!to) +return log_oom(); mkdir_parents_label(to, 0755); if (symlink(from, to) < 0) { log_error("Failed to create symlink '%s' to '%s': %m", from, to); -r = -errno; -goto fail; +return -errno; } free(to); @@ -209,37 +190,21 @@ static int create_disk( e = unit_name_escape(name); to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL); -if (!to) { -r = log_oom(); -goto fail; -} +if (!to) +return log_oom(); mkdir_parents_label(to, 0755); if (symlink(from, to) < 0) { log_error("Failed to create symlink '%s' to '%s': %m", from, to); -r = -errno; -goto fail; +return -er
[systemd-devel] [PATCH] mount: fix manual network mounts
From: Harald Hoyer Now works as expected for me. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 18 +++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 419cf27..353d0e6 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -441,28 +441,38 @@ static int mount_add_default_dependencies(Mount *m) { int r; MountParameters *p; const char *after; +const char *before; assert(m); if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; -p = get_mount_parameters_fragment(m); +p = get_mount_parameters(m); + if (!p) return 0; if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; -else +before = SPECIAL_REMOTE_FS_TARGET; +} +else { after = SPECIAL_LOCAL_FS_PRE_TARGET; +before = SPECIAL_LOCAL_FS_TARGET; +} r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, after, NULL, true); if (r < 0) return r; +r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_REQUIRES, UNIT_BEFORE, before, NULL, true); +if (r < 0) +return r; + r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true); if (r < 0) return r; @@ -1516,7 +1526,9 @@ static int mount_add_one( if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; +} +if (u->load_state == UNIT_LOADED) { /* Load in the extras later on, after we * finished initialization of the unit */ load_extras = true; -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V2] mount: fix network mounts
From: Harald Hoyer Now works as expected for me. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 18 +++--- src/fstab-generator/fstab-generator.c | 4 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 419cf27..0a8e197 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -441,28 +441,38 @@ static int mount_add_default_dependencies(Mount *m) { int r; MountParameters *p; const char *after; +const char *before; assert(m); if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; -p = get_mount_parameters_fragment(m); +p = get_mount_parameters(m); + if (!p) return 0; if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; -else +before = SPECIAL_REMOTE_FS_TARGET; +} +else { after = SPECIAL_LOCAL_FS_PRE_TARGET; +before = SPECIAL_LOCAL_FS_TARGET; +} r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, after, NULL, true); if (r < 0) return r; +r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_PART_OF, UNIT_BEFORE, before, NULL, true); +if (r < 0) +return r; + r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true); if (r < 0) return r; @@ -1516,7 +1526,9 @@ static int mount_add_one( if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; +} +if (u->load_state == UNIT_LOADED) { /* Load in the extras later on, after we * finished initialization of the unit */ load_extras = true; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..00f85e9 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -275,6 +275,10 @@ static int add_mount(const char *what, const char *where, const char *type, cons post); fprintf(f, +"PartOf=%s\n", +post); + +fprintf(f, "\n" "[Mount]\n" "What=%s\n" -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V3] mount: fix manual network mounts
From: Harald Hoyer Now works as expected for me. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs-pre.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemdd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 11 +-- src/fstab-generator/fstab-generator.c | 6 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 419cf27..8d803d8 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -447,15 +447,20 @@ static int mount_add_default_dependencies(Mount *m) { if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; -p = get_mount_parameters_fragment(m); +p = get_mount_parameters(m); + if (!p) return 0; if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; +r = unit_add_dependency_by_name(UNIT(m), UNIT_PART_OF, after, NULL, true); +if (r < 0) +return r; +} else after = SPECIAL_LOCAL_FS_PRE_TARGET; @@ -1516,7 +1521,9 @@ static int mount_add_one( if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; +} +if (u->load_state == UNIT_LOADED) { /* Load in the extras later on, after we * finished initialization of the unit */ load_extras = true; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..f855e95 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -274,6 +274,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons "Before=%s\n", post); +if (isnetwork) { +fprintf(f, +"PartOf=%s\n", +pre); +} + fprintf(f, "\n" "[Mount]\n" -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V4] mount: fix manual network mounts
From: Harald Hoyer Now works as expected for me. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs-pre.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemdd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 10 +++--- src/fstab-generator/fstab-generator.c | 6 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 419cf27..6b90731 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -447,15 +447,20 @@ static int mount_add_default_dependencies(Mount *m) { if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; -p = get_mount_parameters_fragment(m); +p = get_mount_parameters(m); + if (!p) return 0; if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; +r = unit_add_dependency_by_name(UNIT(m), UNIT_PART_OF, after, NULL, true); +if (r < 0) +return r; +} else after = SPECIAL_LOCAL_FS_PRE_TARGET; @@ -1516,7 +1521,6 @@ static int mount_add_one( if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; - /* Load in the extras later on, after we * finished initialization of the unit */ load_extras = true; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..f855e95 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -274,6 +274,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons "Before=%s\n", post); +if (isnetwork) { +fprintf(f, +"PartOf=%s\n", +pre); +} + fprintf(f, "\n" "[Mount]\n" -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] mount: fix network umounts
From: Harald Hoyer Now works as expected for me. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs-pre.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemdd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 10 +++--- src/fstab-generator/fstab-generator.c | 6 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 419cf27..6b90731 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -447,15 +447,20 @@ static int mount_add_default_dependencies(Mount *m) { if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; -p = get_mount_parameters_fragment(m); +p = get_mount_parameters(m); + if (!p) return 0; if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; +r = unit_add_dependency_by_name(UNIT(m), UNIT_PART_OF, after, NULL, true); +if (r < 0) +return r; +} else after = SPECIAL_LOCAL_FS_PRE_TARGET; @@ -1516,7 +1521,6 @@ static int mount_add_one( if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; - /* Load in the extras later on, after we * finished initialization of the unit */ load_extras = true; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 910bbc1..f855e95 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -274,6 +274,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons "Before=%s\n", post); +if (isnetwork) { +fprintf(f, +"PartOf=%s\n", +pre); +} + fprintf(f, "\n" "[Mount]\n" -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] core: do not serialize targets on switch-root
From: Harald Hoyer Targets in the initrd can differ from targets on the switched root. Do not assume these targets are active. --- src/core/main.c| 8 src/core/manager.c | 6 +++--- src/core/manager.h | 2 +- src/core/unit.c| 7 +-- src/core/unit.h| 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 7b03983..b67ef79 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1091,7 +1091,7 @@ static int version(void) { return 0; } -static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) { +static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool do_switch_root) { FILE *f = NULL; FDSet *fds = NULL; int r; @@ -1116,7 +1116,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize goto fail; } -r = manager_serialize(m, f, fds, serialize_jobs); +r = manager_serialize(m, f, fds, do_switch_root); if (r < 0) { log_error("Failed to serialize state: %s", strerror(-r)); goto fail; @@ -1790,7 +1790,7 @@ int main(int argc, char *argv[]) { case MANAGER_REEXECUTE: -if (prepare_reexecute(m, &serialization, &fds, true) < 0) +if (prepare_reexecute(m, &serialization, &fds, false) < 0) goto finish; reexecute = true; @@ -1804,7 +1804,7 @@ int main(int argc, char *argv[]) { m->switch_root = m->switch_root_init = NULL; if (!switch_root_init) -if (prepare_reexecute(m, &serialization, &fds, false) < 0) +if (prepare_reexecute(m, &serialization, &fds, true) < 0) goto finish; reexecute = true; diff --git a/src/core/manager.c b/src/core/manager.c index c261b25..8864615 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2025,7 +2025,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root) { Iterator i; Unit *u; const char *t; @@ -2074,7 +2074,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputs(u->id, f); fputc('\n', f); -if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) { +if ((r = unit_serialize(u, f, fds, do_switch_root)) < 0) { m->n_reloading --; return r; } @@ -2262,7 +2262,7 @@ int manager_reload(Manager *m) { goto finish; } -r = manager_serialize(m, f, fds, true); +r = manager_serialize(m, f, fds, false); if (r < 0) { m->n_reloading --; goto finish; diff --git a/src/core/manager.h b/src/core/manager.h index c486a16..262f390 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -277,7 +277,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid int manager_open_serialization(Manager *m, FILE **_f); -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root); int manager_deserialize(Manager *m, FILE *f, FDSet *fds); int manager_distribute_fds(Manager *m, FDSet *fds); diff --git a/src/core/unit.c b/src/core/unit.c index a6cc3b6..2876531 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2320,7 +2320,7 @@ bool unit_can_serialize(Unit *u) { return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item; } -int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) { +int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool do_switch_root) { int r; assert(u); @@ -2330,11 +2330,14 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) { if (!unit_can_serialize(u)) return 0; +if (do_switch_root && u->type == UNIT_TARGET) +return 0; + if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0) return r; -if (serialize_jobs) { +if (!do_switch_root) { if (u->job) { fprintf(f, "job\n"); job_serialize(u->job, f, fds); diff --git a/src/core/unit.h b/src/core/unit.h index 9029d62..aa87e86 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -511,7 +511,7 @@ int unit_l
[systemd-devel] [PATCH] transaction: if a job wants to be started before a target, set the target dead
From: Harald Hoyer Not sure, if this is the correct place to enforce this, but it seems to work. --- src/core/transaction.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/src/core/transaction.c b/src/core/transaction.c index 4a8d90e..3fed57a 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -915,6 +915,13 @@ int transaction_add_job_and_dependencies( /* Finally, recursively add in all dependencies. */ if (type == JOB_START || type == JOB_RESTART) { +SET_FOREACH(dep, ret->unit->dependencies[UNIT_BEFORE], i) { +if (dep->type == UNIT_TARGET) { +Target *t = TARGET(dep); +t->state = TARGET_DEAD; +} +} + SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) { r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e); if (r < 0) { -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V2] core: do not serialize targets on switch-root
From: Harald Hoyer Targets in the initrd can differ from targets on the switched root. Do not assume these targets are active. --- src/core/main.c| 8 src/core/manager.c | 9 ++--- src/core/manager.h | 2 +- src/core/unit.c| 4 ++-- src/core/unit.h| 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 7b03983..b67ef79 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1091,7 +1091,7 @@ static int version(void) { return 0; } -static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) { +static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool do_switch_root) { FILE *f = NULL; FDSet *fds = NULL; int r; @@ -1116,7 +1116,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize goto fail; } -r = manager_serialize(m, f, fds, serialize_jobs); +r = manager_serialize(m, f, fds, do_switch_root); if (r < 0) { log_error("Failed to serialize state: %s", strerror(-r)); goto fail; @@ -1790,7 +1790,7 @@ int main(int argc, char *argv[]) { case MANAGER_REEXECUTE: -if (prepare_reexecute(m, &serialization, &fds, true) < 0) +if (prepare_reexecute(m, &serialization, &fds, false) < 0) goto finish; reexecute = true; @@ -1804,7 +1804,7 @@ int main(int argc, char *argv[]) { m->switch_root = m->switch_root_init = NULL; if (!switch_root_init) -if (prepare_reexecute(m, &serialization, &fds, false) < 0) +if (prepare_reexecute(m, &serialization, &fds, true) < 0) goto finish; reexecute = true; diff --git a/src/core/manager.c b/src/core/manager.c index c261b25..6e8e6a6 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2025,7 +2025,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root) { Iterator i; Unit *u; const char *t; @@ -2064,6 +2064,9 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputc('\n', f); HASHMAP_FOREACH_KEY(u, t, m->units, i) { +if (do_switch_root && u->type == UNIT_TARGET) +return 0; + if (u->id != t) continue; @@ -2074,7 +2077,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputs(u->id, f); fputc('\n', f); -if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) { +if ((r = unit_serialize(u, f, fds, do_switch_root)) < 0) { m->n_reloading --; return r; } @@ -2262,7 +2265,7 @@ int manager_reload(Manager *m) { goto finish; } -r = manager_serialize(m, f, fds, true); +r = manager_serialize(m, f, fds, false); if (r < 0) { m->n_reloading --; goto finish; diff --git a/src/core/manager.h b/src/core/manager.h index c486a16..262f390 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -277,7 +277,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid int manager_open_serialization(Manager *m, FILE **_f); -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root); int manager_deserialize(Manager *m, FILE *f, FDSet *fds); int manager_distribute_fds(Manager *m, FDSet *fds); diff --git a/src/core/unit.c b/src/core/unit.c index a6cc3b6..4c1fc7e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2320,7 +2320,7 @@ bool unit_can_serialize(Unit *u) { return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item; } -int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) { +int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool do_switch_root) { int r; assert(u); @@ -2334,7 +2334,7 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) { return r; -if (serialize_jobs) { +if (!do_switch_root) { if (u->job) { fprintf(f, "job\n"); job_serialize(u->job, f, fd
[systemd-devel] [PATCH V3] core: do not serialize targets on switch-root
From: Harald Hoyer Targets in the initrd can differ from targets on the switched root. Do not assume these targets are active. --- src/core/main.c| 8 src/core/manager.c | 9 ++--- src/core/manager.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 7b03983..b67ef79 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1091,7 +1091,7 @@ static int version(void) { return 0; } -static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) { +static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool do_switch_root) { FILE *f = NULL; FDSet *fds = NULL; int r; @@ -1116,7 +1116,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize goto fail; } -r = manager_serialize(m, f, fds, serialize_jobs); +r = manager_serialize(m, f, fds, do_switch_root); if (r < 0) { log_error("Failed to serialize state: %s", strerror(-r)); goto fail; @@ -1790,7 +1790,7 @@ int main(int argc, char *argv[]) { case MANAGER_REEXECUTE: -if (prepare_reexecute(m, &serialization, &fds, true) < 0) +if (prepare_reexecute(m, &serialization, &fds, false) < 0) goto finish; reexecute = true; @@ -1804,7 +1804,7 @@ int main(int argc, char *argv[]) { m->switch_root = m->switch_root_init = NULL; if (!switch_root_init) -if (prepare_reexecute(m, &serialization, &fds, false) < 0) +if (prepare_reexecute(m, &serialization, &fds, true) < 0) goto finish; reexecute = true; diff --git a/src/core/manager.c b/src/core/manager.c index c261b25..661534a 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2025,7 +2025,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root) { Iterator i; Unit *u; const char *t; @@ -2064,6 +2064,9 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputc('\n', f); HASHMAP_FOREACH_KEY(u, t, m->units, i) { +if (do_switch_root && u->type == UNIT_TARGET) +return 0; + if (u->id != t) continue; @@ -2074,7 +2077,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputs(u->id, f); fputc('\n', f); -if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) { +if ((r = unit_serialize(u, f, fds, !do_switch_root)) < 0) { m->n_reloading --; return r; } @@ -2262,7 +2265,7 @@ int manager_reload(Manager *m) { goto finish; } -r = manager_serialize(m, f, fds, true); +r = manager_serialize(m, f, fds, false); if (r < 0) { m->n_reloading --; goto finish; diff --git a/src/core/manager.h b/src/core/manager.h index c486a16..262f390 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -277,7 +277,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid int manager_open_serialization(Manager *m, FILE **_f); -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool do_switch_root); int manager_deserialize(Manager *m, FILE *f, FDSet *fds); int manager_distribute_fds(Manager *m, FDSet *fds); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/2] add initrd-fs.target and root-fs.target
From: Harald Hoyer Instead of using local-fs*.target in the initrd, use root-fs.target for sysroot.mount and initrd-fs.target for /sysroot/usr and friends. Using local-fs.target would mean to carry over the activated local-fs.target to the isolated initrd-switch-root.target and thus in the real root. Having local-fs.target already active after deserialization causes ordering problems with the real root services and targets. We better isolate to targets for initrd-switch-root.target, which are only available in the initrd. --- Makefile.am | 2 + man/systemd.special.xml | 30 + src/core/special.h| 2 + src/fstab-generator/fstab-generator.c | 79 --- units/initrd-cleanup.service.in | 4 +- units/initrd-fs.target| 13 ++ units/initrd-parse-etc.service.in | 6 +-- units/initrd-switch-root.target | 4 +- units/root-fs.target | 11 + 9 files changed, 110 insertions(+), 41 deletions(-) create mode 100644 units/initrd-fs.target create mode 100644 units/root-fs.target diff --git a/Makefile.am b/Makefile.am index c8f7b8e..9a98296 100644 --- a/Makefile.am +++ b/Makefile.am @@ -347,6 +347,8 @@ dist_systemunit_DATA = \ units/kexec.target \ units/local-fs.target \ units/local-fs-pre.target \ + units/initrd-fs.target \ + units/root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/systemd.special.xml b/man/systemd.special.xml index 0d1df84..7b78099 100644 --- a/man/systemd.special.xml +++ b/man/systemd.special.xml @@ -64,6 +64,7 @@ halt.target, hibernate.target, hybrid-sleep.target, +initrd-fs.target, kbrequest.target, kexec.target, local-fs.target, @@ -78,6 +79,7 @@ remote-fs.target, remote-fs-pre.target, rescue.target, +root-fs.target, rpcbind.target, runlevel2.target, runlevel3.target, @@ -296,6 +298,22 @@ + initrd-fs.target + +systemd automatically +adds dependencies of type +Before to sysroot-usr.mount and +all mount points fround in +/etc/fstab +that have the +auto and +x-initrd.mount +mount options set. +See also systemd-fstab-generator. + + + + kbrequest.target systemd starts this @@ -505,6 +523,17 @@ + root-fs.target + +systemd automatically +adds dependencies of type +Before to the sysroot.mount unit, +which is generated from the kernel command +line by the systemd-fstab-generator. + + + + rpcbind.target systemd automatically @@ -760,6 +789,7 @@ systemd.socket5, systemd.target5, bootup7 + systemd-fstab-generator8 diff --git a/src/core/special.h b/src/core/special.h index 99c0e12..52e593b 100644 --- a/src/core/special.h +++ b/src/core/special.h @@ -48,6 +48,8 @@ #define SPECIAL_SOCKETS_TARGET "sockets.target" #define SPECIAL_LOCAL_FS_TARGET "local-fs.target" #define SPECIAL_LOCAL_FS_PRE_TARGET "local-fs-pre.target" +#define SPECIAL_INITRD_FS_TARGET "initrd-fs.target" +#define SPECIAL_ROOT_FS_TARGET "root-fs.target" #define SPECIAL_REMOTE_FS_TARGET "remote-fs.target" /* LSB's $remote_fs */ #define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-p
[systemd-devel] [PATCH 2/2] mount: fix network umounts of manual remote-fs mounts
From: Harald Hoyer Revert 6bde0b3, which pulls in remote-fs-pre.target and with this i.e. NetworkManager-wait-online.service. Solve the remote-fs problem with using "PartOf". remote-fs.target is part of multi-user.target, and therefore active by default. By using UNIT_PART_OF from remote fs mount units to remote-fs.target, we ensure, that the mount units are unmounted as soon as remote-fs.target is stopped. $ mount 192.168.2.2:/Public /mnt/test $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago Where: /mnt/test What: 192.168.2.2:/Public Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted $ systemctl stop remote-fs.target $ systemctl status mnt-test.mount mnt-test.mount - /mnt/test Loaded: loaded (/proc/self/mountinfo) Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago Where: /mnt/test Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS) Mär 08 16:24:57 lenovo systemd[1]: Installed new job mnt-test.mount/stop as 744 Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test... Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0 Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test. --- src/core/mount.c | 6 +- src/fstab-generator/fstab-generator.c | 15 +++ units/remote-fs.target| 2 -- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 895aa25..1100ed6 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -455,8 +455,12 @@ static int mount_add_default_dependencies(Mount *m) { if (path_equal(m->where, "/")) return 0; -if (mount_is_network(p)) +if (mount_is_network(p)) { after = SPECIAL_REMOTE_FS_PRE_TARGET; +r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_PART_OF, SPECIAL_REMOTE_FS_TARGET, NULL, true); +if (r < 0) +return r; +} else after = SPECIAL_LOCAL_FS_PRE_TARGET; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b4fb134..6b2673e 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -201,7 +201,7 @@ static bool mount_in_initrd(struct mntent *me) { static int add_mount(const char *what, const char *where, const char *type, const char *opts, int passno, bool noauto, bool nofail, bool automount, bool isbind, - const char *pre, const char *post, const char *source) { + const char *pre, const char *post, const char *partof, const char *source) { char _cleanup_free_ *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL, *automount_name = NULL, *automount_unit = NULL; @@ -267,6 +267,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons "Before=%s\n", post); +if (partof) { +fprintf(f, +"PartOf=%s\n", +partof); +} + fprintf(f, "\n" "[Mount]\n" @@ -422,7 +428,7 @@ static int parse_fstab(const char *prefix, bool initrd) { k = add_swap(what, me); else { bool noauto, nofail, automount, isbind; -const char *pre, *post; +const char *pre, *post, *partof = NULL; noauto = !!hasmntopt(me, "noauto"); nofail = !!hasmntopt(me, "nofail"); @@ -436,6 +442,7 @@ static int parse_fstab(const char *prefix, bool initrd) { pre = NULL; } else if (mount_is_network(me)) { post = SPECIAL_REMOTE_FS_TARGET; +partof = SPECIAL_REMOTE_FS_TARGET; pre = SPECIAL_REMOTE_FS_PRE_TARGET; } else { post = SPECIAL_LOCAL_FS_TARGET; @@ -444,7 +451,7 @@ sta
[systemd-devel] [PATCH] fstab-generator: handle mount units with "x-rootfs.mount"
From: Harald Hoyer Mount units with "x-rootfs.mount" are now ordered before root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the root-fs.target is active. --- src/fstab-generator/fstab-generator.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b4fb134..6905316 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -199,6 +199,13 @@ static bool mount_in_initrd(struct mntent *me) { streq(me->mnt_dir, "/usr"); } +static bool mount_is_rootfs(struct mntent *me) { +assert(me); + +return +hasmntopt(me, "x-rootfs.mount"); +} + static int add_mount(const char *what, const char *where, const char *type, const char *opts, int passno, bool noauto, bool nofail, bool automount, bool isbind, const char *pre, const char *post, const char *source) { @@ -434,6 +441,9 @@ static int parse_fstab(const char *prefix, bool initrd) { if (initrd) { post = SPECIAL_INITRD_FS_TARGET; pre = NULL; +} else if (mount_is_rootfs(me)) { +post = SPECIAL_ROOT_FS_TARGET; +pre = NULL; } else if (mount_is_network(me)) { post = SPECIAL_REMOTE_FS_TARGET; pre = SPECIAL_REMOTE_FS_PRE_TARGET; -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Rename root-fs.target to initrd-root-fs.target, add x-initrd-rootfs.mount
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. --- Makefile.am | 2 +- man/systemd.special.xml | 4 ++-- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 ++- units/initrd-cleanup.service.in | 4 ++-- units/initrd-parse-etc.service.in | 4 ++-- units/{root-fs.target => initrd-root-fs.target} | 0 units/initrd-switch-root.target | 4 ++-- 8 files changed, 20 insertions(+), 11 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (100%) diff --git a/Makefile.am b/Makefile.am index 175d14b..d92b24a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -348,7 +348,7 @@ dist_systemunit_DATA = \ units/local-fs.target \ units/local-fs-pre.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/systemd.special.xml b/man/systemd.special.xml index 7b78099..67a81b6 100644 --- a/man/systemd.special.xml +++ b/man/systemd.special.xml @@ -79,7 +79,7 @@ remote-fs.target, remote-fs-pre.target, rescue.target, -root-fs.target, +initrd-root-fs.target, rpcbind.target, runlevel2.target, runlevel3.target, @@ -523,7 +523,7 @@ - root-fs.target + initrd-root-fs.target systemd automatically adds dependencies of type diff --git a/src/core/special.h b/src/core/special.h index 52e593b..c7b856e 100644 --- a/src/core/special.h +++ b/src/core/special.h @@ -49,7 +49,7 @@ #define SPECIAL_LOCAL_FS_TARGET "local-fs.target" #define SPECIAL_LOCAL_FS_PRE_TARGET "local-fs-pre.target" #define SPECIAL_INITRD_FS_TARGET "initrd-fs.target" -#define SPECIAL_ROOT_FS_TARGET "root-fs.target" +#define SPECIAL_INITRD_ROOT_FS_TARGET "initrd-root-fs.target" #define SPECIAL_REMOTE_FS_TARGET "remote-fs.target" /* LSB's $remote_fs */ #define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-pre.target" #define SPECIAL_SWAP_TARGET "swap.target" diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b4fb134..cf85d31 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -199,6 +199,12 @@ static bool mount_in_initrd(struct mntent *me) { streq(me->mnt_dir, "/usr"); } +static bool mount_is_rootfs(struct mntent *me) { +assert(me); + +return hasmntopt(me, "x-initrd-rootfs.mount"); +} + static int add_mount(const char *what, const char *where, const char *type, const char *opts, int passno, bool noauto, bool nofail, bool automount, bool isbind, const char *pre, const char *post, const char *source) { @@ -434,6 +440,9 @@ static int parse_fstab(const char *prefix, bool initrd) { if (initrd) { post = SPECIAL_INITRD_FS_TARGET; pre = NULL; +} else if (mount_is_rootfs(me)) { +post = SPECIAL_INITRD_ROOT_FS_TARGET; +pre = NULL; } else if (mount_is_network(me)) { post = SPECIAL_REMOTE_FS_TARGET; pre = SPECIAL_REMOTE_FS_PRE_TARGET; @@ -525,7 +534,7 @@ static int parse_new_root_from_proc_cmdline(void) { log_debug("Found entry what=%s where=/sysroot type=%s", what, type); r = add_mount(what, "/sysroot", type, opts, 0, false, false, false, - false, NULL, SPECIAL_ROOT_FS_TARGET, "/proc/cmdline"); + false, NULL, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline"); return (r < 0) ? r : 0; } diff --git a/units/initrd-cleanup.service.in b/units/initrd-cleanup.service.in index 5bef090..1de6b48 100644 --- a/units/initrd-cleanup.service.in +++ b/units/initrd-cleanup.service.in @@ -10,8 +10,8 @@ Description=Cleaning Up and Shutting Down Daemons DefaultDependencies=no ConditionPathE
[systemd-devel] [RFC PATCH] Make initrd-fs.target the default target in the initrd
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd-fs.target can now be isolated and be the default target in the initrd. : : v basic.target | __/| / | initrd-root-fs.target | | | v custom initrd services initrd-parse-etc.service | | | \__ | \| v initrd-fs.target | v initrd-cleanup.service | v __/| / | | custom initrd services initrd-udevadm-cleanup-db.service | | | \__ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root --- Makefile.am | 2 +- man/bootup.xml | 53 + man/systemd.special.xml | 4 +- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 - units/initrd-cleanup.service.in | 4 +- units/initrd-fs.target | 5 +++ units/initrd-parse-etc.service.in | 4 +- units/{root-fs.target => initrd-root-fs.target} | 0 units/initrd-switch-root.target | 4 +- 10 files changed, 78 insertions(+), 11 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (100%) diff --git a/Makefile.am b/Makefile.am index 175d14b..d92b24a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -348,7 +348,7 @@ dist_systemunit_DATA = \ units/local-fs.target \ units/local-fs-pre.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/bootup.xml b/man/bootup.xml index f65abf5..4f0a6b8 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -174,6 +174,59 @@ +Systemd in the Initrd +If the initrd creator used the services provided +by systemd, the default target in the initrd is the +initrd-fs.target. If this target is reached all devices +are found and mounted on /sysroot. +The initrd-cleanup.service isolates to the initrd-switch-root.target, +where cleanup services can run. At the very last end +initrd-switch-root.service is activated, which will cause +the system to switch root to /sysroot. + + + + : + : + v + basic.target + | +__/| + / | + initrd-root-fs.target | + | | + v custom initrd services emergency.service +initrd-parse-etc.service | | + | | v + \__ |
[systemd-devel] [PATCH V2] Make initrd-fs.target the default target in the initrd
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd-fs.target can now be isolated and be the default target in the initrd. (same as above) : : v basic.target | __/| / | | sysroot.mount | | | v | initrd-root-fs.target | | | v |initrd-parse-etc.service (custom initrd services)| | v |(sysroot-usr.mount and | various mounts marked | with fstab option |x-initrd.mount) | | \__ | \| v initrd-fs.target | v initrd-cleanup.service isolates to initrd-switch-root.target | v __/| / | |initrd-udevadm-cleanup-db.service | | (custom initrd services)| | | \__ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root --- Makefile.am | 2 +- man/bootup.xml | 70 + man/systemd.special.xml | 4 +- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 +++- units/initrd-cleanup.service.in | 4 +- units/initrd-fs.target | 5 ++ units/initrd-parse-etc.service.in | 4 +- units/{root-fs.target => initrd-root-fs.target} | 0 units/initrd-switch-root.target | 4 +- 10 files changed, 95 insertions(+), 11 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (100%) diff --git a/Makefile.am b/Makefile.am index 175d14b..d92b24a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -348,7 +348,7 @@ dist_systemunit_DATA = \ units/local-fs.target \ units/local-fs-pre.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/bootup.xml b/man/bootup.xml index f65abf5..26bb917 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -174,6 +174,76 @@ +Systemd in the Initrd +If the initrd creation tool used the services provided +by systemd, the default target in the initrd is the +initrd-fs.target. The process is the same as above until the basic.target is reached. +Systemd now continues to the initrd-fs.target. If the root device could be mounted +on /sysroot, the sysroot.mount unit is active and the initrd-root-fs.target is reached. +initrd-parse-etc.service scans /sysroot/etc/fstab for the /usr mountpoint and for entries +marked with the x-initrd.mount option set. If these mountpoint are +mounted in /sysroot, the initrd-fs.target is reached. +The initrd-cleanup.service isolates to the initrd-switch-root.target, +where cleanup services can run. At the very last end +initrd-switch-root.service is activated, which will cause +the system to switch root to /sysroot. + + + +
[systemd-devel] [PATCH V3] Make initrd-fs.target the default target in the initrd
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd-fs.target can now be isolated and be the default target in the initrd. (same as above) : : v basic.target | __/| / | | sysroot.mount | | | v | initrd-root-fs.target | | | v |initrd-parse-etc.service (custom initrd services)| | v |(sysroot-usr.mount and | various mounts marked | with fstab option |x-initrd.mount) | | \__ | \| v initrd-fs.target | v initrd-cleanup.service isolates to initrd-switch-root.target | v __/| / | |initrd-udevadm-cleanup-db.service | | (custom initrd services)| | | \__ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root --- Makefile.am | 2 +- man/bootup.xml | 70 + man/systemd.special.xml | 4 +- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 +++- units/initrd-cleanup.service.in | 3 +- units/initrd-fs.target | 5 ++ units/initrd-parse-etc.service.in | 6 +-- units/{root-fs.target => initrd-root-fs.target} | 0 units/initrd-switch-root.target | 4 +- 10 files changed, 95 insertions(+), 12 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (100%) diff --git a/Makefile.am b/Makefile.am index 175d14b..d92b24a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -348,7 +348,7 @@ dist_systemunit_DATA = \ units/local-fs.target \ units/local-fs-pre.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/bootup.xml b/man/bootup.xml index f65abf5..26bb917 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -174,6 +174,76 @@ +Systemd in the Initrd +If the initrd creation tool used the services provided +by systemd, the default target in the initrd is the +initrd-fs.target. The process is the same as above until the basic.target is reached. +Systemd now continues to the initrd-fs.target. If the root device could be mounted +on /sysroot, the sysroot.mount unit is active and the initrd-root-fs.target is reached. +initrd-parse-etc.service scans /sysroot/etc/fstab for the /usr mountpoint and for entries +marked with the x-initrd.mount option set. If these mountpoint are +mounted in /sysroot, the initrd-fs.target is reached. +The initrd-cleanup.service isolates to the initrd-switch-root.target, +where cleanup services can run. At the very last end +initrd-switch-root.service is activated, which will cause +the system to switch root to /sysroot. + + + +
[systemd-devel] [PATCH FINAL] Make initrd.target the default target in the initrd
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd.target can be the default target in the initrd. (normal startup) : : v basic.target | __/| / | | sysroot.mount | | | v | initrd-root-fs.target | | | v |initrd-parse-etc.service (custom initrd services)| | v |(sysroot-usr.mount and | various mounts marked | with fstab option |x-initrd.mount) | | | v |initrd-fs.target | | \__ | \| v initrd.target | v initrd-cleanup.service isolates to initrd-switch-root.target | v __/| / | |initrd-udevadm-cleanup-db.service | | (custom initrd services)| | | \__ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root --- Makefile.am | 3 +- man/bootup.xml | 73 + man/systemd.special.xml | 4 +- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 +++- units/initrd-cleanup.service.in | 3 +- units/initrd-fs.target | 2 + units/initrd-parse-etc.service.in | 7 ++- units/{root-fs.target => initrd-root-fs.target} | 2 + units/initrd-switch-root.target | 4 +- units/initrd.target | 17 ++ 11 files changed, 116 insertions(+), 12 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (89%) create mode 100644 units/initrd.target diff --git a/Makefile.am b/Makefile.am index 175d14b..cf21544 100644 --- a/Makefile.am +++ b/Makefile.am @@ -347,8 +347,9 @@ dist_systemunit_DATA = \ units/kexec.target \ units/local-fs.target \ units/local-fs-pre.target \ + units/initrd.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/bootup.xml b/man/bootup.xml index f65abf5..6bd22ef 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -174,6 +174,79 @@ +Systemd in the Initrd +If the initrd creation tool used the services provided +by systemd, the default target in the initrd is the +initrd-fs.target. The process is the same as above until the basic.target is reached. +Systemd now continues to the initrd.target. If the root device could be mounted +on /sysroot, the sysroot.mount unit is active and the initrd-root-fs.target is reached. +initrd-parse-etc.service scans /sysroot/etc/fstab for the /usr mountpoint and for entries +marked with the x-initrd.mount option set. If these mountpoint are +mounted in /sysroot, the initrd-fs.target is reached. +The initrd-cleanup.service isolates to the initrd-switch-root.target, +where cleanup services can run. At the very last end +initrd-switch-root.service is activated, which will cause +
[systemd-devel] [PATCH FINAL FINAL] Make initrd.target the default target in the initrd
From: Harald Hoyer First, rename root-fs.target to initrd-root-fs.target to clarify its usage. Mount units with "x-initrd-rootfs.mount" are now ordered before initrd-root-fs.target. As we sometimes construct /sysroot mounts in /etc/fstab in the initrd, we want these to be mounted before the initrd-root-fs.target is active. initrd.target can be the default target in the initrd. (normal startup) : : v basic.target | __/| / | | sysroot.mount | | | v | initrd-root-fs.target | | | v |initrd-parse-etc.service (custom initrd services)| | v |(sysroot-usr.mount and | various mounts marked | with fstab option |x-initrd.mount) | | | v |initrd-fs.target | | \__ | \| v initrd.target | v initrd-cleanup.service isolates to initrd-switch-root.target | v __/| / | |initrd-udevadm-cleanup-db.service | | (custom initrd services)| | | \__ | \| v initrd-switch-root.target | v initrd-switch-root.service | v switch-root --- Makefile.am | 3 +- man/bootup.xml | 73 + man/systemd.special.xml | 4 +- src/core/special.h | 2 +- src/fstab-generator/fstab-generator.c | 11 +++- units/initrd-cleanup.service.in | 3 +- units/initrd-fs.target | 1 + units/initrd-parse-etc.service.in | 7 ++- units/{root-fs.target => initrd-root-fs.target} | 2 + units/initrd-switch-root.target | 4 +- units/initrd.target | 17 ++ 11 files changed, 115 insertions(+), 12 deletions(-) rename units/{root-fs.target => initrd-root-fs.target} (89%) create mode 100644 units/initrd.target diff --git a/Makefile.am b/Makefile.am index 175d14b..cf21544 100644 --- a/Makefile.am +++ b/Makefile.am @@ -347,8 +347,9 @@ dist_systemunit_DATA = \ units/kexec.target \ units/local-fs.target \ units/local-fs-pre.target \ + units/initrd.target \ units/initrd-fs.target \ - units/root-fs.target \ + units/initrd-root-fs.target \ units/remote-fs.target \ units/remote-fs-pre.target \ units/network.target \ diff --git a/man/bootup.xml b/man/bootup.xml index f65abf5..6bd22ef 100644 --- a/man/bootup.xml +++ b/man/bootup.xml @@ -174,6 +174,79 @@ +Systemd in the Initrd +If the initrd creation tool used the services provided +by systemd, the default target in the initrd is the +initrd-fs.target. The process is the same as above until the basic.target is reached. +Systemd now continues to the initrd.target. If the root device could be mounted +on /sysroot, the sysroot.mount unit is active and the initrd-root-fs.target is reached. +initrd-parse-etc.service scans /sysroot/etc/fstab for the /usr mountpoint and for entries +marked with the x-initrd.mount option set. If these mountpoint are +mounted in /sysroot, the initrd-fs.target is reached. +The initrd-cleanup.service isolates to the initrd-switch-root.target, +where cleanup services can run. At the very last end +initrd-switch-root.service is activated, which will cause +
[systemd-devel] [PATCH] journalctl: add short version for _SYSTEMD_UNIT=
From: Harald Hoyer Instead of typing the rather unusual: $ journalctl _SYSTEMD_UNIT=sshd.service one can now type $ journalctl sshd.service -- Logs begin at So 2013-02-24 20:54:44 CET, end at Mo 2013-03-18 14:01:01 CET. -- Mär 18 07:48:26 lenovo sshd[400]: Server listening on 0.0.0.0 port 22. Mär 18 07:48:26 lenovo sshd[400]: Server listening on :: port 22. --- shell-completion/bash/journalctl | 5 - src/journal/journalctl.c | 12 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl index 1fca5ad..112a526 100644 --- a/shell-completion/bash/journalctl +++ b/shell-completion/bash/journalctl @@ -23,6 +23,9 @@ __contains_word () { return 1 } +__journal_get_all_units () { systemctl --full --no-legend list-units --all \ +| { while read -r a b; do printf "%s\n" "$a"; done; }; } + __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE _{P,U,G}ID _COMM _EXE _CMDLINE @@ -98,7 +101,7 @@ _journalctl() { COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") ) else compopt -o nospace -COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) +COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") $(compgen -W '$(__journal_get_all_units)' -- "$cur") ) fi } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 65114b2..21fb149 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -511,6 +511,10 @@ static int generate_new_id128(void) { return 0; } +static bool arg_is_unit(char *name) { +return strchr(name, '=') == NULL && unit_name_is_valid(name, true); +} + static int add_matches(sd_journal *j, char **args) { char **i; int r; @@ -554,6 +558,14 @@ static int add_matches(sd_journal *j, char **args) { r = sd_journal_add_match(j, t, 0); free(t); +} else if (arg_is_unit(*i)) { +char *t = NULL; +t = strappend("_SYSTEMD_UNIT=", *i); +if (!t) +return log_oom(); + +r = sd_journal_add_match(j, t, 0); +free(t); } else r = sd_journal_add_match(j, *i, 0); -- 1.8.1 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] journalctl: fix logic with parameter "-u"
From: Harald Hoyer When using "-p" and "-b" in combination with "-u", the output is not what you would expect. The reason is the sd_journal_add_disjunction() call in add_matches_for_unit() and add_matches_for_user_unit(), which adds two ORs without taking the other conditions to every OR. Output before: $ journalctl -o short-monotonic -ab -p 0 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Reboot -- [3.216305] lenovo systemd[1]: Starting OpenSSH server daemon... -- Reboot -- [3.168666] lenovo systemd[1]: Starting OpenSSH server daemon... [3.169639] lenovo systemd[1]: Started OpenSSH server daemon. [36285.635389] lenovo systemd[1]: Stopped OpenSSH server daemon. -- Reboot -- [ 10.838657] lenovo systemd[1]: Starting OpenSSH server daemon... [ 10.913698] lenovo systemd[1]: Started OpenSSH server daemon. [ 6881.035183] lenovo systemd[1]: Stopped OpenSSH server daemon. -- Reboot -- [6.636228] lenovo systemd[1]: Starting OpenSSH server daemon... [6.662573] lenovo systemd[1]: Started OpenSSH server daemon. [6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22. [6.681379] lenovo sshd[397]: Server listening on :: port 22. As we see, the output is from _every_ boot and priority 0 is not taken into account. Output after patch: $ journalctl -o short-monotonic -ab -p 0 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:58:21 CET. -- Increasing the priority: $ journalctl -o short-monotonic -ab -p 6 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:59:12 CET. -- [6.636228] lenovo systemd[1]: Starting OpenSSH server daemon... [6.662573] lenovo systemd[1]: Started OpenSSH server daemon. [6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22. [6.681379] lenovo sshd[397]: Server listening on :: port 22. [7.191076] lenovo crond[416]: (CRON) INFO (Syslog will be used instead of sendmail.) [7.191302] lenovo crond[416]: (CRON) INFO (running with inotify support) --- src/journal/journalctl.c | 145 +++ 1 file changed, 120 insertions(+), 25 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index a6ad055..3500c4a 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -511,16 +511,22 @@ static int generate_new_id128(void) { return 0; } -static int add_matches(sd_journal *j, char **args) { -char **i; +static int add_matches(sd_journal *j, char **prematch, char **args) { +char **i, **k; int r; assert(j); STRV_FOREACH(i, args) { -if (streq(*i, "+")) +if (streq(*i, "+")) { r = sd_journal_add_disjunction(j); +STRV_FOREACH(k, prematch) { +if ((r = sd_journal_add_match(j, *k, 0))) +return r; +} +} + else if (path_is_absolute(*i)) { char *p, *t = NULL; const char *path; @@ -566,13 +572,11 @@ static int add_matches(sd_journal *j, char **args) { return 0; } -static int add_this_boot(sd_journal *j) { +static int add_this_boot(char ***prematch) { char match[9+32+1] = "_BOOT_ID="; sd_id128_t boot_id; int r; -assert(j); - if (!arg_this_boot) return 0; @@ -583,16 +587,109 @@ static int add_this_boot(sd_journal *j) { } sd_id128_to_string(boot_id, match + 9); -r = sd_journal_add_match(j, match, strlen(match)); -if (r < 0) { -log_error("Failed to add match: %s", strerror(-r)); + +r = strv_extend(prematch, match); +if (r) +return log_oom(); + +return 0; +} + +static int add_matches_for_unit_prematch(sd_journal *j, char **prematch, const char *unit) { +int r; +_cleanup_free_ char *m1 = NULL, *m2 = NULL, *m3 = NULL; +char **i; + +assert(j); +assert(unit); + +if (asprintf(&m1, "_SYSTEMD_UNIT=%s", unit) < 0 || +asprintf(&m2, "COREDUMP_UNIT=%s", unit) < 0 || +asprintf(&m3, "UNIT=%s", unit) < 0) +return -ENOMEM; + +STRV_FOREACH(i, prematch) { +if ((r = sd_journal_add_match(j, *i, 0))) +return r; +} +/* Look for messages from the service itself */ +if ((r = sd_journal_add_match(j, m1, 0)) || +/* Look for coredumps of the service */ +(r = sd_journal_add_disjunction(j))) return r; + +
[systemd-devel] [PATCH V2] journalctl: fix logic with parameter "-u"
From: Harald Hoyer When using "-p" and "-b" in combination with "-u", the output is not what you would expect. The reason is the sd_journal_add_disjunction() call in add_matches_for_unit() and add_matches_for_user_unit(), which adds two ORs without taking the other conditions to every OR. Output before: $ journalctl -o short-monotonic -ab -p 0 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Reboot -- [3.216305] lenovo systemd[1]: Starting OpenSSH server daemon... -- Reboot -- [3.168666] lenovo systemd[1]: Starting OpenSSH server daemon... [3.169639] lenovo systemd[1]: Started OpenSSH server daemon. [36285.635389] lenovo systemd[1]: Stopped OpenSSH server daemon. -- Reboot -- [ 10.838657] lenovo systemd[1]: Starting OpenSSH server daemon... [ 10.913698] lenovo systemd[1]: Started OpenSSH server daemon. [ 6881.035183] lenovo systemd[1]: Stopped OpenSSH server daemon. -- Reboot -- [6.636228] lenovo systemd[1]: Starting OpenSSH server daemon... [6.662573] lenovo systemd[1]: Started OpenSSH server daemon. [6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22. [6.681379] lenovo sshd[397]: Server listening on :: port 22. As we see, the output is from _every_ boot and priority 0 is not taken into account. Output after patch: $ journalctl -o short-monotonic -ab -p 0 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:58:21 CET. -- Increasing the priority: $ journalctl -o short-monotonic -ab -p 6 -u sshd.service + _SYSTEMD_UNIT=crond.service -- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:59:12 CET. -- [6.636228] lenovo systemd[1]: Starting OpenSSH server daemon... [6.662573] lenovo systemd[1]: Started OpenSSH server daemon. [6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22. [6.681379] lenovo sshd[397]: Server listening on :: port 22. [7.191076] lenovo crond[416]: (CRON) INFO (Syslog will be used instead of sendmail.) [7.191302] lenovo crond[416]: (CRON) INFO (running with inotify support) --- src/journal/journalctl.c | 153 ++- 1 file changed, 126 insertions(+), 27 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ddadc21..e95253c 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -519,16 +519,26 @@ static int generate_new_id128(void) { return 0; } -static int add_matches(sd_journal *j, char **args) { -char **i; +static int add_matches(sd_journal *j, char **prematch, char **args) { +char **i, **k; +int r; assert(j); -STRV_FOREACH(i, args) { -int r; +STRV_FOREACH(k, prematch) { +if ((r = sd_journal_add_match(j, *k, 0))) +return r; +} -if (streq(*i, "+")) +STRV_FOREACH(i, args) { +if (streq(*i, "+")) { r = sd_journal_add_disjunction(j); + +STRV_FOREACH(k, prematch) { +if ((r = sd_journal_add_match(j, *k, 0))) +return r; +} +} else if (path_is_absolute(*i)) { char _cleanup_free_ *p, *t = NULL; const char *path; @@ -569,13 +579,11 @@ static int add_matches(sd_journal *j, char **args) { return 0; } -static int add_this_boot(sd_journal *j) { +static int add_this_boot(char ***prematch) { char match[9+32+1] = "_BOOT_ID="; sd_id128_t boot_id; int r; -assert(j); - if (!arg_this_boot) return 0; @@ -586,16 +594,110 @@ static int add_this_boot(sd_journal *j) { } sd_id128_to_string(boot_id, match + 9); -r = sd_journal_add_match(j, match, strlen(match)); -if (r < 0) { -log_error("Failed to add match: %s", strerror(-r)); + + +r = strv_extend(prematch, match); +if (r) +return log_oom(); + +return 0; +} + +static int add_matches_for_unit_prematch(sd_journal *j, char **prematch, const char *unit) { +int r; +_cleanup_free_ char *m1 = NULL, *m2 = NULL, *m3 = NULL; +char **i; + +assert(j); +assert(unit); + +if (asprintf(&m1, "_SYSTEMD_UNIT=%s", unit) < 0 || +asprintf(&m2, "COREDUMP_UNIT=%s", unit) < 0 || +asprintf(&m3, "UNIT=%s", unit) < 0) +return -ENOMEM; + +STRV_FOREACH(i, prematch) { +if ((r = sd_journal_add_match(j, *i, 0))) +return r; +} +/* Look for messages from the service itself
[systemd-devel] [PATCH] cryptsetup-generator: Add JobTimeoutSec=0 for all known crypt devices
From: Harald Hoyer put JobTimeoutSec=0 in .d/JobTimeoutSec0.conf files This helps with grabbing a cup of coffee while booting and not have the crypto password dialog timeout and systemd in a failed state. This is even needed for "timeout=0" in /etc/crypttab! --- src/cryptsetup/cryptsetup-generator.c | 29 + 1 file changed, 29 insertions(+) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 6b9bc55..5ca9529 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -213,6 +213,35 @@ static int create_disk( return -errno; } +if (!noauto && !nofail) { +free(p); +p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-JobTimeoutSec0.conf", NULL); +if (!p) +return log_oom(); + +mkdir_parents_label(p, 0755); + +if (f) +fclose(f); +f = fopen(p, "wxe"); +if (!f) { +log_error("Failed to create unit file %s: %m", p); +return -errno; +} + +fprintf(f, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n" /* the binary handles timeouts anyway */ +); +fflush(f); + +if (ferror(f)) { +log_error("Failed to write file %s: %m", p); +return -errno; +} +} + return 0; } -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V2] cryptsetup-generator: add JobTimeoutSec=0 for the decrypted crypt devices
From: Harald Hoyer The password query for a crypto device currently times out after 90s, which is too short to grab a cup of coffee when a machine boots up. The resulting decrypted device /dev/mapper/luks- might not be a mountpoint (but part of a LVM PV or raid array) and therefore the timeout cannot be controlled by the settings in /etc/fstab. For this reason this device should not carry its own timeout. Also the encrypted device /dev/disk/by-*/* already has a timeout and additionally the timeout for the password query is set in /etc/crypttab. This patch disables the timeout of the resulting decrypted devices by creating .d/50-job-timeout-sec-0.conf files with "JobTimeoutSec=0". --- src/cryptsetup/cryptsetup-generator.c | 29 + 1 file changed, 29 insertions(+) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 6b9bc55..33604f7 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -213,6 +213,35 @@ static int create_disk( return -errno; } +if (!noauto && !nofail) { +free(p); +p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL); +if (!p) +return log_oom(); + +mkdir_parents_label(p, 0755); + +if (f) +fclose(f); +f = fopen(p, "wxe"); +if (!f) { +log_error("Failed to create unit file %s: %m", p); +return -errno; +} + +fprintf(f, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n" /* the binary handles timeouts anyway */ +); +fflush(f); + +if (ferror(f)) { +log_error("Failed to write file %s: %m", p); +return -errno; +} +} + return 0; } -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V3] cryptsetup-generator: add JobTimeoutSec=0 for the decrypted crypt devices
From: Harald Hoyer The password query for a crypto device currently times out after 90s, which is too short to grab a cup of coffee when a machine boots up. The resulting decrypted device /dev/mapper/luks- might not be a mountpoint (but part of a LVM PV or raid array) and therefore the timeout cannot be controlled by the settings in /etc/fstab. For this reason this device should not carry its own timeout. Also the encrypted device /dev/disk/by-*/* already has a timeout and additionally the timeout for the password query is set in /etc/crypttab. This patch disables the timeout of the resulting decrypted devices by creating .d/50-job-timeout-sec-0.conf files with "JobTimeoutSec=0". --- src/cryptsetup/cryptsetup-generator.c | 17 + 1 file changed, 17 insertions(+) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 6b9bc55..fd2080b 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -213,6 +213,23 @@ static int create_disk( return -errno; } +if (!noauto && !nofail) { +int r; +free(p); +p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL); +if (!p) +return log_oom(); + +mkdir_parents_label(p, 0755); + +r = write_string_file(p, +"# Automatically generated by systemd-cryptsetup-generator\n\n" +"[Unit]\n" +"JobTimeoutSec=0\n"); /* the binary handles timeouts anyway */ +if (r) +return r; +} + return 0; } -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] Do not serialize environment, when switching root
From: Harald Hoyer When switching root, i.e. LANG can be set to the locale of the initramfs or "C", if it was unset. When systemd deserializes LANG in the real root this would overwrite the setting previously gathered by locale_set(). To reproduce, boot with an initramfs without locale.conf or change /etc/locale.conf to a different language than the initramfs and check a daemon started by systemd: $ tr "$\000" '\n' https://bugzilla.redhat.com/show_bug.cgi?id=949525 --- src/core/main.c| 8 src/core/manager.c | 21 +++-- src/core/manager.h | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 921476a..7899761 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1088,7 +1088,7 @@ static int version(void) { return 0; } -static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) { +static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) { FILE *f = NULL; FDSet *fds = NULL; int r; @@ -1113,7 +1113,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize goto fail; } -r = manager_serialize(m, f, fds, serialize_jobs); +r = manager_serialize(m, f, fds, switching_root); if (r < 0) { log_error("Failed to serialize state: %s", strerror(-r)); goto fail; @@ -1780,7 +1780,7 @@ int main(int argc, char *argv[]) { case MANAGER_REEXECUTE: -if (prepare_reexecute(m, &serialization, &fds, true) < 0) +if (prepare_reexecute(m, &serialization, &fds, false) < 0) goto finish; reexecute = true; @@ -1794,7 +1794,7 @@ int main(int argc, char *argv[]) { m->switch_root = m->switch_root_init = NULL; if (!switch_root_init) -if (prepare_reexecute(m, &serialization, &fds, false) < 0) +if (prepare_reexecute(m, &serialization, &fds, true) < 0) goto finish; reexecute = true; diff --git a/src/core/manager.c b/src/core/manager.c index 549153e..cb6f961 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2004,7 +2004,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { Iterator i; Unit *u; const char *t; @@ -2032,16 +2032,17 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp); } -STRV_FOREACH(e, m->environment) { -_cleanup_free_ char *ce; +if (!switching_root) { +STRV_FOREACH(e, m->environment) { +_cleanup_free_ char *ce; -ce = cescape(*e); -if (ce) -fprintf(f, "env=%s\n", *e); +ce = cescape(*e); +if (ce) +fprintf(f, "env=%s\n", *e); +} +fputc('\n', f); } -fputc('\n', f); - HASHMAP_FOREACH_KEY(u, t, m->units, i) { if (u->id != t) continue; @@ -2053,7 +2054,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputs(u->id, f); fputc('\n', f); -if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) { +if ((r = unit_serialize(u, f, fds, !switching_root)) < 0) { m->n_reloading --; return r; } @@ -2241,7 +2242,7 @@ int manager_reload(Manager *m) { goto finish; } -r = manager_serialize(m, f, fds, true); +r = manager_serialize(m, f, fds, false); if (r < 0) { m->n_reloading --; goto finish; diff --git a/src/core/manager.h b/src/core/manager.h index 9d8d943..649a8aa 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -278,7 +278,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid int manager_open_serialization(Manager *m, FILE **_f); -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root); int mana
[systemd-devel] [PATCH V2] Do not serialize environment, when switching root
From: Harald Hoyer When switching root, i.e. LANG can be set to the locale of the initramfs or "C", if it was unset. When systemd deserializes LANG in the real root this would overwrite the setting previously gathered by locale_set(). To reproduce, boot with an initramfs without locale.conf or change /etc/locale.conf to a different language than the initramfs and check a daemon started by systemd: $ tr "$\000" '\n' https://bugzilla.redhat.com/show_bug.cgi?id=949525 --- src/core/main.c| 8 src/core/manager.c | 18 ++ src/core/manager.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 921476a..7899761 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1088,7 +1088,7 @@ static int version(void) { return 0; } -static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize_jobs) { +static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) { FILE *f = NULL; FDSet *fds = NULL; int r; @@ -1113,7 +1113,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool serialize goto fail; } -r = manager_serialize(m, f, fds, serialize_jobs); +r = manager_serialize(m, f, fds, switching_root); if (r < 0) { log_error("Failed to serialize state: %s", strerror(-r)); goto fail; @@ -1780,7 +1780,7 @@ int main(int argc, char *argv[]) { case MANAGER_REEXECUTE: -if (prepare_reexecute(m, &serialization, &fds, true) < 0) +if (prepare_reexecute(m, &serialization, &fds, false) < 0) goto finish; reexecute = true; @@ -1794,7 +1794,7 @@ int main(int argc, char *argv[]) { m->switch_root = m->switch_root_init = NULL; if (!switch_root_init) -if (prepare_reexecute(m, &serialization, &fds, false) < 0) +if (prepare_reexecute(m, &serialization, &fds, true) < 0) goto finish; reexecute = true; diff --git a/src/core/manager.c b/src/core/manager.c index 549153e..f8d097e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2004,7 +2004,7 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { Iterator i; Unit *u; const char *t; @@ -2032,12 +2032,14 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp); } -STRV_FOREACH(e, m->environment) { -_cleanup_free_ char *ce; +if (!switching_root) { +STRV_FOREACH(e, m->environment) { +_cleanup_free_ char *ce; -ce = cescape(*e); -if (ce) -fprintf(f, "env=%s\n", *e); +ce = cescape(*e); +if (ce) +fprintf(f, "env=%s\n", *e); +} } fputc('\n', f); @@ -2053,7 +2055,7 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs) { fputs(u->id, f); fputc('\n', f); -if ((r = unit_serialize(u, f, fds, serialize_jobs)) < 0) { +if ((r = unit_serialize(u, f, fds, !switching_root)) < 0) { m->n_reloading --; return r; } @@ -2241,7 +2243,7 @@ int manager_reload(Manager *m) { goto finish; } -r = manager_serialize(m, f, fds, true); +r = manager_serialize(m, f, fds, false); if (r < 0) { m->n_reloading --; goto finish; diff --git a/src/core/manager.h b/src/core/manager.h index 9d8d943..649a8aa 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -278,7 +278,7 @@ void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid int manager_open_serialization(Manager *m, FILE **_f); -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); +int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root); int manager_deserialize(Manager *m, FILE *f, FDSet *fds); int manager_distribute_fds(Manager *m, FDSet *fds); -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] core/execute.c: debug log final execve() with argv[]
From: Harald Hoyer https://bugzilla.redhat.com/show_bug.cgi?id=772073 --- src/core/execute.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 5083af9..c881e56 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1516,6 +1516,16 @@ int exec_spawn(ExecCommand *command, final_env = strv_env_clean(final_env); +if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { +log_open(); +log_struct_unit(LOG_DEBUG, +unit_id, +"EXECUTABLE=%s", command->path, +"MESSAGE=Executing: %s %s", +command->path, strv_join(&final_argv[1], " "), +NULL); +log_close(); +} execve(command->path, final_argv, final_env); err = -errno; r = EXIT_EXEC; -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V2] core/execute.c: debug log final execve() with argv[]
From: Harald Hoyer https://bugzilla.redhat.com/show_bug.cgi?id=772073 --- src/core/execute.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 5083af9..c881e56 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1516,6 +1516,16 @@ int exec_spawn(ExecCommand *command, final_env = strv_env_clean(final_env); +if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { +log_open(); +log_struct_unit(LOG_DEBUG, +unit_id, +"EXECUTABLE=%s", command->path, +"MESSAGE=Executing: %s %s", +command->path, strv_join(&final_argv[1], " "), +NULL); +log_close(); +} execve(command->path, final_argv, final_env); err = -errno; r = EXIT_EXEC; -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V3] core/execute.c: debug log final execve() with argv[]
From: Harald Hoyer https://bugzilla.redhat.com/show_bug.cgi?id=772073 --- src/core/execute.c | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 5083af9..c881e56 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1516,6 +1516,16 @@ int exec_spawn(ExecCommand *command, final_env = strv_env_clean(final_env); +if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { +log_open(); +log_struct_unit(LOG_DEBUG, +unit_id, +"EXECUTABLE=%s", command->path, +"MESSAGE=Executing: %s %s", +command->path, strv_join(&final_argv[1], " "), +NULL); +log_close(); +} execve(command->path, final_argv, final_env); err = -errno; r = EXIT_EXEC; -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH V4] core/execute.c: debug log final execve() with argv[]
From: Harald Hoyer https://bugzilla.redhat.com/show_bug.cgi?id=772073 --- src/core/execute.c | 12 1 file changed, 12 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 5083af9..fabd38e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1516,6 +1516,18 @@ int exec_spawn(ExecCommand *command, final_env = strv_env_clean(final_env); +if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { +char _cleanup_free_ *argvs = NULL; +log_open(); +argvs = strv_join(&final_argv[1], " "); +log_struct_unit(LOG_DEBUG, +unit_id, +"EXECUTABLE=%s", command->path, +"MESSAGE=Executing: %s %s", +command->path, argvs, +NULL); +log_close(); +} execve(command->path, final_argv, final_env); err = -errno; r = EXIT_EXEC; -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] systemctl: clarify usage of "--all" versus list-unit-files
From: Harald Hoyer Novice users might think, that $ systemctl --all is equal to $ systemctl list-unit-files https://bugzilla.redhat.com/show_bug.cgi?id=748512 --- man/systemctl.xml | 4 +++- src/systemctl/systemctl.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/man/systemctl.xml b/man/systemctl.xml index 5656564..053d25c 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -132,10 +132,12 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. --all - When listing units, show all units, regardless of + When listing units, show all internally loaded units, regardless of their state, including inactive units. When showing unit/job/manager properties, show all properties regardless whether they are set or not. + To list all units installed on disk, use the command + list-unit-files instead. diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index fd9f580..3373b88 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4147,7 +4147,9 @@ static int systemctl_help(void) { " --versionShow package version\n" " -t --type=TYPE List only units of a particular type\n" " -p --property=NAME Show only properties by this name\n" - " -a --allShow all units/properties, including dead/empty ones\n" + " -a --allShow all internally loaded units/properties,\n" + " including dead/empty ones. To list all units installed\n" + " on disk, use the command 'list-unit-files' instead.\n" " --failed Show only failed units\n" " --full Don't ellipsize unit names on output\n" " --fail When queueing a new job, fail if conflicting jobs are\n" -- 1.8.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] service: Support environment variable substition for PIDFile=
From: Harald Hoyer RFE: https://bugzilla.redhat.com/show_bug.cgi?id=840260 $ cat test.service [Unit] Description=test [Service] PIDFile=${PIDFILE} EnvironmentFile=/etc/test-file ExecStart=/bin/bash -c 'sleep 1& jobs -p > $$PIDFILE; exit 0' Type=forking $ cat /etc/test-file PIDFILE=/tmp/test.pid $ systemctl status test.service test.service - test Loaded: loaded (/usr/lib/systemd/system/test.service; static) Active: active (running) since Mi 2013-04-10 15:06:42 CEST; 2s ago Process: 22407 ExecStart=/bin/bash -c sleep 1& jobs -p > $$PIDFILE; exit 0 (code=exited, status=0/SUCCESS) Main PID: 22408 (sleep) CGroup: name=systemd:/system/test.service └─22408 sleep 1 Apr 10 15:06:42 lenovo systemd[1]: Started test. --- man/systemd.service.xml | 3 +++ src/core/load-fragment-gperf.gperf.m4 | 2 +- src/core/service.c| 25 - src/core/service.h| 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/man/systemd.service.xml b/man/systemd.service.xml index b82a5c1..14ce395 100644 --- a/man/systemd.service.xml +++ b/man/systemd.service.xml @@ -276,6 +276,9 @@ the daemon after start-up of the service. systemd will not write to the file configured here. +Basic environment variable +substitution is supported like in +ExecStart=. diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index d5e579f..4592f3d 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -140,7 +140,7 @@ Unit.ConditionHost, config_parse_unit_condition_string, CONDITION_H Unit.ConditionACPower, config_parse_unit_condition_string, CONDITION_AC_POWER,0 Unit.ConditionNull, config_parse_unit_condition_null, 0, 0 m4_dnl -Service.PIDFile, config_parse_unit_path_printf, 0, offsetof(Service, pid_file) +Service.PIDFile, config_parse_unit_string_printf,0, offsetof(Service, pid_file) Service.ExecStartPre,config_parse_exec, SERVICE_EXEC_START_PRE,offsetof(Service, exec_command) Service.ExecStart, config_parse_exec, SERVICE_EXEC_START,offsetof(Service, exec_command) Service.ExecStartPost, config_parse_exec, SERVICE_EXEC_START_POST, offsetof(Service, exec_command) diff --git a/src/core/service.c b/src/core/service.c index a104b30..0de8f20 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -275,6 +275,9 @@ static void service_done(Unit *u) { free(s->pid_file); s->pid_file = NULL; +free(s->pid_file_env); +s->pid_file_env = NULL; + #ifdef HAVE_SYSV_COMPAT free(s->sysv_runlevels); s->sysv_runlevels = NULL; @@ -703,7 +706,9 @@ static int service_load_sysv_path(Service *s, const char *path) { } free(s->pid_file); +free(s->pid_file_env); s->pid_file = fn; +s->pid_file_env = NULL; } } else if (state == DESCRIPTION) { @@ -1376,18 +1381,27 @@ static int service_load_pid_file(Service *s, bool may_warn) { char _cleanup_free_ *k = NULL; int r; pid_t pid; +char _cleanup_strv_free_ **context_env = NULL; +char _cleanup_free_ *fe = NULL; assert(s); if (!s->pid_file) return -ENOENT; -r = read_one_line_file(s->pid_file, &k); +if (!s->pid_file_env) +if (!exec_context_load_environment(&s->exec_context, &context_env)) +s->pid_file_env = replace_env(s->pid_file, context_env); + +if (!s->pid_file_env) +s->pid_file_env = strdup(s->pid_file); + +r = read_one_line_file(s->pid_file_env, &k); if (r < 0) { if (may_warn) log_info_unit(UNIT(s)->id, "PID file %s not readable (yet?) after %s.", - s->pid_file, service_state_to_string(s->state)); + s->pid_file_env, service_state_to_string(s->state)); return r; } @@ -1396,7 +1410,7 @@ static int servi