]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #25791 from keszybz/ukify-check-inputs
authorLuca Boccassi <bluca@debian.org>
Thu, 22 Dec 2022 11:10:32 +0000 (12:10 +0100)
committerGitHub <noreply@github.com>
Thu, 22 Dec 2022 11:10:32 +0000 (12:10 +0100)
ukify: check inputs

97 files changed:
.github/ISSUE_TEMPLATE/bug_report.yml
.github/ISSUE_TEMPLATE/feature_request.yml
docs/ENVIRONMENT.md
hwdb.d/60-keyboard.hwdb
hwdb.d/60-sensor.hwdb
man/kernel-command-line.xml
man/systemctl.xml
man/systemd-gpt-auto-generator.xml
man/systemd.syntax.xml
rules.d/60-evdev.rules
src/basic/async.c
src/basic/chase-symlinks.c
src/basic/fd-util.c
src/basic/fd-util.h
src/basic/fileio.c
src/basic/io-util.h
src/basic/macro.h
src/basic/string-util.h
src/basic/terminal-util.c
src/cgroups-agent/cgroups-agent.c
src/core/automount.c
src/core/dynamic-user.c
src/core/execute.c
src/core/manager.c
src/core/namespace.c
src/core/service.c
src/core/socket.c
src/coredump/coredump.c
src/creds/creds.c
src/firstboot/firstboot.c
src/fsck/fsck.c
src/fuzz/fuzz-varlink.c
src/gpt-auto-generator/gpt-auto-generator.c
src/import/import-common.c
src/import/importd.c
src/import/pull-common.c
src/initctl/initctl.c
src/journal/fuzz-journald-stream.c
src/libsystemd-network/arp-util.c
src/libsystemd-network/dhcp-network.c
src/libsystemd-network/dhcp6-network.c
src/libsystemd-network/fuzz-dhcp6-client.c
src/libsystemd-network/fuzz-lldp-rx.c
src/libsystemd-network/fuzz-ndisc-rs.c
src/libsystemd-network/icmp6-util.c
src/libsystemd-network/test-dhcp6-client.c
src/libsystemd-network/test-lldp-rx.c
src/libsystemd/sd-bus/bus-container.c
src/libsystemd/sd-bus/test-bus-benchmark.c
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-daemon/sd-daemon.c
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-login/test-login.c
src/machine/image-dbus.c
src/machine/machine-dbus.c
src/machine/machined-dbus.c
src/nspawn/nspawn-setuid.c
src/nspawn/nspawn.c
src/portable/portable.c
src/portable/portabled-image-bus.c
src/resolve/resolved-dns-search-domain.c
src/resolve/resolved-llmnr.c
src/resolve/resolved-mdns.c
src/rfkill/rfkill.c
src/run/run.c
src/shared/copy.c
src/shared/data-fd-util.c
src/shared/dissect-image.c
src/shared/dissect-image.h
src/shared/elf-util.c
src/shared/logs-show.c
src/shared/loop-util.c
src/shared/mount-util.c
src/shared/pager.c
src/socket-proxy/socket-proxyd.c
src/systemctl/systemctl-edit.c
src/systemctl/systemctl-start-unit.c
src/systemctl/systemctl.c
src/systemctl/systemctl.h
src/sysupdate/sysupdate-resource.c
src/sysusers/sysusers.c
src/test/test-compress.c
src/test/test-copy.c
src/test/test-data-fd-util.c
src/test/test-execute.c
src/test/test-fd-util.c
src/test/test-fileio.c
src/test/test-namespace.c
src/test/test-terminal-util.c
src/test/test-varlink.c
src/timesync/timesyncd-manager.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/udev-ctrl.c
src/udev/udev-event.c
src/udev/udevd.c

index d25f5ea68b993b37d5fb636e314e88a4f00ae60c..3a3dbb70e8898b3adb51241292769f38e214c955 100644 (file)
@@ -18,7 +18,7 @@ body:
         If a distro build is used, please just paste the package version, e.g. `systemd-250.7-1.fc36.x86_64`.
         See https://github.com/systemd/systemd-stable/tags for the list of most recent releases.
         For older version please use distribution trackers (see https://systemd.io/CONTRIBUTING#filing-issues).
-      placeholder: '251'
+      placeholder: '252'
     validations:
       required: true
 
index 1f24851b104f085ff2b88b6c9aeb2533edfdec31..b281a7fbf035f6ef9e7467fba53a14a53be6f61c 100644 (file)
@@ -119,6 +119,6 @@ body:
     attributes:
       label: The systemd version you checked that didn't have the feature you are asking for
       description: If this is not the most recently released upstream version, then please check first if it has that feature already.
-      placeholder: '251'
+      placeholder: '252'
     validations:
       required: false
index b4fa682cae8984359f0ebf3dbaaac0a06eba1d03..fb353004190fe6f004146bb47ee00a5f38a97a87 100644 (file)
@@ -415,6 +415,10 @@ disk images with `--image=` or similar:
 * `$SYSTEMD_DISSECT_VERITY_TIMEOUT_SEC=sec` â€” takes a timespan, which controls
   the timeout waiting for the image to be configured. Defaults to 100 msec.
 
+* `$SYSTEMD_DISSECT_FILE_SYSTEMS=` â€” takes a colon-separated list of file
+  systems that may be mounted for automatically dissected disk images. If not
+  specified defaults to something like: `ext4:btrfs:xfs:vfat:erofs:squashfs`
+
 * `$SYSTEMD_LOOP_DIRECT_IO` â€“ takes a boolean, which controls whether to enable
   LO_FLAGS_DIRECT_IO (i.e. direct IO + asynchronous IO) on loopback block
   devices when opening them. Defaults to on, set this to "0" to disable this
index c14ebbe6a21f4cb38e0767180a8933bf79a31f82..a31beda268344526961e58b19b6a5d5fc9632e17 100644 (file)
@@ -1385,6 +1385,7 @@ evdev:input:b0003v1532p0200*
 
 evdev:atkbd:dmi:bvn*:bvr*:bd*:svnMICRO-STAR*:pn*:*
 evdev:atkbd:dmi:bvn*:bvr*:bd*:svnMicro-Star*:pn*:*
+ KEYBOARD_KEY_91=config                                 # MSIControl Center
  KEYBOARD_KEY_a0=mute                                   # Fn+F9
  KEYBOARD_KEY_ae=volumedown                             # Fn+F7
  KEYBOARD_KEY_b0=volumeup                               # Fn+F8
@@ -1395,6 +1396,8 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnMicro-Star*:pn*:*
  KEYBOARD_KEY_e4=f21                                    # Fn+F3 Touchpad disable
  KEYBOARD_KEY_ec=email                                  # envelope button
  KEYBOARD_KEY_ee=camera                                 # Fn+F6 camera disable
+ KEYBOARD_KEY_f1=f20                                    # Microphone mute
+ KEYBOARD_KEY_f2=rotate_display                         # Rotate screen
  KEYBOARD_KEY_f6=wlan                                   # satellite dish1
  KEYBOARD_KEY_f7=brightnessdown                         # Fn+F4
  KEYBOARD_KEY_f8=brightnessup                           # Fn+F5
@@ -1436,10 +1439,6 @@ evdev:name:MSI Laptop hotkeys:dmi:bvn*:bvr*:bd*:svn*:pnM[iI][cC][rR][oO]-S[tT][a
  KEYBOARD_KEY_0213=f22
  KEYBOARD_KEY_0214=f23
 
-# MSI Bravo 15-B5DX FnKeys
-evdev:atkbd:dmi:bvn*:bvr*:bd*:svnMicro-Star*:pn*Bravo15B5D*:*
- KEYBOARD_KEY_f1=f20                                    # Fn+F5 Micmute
-
 ##########################################
 # NEC
 ##########################################
index 39abf4db19f765f413a8445d808b95d439ad87b2..6c26b730601060df3cf3c182c378701e7ac3580f 100644 (file)
@@ -45,8 +45,8 @@
 # subsystem[1]. The default, when unset, is equivalent to:
 #   ACCEL_MOUNT_MATRIX=1, 0, 0; 0, 1, 0; 0, 0, 1
 # eg. the identity matrix,
-# and <value> is an integer value above which an object is considered
-# close by a proximity sensor:
+# and <value> is an integer value above or equal to which an object is
+# considered close by a proximity sensor:
 #   PROXIMITY_NEAR_LEVEL=100
 #
 # [1]: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=dfc57732ad38f93ae6232a3b4e64fd077383a0f1
index fcab0a90f40a6d3ec5c155eaf05200733467bac0..545dc40798ae803bab86783f64bf155069b1f64d 100644 (file)
         <term><varname>rw</varname></term>
 
         <listitem>
-          <para>Configures the root file system and its file system
-          type and mount options, as well as whether it shall be
-          mounted read-only or read-write initially. For details,
-          see
+          <para>Configures the root file system and its file system type and mount options, as well as
+          whether it shall be mounted read-only or read-write initially. For details, see
           <citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
+
+          <para>If <varname>root=</varname> is not set (or set to <literal>gpt-auto</literal>) the automatic
+          root partition discovery implemented by
+          <citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+          will be in effect. In this case <varname>rootfstype=</varname>, <varname>rootflags=</varname>,
+          <varname>ro</varname>, <varname>rw</varname> will be interpreted by
+          <command>systemd-gpt-auto-generator</command>.</para>
         </listitem>
       </varlistentry>
 
index 193f6b9800476f4c4b9e488c21cca00c28be291d..a4023349d5f5e6dd88cc06b5d90b3272a5afcc8d 100644 (file)
@@ -1061,6 +1061,9 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
             temporary files which will be written to the real location if the
             editor exits successfully.</para>
 
+            <para>If <option>--drop-in=</option> is specified, the given drop-in file name
+            will be used instead of the default <filename>override.conf</filename>.</para>
+
             <para>If <option>--full</option> is specified, this will copy the
             original units instead of creating drop-in files.</para>
 
@@ -2417,6 +2420,15 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
         <listitem><para>When used with <command>bind</command>, creates a read-only bind mount.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--drop-in=</option></term>
+
+        <listitem>
+          <para>When used with <command>edit</command>, use the given drop-in file name instead of
+          <filename>override.conf</filename>.</para>
+        </listitem>
+      </varlistentry>
+
       <xi:include href="user-system-options.xml" xpointer="host" />
       <xi:include href="user-system-options.xml" xpointer="machine" />
 
index 3b166b87f90dbad02d745874cead8d837d1a6e8a..4ccc80994d0a0bbaaaf164f5e78c78580eab3c0f 100644 (file)
 
       <varlistentry>
         <term><varname>root=</varname></term>
+        <term><varname>rootfstype=</varname></term>
+        <term><varname>rootflags=</varname></term>
 
-        <listitem><para>When used with the special value <literal>gpt-auto</literal>, automatic discovery of
-        the root partition based on the GPT partition type is enabled.  Any other value disables this
-        generator.</para></listitem>
+        <listitem><para>When <varname>root=</varname> is used with the special value
+        <literal>gpt-auto</literal> (or if the parameter is not used at all), automatic discovery of the root
+        partition based on the GPT partition type is enabled. Any other value disables this
+        logic.</para>
+
+        <para>The <varname>rootfstype=</varname> and <varname>rootflags=</varname> are used to select the
+        file system type and options when the root file system is automatically discovered.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 1441b2bb52b19e60a28e773ba8cf55199ac93161..2fc22885ca60b42de71c4bddf20916f847969e9f 100644 (file)
@@ -42,8 +42,7 @@
       <citerefentry><refentrytitle>systemd.path</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
       <citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
       <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
-      <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
-      <citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+      <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>
       </para></listitem>
 
       <listitem><para>link files, see
       <citerefentry><refentrytitle>systemd-sleep.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
       <citerefentry><refentrytitle>timesyncd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
       </para></listitem>
+
+      <listitem><para>nspawn files, see
+        <citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+      </para></listitem>
     </itemizedlist>
     </para>
 
index 15483101e7515c740893dd9f51eabe88659ed93f..c97cdecb58d26a124d8e0740f56bfa1fd23dc1b9 100644 (file)
@@ -6,7 +6,7 @@ KERNEL!="event*", GOTO="evdev_end"
 # Execute the match patterns below, from least-to-most specific.
 
 # Device matching the modalias string (bustype, vendor, product, version, other properties)
-IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=evdev:",
+IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=evdev:", \
   ENV{.HAVE_HWDB_PROPERTIES}="1"
 
 # AT keyboard matching by the machine's DMI data
index 241803f33a6a6c8effc4b0bff49bcce8e70f1b73..73de889a2b0de2eaf47788c42b79e62e295f080f 100644 (file)
@@ -103,5 +103,5 @@ int asynchronous_close(int fd) {
                          assert_se(close_nointr(fd) != -EBADF);
         }
 
-        return -1;
+        return -EBADF;
 }
index a9de17b47631f30f2cc8c542cbe169cb4ab2e90a..a0134fd330bb3365006874b0b6b845c8394010cd 100644 (file)
@@ -206,7 +206,7 @@ int chase_symlinks_at(
 
         for (todo = buffer;;) {
                 _cleanup_free_ char *first = NULL;
-                _cleanup_close_ int child = -1;
+                _cleanup_close_ int child = -EBADF;
                 struct stat st;
                 const char *e;
 
index 8879b998ca49360f86dc968062bcf41b9a59ce9a..4d6d01cd9928d69af955471f6992f8f9a40b0354 100644 (file)
@@ -246,7 +246,7 @@ static int close_all_fds_frugal(const int except[], size_t n_except) {
                                        "Refusing to loop over %d potential fds.",
                                        max_fd);
 
-        for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -1) {
+        for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -EBADF) {
                 int q;
 
                 if (fd_in_set(fd, except, n_except))
index 530270a73fe00acb083a666b1672299b095e2b5b..97339254baaa7c1a7c011757ee0016a842e0307f 100644 (file)
 /* Make sure we can distinguish fd 0 and NULL */
 #define FD_TO_PTR(fd) INT_TO_PTR((fd)+1)
 #define PTR_TO_FD(p) (PTR_TO_INT(p)-1)
+#define PIPE_EBADF { -EBADF, -EBADF }
 
 int close_nointr(int fd);
 int safe_close(int fd);
 void safe_close_pair(int p[static 2]);
 
 static inline int safe_close_above_stdio(int fd) {
-        if (fd < 3) /* Don't close stdin/stdout/stderr, but still invalidate the fd by returning -1 */
-                return -1;
+        if (fd < 3) /* Don't close stdin/stdout/stderr, but still invalidate the fd by returning -EBADF. */
+                return -EBADF;
 
         return safe_close(fd);
 }
@@ -86,7 +87,7 @@ int fd_move_above_stdio(int fd);
 int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd);
 
 static inline int make_null_stdio(void) {
-        return rearrange_stdio(-1, -1, -1);
+        return rearrange_stdio(-EBADF, -EBADF, -EBADF);
 }
 
 /* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
index a9015979620e810adc2621487439000cb04a222b..0937e58a1527ff20a99076dc018267628ac24c78 100644 (file)
@@ -767,7 +767,7 @@ int read_full_file_full(
 
         r = xfopenat(dir_fd, filename, "re", 0, &f);
         if (r < 0) {
-                _cleanup_close_ int sk = -1;
+                _cleanup_close_ int sk = -EBADF;
 
                 /* ENXIO is what Linux returns if we open a node that is an AF_UNIX socket */
                 if (r != -ENXIO)
index 39728e06bcfa7200fa162e4d675083dda8124881..3afb134266a070274a116f4c5ce425504df310ec 100644 (file)
@@ -91,7 +91,16 @@ struct iovec_wrapper *iovw_new(void);
 struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw);
 struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
 void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
+
 int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
+static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
+        /* Move data into iovw or free on error */
+        int r = iovw_put(iovw, data, len);
+        if (r < 0)
+                free(data);
+        return r;
+}
+
 int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value);
 int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value);
 void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new);
index 3d1b1751231b995979150617b636df9931c2b9bd..a00d60824dd1249bdea44f410c928407f2ffb3c2 100644 (file)
         _Pragma("GCC diagnostic push")
 #endif
 
-#define DISABLE_WARNING_TYPE_LIMITS \
+#define DISABLE_WARNING_TYPE_LIMITS                                     \
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wtype-limits\"")
 
+#define DISABLE_WARNING_ADDRESS                                         \
+        _Pragma("GCC diagnostic push");                                 \
+        _Pragma("GCC diagnostic ignored \"-Waddress\"")
+
 #define REENABLE_WARNING                                                \
         _Pragma("GCC diagnostic pop")
 
@@ -318,10 +322,14 @@ static inline int __coverity_check_and_return__(int condition) {
                         *p = func(*p);                          \
         }
 
-/* When func() doesn't return the appropriate type, set variable to empty afterwards */
+/* When func() doesn't return the appropriate type, set variable to empty afterwards.
+ * The func() may be provided by a dynamically loaded shared library, hence add an assertion. */
 #define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty)     \
         static inline void func##p(type *p) {                   \
                 if (*p != (empty)) {                            \
+                        DISABLE_WARNING_ADDRESS;                \
+                        assert(func);                           \
+                        REENABLE_WARNING;                       \
                         func(*p);                               \
                         *p = (empty);                           \
                 }                                               \
index 46681ced99764a5abca7272169683cb974b9166e..a78b7960e3606986274293a6a4da726a3ad3168e 100644 (file)
@@ -53,9 +53,13 @@ static inline const char* enable_disable(bool b) {
         return b ? "enable" : "disable";
 }
 
-static inline const char *empty_to_null(const char *p) {
-        return isempty(p) ? NULL : p;
-}
+/* This macro's return pointer will have the "const" qualifier set or unset the same way as the input
+ * pointer. */
+#define empty_to_null(p)                                \
+        ({                                              \
+                const char *_p = (p);                   \
+                (typeof(p)) (isempty(_p) ? NULL : _p);  \
+        })
 
 static inline const char *empty_to_na(const char *p) {
         return isempty(p) ? "n/a" : p;
@@ -74,6 +78,11 @@ static inline bool empty_or_dash(const char *str) {
 static inline const char *empty_or_dash_to_null(const char *p) {
         return empty_or_dash(p) ? NULL : p;
 }
+#define empty_or_dash_to_null(p)                                \
+        ({                                                      \
+                const char *_p = (p);                           \
+                (typeof(p)) (empty_or_dash(_p) ? NULL : _p);    \
+        })
 
 char *first_word(const char *s, const char *word) _pure_;
 
index 6afcf066cd10bd50209d8ee488a38eccc667edc3..5cf2055dc6e6be764a09012a86d2b5d57b95e9fc 100644 (file)
@@ -1130,7 +1130,7 @@ static int ptsname_namespace(int pty, char **ret) {
 
 int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
         _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF;
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         pid_t child;
         int r;
 
@@ -1183,7 +1183,7 @@ int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
 
 int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
         _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         pid_t child;
         int r;
 
index d6480097b5e991db92b0c27026ab98e9a7cab5d0..16c5a2a6934280e4a2182c9d52d8eafbc3e9489e 100644 (file)
@@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
         size_t l;
         int r;
 
-        r = rearrange_stdio(-1, -1, -1);
+        r = make_null_stdio();
         if (r < 0) {
                 log_error_errno(r, "Failed to connect stdin/stdout/stderr with /dev/null: %m");
                 return EXIT_FAILURE;
index 361034d7f4f20b426704e1d7fb07d5442d997873..4cffca419cc48039ecd7244827911d0e3162132b 100644 (file)
@@ -573,7 +573,7 @@ static void automount_trigger_notify(Unit *u, Unit *other) {
 
 static void automount_enter_waiting(Automount *a) {
         _cleanup_close_ int ioctl_fd = -EBADF;
-        int pipe_fd[2] = { -EBADF, -EBADF };
+        int pipe_fd[2] = PIPE_EBADF;
         char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1];
         _cleanup_free_ char *options = NULL;
         bool mounted = false;
index 763f5d4c84616cadb0aa7fc3024aed416442e525..c756c1c5248207b1803fab56045c534289d594f5 100644 (file)
@@ -74,7 +74,7 @@ static int dynamic_user_add(Manager *m, const char *name, int storage_socket[sta
 }
 
 static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret) {
-        _cleanup_close_pair_ int storage_socket[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int storage_socket[2] = PIPE_EBADF;
         DynamicUser *d;
         int r;
 
@@ -127,7 +127,7 @@ static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret)
         if (r < 0)
                 return r;
 
-        storage_socket[0] = storage_socket[1] = -1;
+        storage_socket[0] = storage_socket[1] = -EBADF;
 
         if (ret) {
                 d->n_ref++;
@@ -382,7 +382,7 @@ static int dynamic_user_realize(
                 uid_t *ret_uid, gid_t *ret_gid,
                 bool is_user) {
 
-        _cleanup_(unlockfp) int storage_socket0_lock = -1;
+        _cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
         _cleanup_close_ int uid_lock_fd = -EBADF;
         _cleanup_close_ int etc_passwd_lock_fd = -EBADF;
         uid_t num = UID_INVALID; /* a uid if is_user, and a gid otherwise */
@@ -524,7 +524,7 @@ static int dynamic_user_realize(
 }
 
 int dynamic_user_current(DynamicUser *d, uid_t *ret) {
-        _cleanup_(unlockfp) int storage_socket0_lock = -1;
+        _cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
         _cleanup_close_ int lock_fd = -EBADF;
         uid_t uid;
         int r;
@@ -567,7 +567,7 @@ static DynamicUser* dynamic_user_unref(DynamicUser *d) {
 }
 
 static int dynamic_user_close(DynamicUser *d) {
-        _cleanup_(unlockfp) int storage_socket0_lock = -1;
+        _cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
         _cleanup_close_ int lock_fd = -EBADF;
         uid_t uid;
         int r;
index 5784c8ce5c22d918bfccfe1f45af1acaa78962c6..5dc8535a47a99ea956d396d665f7937d7adb995a 100644 (file)
@@ -2099,7 +2099,7 @@ bool exec_needs_mount_namespace(
 
 static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) {
         _cleanup_free_ char *uid_map = NULL, *gid_map = NULL;
-        _cleanup_close_pair_ int errno_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe[2] = PIPE_EBADF;
         _cleanup_close_ int unshare_ready_fd = -EBADF;
         _cleanup_(sigkill_waitp) pid_t pid = 0;
         uint64_t c = 1;
@@ -6609,8 +6609,8 @@ static int exec_runtime_allocate(ExecRuntime **ret, const char *id) {
 
         *n = (ExecRuntime) {
                 .id = TAKE_PTR(id_copy),
-                .netns_storage_socket = { -EBADF, -EBADF },
-                .ipcns_storage_socket = { -EBADF, -EBADF },
+                .netns_storage_socket = PIPE_EBADF,
+                .ipcns_storage_socket = PIPE_EBADF,
         };
 
         *ret = n;
@@ -6672,7 +6672,7 @@ static int exec_runtime_make(
                 ExecRuntime **ret) {
 
         _cleanup_(namespace_cleanup_tmpdirp) char *tmp_dir = NULL, *var_tmp_dir = NULL;
-        _cleanup_close_pair_ int netns_storage_socket[2] = { -EBADF, -EBADF }, ipcns_storage_socket[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int netns_storage_socket[2] = PIPE_EBADF, ipcns_storage_socket[2] = PIPE_EBADF;
         int r;
 
         assert(m);
index 4e15f5cb8b13dca6450353bb50d99e046356a2a5..3332d5775b2dfdbc5f6d1676d1749fc0d3df0223 100644 (file)
@@ -851,7 +851,7 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager *
                 .notify_fd = -EBADF,
                 .cgroups_agent_fd = -EBADF,
                 .signal_fd = -EBADF,
-                .user_lookup_fds = { -EBADF, -EBADF },
+                .user_lookup_fds = PIPE_EBADF,
                 .private_listen_fd = -EBADF,
                 .dev_autofs_fd = -EBADF,
                 .cgroup_inotify_fd = -EBADF,
index d7c911a509f74c7ddeedaefc9dfa5725f863da48..d46daa3c05c8c0a663745731c44f0e800901ba1b 100644 (file)
@@ -2832,7 +2832,7 @@ int setup_tmp_dirs(const char *id, char **tmp_dir, char **var_tmp_dir) {
 }
 
 int setup_shareable_ns(const int ns_storage_socket[static 2], unsigned long nsflag) {
-        _cleanup_close_ int ns = -1;
+        _cleanup_close_ int ns = -EBADF;
         int r, q;
         const char *ns_name, *ns_path;
 
@@ -2900,7 +2900,7 @@ fail:
 }
 
 int open_shareable_ns_path(const int ns_storage_socket[static 2], const char *path, unsigned long nsflag) {
-        _cleanup_close_ int ns = -1;
+        _cleanup_close_ int ns = -EBADF;
         int q, r;
 
         assert(ns_storage_socket);
index c967dc989796c4bc68f5b17f693f5cc2e48340d1..b1fe19127f6ad9ce292916450248b19cff6be34f 100644 (file)
@@ -1402,7 +1402,7 @@ static int service_allocate_exec_fd(
                 sd_event_source **ret_event_source,
                 int *ret_exec_fd) {
 
-        _cleanup_close_pair_ int p[] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int p[] = PIPE_EBADF;
         int r;
 
         assert(s);
index 518f27705395a8fa4794ead29f475b94aa3314f8..409d415d8d99295a25164aa645110ebec6d29df8 100644 (file)
@@ -1502,7 +1502,7 @@ static int socket_address_listen_in_cgroup(
                 const SocketAddress *address,
                 const char *label) {
 
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         int fd, r;
         pid_t pid;
 
@@ -2899,7 +2899,7 @@ static int socket_accept_do(Socket *s, int fd) {
 }
 
 static int socket_accept_in_cgroup(Socket *s, SocketPort *p, int fd) {
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         int cfd, r;
         pid_t pid;
 
index 4ca19370f3e280165dcab70cac3ea4e45d97f6a4..192dc4c654b044dbcba6cc2740c1a5e952b5629c 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <sys/prctl.h>
 #include <sys/statvfs.h>
+#include <sys/auxv.h>
 #include <sys/xattr.h>
 #include <unistd.h>
 
@@ -107,24 +108,27 @@ enum {
 
         META_EXE = _META_MANDATORY_MAX,
         META_UNIT,
+        META_PROC_AUXV,
         _META_MAX
 };
 
 static const char * const meta_field_names[_META_MAX] = {
-        [META_ARGV_PID]          = "COREDUMP_PID=",
-        [META_ARGV_UID]          = "COREDUMP_UID=",
-        [META_ARGV_GID]          = "COREDUMP_GID=",
-        [META_ARGV_SIGNAL]       = "COREDUMP_SIGNAL=",
-        [META_ARGV_TIMESTAMP]    = "COREDUMP_TIMESTAMP=",
-        [META_ARGV_RLIMIT]       = "COREDUMP_RLIMIT=",
-        [META_ARGV_HOSTNAME]     = "COREDUMP_HOSTNAME=",
-        [META_COMM]              = "COREDUMP_COMM=",
-        [META_EXE]               = "COREDUMP_EXE=",
-        [META_UNIT]              = "COREDUMP_UNIT=",
+        [META_ARGV_PID]       = "COREDUMP_PID=",
+        [META_ARGV_UID]       = "COREDUMP_UID=",
+        [META_ARGV_GID]       = "COREDUMP_GID=",
+        [META_ARGV_SIGNAL]    = "COREDUMP_SIGNAL=",
+        [META_ARGV_TIMESTAMP] = "COREDUMP_TIMESTAMP=",
+        [META_ARGV_RLIMIT]    = "COREDUMP_RLIMIT=",
+        [META_ARGV_HOSTNAME]  = "COREDUMP_HOSTNAME=",
+        [META_COMM]           = "COREDUMP_COMM=",
+        [META_EXE]            = "COREDUMP_EXE=",
+        [META_UNIT]           = "COREDUMP_UNIT=",
+        [META_PROC_AUXV]      = "COREDUMP_PROC_AUXV=",
 };
 
 typedef struct Context {
         const char *meta[_META_MAX];
+        size_t meta_size[_META_MAX];
         pid_t pid;
         bool is_pid1;
         bool is_journald;
@@ -139,9 +143,9 @@ typedef enum CoredumpStorage {
 } CoredumpStorage;
 
 static const char* const coredump_storage_table[_COREDUMP_STORAGE_MAX] = {
-        [COREDUMP_STORAGE_NONE] = "none",
+        [COREDUMP_STORAGE_NONE]     = "none",
         [COREDUMP_STORAGE_EXTERNAL] = "external",
-        [COREDUMP_STORAGE_JOURNAL] = "journal",
+        [COREDUMP_STORAGE_JOURNAL]  = "journal",
 };
 
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP(coredump_storage, CoredumpStorage);
@@ -157,13 +161,13 @@ static uint64_t arg_max_use = UINT64_MAX;
 
 static int parse_config(void) {
         static const ConfigTableItem items[] = {
-                { "Coredump", "Storage",          config_parse_coredump_storage,           0, &arg_storage           },
-                { "Coredump", "Compress",         config_parse_bool,                       0, &arg_compress          },
-                { "Coredump", "ProcessSizeMax",   config_parse_iec_uint64,                 0, &arg_process_size_max  },
-                { "Coredump", "ExternalSizeMax",  config_parse_iec_uint64_infinity,        0, &arg_external_size_max },
-                { "Coredump", "JournalSizeMax",   config_parse_iec_size,                   0, &arg_journal_size_max  },
-                { "Coredump", "KeepFree",         config_parse_iec_uint64,                 0, &arg_keep_free         },
-                { "Coredump", "MaxUse",           config_parse_iec_uint64,                 0, &arg_max_use           },
+                { "Coredump", "Storage",          config_parse_coredump_storage,     0, &arg_storage           },
+                { "Coredump", "Compress",         config_parse_bool,                 0, &arg_compress          },
+                { "Coredump", "ProcessSizeMax",   config_parse_iec_uint64,           0, &arg_process_size_max  },
+                { "Coredump", "ExternalSizeMax",  config_parse_iec_uint64_infinity,  0, &arg_external_size_max },
+                { "Coredump", "JournalSizeMax",   config_parse_iec_size,             0, &arg_journal_size_max  },
+                { "Coredump", "KeepFree",         config_parse_iec_uint64,           0, &arg_keep_free         },
+                { "Coredump", "MaxUse",           config_parse_iec_uint64,           0, &arg_max_use           },
                 {}
         };
 
@@ -186,13 +190,16 @@ static uint64_t storage_size_max(void) {
         return 0;
 }
 
-static int fix_acl(int fd, uid_t uid) {
+static int fix_acl(int fd, uid_t uid, bool allow_user) {
+        assert(fd >= 0);
+        assert(uid_is_valid(uid));
 
 #if HAVE_ACL
         int r;
 
-        assert(fd >= 0);
-        assert(uid_is_valid(uid));
+        /* We don't allow users to read coredumps if the uid or capabilities were changed. */
+        if (!allow_user)
+                return 0;
 
         if (uid_is_system(uid) || uid_is_dynamic(uid) || uid == UID_NOBODY)
                 return 0;
@@ -209,15 +216,15 @@ static int fix_acl(int fd, uid_t uid) {
 static int fix_xattr(int fd, const Context *context) {
 
         static const char * const xattrs[_META_MAX] = {
-                [META_ARGV_PID]          = "user.coredump.pid",
-                [META_ARGV_UID]          = "user.coredump.uid",
-                [META_ARGV_GID]          = "user.coredump.gid",
-                [META_ARGV_SIGNAL]       = "user.coredump.signal",
-                [META_ARGV_TIMESTAMP]    = "user.coredump.timestamp",
-                [META_ARGV_RLIMIT]       = "user.coredump.rlimit",
-                [META_ARGV_HOSTNAME]     = "user.coredump.hostname",
-                [META_COMM]              = "user.coredump.comm",
-                [META_EXE]               = "user.coredump.exe",
+                [META_ARGV_PID]       = "user.coredump.pid",
+                [META_ARGV_UID]       = "user.coredump.uid",
+                [META_ARGV_GID]       = "user.coredump.gid",
+                [META_ARGV_SIGNAL]    = "user.coredump.signal",
+                [META_ARGV_TIMESTAMP] = "user.coredump.timestamp",
+                [META_ARGV_RLIMIT]    = "user.coredump.rlimit",
+                [META_ARGV_HOSTNAME]  = "user.coredump.hostname",
+                [META_COMM]           = "user.coredump.comm",
+                [META_EXE]            = "user.coredump.exe",
         };
 
         int r = 0;
@@ -252,7 +259,8 @@ static int fix_permissions(
                 const char *filename,
                 const char *target,
                 const Context *context,
-                uid_t uid) {
+                uid_t uid,
+                bool allow_user) {
 
         int r;
 
@@ -262,7 +270,7 @@ static int fix_permissions(
 
         /* Ignore errors on these */
         (void) fchmod(fd, 0640);
-        (void) fix_acl(fd, uid);
+        (void) fix_acl(fd, uid, allow_user);
         (void) fix_xattr(fd, context);
 
         r = fsync_full(fd);
@@ -332,6 +340,153 @@ static int make_filename(const Context *context, char **ret) {
         return 0;
 }
 
+static int parse_auxv64(
+                const uint64_t *auxv,
+                size_t size_bytes,
+                int *at_secure,
+                uid_t *uid,
+                uid_t *euid,
+                gid_t *gid,
+                gid_t *egid) {
+
+        assert(auxv || size_bytes == 0);
+
+        if (size_bytes % (2 * sizeof(uint64_t)) != 0)
+                return log_warning_errno(SYNTHETIC_ERRNO(EIO), "Incomplete auxv structure (%zu bytes).", size_bytes);
+
+        size_t words = size_bytes / sizeof(uint64_t);
+
+        /* Note that we set output variables even on error. */
+
+        for (size_t i = 0; i + 1 < words; i += 2)
+                switch (auxv[i]) {
+                case AT_SECURE:
+                        *at_secure = auxv[i + 1] != 0;
+                        break;
+                case AT_UID:
+                        *uid = auxv[i + 1];
+                        break;
+                case AT_EUID:
+                        *euid = auxv[i + 1];
+                        break;
+                case AT_GID:
+                        *gid = auxv[i + 1];
+                        break;
+                case AT_EGID:
+                        *egid = auxv[i + 1];
+                        break;
+                case AT_NULL:
+                        if (auxv[i + 1] != 0)
+                                goto error;
+                        return 0;
+                }
+ error:
+        return log_warning_errno(SYNTHETIC_ERRNO(ENODATA),
+                                 "AT_NULL terminator not found, cannot parse auxv structure.");
+}
+
+static int parse_auxv32(
+                const uint32_t *auxv,
+                size_t size_bytes,
+                int *at_secure,
+                uid_t *uid,
+                uid_t *euid,
+                gid_t *gid,
+                gid_t *egid) {
+
+        assert(auxv || size_bytes == 0);
+
+        size_t words = size_bytes / sizeof(uint32_t);
+
+        if (size_bytes % (2 * sizeof(uint32_t)) != 0)
+                return log_warning_errno(SYNTHETIC_ERRNO(EIO), "Incomplete auxv structure (%zu bytes).", size_bytes);
+
+        /* Note that we set output variables even on error. */
+
+        for (size_t i = 0; i + 1 < words; i += 2)
+                switch (auxv[i]) {
+                case AT_SECURE:
+                        *at_secure = auxv[i + 1] != 0;
+                        break;
+                case AT_UID:
+                        *uid = auxv[i + 1];
+                        break;
+                case AT_EUID:
+                        *euid = auxv[i + 1];
+                        break;
+                case AT_GID:
+                        *gid = auxv[i + 1];
+                        break;
+                case AT_EGID:
+                        *egid = auxv[i + 1];
+                        break;
+                case AT_NULL:
+                        if (auxv[i + 1] != 0)
+                                goto error;
+                        return 0;
+                }
+ error:
+        return log_warning_errno(SYNTHETIC_ERRNO(ENODATA),
+                                 "AT_NULL terminator not found, cannot parse auxv structure.");
+}
+
+static int grant_user_access(int core_fd, const Context *context) {
+        int at_secure = -1;
+        uid_t uid = UID_INVALID, euid = UID_INVALID;
+        uid_t gid = GID_INVALID, egid = GID_INVALID;
+        int r;
+
+        assert(core_fd >= 0);
+        assert(context);
+
+        if (!context->meta[META_PROC_AUXV])
+                return log_warning_errno(SYNTHETIC_ERRNO(ENODATA), "No auxv data, not adjusting permissions.");
+
+        uint8_t elf[EI_NIDENT];
+        errno = 0;
+        if (pread(core_fd, &elf, sizeof(elf), 0) != sizeof(elf))
+                return log_warning_errno(errno_or_else(EIO),
+                                         "Failed to pread from coredump fd: %s", STRERROR_OR_EOF(errno));
+
+        if (elf[EI_MAG0] != ELFMAG0 ||
+            elf[EI_MAG1] != ELFMAG1 ||
+            elf[EI_MAG2] != ELFMAG2 ||
+            elf[EI_MAG3] != ELFMAG3 ||
+            elf[EI_VERSION] != EV_CURRENT)
+                return log_info_errno(SYNTHETIC_ERRNO(EUCLEAN),
+                                      "Core file does not have ELF header, not adjusting permissions.");
+        if (!IN_SET(elf[EI_CLASS], ELFCLASS32, ELFCLASS64) ||
+            !IN_SET(elf[EI_DATA], ELFDATA2LSB, ELFDATA2MSB))
+                return log_info_errno(SYNTHETIC_ERRNO(EUCLEAN),
+                                      "Core file has strange ELF class, not adjusting permissions.");
+
+        if ((elf[EI_DATA] == ELFDATA2LSB) != (__BYTE_ORDER == __LITTLE_ENDIAN))
+                return log_info_errno(SYNTHETIC_ERRNO(EUCLEAN),
+                                      "Core file has non-native endianness, not adjusting permissions.");
+
+        if (elf[EI_CLASS] == ELFCLASS64)
+                r = parse_auxv64((const uint64_t*) context->meta[META_PROC_AUXV],
+                                 context->meta_size[META_PROC_AUXV],
+                                 &at_secure, &uid, &euid, &gid, &egid);
+        else
+                r = parse_auxv32((const uint32_t*) context->meta[META_PROC_AUXV],
+                                 context->meta_size[META_PROC_AUXV],
+                                 &at_secure, &uid, &euid, &gid, &egid);
+        if (r < 0)
+                return r;
+
+        /* We allow access if we got all the data and at_secure is not set and
+         * the uid/gid matches euid/egid. */
+        bool ret =
+                at_secure == 0 &&
+                uid != UID_INVALID && euid != UID_INVALID && uid == euid &&
+                gid != GID_INVALID && egid != GID_INVALID && gid == egid;
+        log_debug("Will %s access (uid="UID_FMT " euid="UID_FMT " gid="GID_FMT " egid="GID_FMT " at_secure=%s)",
+                  ret ? "permit" : "restrict",
+                  uid, euid, gid, egid, yes_no(at_secure));
+        return ret;
+}
+
 static int save_external_coredump(
                 const Context *context,
                 int input_fd,
@@ -454,6 +609,8 @@ static int save_external_coredump(
                                 context->meta[META_ARGV_PID], context->meta[META_COMM]);
         truncated = r == 1;
 
+        bool allow_user = grant_user_access(fd, context) > 0;
+
 #if HAVE_COMPRESSION
         if (arg_compress) {
                 _cleanup_(unlink_and_freep) char *tmp_compressed = NULL;
@@ -491,7 +648,7 @@ static int save_external_coredump(
                         uncompressed_size += partial_uncompressed_size;
                 }
 
-                r = fix_permissions(fd_compressed, tmp_compressed, fn_compressed, context, uid);
+                r = fix_permissions(fd_compressed, tmp_compressed, fn_compressed, context, uid, allow_user);
                 if (r < 0)
                         return r;
 
@@ -518,7 +675,7 @@ static int save_external_coredump(
                            "SIZE_LIMIT=%"PRIu64, max_size,
                            "MESSAGE_ID=" SD_MESSAGE_TRUNCATED_CORE_STR);
 
-        r = fix_permissions(fd, tmp, fn, context, uid);
+        r = fix_permissions(fd, tmp, fn, context, uid, allow_user);
         if (r < 0)
                 return log_error_errno(r, "Failed to fix permissions and finalize coredump %s into %s: %m", coredump_tmpfile_name(tmp), fn);
 
@@ -766,7 +923,7 @@ static int change_uid_gid(const Context *context) {
 }
 
 static int submit_coredump(
-                Context *context,
+                const Context *context,
                 struct iovec_wrapper *iovw,
                 int input_fd) {
 
@@ -945,16 +1102,15 @@ static int save_context(Context *context, const struct iovec_wrapper *iovw) {
                 struct iovec *iovec = iovw->iovec + n;
 
                 for (size_t i = 0; i < ELEMENTSOF(meta_field_names); i++) {
-                        char *p;
-
                         /* Note that these strings are NUL terminated, because we made sure that a
                          * trailing NUL byte is in the buffer, though not included in the iov_len
                          * count (see process_socket() and gather_pid_metadata_*()) */
                         assert(((char*) iovec->iov_base)[iovec->iov_len] == 0);
 
-                        p = startswith(iovec->iov_base, meta_field_names[i]);
+                        const char *p = startswith(iovec->iov_base, meta_field_names[i]);
                         if (p) {
                                 context->meta[i] = p;
+                                context->meta_size[i] = iovec->iov_len - strlen(meta_field_names[i]);
                                 break;
                         }
                 }
@@ -1191,6 +1347,7 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
         uid_t owner_uid;
         pid_t pid;
         char *t;
+        size_t size;
         const char *p;
         int r;
 
@@ -1255,13 +1412,26 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_LIMITS=", t);
 
         p = procfs_file_alloca(pid, "cgroup");
-        if (read_full_virtual_file(p, &t, NULL) >=0)
+        if (read_full_virtual_file(p, &t, NULL) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_CGROUP=", t);
 
         p = procfs_file_alloca(pid, "mountinfo");
-        if (read_full_virtual_file(p, &t, NULL) >=0)
+        if (read_full_virtual_file(p, &t, NULL) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_PROC_MOUNTINFO=", t);
 
+        /* We attach /proc/auxv here. ELF coredumps also contain a note for this (NT_AUXV), see elf(5). */
+        p = procfs_file_alloca(pid, "auxv");
+        if (read_full_virtual_file(p, &t, &size) >= 0) {
+                char *buf = malloc(strlen("COREDUMP_PROC_AUXV=") + size + 1);
+                if (buf) {
+                        /* Add a dummy terminator to make save_context() happy. */
+                        *((uint8_t*) mempcpy(stpcpy(buf, "COREDUMP_PROC_AUXV="), t, size)) = '\0';
+                        (void) iovw_consume(iovw, buf, size + strlen("COREDUMP_PROC_AUXV="));
+                }
+
+                free(t);
+        }
+
         if (get_process_cwd(pid, &t) >= 0)
                 (void) iovw_put_string_field_free(iovw, "COREDUMP_CWD=", t);
 
@@ -1293,7 +1463,7 @@ static int process_kernel(int argc, char* argv[]) {
         /* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds
          * could get reallocated. To avoid hard to debug issues, let's instead bind stdout/stderr to
          * /dev/null. */
-        r = rearrange_stdio(STDIN_FILENO, -1, -1);
+        r = rearrange_stdio(STDIN_FILENO, -EBADF, -EBADF);
         if (r < 0)
                 return log_error_errno(r, "Failed to connect stdout/stderr to /dev/null: %m");
 
index d987f04ef43775edb922502ca2a64d810a46369c..71bf355b383ede14d95e11e055c3903a3033b234 100644 (file)
@@ -563,7 +563,7 @@ static int verb_decrypt(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return log_error_errno(r, "Failed to read encrypted credential data: %m");
 
-        output_path = (argc < 3 || isempty(argv[2]) || streq(argv[2], "-")) ? NULL : argv[2];
+        output_path = (argc < 3 || empty_or_dash(argv[2])) ? NULL : argv[2];
 
         if (arg_name_any)
                 name = NULL;
index 7cd9aed579974bfb347522f0ef3089b81fd698fc..651415568d6caed7ed84a2a43f8958243151916b 100644 (file)
@@ -881,7 +881,7 @@ static int write_root_shadow(const char *shadow_path, const char *hashed_passwor
 }
 
 static int process_root_account(void) {
-        _cleanup_close_ int lock = -1;
+        _cleanup_close_ int lock = -EBADF;
         _cleanup_(erase_and_freep) char *_hashed_password = NULL;
         const char *password, *hashed_password;
         const char *etc_passwd, *etc_shadow;
index 29265d9220ed09dc398f363f1b3852e2238b7952..37fdfa540f1a3be8fdfbd8d2632c266586177fde 100644 (file)
@@ -241,7 +241,7 @@ static int fsck_progress_socket(void) {
 }
 
 static int run(int argc, char *argv[]) {
-        _cleanup_close_pair_ int progress_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int progress_pipe[2] = PIPE_EBADF;
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
         _cleanup_free_ char *dpath = NULL;
         _cleanup_fclose_ FILE *console = NULL;
index c97586be9efe28f5ff8000ba3c5f066cd8c87b0f..cbfde088d90ba7c9bb958b5f9f0da1fafc31ee54 100644 (file)
@@ -85,7 +85,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         struct iovec server_iov = IOVEC_MAKE((void*) data, size), client_iov = IOVEC_MAKE((void*) data, size);
         /* Important: the declaration order matters here! we want that the fds are closed on return after the
          * event sources, hence we declare the fds first, the event sources second */
-        _cleanup_close_pair_ int server_pair[2] = { -EBADF, -EBADF }, client_pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int server_pair[2] = PIPE_EBADF, client_pair[2] = PIPE_EBADF;
         _cleanup_(sd_event_source_unrefp) sd_event_source *idle_event_source = NULL,
                 *server_event_source = NULL, *client_event_source = NULL;
         _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL;
index f2f6cc1a53d901c9e2fc147acc7b75795dea165c..1d626f2a5a0ffa795bb43b948eb165b4281b6b11 100644 (file)
 static const char *arg_dest = NULL;
 static bool arg_enabled = true;
 static bool arg_root_enabled = true;
+static char *arg_root_fstype = NULL;
+static char *arg_root_options = NULL;
 static int arg_root_rw = -1;
 
+STATIC_DESTRUCTOR_REGISTER(arg_root_fstype, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_root_options, freep);
+
 static int add_cryptsetup(
                 const char *id,
                 const char *what,
@@ -165,6 +170,15 @@ static int add_mount(
 
                 what = crypto_what;
                 fstype = NULL;
+        } else if (fstype) {
+                r = dissect_fstype_ok(fstype);
+                if (r < 0)
+                        return log_error_errno(r, "Unable to determine of dissected file system type '%s' is permitted: %m", fstype);
+                if (!r)
+                        return log_error_errno(
+                                        SYNTHETIC_ERRNO(EIDRM),
+                                        "Refusing to automatically mount uncommon file system '%s' to '%s'.",
+                                        fstype, where);
         }
 
         r = unit_name_from_path(where, ".mount", &unit);
@@ -622,10 +636,10 @@ static int add_root_mount(void) {
                         "root",
                         "/dev/gpt-auto-root",
                         in_initrd() ? "/sysroot" : "/",
-                        NULL,
+                        arg_root_fstype,
                         /* rw= */ arg_root_rw > 0,
                         /* growfs= */ false,
-                        NULL,
+                        arg_root_options,
                         "Root Partition",
                         in_initrd() ? SPECIAL_INITRD_ROOT_FS_TARGET : SPECIAL_LOCAL_FS_TARGET);
 #else
@@ -801,6 +815,21 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
 
                 arg_root_enabled = false;
 
+        } else if (streq(key, "rootfstype")) {
+
+                if (proc_cmdline_value_missing(key, value))
+                        return 0;
+
+                return free_and_strdup_warn(&arg_root_fstype, value);
+
+        } else if (streq(key, "rootflags")) {
+
+                if (proc_cmdline_value_missing(key, value))
+                        return 0;
+
+                if (!strextend_with_separator(&arg_root_options, ",", value))
+                        return log_oom();
+
         } else if (proc_cmdline_key_streq(key, "rw") && !value)
                 arg_root_rw = true;
         else if (proc_cmdline_key_streq(key, "ro") && !value)
index eb52c6c116c9af345300e844f61387d4e16f9897..0e2c7edae1c108487dacdbac7363bd9b5f7f13b2 100644 (file)
@@ -23,7 +23,7 @@
 #include "tmpfile-util.h"
 
 int import_fork_tar_x(const char *path, pid_t *ret) {
-        _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
         bool use_selinux;
         pid_t pid;
         int r;
@@ -64,7 +64,7 @@ int import_fork_tar_x(const char *path, pid_t *ret) {
 
                 pipefd[1] = safe_close(pipefd[1]);
 
-                r = rearrange_stdio(TAKE_FD(pipefd[0]), -1, STDERR_FILENO);
+                r = rearrange_stdio(TAKE_FD(pipefd[0]), -EBADF, STDERR_FILENO);
                 if (r < 0) {
                         log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
                         _exit(EXIT_FAILURE);
@@ -96,7 +96,7 @@ int import_fork_tar_x(const char *path, pid_t *ret) {
 }
 
 int import_fork_tar_c(const char *path, pid_t *ret) {
-        _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
         bool use_selinux;
         pid_t pid;
         int r;
@@ -130,7 +130,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
 
                 pipefd[0] = safe_close(pipefd[0]);
 
-                r = rearrange_stdio(-1, TAKE_FD(pipefd[1]), STDERR_FILENO);
+                r = rearrange_stdio(-EBADF, TAKE_FD(pipefd[1]), STDERR_FILENO);
                 if (r < 0) {
                         log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
                         _exit(EXIT_FAILURE);
index b6d90cde103e5699c45dec4db5f8c17ca5044585..65647a66a6342e0ea1ab599fcf09cc78b403058e 100644 (file)
@@ -356,7 +356,7 @@ static int transfer_on_log(sd_event_source *s, int fd, uint32_t revents, void *u
 }
 
 static int transfer_start(Transfer *t) {
-        _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
         int r;
 
         assert(t);
index 1c7194fd6b153d1cdf224936bb3a67b52fffafc5..6980f12a796cc4c56de40ec3ed3d6cae3cf30c34 100644 (file)
@@ -381,7 +381,7 @@ static int verify_gpg(
                 const void *payload, size_t payload_size,
                 const void *signature, size_t signature_size) {
 
-        _cleanup_close_pair_ int gpg_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int gpg_pipe[2] = PIPE_EBADF;
         char sig_file_path[] = "/tmp/sigXXXXXX", gpg_home[] = "/tmp/gpghomeXXXXXX";
         _cleanup_(sigkill_waitp) pid_t pid = 0;
         bool gpg_home_created = false;
@@ -395,7 +395,7 @@ static int verify_gpg(
                 return log_error_errno(errno, "Failed to create pipe for gpg: %m");
 
         if (signature_size > 0) {
-                _cleanup_close_ int sig_file = -1;
+                _cleanup_close_ int sig_file = -EBADF;
 
                 sig_file = mkostemp(sig_file_path, O_RDWR);
                 if (sig_file < 0)
@@ -440,7 +440,7 @@ static int verify_gpg(
 
                 gpg_pipe[1] = safe_close(gpg_pipe[1]);
 
-                r = rearrange_stdio(TAKE_FD(gpg_pipe[0]), -1, STDERR_FILENO);
+                r = rearrange_stdio(TAKE_FD(gpg_pipe[0]), -EBADF, STDERR_FILENO);
                 if (r < 0) {
                         log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
                         _exit(EXIT_FAILURE);
index 74842000659faba2a45ec648bb2cac5eb7e5be22..0882570a660bfc4656a1394254581330906c5806 100644 (file)
@@ -311,7 +311,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
 }
 
 static int run(int argc, char *argv[]) {
-        _cleanup_(server_done) Server server = { .epoll_fd = -1 };
+        _cleanup_(server_done) Server server = { .epoll_fd = -EBADF };
         _unused_ _cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
         int r, n;
 
index cece8c440e88487bde3df9c96420f966610c9bd4..ed52f950d2e122db00ceeff8b9f7be83b951a581 100644 (file)
@@ -9,7 +9,7 @@
 #include "fuzz-journald.h"
 #include "journald-stream.h"
 
-static int stream_fds[2] = { -EBADF, -EBADF };
+static int stream_fds[2] = PIPE_EBADF;
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         Server s;
index eec794a653b47eaf85afb0eba4f7d65a46f06160..ad61614f12f6769b7636b2bc5f89d9f5d9cbb72a 100644 (file)
@@ -73,7 +73,7 @@ int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const stru
                 .ll.sll_halen    = ETH_ALEN,
                 .ll.sll_addr     = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(ifindex > 0);
index 0ee977a8c82c77a4795c29f6db617cdd0d74b0c1..4e4b1ccb751b097c5a89ce56a3f36962c058807a 100644 (file)
@@ -98,7 +98,7 @@ static int _bind_raw_socket(
                 .len = ELEMENTSOF(filter),
                 .filter = filter
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
@@ -178,7 +178,7 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int
                 .in.sin_port = htobe16(port),
                 .in.sin_addr.s_addr = address,
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
index eedd92d3c2422e578876abdde2c5040b9a4c78ad..a3e4e19e8e164cf839e31c8fe7323615926c87e3 100644 (file)
@@ -23,7 +23,7 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
                 .in6.sin6_port = htobe16(DHCP6_PORT_CLIENT),
                 .in6.sin6_scope_id = ifindex,
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(ifindex > 0);
index 7da285e54e37a428e207fb679bf5be1968c99dbf..356a9f48fd19ce82aaa51569a5518552deb93763 100644 (file)
@@ -10,7 +10,7 @@
 #include "fd-util.h"
 #include "fuzz.h"
 
-static int test_dhcp_fd[2] = { -EBADF, -EBADF };
+static int test_dhcp_fd[2] = PIPE_EBADF;
 
 int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address, const void *packet, size_t len) {
         return len;
index 00a98bbeb0ec97b85aef356e903f60b790043797..2d8e201854024879c76ccd600caf606de3929219 100644 (file)
@@ -10,7 +10,7 @@
 #include "fuzz.h"
 #include "lldp-network.h"
 
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
 
 int lldp_network_bind_raw_socket(int ifindex) {
         if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
index b794e2ad423ccd2161b17eb36c704e27478e74c0..7a5c45a2f97395d1d649f4b55a1f583b157d37aa 100644 (file)
@@ -4,14 +4,16 @@
 #include <netinet/icmp6.h>
 #include <unistd.h>
 
+#include "sd-ndisc.h"
+
 #include "alloc-util.h"
-#include "icmp6-util.h"
+#include "fd-util.h"
 #include "fuzz.h"
-#include "sd-ndisc.h"
-#include "socket-util.h"
+#include "icmp6-util.h"
 #include "ndisc-internal.h"
+#include "socket-util.h"
 
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
 
 int icmp6_bind_router_solicitation(int index) {
         assert_se(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0);
index b66953148780d0edfed6e562ace05d7ae11195e8..00a59291a1c43112835045e35d5ce61164787dbd 100644 (file)
@@ -31,7 +31,7 @@
 static int icmp6_bind_router_message(const struct icmp6_filter *filter,
                                      const struct ipv6_mreq *mreq) {
         int ifindex = mreq->ipv6mr_interface;
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(filter);
index 7344099e77e6045e88347d5deffa07739dcb3237..3e1c52a306136fe386250ad8e24a358ed5d5ba51 100644 (file)
@@ -73,7 +73,7 @@ static const uint8_t server_id[] = { SERVER_ID_BYTES };
 static const struct ether_addr mac = {
         .ether_addr_octet = { 'A', 'B', 'C', '1', '2', '3' },
 };
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
 static int test_ifindex = 42;
 static unsigned test_client_sent_message_count = 0;
 static sd_dhcp6_client *client_ref = NULL;
index 7ec1ab1ee90e519b80220a1d18bb7cd59e1c2a13..387e1e2203a45eac8fee44bb1756bc2348f04d1b 100644 (file)
@@ -20,7 +20,7 @@
 #define TEST_LLDP_TYPE_SYSTEM_NAME "systemd-lldp"
 #define TEST_LLDP_TYPE_SYSTEM_DESC "systemd-lldp-desc"
 
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
 static int lldp_rx_handler_calls;
 
 int lldp_network_bind_raw_socket(int ifindex) {
index 4a1d4d2ef82dc33ad4ecbeace35226deb3958021..eddd634d8a653a19267da86c4288c17f737c6342 100644 (file)
@@ -12,7 +12,7 @@
 #include "string-util.h"
 
 int bus_container_connect_socket(sd_bus *b) {
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
         int r, error_buf = 0;
         pid_t child;
index a402a70223a02d6d8c780b313ab48501cfc65ace..1eb6edd3291d51ab6384f61ce15cfd63fa034d3b 100644 (file)
@@ -211,9 +211,9 @@ int main(int argc, char *argv[]) {
                 MODE_CHART,
         } mode = MODE_BISECT;
         Type type = TYPE_LEGACY;
-        int i, pair[2] = { -EBADF, -EBADF };
+        int i, pair[2] = PIPE_EBADF;
         _cleanup_free_ char *address = NULL, *server_name = NULL;
-        _cleanup_close_ int bus_ref = -1;
+        _cleanup_close_ int bus_ref = -EBADF;
         const char *unique;
         cpu_set_t cpuset;
         size_t result;
index 382761171c64a4ff5a737e5327b155b49aabd584..8e66919b4637b5e6d1a19e203c9da96b0fc30753 100644 (file)
@@ -260,7 +260,7 @@ static void* client1(void *p) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *hello;
         int r;
-        _cleanup_close_pair_ int pp[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pp[2] = PIPE_EBADF;
         char x;
 
         r = sd_bus_open_user(&bus);
index 46125fedf113671b6d11b9174ab9375ac543be0d..6da351dd9bc1ca6b66405b93685372e121616edf 100644 (file)
@@ -549,7 +549,7 @@ finish:
 }
 
 _public_ int sd_notify_barrier(int unset_environment, uint64_t timeout) {
-        _cleanup_close_pair_ int pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pipe_fd[2] = PIPE_EBADF;
         int r;
 
         if (pipe2(pipe_fd, O_CLOEXEC) < 0)
index 5c8e043fc6f7b876eaab89f4c6395894cf662f65..049b3aa97f2e85a72da5fc8e9646b8296902987c 100644 (file)
@@ -130,7 +130,7 @@ int device_monitor_get_fd(sd_device_monitor *m) {
 
 int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group, int fd) {
         _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
-        _cleanup_close_ int sock = -1;
+        _cleanup_close_ int sock = -EBADF;
         int r;
 
         assert(group >= 0 && group < _MONITOR_NETLINK_GROUP_MAX);
@@ -184,7 +184,7 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
         }
 
         if (DEBUG_LOGGING) {
-                _cleanup_close_ int netns = -1;
+                _cleanup_close_ int netns = -EBADF;
 
                 /* So here's the thing: only AF_NETLINK sockets from the main network namespace will get
                  * hardware events. Let's check if ours is from there, and if not generate a debug message,
index b9df1c86c364a2d926cdb6a541b593b77ec674f6..ce1104b073edabaaa93f9a476335930615309433 100644 (file)
@@ -2072,7 +2072,7 @@ static int event_add_inotify_fd_internal(
                 sd_event_inotify_handler_t callback,
                 void *userdata) {
 
-        _cleanup_close_ int donated_fd = donate ? fd : -1;
+        _cleanup_close_ int donated_fd = donate ? fd : -EBADF;
         _cleanup_(source_freep) sd_event_source *s = NULL;
         struct inotify_data *inotify_data = NULL;
         struct inode_data *inode_data = NULL;
index 7cc4cc9e28382b125c52d8dc41d15a239c708506..591eab8896e97a542e579c46f32a52636c3f7bb4 100644 (file)
@@ -198,8 +198,8 @@ static void test_basic_one(bool with_pidfd) {
         sd_event *e = NULL;
         sd_event_source *w = NULL, *x = NULL, *y = NULL, *z = NULL, *q = NULL, *t = NULL;
         static const char ch = 'x';
-        int a[2] = { -EBADF, -EBADF }, b[2] = { -EBADF, -EBADF },
-            d[2] = { -EBADF, -EBADF }, k[2] = { -EBADF, -EBADF };
+        int a[2] = PIPE_EBADF, b[2] = PIPE_EBADF,
+            d[2] = PIPE_EBADF, k[2] = PIPE_EBADF;
         uint64_t event_now;
         int64_t priority;
 
@@ -628,7 +628,7 @@ static int ratelimit_expired(sd_event_source *s, void *userdata) {
 }
 
 TEST(ratelimit) {
-        _cleanup_close_pair_ int p[2] = {-1, -1};
+        _cleanup_close_pair_ int p[2] = PIPE_EBADF;
         _cleanup_(sd_event_unrefp) sd_event *e = NULL;
         _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
         uint64_t interval;
index 2b2d1c4b64000049972fc4b4873ee4864f548620..96a8c567fc7654204a7f05902a1ed79c2de693ea 100644 (file)
@@ -37,7 +37,7 @@ static const char *e(int r) {
 }
 
 TEST(login) {
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         _cleanup_free_ char *pp = NULL, *qq = NULL,
                 *display_session = NULL, *cgroup = NULL,
                 *display = NULL, *remote_user = NULL, *remote_host = NULL,
index f8c09a8b7cf34c0b942bcfdc4da731f33d588f20..bf65eecfdd4232f19132efc045ebb4326207df92 100644 (file)
@@ -31,7 +31,7 @@ int bus_image_method_remove(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         Image *image = ASSERT_PTR(userdata);
         Manager *m = image->userdata;
         pid_t child;
@@ -145,7 +145,7 @@ int bus_image_method_clone(
                 void *userdata,
                 sd_bus_error *error) {
 
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         Image *image = ASSERT_PTR(userdata);
         Manager *m = ASSERT_PTR(image->userdata);
         const char *new_name;
index 1867893004d959b6f6fc4b4ab080536281672198..7a45811614cbf94b2a4b0e981552f085f261783e 100644 (file)
@@ -223,7 +223,7 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd
         }
 
         case MACHINE_CONTAINER: {
-                _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+                _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
                 _cleanup_free_ char *us = NULL, *them = NULL;
                 _cleanup_close_ int netns_fd = -EBADF;
                 const char *p;
@@ -371,7 +371,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
 
         case MACHINE_CONTAINER: {
                 _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF;
-                _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+                _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
                 _cleanup_fclose_ FILE *f = NULL;
                 pid_t child;
 
@@ -436,7 +436,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
 int bus_machine_method_open_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_free_ char *pty_name = NULL;
-        _cleanup_close_ int master = -1;
+        _cleanup_close_ int master = -EBADF;
         Machine *m = ASSERT_PTR(userdata);
         int r;
 
@@ -525,7 +525,7 @@ int bus_machine_method_open_login(sd_bus_message *message, void *userdata, sd_bu
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_free_ char *pty_name = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *allocated_bus = NULL;
-        _cleanup_close_ int master = -1;
+        _cleanup_close_ int master = -EBADF;
         sd_bus *container_bus = NULL;
         Machine *m = ASSERT_PTR(userdata);
         const char *p, *getty;
@@ -588,7 +588,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
         _cleanup_free_ char *pty_name = NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *allocated_bus = NULL;
         sd_bus *container_bus = NULL;
-        _cleanup_close_ int master = -1, slave = -1;
+        _cleanup_close_ int master = -EBADF, slave = -EBADF;
         _cleanup_strv_free_ char **env = NULL, **args_wire = NULL, **args = NULL;
         Machine *m = ASSERT_PTR(userdata);
         const char *p, *unit, *user, *path, *description, *utmp_id;
@@ -888,7 +888,7 @@ int bus_machine_method_bind_mount(sd_bus_message *message, void *userdata, sd_bu
 int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_free_ char *host_basename = NULL, *container_basename = NULL;
         const char *src, *dest, *host_path, *container_path;
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         CopyFlags copy_flags = COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS;
         _cleanup_close_ int hostfd = -EBADF;
         Machine *m = ASSERT_PTR(userdata);
@@ -1085,7 +1085,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
 
         case MACHINE_CONTAINER: {
                 _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
-                _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+                _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
                 pid_t child;
 
                 r = namespace_open(m->leader, NULL, &mntns_fd, NULL, NULL, &root_fd);
index ed2862782694ef5c36c97d60e141f677de65b7fe..0c157a981aff495bf716715bfc98489e25dd0cf6 100644 (file)
@@ -683,7 +683,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
                 REMOVE_HIDDEN,
         } mode;
 
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         _cleanup_close_ int result_fd = -EBADF;
         Manager *m = userdata;
         Operation *operation;
index a91ab9f25ecf04a4342a8bd93211bec18b593895..e396d66441297b6f3457c05307e959ced1af91c2 100644 (file)
@@ -39,7 +39,7 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
 
                 pipe_fds[0] = safe_close(pipe_fds[0]);
 
-                if (rearrange_stdio(-1, TAKE_FD(pipe_fds[1]), -1) < 0)
+                if (rearrange_stdio(-EBADF, TAKE_FD(pipe_fds[1]), -EBADF) < 0)
                         _exit(EXIT_FAILURE);
 
                 (void) close_all_fds(NULL, 0);
index de3e95145b6ae0cb3c90e4619fc6033e7ca909c0..067efbe3f069fe84d078b243cdc003bdc0626f98 100644 (file)
@@ -2376,7 +2376,7 @@ static int setup_pts(const char *dest) {
 }
 
 static int setup_stdio_as_dev_console(void) {
-        _cleanup_close_ int terminal = -1;
+        _cleanup_close_ int terminal = -EBADF;
         int r;
 
         /* We open the TTY in O_NOCTTY mode, so that we do not become controller yet. We'll do that later
@@ -3348,7 +3348,7 @@ static int inner_child(
         }
 
         if (arg_console_mode != CONSOLE_PIPE) {
-                _cleanup_close_ int master = -1;
+                _cleanup_close_ int master = -EBADF;
                 _cleanup_free_ char *console = NULL;
 
                 /* Allocate a pty and make it available as /dev/console. */
@@ -4742,12 +4742,12 @@ static int run_container(
         };
 
         _cleanup_(release_lock_file) LockFile uid_shift_lock = LOCK_FILE_INIT;
-        _cleanup_close_ int etc_passwd_lock = -1;
+        _cleanup_close_ int etc_passwd_lock = -EBADF;
         _cleanup_close_pair_ int
-                fd_inner_socket_pair[2] = { -EBADF, -EBADF },
-                fd_outer_socket_pair[2] = { -EBADF, -EBADF };
+                fd_inner_socket_pair[2] = PIPE_EBADF,
+                fd_outer_socket_pair[2] = PIPE_EBADF;
 
-        _cleanup_close_ int notify_socket = -1, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
+        _cleanup_close_ int notify_socket = -EBADF, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
         _cleanup_(barrier_destroy) Barrier barrier = BARRIER_NULL;
         _cleanup_(sd_event_source_unrefp) sd_event_source *notify_event_source = NULL;
         _cleanup_(sd_event_unrefp) sd_event *event = NULL;
@@ -5413,7 +5413,7 @@ static int cant_be_in_netns(void) {
 static int run(int argc, char *argv[]) {
         bool secondary = false, remove_directory = false, remove_image = false,
                 veth_created = false, remove_tmprootdir = false;
-        _cleanup_close_ int master = -1;
+        _cleanup_close_ int master = -EBADF;
         _cleanup_fdset_free_ FDSet *fds = NULL;
         int r, n_fd_passed, ret = EXIT_SUCCESS;
         char veth_name[IFNAMSIZ] = "";
index 28d9ccd302d6ad49f5b80483dd42412b06533959..7be1afbcc4bd8d4969bfc6265019945b1c44c62e 100644 (file)
@@ -355,7 +355,7 @@ static int portable_extract_by_path(
         else {
                 _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
                 _cleanup_(rmdir_and_freep) char *tmpdir = NULL;
-                _cleanup_(close_pairp) int seq[2] = { -EBADF, -EBADF };
+                _cleanup_(close_pairp) int seq[2] = PIPE_EBADF;
                 _cleanup_(sigkill_waitp) pid_t child = 0;
 
                 /* We now have a loopback block device, let's fork off a child in its own mount namespace, mount it
index f0eb71b7103591f15ca92f58be7dd5bc51062137..07d10b05bf12688434b276f539ad37e329704b4d 100644 (file)
@@ -486,7 +486,7 @@ int bus_image_common_remove(
                 Image *image,
                 sd_bus_error *error) {
 
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         _cleanup_(sigkill_waitp) pid_t child = 0;
         PortableState state;
         int r;
index bcbb2754d78df263851f0e84c069f5a197267c04..647c0bd1f96c69169b424b05e4e265ee81dfc74e 100644 (file)
@@ -52,7 +52,7 @@ int dns_search_domain_new(
                 l->n_search_domains++;
                 break;
 
-        case DNS_SERVER_SYSTEM:
+        case DNS_SEARCH_DOMAIN_SYSTEM:
                 LIST_APPEND(domains, m->search_domains, d);
                 m->n_search_domains++;
                 break;
index 897674ba5145a33d3176779306a2ae5d3c3fd2b6..4ab455eb2fe45e4080c240913c9e423ebb3dae6b 100644 (file)
@@ -141,7 +141,7 @@ int manager_llmnr_ipv4_udp_fd(Manager *m) {
                 .in.sin_family = AF_INET,
                 .in.sin_port = htobe16(LLMNR_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
@@ -211,7 +211,7 @@ int manager_llmnr_ipv6_udp_fd(Manager *m) {
                 .in6.sin6_family = AF_INET6,
                 .in6.sin6_port = htobe16(LLMNR_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
@@ -344,7 +344,7 @@ int manager_llmnr_ipv4_tcp_fd(Manager *m) {
                 .in.sin_family = AF_INET,
                 .in.sin_port = htobe16(LLMNR_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
@@ -410,7 +410,7 @@ int manager_llmnr_ipv6_tcp_fd(Manager *m) {
                 .in6.sin6_family = AF_INET6,
                 .in6.sin6_port = htobe16(LLMNR_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
index 8d51017b5d555012bb56379b8a3e46423c2c0d97..cf6c22df3b2ad96a03cf353b8c45f9932522b53f 100644 (file)
@@ -466,7 +466,7 @@ int manager_mdns_ipv4_fd(Manager *m) {
                 .in.sin_family = AF_INET,
                 .in.sin_port = htobe16(MDNS_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
@@ -541,7 +541,7 @@ int manager_mdns_ipv6_fd(Manager *m) {
                 .in6.sin6_family = AF_INET6,
                 .in6.sin6_port = htobe16(MDNS_PORT),
         };
-        _cleanup_close_ int s = -1;
+        _cleanup_close_ int s = -EBADF;
         int r;
 
         assert(m);
index 773b25d8166da43cf026f0ea88f9e047487c8817..96315136286b15df224e825ae5b4f39364d38d80 100644 (file)
@@ -267,7 +267,7 @@ static void context_save_and_clear(Context *c) {
 }
 
 static int run(int argc, char *argv[]) {
-        _cleanup_(context_save_and_clear) Context c = { .rfkill_fd = -1 };
+        _cleanup_(context_save_and_clear) Context c = { .rfkill_fd = -EBADF };
         bool ready = false;
         int r, n;
 
index 5f7d651b905c3fb04ba5b5dd7adf3ee20c0b77ac..471d15924a04f7e3685af532b85dcda3e408f27f 100644 (file)
@@ -1107,7 +1107,7 @@ static int start_transient_service(
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
         _cleanup_free_ char *service = NULL, *pty_path = NULL;
-        _cleanup_close_ int master = -1;
+        _cleanup_close_ int master = -EBADF;
         int r;
 
         assert(bus);
index e103aa0f7ff0deaa4d623daa5de7840b267989ce..4eb4f9f765ca9c8450bf8fe636d0cd6a2b1831cc 100644 (file)
@@ -526,7 +526,7 @@ static int hardlink_context_setup(
                 const char *to,
                 CopyFlags copy_flags) {
 
-        _cleanup_close_ int dt_copy = -1;
+        _cleanup_close_ int dt_copy = -EBADF;
         int r;
 
         assert(c);
index 0a4ef3fffc21591985783bda0c937c981e3a807e..895d8e8b334d0f70e460eb3d733e67381d58dc01 100644 (file)
@@ -26,7 +26,7 @@
 #define DATA_FD_TMP_LIMIT (1024U*1024U)
 
 int acquire_data_fd(const void *data, size_t size, unsigned flags) {
-        _cleanup_close_pair_ int pipefds[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pipefds[2] = PIPE_EBADF;
         char pattern[] = "/dev/shm/data-fd-XXXXXX";
         _cleanup_close_ int fd = -EBADF;
         int isz = 0, r;
@@ -218,7 +218,7 @@ int copy_data_fd(int fd) {
                         /* Hmm, pity, this didn't fit. Let's fall back to /tmp then, see below */
 
                 } else {
-                        _cleanup_(close_pairp) int pipefds[2] = { -EBADF, -EBADF };
+                        _cleanup_(close_pairp) int pipefds[2] = PIPE_EBADF;
                         int isz;
 
                         /* If memfds aren't available, use a pipe. Set O_NONBLOCK so that we will get EAGAIN rather
index e2905b646dc2ab64b0bece6b4b27a069a9a68b9f..100b8cc8f147baccae30a32bbe550313efe3ef3a 100644 (file)
 /* how many times to wait for the device nodes to appear */
 #define N_DEVICE_NODE_LIST_ATTEMPTS 10
 
+int dissect_fstype_ok(const char *fstype) {
+        const char *e;
+        bool b;
+
+        /* When we automatically mount file systems, be a bit conservative by default what we are willing to
+         * mount, just as an extra safety net to not mount with badly maintained legacy file system
+         * drivers. */
+
+        e = secure_getenv("SYSTEMD_DISSECT_FILE_SYSTEMS");
+        if (e) {
+                _cleanup_strv_free_ char **l = NULL;
+
+                l = strv_split(e, ":");
+                if (!l)
+                        return -ENOMEM;
+
+                b = strv_contains(l, fstype);
+        } else
+                b = STR_IN_SET(fstype,
+                               "btrfs",
+                               "erofs",
+                               "ext4",
+                               "squashfs",
+                               "vfat",
+                               "xfs");
+        if (b)
+                return true;
+
+        log_debug("File system type '%s' is not allowed to be mounted as result of automatic dissection.", fstype);
+        return false;
+}
+
 int probe_filesystem_full(
                 int fd,
                 const char *path,
@@ -1339,6 +1371,11 @@ static int mount_partition(
 
         if (!fstype)
                 return -EAFNOSUPPORT;
+        r = dissect_fstype_ok(fstype);
+        if (r < 0)
+                return r;
+        if (!r)
+                return -EIDRM; /* Recognizable error */
 
         /* We are looking at an encrypted partition? This either means stacked encryption, or the caller
          * didn't call dissected_image_decrypt() beforehand. Let's return a recognizable error for this
@@ -1488,6 +1525,7 @@ int dissected_image_mount(
          *  -EUCLEAN      â†’ fsck for file system failed
          *  -EBUSY        â†’ File system already mounted/used elsewhere (kernel)
          *  -EAFNOSUPPORT â†’ File system type not supported or not known
+         *  -EIDRM        â†’ File system is not among allowlisted "common" file systems
          */
 
         if (!(m->partitions[PARTITION_ROOT].found ||
@@ -1625,6 +1663,8 @@ int dissected_image_mount_and_warn(
                 return log_error_errno(r, "File system already mounted elsewhere.");
         if (r == -EAFNOSUPPORT)
                 return log_error_errno(r, "File system type not supported or not known.");
+        if (r == -EIDRM)
+                return log_error_errno(r, "File system is too uncommon, refused.");
         if (r < 0)
                 return log_error_errno(r, "Failed to mount image: %m");
 
@@ -2696,7 +2736,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
         };
 
         _cleanup_strv_free_ char **machine_info = NULL, **os_release = NULL, **initrd_release = NULL, **extension_release = NULL;
-        _cleanup_close_pair_ int error_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int error_pipe[2] = PIPE_EBADF;
         _cleanup_(rmdir_and_freep) char *t = NULL;
         _cleanup_(sigkill_waitp) pid_t child = 0;
         sd_id128_t machine_id = SD_ID128_NULL;
index 37a41e050a9b16a6c6b30aa6b63fe1ca67352b69..b65193f8872aa9df610bc482e6635a12b597a7d3 100644 (file)
@@ -183,3 +183,5 @@ bool dissected_image_verity_sig_ready(const DissectedImage *image, PartitionDesi
 int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device);
 
 int verity_dissect_and_mount(int src_fd, const char *src, const char *dest, const MountOptions *options, const char *required_host_os_release_id, const char *required_host_os_release_version_id, const char *required_host_os_release_sysext_level, const char *required_sysext_scope);
+
+int dissect_fstype_ok(const char *fstype);
index bbe59f7af6b1c436a1f558a0e1ebf1c102a2eb1f..8da16f528fe373fc93ff64dd133dff94d6f28be6 100644 (file)
@@ -744,9 +744,9 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r
 }
 
 int parse_elf_object(int fd, const char *executable, bool fork_disable_dump, char **ret, JsonVariant **ret_package_metadata) {
-        _cleanup_close_pair_ int error_pipe[2] = { -EBADF, -EBADF },
-                                 return_pipe[2] = { -EBADF, -EBADF },
-                                 json_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int error_pipe[2] = PIPE_EBADF,
+                                 return_pipe[2] = PIPE_EBADF,
+                                 json_pipe[2] = PIPE_EBADF;
         _cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL;
         _cleanup_free_ char *buf = NULL;
         int r;
index 1be22a62c6ed1a2069c69d30e5bb72e6545922dd..5c9dd61898a63efb5b7c0d21ee6e1821f83982d0 100644 (file)
@@ -1624,7 +1624,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
 }
 
 static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
-        _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
         _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, rootfd = -EBADF;
         char buf[SD_ID128_UUID_STRING_MAX];
         pid_t pid, child;
index eb1a5bb59fdb394a870c335311e68c5ce67c240d..3224286186c8f5c69fdc1a0e165089ecc1b13c67 100644 (file)
@@ -683,7 +683,7 @@ int loop_device_make_by_path_memory(
 }
 
 static LoopDevice* loop_device_free(LoopDevice *d) {
-        _cleanup_close_ int control = -1;
+        _cleanup_close_ int control = -EBADF;
         int r;
 
         if (!d)
index 80cf87526ee0a45b5a248d57a85bd65b1806dcec..603eb7b780f778e8cac43d92187d2eb8b1e9c7ed 100644 (file)
@@ -806,7 +806,7 @@ static int mount_in_namespace(
                 const MountOptions *options,
                 bool is_image) {
 
-        _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
         _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, chased_src_fd = -EBADF;
         char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
         bool mount_slave_created = false, mount_slave_mounted = false,
index 831cc1dce04e1e5f05c457f1e45d54a65285ce03..6ed35a3ca9983733206f40a2d037952b453ce56c 100644 (file)
@@ -83,7 +83,7 @@ static int no_quit_on_interrupt(int exe_name_fd, const char *less_opts) {
 }
 
 void pager_open(PagerFlags flags) {
-        _cleanup_close_pair_ int fd[2] = { -EBADF, -EBADF }, exe_name_pipe[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int fd[2] = PIPE_EBADF, exe_name_pipe[2] = PIPE_EBADF;
         _cleanup_strv_free_ char **pager_args = NULL;
         _cleanup_free_ char *l = NULL;
         const char *pager, *less_opts;
index d73bdbdc1ea6e798a6b4286da4b1149028bd69a3..821049e667573d6602a03445417e41293671b28d 100644 (file)
@@ -487,8 +487,8 @@ static int add_connection_socket(Context *context, int fd) {
                .context = context,
                .server_fd = fd,
                .client_fd = -EBADF,
-               .server_to_client_buffer = { -EBADF, -EBADF },
-               .client_to_server_buffer = { -EBADF, -EBADF },
+               .server_to_client_buffer = PIPE_EBADF,
+               .client_to_server_buffer = PIPE_EBADF,
         };
 
         r = set_ensure_put(&context->connections, NULL, c);
index 3d519ccb8d3d1d84450d0fc76ffda9d991979864..133bce663142048d01d228342b55af0c529c6fc5 100644 (file)
@@ -426,12 +426,32 @@ static int find_paths_to_edit(
         _cleanup_(hashmap_freep) Hashmap *cached_name_map = NULL, *cached_id_map = NULL;
         _cleanup_(edit_file_free_all) EditFile *edit_files = NULL;
         _cleanup_(lookup_paths_free) LookupPaths lp = {};
+        _cleanup_free_ char *drop_in_alloc = NULL, *suffix = NULL;
+        const char *drop_in;
         size_t n_edit_files = 0;
         int r;
 
         assert(names);
         assert(ret_edit_files);
 
+        if (isempty(arg_drop_in))
+                drop_in = "override.conf";
+        else if (!endswith(arg_drop_in, ".conf")) {
+                drop_in_alloc = strjoin(arg_drop_in, ".conf");
+                if (!drop_in_alloc)
+                        return log_oom();
+
+                drop_in = drop_in_alloc;
+        } else
+                drop_in = arg_drop_in;
+
+        if (!filename_is_valid(drop_in))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid drop-in file name '%s'.", drop_in);
+
+        suffix = strjoin(".d/", drop_in);
+        if (!suffix)
+                return log_oom();
+
         r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
         if (r < 0)
                 return r;
@@ -468,7 +488,7 @@ static int find_paths_to_edit(
                         r = unit_file_create_new(
                                         &lp,
                                         *name,
-                                        arg_full ? NULL : ".d/override.conf",
+                                        arg_full ? NULL : suffix,
                                         NULL,
                                         edit_files + n_edit_files);
                 } else {
@@ -508,7 +528,7 @@ static int find_paths_to_edit(
                                 r = unit_file_create_new(
                                                 &lp,
                                                 unit_name,
-                                                ".d/override.conf",
+                                                suffix,
                                                 unit_paths,
                                                 edit_files + n_edit_files);
                         }
index 42a5b086c37b7e34677e70236d9f5d44d5e191ed..224e831b99f586ffc06f1ddd24610738a35167c7 100644 (file)
@@ -299,7 +299,7 @@ int verb_start(int argc, char *argv[], void *userdata) {
                                 mode = "isolate";
                                 suffix = ".target";
                         } else if (!arg_marked) {
-                                /* A command in style of "systemctl start <unit1> <unit2> â€¦", "sysemctl stop <unit1> <unit2> â€¦" and so on */
+                                /* A command in style of "systemctl start <unit1> <unit2> â€¦", "systemctl stop <unit1> <unit2> â€¦" and so on */
                                 method = verb_to_method(argv[0]);
                                 job_type = verb_to_job_type(argv[0]);
                                 mode = arg_job_mode();
index d13c7867e228e844b46227a13fa28924eb5dec5e..ae9b95620e59ea8fd6fca51f2976bb1d18d0174f 100644 (file)
@@ -118,6 +118,7 @@ TimestampStyle arg_timestamp_style = TIMESTAMP_PRETTY;
 bool arg_read_only = false;
 bool arg_mkdir = false;
 bool arg_marked = false;
+const char *arg_drop_in = NULL;
 
 STATIC_DESTRUCTOR_REGISTER(arg_types, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_states, strv_freep);
@@ -131,6 +132,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_reboot_argument, unsetp);
 STATIC_DESTRUCTOR_REGISTER(arg_host, unsetp);
 STATIC_DESTRUCTOR_REGISTER(arg_boot_loader_entry, unsetp);
 STATIC_DESTRUCTOR_REGISTER(arg_clean_what, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_drop_in, unsetp);
 
 static int systemctl_help(void) {
         _cleanup_free_ char *link = NULL;
@@ -316,6 +318,7 @@ static int systemctl_help(void) {
                "     --read-only         Create read-only bind mount\n"
                "     --mkdir             Create directory before mounting, if missing\n"
                "     --marked            Restart/reload previously marked units\n"
+               "     --drop-in=NAME      Edit unit files using the specified drop-in file name\n"
                "\nSee the %2$s for details.\n",
                program_invocation_short_name,
                link,
@@ -438,6 +441,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 ARG_MKDIR,
                 ARG_MARKED,
                 ARG_NO_WARN,
+                ARG_DROP_IN,
         };
 
         static const struct option options[] = {
@@ -500,6 +504,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 { "read-only",           no_argument,       NULL, ARG_READ_ONLY           },
                 { "mkdir",               no_argument,       NULL, ARG_MKDIR               },
                 { "marked",              no_argument,       NULL, ARG_MARKED              },
+                { "drop-in",             required_argument, NULL, ARG_DROP_IN             },
                 {}
         };
 
@@ -936,6 +941,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         arg_no_warn = true;
                         break;
 
+                case ARG_DROP_IN:
+                        arg_drop_in = optarg;
+                        break;
+
                 case '.':
                         /* Output an error mimicking getopt, and print a hint afterwards */
                         log_error("%s: invalid option -- '.'", program_invocation_name);
index 1a7a6e28d39c961c7320bc8c8c3fe18566e4f399..9f9b8faa6963e36125a73f73f7729c378e12dafb 100644 (file)
@@ -97,6 +97,7 @@ extern TimestampStyle arg_timestamp_style;
 extern bool arg_read_only;
 extern bool arg_mkdir;
 extern bool arg_marked;
+extern const char *arg_drop_in;
 
 static inline const char* arg_job_mode(void) {
         return _arg_job_mode ?: "replace";
index 759c81a4f0b8bd9ba33ce9ca636f491dd157e35a..04d425299d2c5ee6983524f4ffd8902fdbbc4ab7 100644 (file)
@@ -242,7 +242,7 @@ static int download_manifest(
                 size_t *ret_size) {
 
         _cleanup_free_ char *buffer = NULL, *suffixed_url = NULL;
-        _cleanup_(close_pairp) int pfd[2] = { -EBADF, -EBADF };
+        _cleanup_(close_pairp) int pfd[2] = PIPE_EBADF;
         _cleanup_fclose_ FILE *manifest = NULL;
         size_t size = 0;
         pid_t pid;
@@ -282,7 +282,7 @@ static int download_manifest(
 
                 pfd[0] = safe_close(pfd[0]);
 
-                r = rearrange_stdio(-1, pfd[1], STDERR_FILENO);
+                r = rearrange_stdio(-EBADF, pfd[1], STDERR_FILENO);
                 if (r < 0) {
                         log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
                         _exit(EXIT_FAILURE);
index b68a7d6d5ac31d3a56fd4fe83d0199eb8db841ea..6e197b964dbbf9fb3327032360e3aafb503c6aee 100644 (file)
@@ -251,7 +251,7 @@ static int load_group_database(void) {
 static int make_backup(const char *target, const char *x) {
         _cleanup_(unlink_and_freep) char *dst_tmp = NULL;
         _cleanup_fclose_ FILE *dst = NULL;
-        _cleanup_close_ int src = -1;
+        _cleanup_close_ int src = -EBADF;
         const char *backup;
         struct stat st;
         int r;
@@ -2093,7 +2093,7 @@ static int run(int argc, char *argv[]) {
         _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
         _cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
 #endif
-        _cleanup_close_ int lock = -1;
+        _cleanup_close_ int lock = -EBADF;
         Item *i;
         int r;
 
index 339482a438241cd0bd9e021c82872d40dab46a1a..f5ec47cb3c8a6216a1331e1c3a7a12601b7fef3c 100644 (file)
@@ -170,7 +170,7 @@ _unused_ static void test_compress_stream(int flag,
                                           decompress_stream_t decompress,
                                           const char *srcfile) {
 
-        _cleanup_close_ int src = -1, dst = -1, dst2 = -1;
+        _cleanup_close_ int src = -EBADF, dst = -EBADF, dst2 = -EBADF;
         _cleanup_(unlink_tempfilep) char
                 pattern[] = "/tmp/systemd-test.compressed.XXXXXX",
                 pattern2[] = "/tmp/systemd-test.compressed.XXXXXX";
index 2568b9b384e0e7f6a817a8ee327745acce8d31e1..5a4af174fe1c9854a058a232ee6c328f20a2da90 100644 (file)
@@ -78,7 +78,7 @@ TEST(copy_tree_replace_file) {
 
 TEST(copy_tree_replace_dirs) {
         _cleanup_(rm_rf_physical_and_freep) char *srcp = NULL, *dstp = NULL;
-        _cleanup_close_ int src = -1, dst = -1;
+        _cleanup_close_ int src = -EBADF, dst = -EBADF;
 
         /* Create the random source/destination directories */
         assert_se((src = mkdtemp_open(NULL, 0, &srcp)) >= 0);
@@ -257,7 +257,7 @@ TEST(copy_tree) {
 }
 
 TEST(copy_bytes) {
-        _cleanup_close_pair_ int pipefd[2] = {-1, -1};
+        _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
         _cleanup_close_ int infd = -EBADF;
         int r, r2;
         char buf[1024], buf2[1024];
index d69648842e0889543d981d83a41f8586b74cdb50..c0febec2080d77ebcc4625fbafddaebdfe24e75e 100644 (file)
@@ -81,7 +81,7 @@ static void assert_equal_fd(int fd1, int fd2) {
 
 TEST(copy_data_fd) {
         _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
-        _cleanup_(close_pairp) int sfd[2] = { -EBADF, -EBADF };
+        _cleanup_(close_pairp) int sfd[2] = PIPE_EBADF;
         _cleanup_(sigkill_waitp) pid_t pid = -1;
         int r;
 
index 51c3e755e04efe8618c272ae6319eea2dcac743f..7fe78207e0163d26a19973c3696dbc32948f5023 100644 (file)
@@ -559,7 +559,7 @@ static int find_libraries(const char *exec, char ***ret) {
         _cleanup_(sd_event_source_unrefp) sd_event_source *sigchld_source = NULL;
         _cleanup_(sd_event_source_unrefp) sd_event_source *stdout_source = NULL;
         _cleanup_(sd_event_source_unrefp) sd_event_source *stderr_source = NULL;
-        _cleanup_close_pair_ int outpipe[2] = {-1, -1}, errpipe[2] = {-1, -1};
+        _cleanup_close_pair_ int outpipe[2] = PIPE_EBADF, errpipe[2] = PIPE_EBADF;
         _cleanup_strv_free_ char **libraries = NULL;
         _cleanup_free_ char *result = NULL;
         pid_t pid;
@@ -576,7 +576,7 @@ static int find_libraries(const char *exec, char ***ret) {
         r = safe_fork("(spawn-ldd)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid);
         assert_se(r >= 0);
         if (r == 0) {
-                if (rearrange_stdio(-1, TAKE_FD(outpipe[1]), TAKE_FD(errpipe[1])) < 0)
+                if (rearrange_stdio(-EBADF, TAKE_FD(outpipe[1]), TAKE_FD(errpipe[1])) < 0)
                         _exit(EXIT_FAILURE);
 
                 (void) close_all_fds(NULL, 0);
index f08d0f0dd47adf422686aa99902a9a44af078532..1ca9ef8bbd7a2ee5e871f2643c06745deca63f72 100644 (file)
@@ -133,7 +133,7 @@ TEST(rearrange_stdio) {
 
                 safe_close(STDERR_FILENO); /* Let's close an fd < 2, to make it more interesting */
 
-                assert_se(rearrange_stdio(-1, -1, -1) >= 0);
+                assert_se(rearrange_stdio(-EBADF, -EBADF, -EBADF) >= 0);
 
                 assert_se(fd_get_path(STDIN_FILENO, &path) >= 0);
                 assert_se(path_equal(path, "/dev/null"));
@@ -170,7 +170,7 @@ TEST(rearrange_stdio) {
                 assert_se(read(0, buffer, sizeof(buffer)) == 6);
                 assert_se(memcmp(buffer, "foobar", 6) == 0);
 
-                assert_se(rearrange_stdio(-1, 1, 2) >= 0);
+                assert_se(rearrange_stdio(-EBADF, 1, 2) >= 0);
                 assert_se(write(1, "a", 1) < 0 && errno == ENOSPC);
                 assert_se(write(2, "y", 1) == 1);
                 assert_se(read(3, buffer, sizeof(buffer)) == 1);
@@ -532,7 +532,7 @@ TEST(fd_reopen_condition) {
 
 TEST(take_fd) {
         _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
-        int array[2] = { -EBADF, -EBADF }, i = 0;
+        int array[2] = PIPE_EBADF, i = 0;
 
         assert_se(fd1 == -EBADF);
         assert_se(fd2 == -EBADF);
index 2009c0f972b9faf7614b7514cf39e9e08c77ab61..9d9c7198756697d5041c578729e489d6ca645204 100644 (file)
@@ -877,7 +877,7 @@ TEST(read_nul_string) {
 
 TEST(read_full_file_socket) {
         _cleanup_(rm_rf_physical_and_freep) char *z = NULL;
-        _cleanup_close_ int listener = -1;
+        _cleanup_close_ int listener = -EBADF;
         _cleanup_free_ char *data = NULL, *clientname = NULL;
         union sockaddr_union sa;
         const char *j, *jj;
index be09f71e75233f609923c300a113fc3a4bfbb0a3..72155127c1e90563378ee29a187d2cefe10f1c32 100644 (file)
@@ -83,7 +83,7 @@ TEST(tmpdir) {
 }
 
 static void test_shareable_ns(unsigned long nsflag) {
-        _cleanup_close_pair_ int s[2] = { -EBADF, -EBADF };
+        _cleanup_close_pair_ int s[2] = PIPE_EBADF;
         pid_t pid1, pid2, pid3;
         int r, n = 0;
         siginfo_t si;
index 8d0e45203827756599963a16c583de083016ad03..8d5b24e5025fc2c5bb3e188bc26018befec7d912 100644 (file)
@@ -66,7 +66,7 @@ TEST(read_one_char) {
 
 TEST(getttyname_malloc) {
         _cleanup_free_ char *ttyname = NULL;
-        _cleanup_close_ int master = -1;
+        _cleanup_close_ int master = -EBADF;
 
         assert_se((master = posix_openpt(O_RDWR|O_NOCTTY)) >= 0);
         assert_se(getttyname_malloc(master, &ttyname) >= 0);
index 58112591831b4a488ea7c1a25784a86e6c69bcc2..e961887fecb20d0b49a18b91704dbb8ac594274f 100644 (file)
@@ -191,7 +191,7 @@ int main(int argc, char *argv[]) {
         _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
         _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
         _cleanup_(sd_event_unrefp) sd_event *e = NULL;
-        _cleanup_(close_pairp) int block_fds[2] = { -EBADF, -EBADF };
+        _cleanup_(close_pairp) int block_fds[2] = PIPE_EBADF;
         pthread_t t;
         const char *sp;
 
index f70873ff6eb7e2eb44a0f72e28aff47bd3c3d725..b26de6ecd6b98461b2277118075624ef3a0a8ac6 100644 (file)
@@ -1113,7 +1113,7 @@ int manager_new(Manager **ret) {
 
                 .connection_retry_usec = DEFAULT_CONNECTION_RETRY_USEC,
 
-                .server_socket = -1,
+                .server_socket = -EBADF,
 
                 .ratelimit = (const RateLimit) {
                         RATELIMIT_INTERVAL_USEC,
index 9166e1f9ecd09c7c349268701e21101609ed7e06..46d2307ad315407eaab14e345e032035abc5c199 100644 (file)
@@ -338,7 +338,7 @@ static int process_and_watch_password_files(bool watch) {
         };
 
         _unused_ _cleanup_close_ int tty_block_fd = -EBADF;
-        _cleanup_close_ int notify = -1, signal_fd = -EBADF;
+        _cleanup_close_ int notify = -EBADF, signal_fd = -EBADF;
         struct pollfd pollfd[_FD_MAX];
         sigset_t mask;
         int r;
index 625c4faad83813a826e14efb588aeb09aa7db71e..24180f9418fe0260b51b1f2092c0bdc7eec68592 100644 (file)
@@ -46,7 +46,7 @@ struct UdevCtrl {
 };
 
 int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd) {
-        _cleanup_close_ int sock = -1;
+        _cleanup_close_ int sock = -EBADF;
         UdevCtrl *uctrl;
 
         assert(ret);
@@ -64,7 +64,7 @@ int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd) {
         *uctrl = (UdevCtrl) {
                 .n_ref = 1,
                 .sock = fd >= 0 ? fd : TAKE_FD(sock),
-                .sock_connect = -1,
+                .sock_connect = -EBADF,
                 .bound = fd >= 0,
         };
 
@@ -217,7 +217,7 @@ static int udev_ctrl_connection_event_handler(sd_event_source *s, int fd, uint32
 
 static int udev_ctrl_event_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         UdevCtrl *uctrl = ASSERT_PTR(userdata);
-        _cleanup_close_ int sock = -1;
+        _cleanup_close_ int sock = -EBADF;
         struct ucred ucred;
         int r;
 
index 63be5275e4b418ce83ccce15e55c83bc2335f4ac..7a59e7c759cb20b6184ce2d2a542a4943c29e282 100644 (file)
@@ -763,7 +763,7 @@ int udev_event_spawn(
                 size_t ressize,
                 bool *ret_truncated) {
 
-        _cleanup_close_pair_ int outpipe[2] = {-1, -1}, errpipe[2] = {-1, -1};
+        _cleanup_close_pair_ int outpipe[2] = PIPE_EBADF, errpipe[2] = PIPE_EBADF;
         _cleanup_strv_free_ char **argv = NULL;
         char **envp = NULL;
         Spawn spawn;
@@ -815,7 +815,7 @@ int udev_event_spawn(
                 return log_device_error_errno(event->dev, r,
                                               "Failed to fork() to execute command '%s': %m", cmd);
         if (r == 0) {
-                if (rearrange_stdio(-1, TAKE_FD(outpipe[WRITE_END]), TAKE_FD(errpipe[WRITE_END])) < 0)
+                if (rearrange_stdio(-EBADF, TAKE_FD(outpipe[WRITE_END]), TAKE_FD(errpipe[WRITE_END])) < 0)
                         _exit(EXIT_FAILURE);
 
                 (void) close_all_fds(NULL, 0);
index 4942c852a0b19faf9088f2a20913944c0f0ee3cb..28b76bfbab2c19b4805fa0435ad39d736fb27b19 100644 (file)
@@ -1848,7 +1848,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent) {
 
         *manager = (Manager) {
                 .inotify_fd = -EBADF,
-                .worker_watch = { -EBADF, -EBADF },
+                .worker_watch = PIPE_EBADF,
                 .cgroup = TAKE_PTR(cgroup),
         };