From 00e68d95b160ed31d30d4895ef0bc831d4e280dc Mon Sep 17 00:00:00 2001
From: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Date: Jan 17 2017 15:11:56 +0000
Subject: Backport mtime==0 fix


---

diff --git a/0020-Various-simplifications.patch b/0020-Various-simplifications.patch
new file mode 100644
index 0000000..6560524
--- /dev/null
+++ b/0020-Various-simplifications.patch
@@ -0,0 +1,70 @@
+From 2f38e2f3ceaf753979a63a7dcec601fc6c811b11 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
+Date: Tue, 15 Nov 2016 15:01:40 -0500
+Subject: [PATCH] Various simplifications
+
+---
+ src/core/scope.c |  8 +++++---
+ src/core/unit.c  | 11 +++++------
+ 2 files changed, 10 insertions(+), 9 deletions(-)
+
+diff --git a/src/core/scope.c b/src/core/scope.c
+index b45e238974..caed476065 100644
+--- a/src/core/scope.c
++++ b/src/core/scope.c
+@@ -244,7 +244,9 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
+         if (state == SCOPE_STOP_SIGTERM)
+                 skip_signal = bus_scope_send_request_stop(s) > 0;
+ 
+-        if (!skip_signal) {
++        if (skip_signal)
++                r = 1; /* wait */
++        else {
+                 r = unit_kill_context(
+                                 UNIT(s),
+                                 &s->kill_context,
+@@ -254,8 +256,8 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
+                                 -1, -1, false);
+                 if (r < 0)
+                         goto fail;
+-        } else
+-                r = 1;
++        }
++        log_unit_debug(UNIT(s), "Killing unit %s: ret=%d", UNIT(s)->id, r);
+ 
+         if (r > 0) {
+                 r = scope_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_stop_usec));
+diff --git a/src/core/unit.c b/src/core/unit.c
+index 4934a0e56f..6726ce0749 100644
+--- a/src/core/unit.c
++++ b/src/core/unit.c
+@@ -3558,14 +3558,14 @@ int unit_kill_context(
+                 bool main_pid_alien) {
+ 
+         bool wait_for_exit = false, send_sighup;
+-        cg_kill_log_func_t log_func;
++        cg_kill_log_func_t log_func = NULL;
+         int sig, r;
+ 
+         assert(u);
+         assert(c);
+ 
+-        /* Kill the processes belonging to this unit, in preparation for shutting the unit down. Returns > 0 if we
+-         * killed something worth waiting for, 0 otherwise. */
++        /* Kill the processes belonging to this unit, in preparation for shutting the unit down.
++         * Returns > 0 if we killed something worth waiting for, 0 otherwise. */
+ 
+         if (c->kill_mode == KILL_NONE)
+                 return 0;
+@@ -3577,9 +3577,8 @@ int unit_kill_context(
+                 IN_SET(k, KILL_TERMINATE, KILL_TERMINATE_AND_LOG) &&
+                 sig != SIGHUP;
+ 
+-        log_func =
+-                k != KILL_TERMINATE ||
+-                IN_SET(sig, SIGKILL, SIGABRT) ? log_kill : NULL;
++        if (k != KILL_TERMINATE || IN_SET(sig, SIGKILL, SIGABRT))
++                log_func = log_kill;
+ 
+         if (main_pid > 0) {
+                 if (log_func)
diff --git a/0020-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch b/0020-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
deleted file mode 100644
index aadac4f..0000000
--- a/0020-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
+++ /dev/null
@@ -1,48 +0,0 @@
-From 047be3e733cff7717ccd49d6422ea0002bd0c515 Mon Sep 17 00:00:00 2001
-From: Jan Synacek <jsynacek@redhat.com>
-Date: Mon, 16 Jan 2017 13:00:03 +0100
-Subject: [PATCH] build-sys: check for lz4 in the old and new numbering scheme
- (#4717)
-
-lz4 upstream decided to switch to an incompatible numbering scheme
-(1.7.3 follows 131, to match the so version).  PKG_CHECK_MODULES does
-not allow two version matches for the same package, so e.g. lz4 < 10 ||
-lz4 >= 125 cannot be used. Check twice, once for "new" numbers (anything
-below 10 is assume to be new), once for the "old" numbers (anything
-above >= 125). This assumes that the "new" versioning will not get to 10
-to quickly. I think that's a safe assumption, lz4 is a mature project.
-
-Fixed #4690.
-
-Cherry-picked from
-https://github.com/systemd/systemd/commit/3d4cf7de48a74726694abbaa09f9804b845ff3ba
-
-Resolves: #1404406
----
- configure.ac | 9 ++++++---
- 1 file changed, 6 insertions(+), 3 deletions(-)
-
-diff --git a/configure.ac b/configure.ac
-index cf595e6..4a0b269 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -602,10 +602,13 @@ AM_CONDITIONAL(HAVE_BZIP2, [test "$have_bzip2" = "yes"])
- have_lz4=no
- AC_ARG_ENABLE(lz4, AS_HELP_STRING([--disable-lz4], [Disable optional LZ4 support]))
- AS_IF([test "x$enable_lz4" != "xno"], [
--        PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ],
--               [AC_DEFINE(HAVE_LZ4, 1, [Define in LZ4 is available])
-+        PKG_CHECK_MODULES(LZ4, [ liblz4 < 10 ],
-+               [AC_DEFINE(HAVE_LZ4, 1, [Define if LZ4 is available])
-                 have_lz4=yes],
--                have_lz4=no)
-+                [PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ],
-+                      [AC_DEFINE(HAVE_LZ4, 1, [Define if LZ4 is available])
-+                      have_lz4=yes],
-+                      have_lz4=no)])
-         AS_IF([test "x$have_lz4" = xno -a "x$enable_lz4" = xyes],
-               [AC_MSG_ERROR([*** LZ4 support requested but libraries not found])])
- ])
--- 
-2.9.3
-
diff --git a/0021-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch b/0021-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
new file mode 100644
index 0000000..6a8e538
--- /dev/null
+++ b/0021-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
@@ -0,0 +1,42 @@
+From 2901e7ae25cb417d1e4902f71147a3de853c94b3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
+Date: Wed, 23 Nov 2016 10:18:30 -0500
+Subject: [PATCH] build-sys: check for lz4 in the old and new numbering scheme
+ (#4717)
+
+lz4 upstream decided to switch to an incompatible numbering scheme
+(1.7.3 follows 131, to match the so version).
+PKG_CHECK_MODULES does not allow two version matches for the same package,
+so e.g. lz4 < 10 || lz4 >= 125 cannot be used. Check twice, once for
+"new" numbers (anything below 10 is assume to be new), once for the "old"
+numbers (anything above >= 125). This assumes that the "new" versioning
+will not get to 10 to quickly. I think that's a safe assumption, lz4 is a
+mature project.
+
+Fixed #4690.
+(cherry picked from commit 3d4cf7de48a74726694abbaa09f9804b845ff3ba)
+---
+ configure.ac | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index cf595e68c0..4a0b2691d6 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -602,10 +602,13 @@ AM_CONDITIONAL(HAVE_BZIP2, [test "$have_bzip2" = "yes"])
+ have_lz4=no
+ AC_ARG_ENABLE(lz4, AS_HELP_STRING([--disable-lz4], [Disable optional LZ4 support]))
+ AS_IF([test "x$enable_lz4" != "xno"], [
+-        PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ],
+-               [AC_DEFINE(HAVE_LZ4, 1, [Define in LZ4 is available])
++        PKG_CHECK_MODULES(LZ4, [ liblz4 < 10 ],
++               [AC_DEFINE(HAVE_LZ4, 1, [Define if LZ4 is available])
+                 have_lz4=yes],
+-                have_lz4=no)
++                [PKG_CHECK_MODULES(LZ4, [ liblz4 >= 125 ],
++                      [AC_DEFINE(HAVE_LZ4, 1, [Define if LZ4 is available])
++                      have_lz4=yes],
++                      have_lz4=no)])
+         AS_IF([test "x$have_lz4" = xno -a "x$enable_lz4" = xyes],
+               [AC_MSG_ERROR([*** LZ4 support requested but libraries not found])])
+ ])
diff --git a/0022-pid1-do-not-use-mtime-0-as-sign-of-masking-4388.patch b/0022-pid1-do-not-use-mtime-0-as-sign-of-masking-4388.patch
new file mode 100644
index 0000000..d5225e3
--- /dev/null
+++ b/0022-pid1-do-not-use-mtime-0-as-sign-of-masking-4388.patch
@@ -0,0 +1,71 @@
+From 48aab8bd94f75072a8d44f351a66cf74db450275 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
+Date: Mon, 17 Oct 2016 01:15:03 -0400
+Subject: [PATCH] pid1: do not use mtime==0 as sign of masking (#4388)
+
+It is allowed for unit files to have an mtime==0, so instead of assuming that
+any file that had mtime==0 was masked, use the load_state to filter masked
+units.
+
+Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1384150.
+(cherry picked from commit ba25d39e449347952522162c3fa110b04308e28c)
+---
+ src/core/unit.c | 20 ++++++++++++--------
+ 1 file changed, 12 insertions(+), 8 deletions(-)
+
+diff --git a/src/core/unit.c b/src/core/unit.c
+index 6726ce0749..d94b3eb5ab 100644
+--- a/src/core/unit.c
++++ b/src/core/unit.c
+@@ -2950,7 +2950,7 @@ int unit_coldplug(Unit *u) {
+         return 0;
+ }
+ 
+-static bool fragment_mtime_newer(const char *path, usec_t mtime) {
++static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_masked) {
+         struct stat st;
+ 
+         if (!path)
+@@ -2960,12 +2960,12 @@ static bool fragment_mtime_newer(const char *path, usec_t mtime) {
+                 /* What, cannot access this anymore? */
+                 return true;
+ 
+-        if (mtime > 0)
++        if (path_masked)
++                /* For masked files check if they are still so */
++                return !null_or_empty(&st);
++        else
+                 /* For non-empty files check the mtime */
+                 return timespec_load(&st.st_mtim) > mtime;
+-        else if (!null_or_empty(&st))
+-                /* For masked files check if they are still so */
+-                return true;
+ 
+         return false;
+ }
+@@ -2976,18 +2976,22 @@ bool unit_need_daemon_reload(Unit *u) {
+ 
+         assert(u);
+ 
+-        if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime))
++        /* For unit files, we allow masking… */
++        if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime,
++                                 u->load_state == UNIT_MASKED))
+                 return true;
+ 
+-        if (fragment_mtime_newer(u->source_path, u->source_mtime))
++        /* Source paths should not be masked… */
++        if (fragment_mtime_newer(u->source_path, u->source_mtime, false))
+                 return true;
+ 
+         (void) unit_find_dropin_paths(u, &t);
+         if (!strv_equal(u->dropin_paths, t))
+                 return true;
+ 
++        /* … any drop-ins that are masked are simply omitted from the list. */
+         STRV_FOREACH(path, u->dropin_paths)
+-                if (fragment_mtime_newer(*path, u->dropin_mtime))
++                if (fragment_mtime_newer(*path, u->dropin_mtime, false))
+                         return true;
+ 
+         return false;
diff --git a/systemd.spec b/systemd.spec
index 38e6276..f2024d9 100644
--- a/systemd.spec
+++ b/systemd.spec
@@ -12,7 +12,7 @@
 Name:           systemd
 Url:            http://www.freedesktop.org/wiki/Software/systemd
 Version:        231
-Release:        12%{?gitcommit:.git%{gitcommitshort}}%{?dist}
+Release:        13%{?gitcommit:.git%{gitcommitshort}}%{?dist}
 # For a breakdown of the licensing, see README
 License:        LGPLv2+ and MIT and GPLv2+
 Summary:        A System and Service Manager
@@ -37,26 +37,28 @@ Source8:        systemd-journal-gatewayd.xml
 Source9:        20-yama-ptrace.conf
 Source10:       systemd-udev-trigger-no-reload.conf
 
-Patch0001: 0001-systemctl-be-sure-to-be-quiet-with-systemctl-is-enab.patch
-Patch0002: 0002-logind-0-and-100-should-be-valid-for-UserTasksMax-38.patch
-Patch0003: 0003-systemd-ask-password-make-sure-directory-watch-is-st.patch
-Patch0004: 0004-Revert-logind-really-handle-KeyIgnoreInhibited-optio.patch
-Patch0005: 0005-man-explain-that-KeyIgnoreInhibited-only-apply-to-a-.patch
-Patch0006: 0006-systemctl-fix-preset-all-with-missing-etc-systemd-sy.patch
-Patch0007: 0007-shared-install-remove-unused-paramater-and-add-more-.patch
-Patch0008: 0008-shared-install-ignore-unit-symlinks-when-doing-prese.patch
-Patch0009: 0009-man-describe-what-symlinks-to-unit-do-and-specify-th.patch
-Patch0010: 0010-shared-install-move-root-skipping-into-create_symlin.patch
-Patch0011: 0011-shared-install-when-creating-symlinks-keep-existing-.patch
-Patch0012: 0012-shared-install-properly-report-masked-units-listed-i.patch
-Patch0013: 0013-Revert-pid1-reconnect-to-the-console-before-being-re.patch
-Patch0014: 0014-systemd-ignore-lack-of-tty-when-checking-whether-col.patch
-Patch0015: 0015-shared-install-do-not-enable-masked-instances-4005.patch
-Patch0016: 0016-If-the-notification-message-length-is-0-ignore-the-m.patch
-Patch0017: 0017-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch
-Patch0018: 0018-pid1-process-zero-length-notification-messages-again.patch
-Patch0019: 0019-shared-install-fix-set-default-with-empty-root-4118.patch
-Patch0020: 0020-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
+Patch0001:      0001-systemctl-be-sure-to-be-quiet-with-systemctl-is-enab.patch
+Patch0002:      0002-logind-0-and-100-should-be-valid-for-UserTasksMax-38.patch
+Patch0003:      0003-systemd-ask-password-make-sure-directory-watch-is-st.patch
+Patch0004:      0004-Revert-logind-really-handle-KeyIgnoreInhibited-optio.patch
+Patch0005:      0005-man-explain-that-KeyIgnoreInhibited-only-apply-to-a-.patch
+Patch0006:      0006-systemctl-fix-preset-all-with-missing-etc-systemd-sy.patch
+Patch0007:      0007-shared-install-remove-unused-paramater-and-add-more-.patch
+Patch0008:      0008-shared-install-ignore-unit-symlinks-when-doing-prese.patch
+Patch0009:      0009-man-describe-what-symlinks-to-unit-do-and-specify-th.patch
+Patch0010:      0010-shared-install-move-root-skipping-into-create_symlin.patch
+Patch0011:      0011-shared-install-when-creating-symlinks-keep-existing-.patch
+Patch0012:      0012-shared-install-properly-report-masked-units-listed-i.patch
+Patch0013:      0013-Revert-pid1-reconnect-to-the-console-before-being-re.patch
+Patch0014:      0014-systemd-ignore-lack-of-tty-when-checking-whether-col.patch
+Patch0015:      0015-shared-install-do-not-enable-masked-instances-4005.patch
+Patch0016:      0016-If-the-notification-message-length-is-0-ignore-the-m.patch
+Patch0017:      0017-pid1-don-t-return-any-error-in-manager_dispatch_noti.patch
+Patch0018:      0018-pid1-process-zero-length-notification-messages-again.patch
+Patch0019:      0019-shared-install-fix-set-default-with-empty-root-4118.patch
+Patch0020:      0020-Various-simplifications.patch
+Patch0021:      0021-build-sys-check-for-lz4-in-the-old-and-new-numbering.patch
+Patch0022:      0022-pid1-do-not-use-mtime-0-as-sign-of-masking-4388.patch
 
 Patch0998:      0998-resolved-create-etc-resolv.conf-symlink-at-runtime.patch
 
@@ -954,7 +956,10 @@ getent passwd systemd-journal-upload >/dev/null 2>&1 || useradd -r -l -g systemd
 %{_mandir}/man[1578]/systemd-nspawn.*
 
 %changelog
-* Mon Jan 16 2017 Jan Synacek <jsynacek@redhat.com> - 231-12
+* Tue Jan 17 2017 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 231-13
+- Backport mtime==0 fix (#1384150)
+
+* Mon Jan 16 2017 Jan Synáček <jsynacek@redhat.com> - 231-12
 - Fix buildsystem to check for lz4 correctly (#1404406)
 
 * Wed Jan 11 2017 Jan Synáček <jsynacek@redhat.com> - 231-11