]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #23021 from fbuihuu/tmpfiles-fix-precedence-with-plus-sign
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 15 Apr 2022 16:36:51 +0000 (01:36 +0900)
committerGitHub <noreply@github.com>
Fri, 15 Apr 2022 16:36:51 +0000 (01:36 +0900)
Tmpfiles fix precedence with plus sign

1  2 
src/tmpfiles/tmpfiles.c
test/test-functions

diff --combined src/tmpfiles/tmpfiles.c
index 0842d67d8557914cbf92ae2a5f44b126a1f6f9a7,be09d19a9af24adf2d00bddc94a4bfcbbb8a25e8..94973c2aa5c231ebbc688466022f8ae9575f7705
@@@ -26,7 -26,6 +26,7 @@@
  #include "conf-files.h"
  #include "copy.h"
  #include "def.h"
 +#include "devnum-util.h"
  #include "dirent-util.h"
  #include "dissect-image.h"
  #include "env-util.h"
@@@ -59,6 -58,7 +59,6 @@@
  #include "set.h"
  #include "sort-util.h"
  #include "specifier.h"
 -#include "stat-util.h"
  #include "stdio-util.h"
  #include "string-table.h"
  #include "string-util.h"
@@@ -2657,7 -2657,7 +2657,7 @@@ static int item_compare(const Item *a, 
          return CMP(a->type, b->type);
  }
  
- static bool item_compatible(Item *a, Item *b) {
+ static bool item_compatible(const Item *a, const Item *b) {
          assert(a);
          assert(b);
          assert(streq(a->path, b->path));
@@@ -2896,6 -2896,26 +2896,26 @@@ static int parse_age_by_from_arg(const 
          return 0;
  }
  
+ static bool is_duplicated_item(ItemArray *existing, const Item *i) {
+         assert(existing);
+         assert(i);
+         for (size_t n = 0; n < existing->n_items; n++) {
+                 const Item *e = existing->items + n;
+                 if (item_compatible(e, i))
+                         continue;
+                 /* Only multiple 'w+' lines for the same path are allowed. */
+                 if (e->type != WRITE_FILE || !e->append_or_force ||
+                     i->type != WRITE_FILE || !i->append_or_force)
+                         return true;
+         }
+         return false;
+ }
  static int parse_line(
                  const char *fname,
                  unsigned line,
                  { 'a', specifier_architecture,    NULL },
                  { 'b', specifier_boot_id,         NULL },
                  { 'B', specifier_os_build_id,     NULL },
 -                { 'H', specifier_host_name,       NULL },
 -                { 'l', specifier_short_host_name, NULL },
 +                { 'H', specifier_hostname,        NULL },
 +                { 'l', specifier_short_hostname,  NULL },
                  { 'm', specifier_machine_id_safe, NULL },
                  { 'o', specifier_os_id,           NULL },
                  { 'v', specifier_kernel_release,  NULL },
                          return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Device file requires argument.");
                  }
  
 -                r = parse_dev(i.argument, &i.major_minor);
 +                r = parse_devnum(i.argument, &i.major_minor);
                  if (r < 0) {
                          *invalid_config = true;
                          return log_syntax(NULL, LOG_ERR, fname, line, r, "Can't parse device file major/minor '%s'.", i.argument);
  
          existing = ordered_hashmap_get(h, i.path);
          if (existing) {
-                 size_t n;
-                 for (n = 0; n < existing->n_items; n++) {
-                         if (!item_compatible(existing->items + n, &i) && !i.append_or_force) {
-                                 log_syntax(NULL, LOG_NOTICE, fname, line, 0, "Duplicate line for path \"%s\", ignoring.", i.path);
-                                 return 0;
-                         }
+                 if (is_duplicated_item(existing, &i)) {
+                         log_syntax(NULL, LOG_NOTICE, fname, line, 0,
+                                    "Duplicate line for path \"%s\", ignoring.", i.path);
+                         return 0;
                  }
          } else {
                  existing = new0(ItemArray, 1);
diff --combined test/test-functions
index b5a618c741763237464db1b4f8b9ccd0f3a11cba,e1d6ed646f1de5be2daedaf3db1659dc866a6ade..7155e99c0e779bbd3c813f211046b11691e9211c
@@@ -1055,29 -1055,6 +1055,29 @@@ install_iscsi() 
      fi
  }
  
 +install_mdadm() {
 +    local unit
 +    local mdadm_units=(
 +        system/mdadm-grow-continue@.service
 +        system/mdadm-last-resort@.service
 +        system/mdadm-last-resort@.timer
 +        system/mdmon@.service
 +        system/mdmonitor-oneshot.service
 +        system/mdmonitor-oneshot.timer
 +        system/mdmonitor.service
 +        system-shutdown/mdadm.shutdown
 +    )
 +
 +    image_install mdadm mdmon
 +    inst_rules 01-md-raid-creating.rules 63-md-raid-arrays.rules 64-md-raid-assembly.rules 69-md-clustered-confirm-device.rules
 +    # Fedora/CentOS/RHEL ships this rule file
 +    [[ -f /lib/udev/rules.d/65-md-incremental.rules ]] && inst_rules 65-md-incremental.rules
 +
 +    for unit in "${mdadm_units[@]}"; do
 +        image_install "${ROOTLIBDIR:?}/$unit"
 +    done
 +}
 +
  install_compiled_systemd() {
      dinfo "Install compiled systemd"
  
@@@ -1429,8 -1406,8 +1429,8 @@@ check_coverage_reports() 
      # usually due to the sandbox being too restrictive (e.g. ProtectSystem=yes,
      # ProtectHome=yes) or the $BUILD_DIR being inaccessible to non-root users - see
      # `setfacl` stuff in install_compiled_systemd().
 -
 -    if "${JOURNALCTL:?}" -q --no-pager -D "${root:?}/var/log/journal" --grep "profiling:.+?gcda:[Cc]annot open"; then
 +    if ! get_bool "${IGNORE_MISSING_COVERAGE:=}" && \
 +       "${JOURNALCTL:?}" -q --no-pager -D "${root:?}/var/log/journal" --grep "profiling:.+?gcda:[Cc]annot open"; then
          derror "Detected possibly missing coverage, check the journal"
          return 1
      fi
@@@ -1869,7 -1846,7 +1869,7 @@@ install_pam() 
          paths+=(/lib*/security)
      fi
  
-     for d in /etc/pam.d /etc/security /usr/{etc,lib}/pam.d; do
+     for d in /etc/pam.d /{usr/,}etc/security /usr/{etc,lib}/pam.d; do
          [ -d "$d" ] && paths+=("$d")
      done