]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #12441 from ssahani/bridge-fdb
authorChris Down <chris@chrisdown.name>
Fri, 3 May 2019 13:50:47 +0000 (09:50 -0400)
committerGitHub <noreply@github.com>
Fri, 3 May 2019 13:50:47 +0000 (09:50 -0400)
networkd: add support for bridge fdb destination address.

56 files changed:
coccinelle/const-strlen.disabled [moved from coccinelle/const-strlen.cocci with 80% similarity]
coccinelle/debug-logging.cocci
coccinelle/dup-fcntl.cocci
coccinelle/empty-to-null.cocci
coccinelle/flags-set.cocci
coccinelle/in_set.cocci
coccinelle/isempty.cocci
coccinelle/memzero.cocci
coccinelle/mfree_return.cocci
coccinelle/not_in_set.cocci
coccinelle/run-coccinelle.sh
coccinelle/strempty.cocci
coccinelle/synthetic-errno.cocci
coccinelle/systemd-definitions.iso [new file with mode: 0644]
coccinelle/take-fd.cocci
man/vtable-example.c
meson.build
src/basic/alloc-util.c
src/basic/rm-rf.c
src/basic/umask-util.h
src/core/dbus-socket.c
src/core/mount.c
src/coredump/coredump.c
src/fstab-generator/fstab-generator.c
src/fuzz/meson.build
src/import/importd.c
src/journal-remote/journal-remote.c
src/libsystemd-network/network-internal.c
src/libsystemd/sd-bus/bus-message.c
src/login/logind-core.c
src/login/logind-user.c
src/mount/mount-tool.c
src/network/networkd-dhcp6.c
src/network/networkd-radv.c
src/nspawn/meson.build
src/shared/dns-domain.c
src/shared/efivars.c
src/shared/journal-importer.c
src/shared/libmount-util.h
src/shared/machine-image.c
src/shared/mount-util.c
src/shared/switch-root.c
src/shutdown/umount.c
src/test/meson.build
src/test/test-libmount.c
src/test/test-libudev.c
src/test/test-nss.c
src/test/test-umask-util.c [new file with mode: 0644]
src/timesync/timesyncd-manager.c
src/tmpfiles/tmpfiles.c
src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/scsi_id/scsi_id.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-usb_id.c
src/udev/v4l_id/v4l_id.c

similarity index 80%
rename from coccinelle/const-strlen.cocci
rename to coccinelle/const-strlen.disabled
index 38bf9b118fd5d01117edb2046ee0eaf1d49742cd..30a6e5a88ed80308e9a4ffcb27e310a0dbdb6310 100644 (file)
@@ -1,8 +1,12 @@
 @@
 constant s;
 @@
+(
+#define STRLEN
+&
 - sizeof(s)-1
 + STRLEN(s)
+)
 @@
 constant s;
 @@
index 9084cf773bf685af625e7861aed76305899c97a0..a679dab01150a38b212c61b1c53d38177cc2e694 100644 (file)
@@ -1,8 +1,16 @@
 @@
 @@
+(
+#define DEBUG_LOGGING
+&
 - _unlikely_(log_get_max_level() >= LOG_DEBUG)
 + DEBUG_LOGGING
+)
 @@
 @@
+(
+#define DEBUG_LOGGING
+&
 - log_get_max_level() >= LOG_DEBUG
 + DEBUG_LOGGING
+)
index ef1356428223aaf2d8378cd86f0dc2305613214b..8b133b3a24f6547062dd1c0d803dace33c94cd6a 100644 (file)
@@ -1,5 +1,7 @@
 @@
+/* We want to stick with dup() in test-fd-util.c */
+position p : script:python() { p[0].file != "src/test/test-fd-util.c" };
 expression fd;
 @@
-- dup(fd)
+- dup@p(fd)
 + fcntl(fd, F_DUPFD, 3)
index fbc75b9c343ca49688435e34e9cef32c35d81ff5..bc6c656e798a22cfde36457facb9c85042740f64 100644 (file)
@@ -1,5 +1,8 @@
 @@
+/* Avoid running this transformation on the empty_to_null function itself */
+position p : script:python() { p[0].current_element != "empty_to_null" };
 expression s;
 @@
-- isempty(s) ? NULL : s
+
+- isempty@p(s) ? NULL : s
 + empty_to_null(s)
index 1a70717e76cb855ba75db28be584496c53e6f627..73966b02e5d27861900299f0a5adecd4f1fa0db2 100644 (file)
@@ -1,15 +1,16 @@
 @@
+/* Disable this transformation for the securebits-util.h, as it makes
+ * the expression there confusing. */
+position p : script:python() { p[0].file != "src/shared/securebits-util.h" };
 expression x, y;
 @@
-- ((x) & (y)) == (y)
+(
+- ((x@p) & (y)) == (y)
 + FLAGS_SET(x, y)
-@@
-expression x, y;
-@@
-- (x & (y)) == (y)
+|
+- (x@p & (y)) == (y)
 + FLAGS_SET(x, y)
-@@
-expression x, y;
-@@
-- ((x) & y) == y
+|
+- ((x@p) & y) == y
 + FLAGS_SET(x, y)
+)
index 12d5475fd91617d76883bcfe6e27db793c49027b..2c9b94ceb67438418efdbc5e42604a598dc1caa6 100644 (file)
@@ -1,54 +1,37 @@
 @@
 expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
-@@
+/* Exclude JsonVariant * from the transformation, as it can't work with the
+ * current version of the IN_SET macro */
+typedef JsonVariant;
+type T != JsonVariant*;
+constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
+@@
+
+(
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8 || e == n9
 + IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7, n8;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8
 + IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7
 + IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6
 + IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5
 + IN_SET(e, n0, n1, n2, n3, n4, n5)
-@@
-expression e;
-constant n0, n1, n2, n3, n4;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3 || e == n4
 + IN_SET(e, n0, n1, n2, n3, n4)
-@@
-expression e;
-constant n0, n1, n2, n3;
-@@
+|
 - e == n0 || e == n1 || e == n2 || e == n3
 + IN_SET(e, n0, n1, n2, n3)
-@@
-expression e;
-constant n0, n1, n2;
-@@
+|
 - e == n0 || e == n1 || e == n2
 + IN_SET(e, n0, n1, n2)
-@@
-expression e;
-constant n0, n1;
-@@
+|
 - e == n0 || e == n1
 + IN_SET(e, n0, n1)
+)
index d8d52758892e8e0735d256bc3ae30ccec906b6e3..e0a9f07ca6d0107524d41afb445d3c5f4f82bb9d 100644 (file)
@@ -1,60 +1,42 @@
 @@
+/* Disable this transformation for the test-string-util.c */
+position p : script:python() { p[0].file != "src/test/test-string-util.c" };
 expression s;
 @@
-- strv_length(s) == 0
+(
+- strv_length@p(s) == 0
 + strv_isempty(s)
-@@
-expression s;
-@@
-- strv_length(s) <= 0
+|
+- strv_length@p(s) <= 0
 + strv_isempty(s)
-@@
-expression s;
-@@
-- strv_length(s) > 0
+|
+- strv_length@p(s) > 0
 + !strv_isempty(s)
-@@
-expression s;
-@@
-- strv_length(s) != 0
+|
+- strv_length@p(s) != 0
 + !strv_isempty(s)
-@@
-expression s;
-@@
-- strlen(s) == 0
+|
+- strlen@p(s) == 0
 + isempty(s)
-@@
-expression s;
-@@
-- strlen(s) <= 0
+|
+- strlen@p(s) <= 0
 + isempty(s)
-@@
-expression s;
-@@
-- strlen(s) > 0
+|
+- strlen@p(s) > 0
 + !isempty(s)
-@@
-expression s;
-@@
-- strlen(s) != 0
+|
+- strlen@p(s) != 0
 + !isempty(s)
-@@
-expression s;
-@@
-- strlen_ptr(s) == 0
+|
+- strlen_ptr@p(s) == 0
 + isempty(s)
-@@
-expression s;
-@@
-- strlen_ptr(s) <= 0
+|
+- strlen_ptr@p(s) <= 0
 + isempty(s)
-@@
-expression s;
-@@
-- strlen_ptr(s) > 0
+|
+- strlen_ptr@p(s) > 0
 + !isempty(s)
-@@
-expression s;
-@@
-- strlen_ptr(s) != 0
+|
+- strlen_ptr@p(s) != 0
 + !isempty(s)
+)
index ebdc3f6a2a9493440fc66cc080a80a74ecaa7439..8198cc84b4cd4ad854f72ef25c0b82c2a6ced964 100644 (file)
@@ -21,10 +21,18 @@ expression s;
 @@
 expression a, b;
 @@
+(
+#define memzero
+&
 - memset(a, 0, b)
 + memzero(a, b)
+)
 @@
 expression a, b;
 @@
+(
+#define memzero
+&
 - bzero(a, b)
 + memzero(a, b)
+)
index 8119fe07f29f738f9749f8f46e63212fca054681..15e6c7d566bd08281e841892b3383500871da64f 100644 (file)
@@ -1,6 +1,8 @@
 @@
-expression p;
+/* Avoid running this transformation on the mfree function itself */
+position p : script:python() { p[0].current_element != "mfree" };
+expression e;
 @@
-- free(p);
+- free@p(e);
 - return NULL;
-+ return mfree(p);
++ return mfree(e);
index 7cf98500cd425369f6035ab259ffc49a5d37271e..aed2c3490c4f75485c2d5672058b285073322a3a 100644 (file)
@@ -1,54 +1,34 @@
 @@
 expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
+typedef JsonVariant;
+type T != JsonVariant*;
+constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
 @@
+(
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9
 + !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7, n8;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8
 + !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6, n7;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7
 + !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5, n6;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6
 + !IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
-@@
-expression e;
-constant n0, n1, n2, n3, n4, n5;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5
 + !IN_SET(e, n0, n1, n2, n3, n4, n5)
-@@
-expression e;
-constant n0, n1, n2, n3, n4;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3 && e != n4
 + !IN_SET(e, n0, n1, n2, n3, n4)
-@@
-expression e;
-constant n0, n1, n2, n3;
-@@
+|
 - e != n0 && e != n1 && e != n2 && e != n3
 + !IN_SET(e, n0, n1, n2, n3)
-@@
-expression e;
-constant n0, n1, n2;
-@@
+|
 - e != n0 && e != n1 && e != n2
 + !IN_SET(e, n0, n1, n2)
-@@
-expression e;
-constant n0, n1;
-@@
+|
 - e != n0 && e != n1
 + !IN_SET(e, n0, n1)
+)
index 520de0ac4215f012f644cefc78687133621d4b2e..be80a76a5f3b50cb0c60dd96e8d5bd3176541d4c 100755 (executable)
@@ -1,9 +1,25 @@
 #!/bin/bash -e
 
+# Exclude following paths from the Coccinelle transformations
+EXCLUDED_PATHS=(
+    "src/boot/efi/*"
+    "src/shared/linux/*"
+    "src/basic/linux/*"
+    # Symlinked to test-bus-vtable-cc.cc, which causes issues with the IN_SET macro
+    "src/libsystemd/sd-bus/test-bus-vtable.c"
+)
+
 top="$(git rev-parse --show-toplevel)"
-files="$(git ls-files ':/*.[ch]')"
+iso_defs="$top/coccinelle/systemd-definitions.iso"
 args=
 
+# Create an array from files tracked by git...
+mapfile -t files < <(git ls-files ':/*.[ch]')
+# ...and filter everything that matches patterns from EXCLUDED_PATHS
+for excl in "${EXCLUDED_PATHS[@]}"; do
+    files=(${files[@]//$excl})
+done
+
 case "$1" in
     -i)
         args="$args --in-place"
@@ -21,7 +37,7 @@ for SCRIPT in ${@-$top/coccinelle/*.cocci} ; do
     TMPFILE=`mktemp`
     echo "+ spatch --sp-file $SCRIPT $args ..."
     parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \
-             spatch --sp-file $SCRIPT $args ::: $files \
+             spatch --iso-file $iso_defs --sp-file $SCRIPT $args ::: "${files[@]}" \
              2>"$TMPFILE" || cat "$TMPFILE"
     echo -e "--x-- Processed $SCRIPT --x--\n"
 done
index 13ceb338f199dad900efa29f5f94d97db762a5e3..7901da3652ce7bb4c9d023e2ffaf7cb84b15ac5d 100644 (file)
@@ -1,48 +1,60 @@
 @@
+/* Avoid running this transformation on the strempty function itself */
+position p : script:python() { p[0].current_element != "strempty" };
 expression s;
 @@
-- s ?: ""
+(
+- s@p ?: ""
 + strempty(s)
-@@
-expression s;
-@@
-- s ? s : ""
+|
+- s@p ? s : ""
 + strempty(s)
+)
+
 @@
+position p : script:python() { p[0].current_element != "strempty" };
 expression s;
 @@
-- if (!s)
+- if (!s@p)
 -         s = "";
 + s = strempty(s);
+
 @@
+position p : script:python() { p[0].current_element != "strnull" };
 expression s;
 @@
-- s ?: "(null)"
+(
+- s@p ?: "(null)"
 + strnull(s)
-@@
-expression s;
-@@
-- s ? s : "(null)"
+|
+- s@p ? s : "(null)"
 + strnull(s)
+)
+
 @@
+position p : script:python() { p[0].current_element != "strnull" };
 expression s;
 @@
-- if (!s)
+- if (!s@p)
 -         s = "(null)";
 + s = strnull(s);
+
 @@
+position p : script:python() { p[0].current_element != "strna" };
 expression s;
 @@
-- s ?: "n/a"
+(
+- s@p ?: "n/a"
 + strna(s)
-@@
-expression s;
-@@
-- s ? s : "n/a"
+|
+- s@p ? s : "n/a"
 + strna(s)
+)
+
 @@
+position p : script:python() { p[0].current_element != "strna" };
 expression s;
 @@
-- if (!s)
+- if (!s@p)
 -         s = "n/a";
 + s = strna(s);
index 645bfc945f4b4b0e426ec72b72aca8529fb0a347..3ddb69cb4cff498ab310f6ffd9eba2504eef6192 100644 (file)
@@ -2,9 +2,15 @@
 expression e;
 expression list args;
 @@
+(
+/* Ignore one specific case in src/shared/bootspec.c where we want to stick
+ * with the log_debug() + return pattern */
+log_debug("Found no default boot entry :(");
+|
 - log_debug(args);
 - return -e;
 + return log_debug_errno(SYNTHETIC_ERRNO(e), args);
+)
 @@
 expression e;
 expression list args;
diff --git a/coccinelle/systemd-definitions.iso b/coccinelle/systemd-definitions.iso
new file mode 100644 (file)
index 0000000..92db763
--- /dev/null
@@ -0,0 +1,20 @@
+/* Statement isomorphisms - replace explicit checks against NULL with a
+ * shorter variant, which relies on C's downgrade-to-bool feature.
+ * The expression metavariables should be declared as pointers, however,
+ * that doesn't work well with complex expressions like:
+ * if (UNIT(p)->default_dependencies != NULL)
+ */
+
+Statement
+@@
+expression X;
+statement S;
+@@
+if (X == NULL) S => if (!X) S
+
+Statement
+@@
+expression X;
+statement S;
+@@
+if (X != NULL) S => if (X) S
index ba242483cd50c7d9f30081fb46fb85af02187303..f7124e789651cfe6db9571c63527cf11839bb8d7 100644 (file)
@@ -6,8 +6,15 @@ expression q;
 - q = -1;
 - return p;
 + return TAKE_FD(q);
+
+/* The ideal solution would use 'local idexpression' to avoid matching errno,
+ * which is a global variable. However, 'idexpression' nor 'identifier'
+ * would match, for example, "x->fd", which is considered 'expression' in
+ * the SmPL grammar
+ */
 @@
-expression p, q;
+expression p != errno;
+expression q;
 @@
 - p = q;
 - q = -1;
index a2a6cd18d7527b057382320e719567678290fb43..98c20eec5227d191fe974a1728dc250725900493 100644 (file)
@@ -59,7 +59,7 @@ int main(int argc, char **argv) {
                                  vtable,
                                  &object));
 
-  while (true) {
+  for (;;) {
     check(sd_bus_wait(bus, UINT64_MAX));
     check(sd_bus_process(bus, NULL));
   }
index 33fff909b419018990d3528a9ed7f5bb9ccc7895..24ef643d44e92a399cd6e1fb8c2cb3df35de6713 100644 (file)
@@ -2470,6 +2470,7 @@ exe = executable('systemd-mount',
                  'src/mount/mount-tool.c',
                  include_directories : includes,
                  link_with : [libshared],
+                 dependencies: [libmount],
                  install_rpath : rootlibexecdir,
                  install : true)
 public_programs += exe
index 1e4ee722f204c4748ae916aa485f8e102c245570..f4bd33f4e014246a9c9e68f8f75e0023541a967d 100644 (file)
@@ -1,6 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#include <malloc.h>
 #include <stdint.h>
 #include <string.h>
 
@@ -65,7 +64,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
                 return NULL;
 
         *p = q;
-        *allocated = _unlikely_(size == 0) ? newalloc : malloc_usable_size(q) / size;
+        *allocated = newalloc;
         return q;
 }
 
index acc0f88cd24a6918e369db701717b5c8db86d18e..b751933c83b4c9974d807d9059a19b9278b3a813 100644 (file)
@@ -33,8 +33,8 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
 
         assert(fd >= 0);
 
-        /* This returns the first error we run into, but nevertheless
-         * tries to go on. This closes the passed fd. */
+        /* This returns the first error we run into, but nevertheless tries to go on. This closes the passed
+         * fd, in all cases, including on failure.. */
 
         if (!(flags & REMOVE_PHYSICAL)) {
 
@@ -85,7 +85,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
                         is_dir = de->d_type == DT_DIR;
 
                 if (is_dir) {
-                        int subdir_fd;
+                        _cleanup_close_ int subdir_fd = -1;
 
                         /* if root_dev is set, remove subdirectories only if device is same */
                         if (root_dev && st.st_dev != root_dev->st_dev)
@@ -104,13 +104,10 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
                                 if (ret == 0 && r != -ENOENT)
                                         ret = r;
 
-                                safe_close(subdir_fd);
                                 continue;
                         }
-                        if (r) {
-                                safe_close(subdir_fd);
+                        if (r > 0)
                                 continue;
-                        }
 
                         if ((flags & REMOVE_SUBVOLUME) && st.st_ino == 256) {
 
@@ -122,24 +119,18 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
                                                 if (ret == 0)
                                                         ret = r;
 
-                                                safe_close(subdir_fd);
                                                 continue;
                                         }
 
-                                        /* ENOTTY, then it wasn't a
-                                         * btrfs subvolume, continue
-                                         * below. */
-                                } else {
+                                        /* ENOTTY, then it wasn't a btrfs subvolume, continue below. */
+                                } else
                                         /* It was a subvolume, continue. */
-                                        safe_close(subdir_fd);
                                         continue;
-                                }
                         }
 
-                        /* We pass REMOVE_PHYSICAL here, to avoid
-                         * doing the fstatfs() to check the file
+                        /* We pass REMOVE_PHYSICAL here, to avoid doing the fstatfs() to check the file
                          * system type again for each directory */
-                        r = rm_rf_children(subdir_fd, flags | REMOVE_PHYSICAL, root_dev);
+                        r = rm_rf_children(TAKE_FD(subdir_fd), flags | REMOVE_PHYSICAL, root_dev);
                         if (r < 0 && ret == 0)
                                 ret = r;
 
index e964292eaf4813893ecb0f7937a5514a9dd912be..cad745170ebfb0d0eec652bb54dbfd97f215c2d1 100644 (file)
@@ -8,21 +8,19 @@
 #include "macro.h"
 
 static inline void umaskp(mode_t *u) {
-        umask(*u);
+        umask(*u & 0777);
 }
 
 #define _cleanup_umask_ _cleanup_(umaskp)
 
-struct _umask_struct_ {
-        mode_t mask;
-        bool quit;
-};
+/* We make use of the fact here that the umask() concept is using only the lower 9 bits of mode_t, although
+ * mode_t has space for the file type in the bits further up. We simply OR in the file type mask S_IFMT to
+ * distinguish the first and the second iteration of the RUN_WITH_UMASK() loop, so that we can run the first
+ * one, and exit on the second. */
 
-static inline void _reset_umask_(struct _umask_struct_ *s) {
-        umask(s->mask);
-};
+assert_cc((S_IFMT & 0777) == 0);
 
 #define RUN_WITH_UMASK(mask)                                            \
-        for (_cleanup_(_reset_umask_) struct _umask_struct_ _saved_umask_ = { umask(mask), false }; \
-             !_saved_umask_.quit ;                                      \
-             _saved_umask_.quit = true)
+        for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
+             FLAGS_SET(_saved_umask_, S_IFMT);                          \
+             _saved_umask_ &= 0777)
index 83ac7ad1107874df565c4bee528953f2ddafda46..0aadc98c9b59193dc4c6c351b3d3a2a2dddbba80 100644 (file)
@@ -303,8 +303,12 @@ static int bus_socket_set_transient_property(
         if (streq(name, "SocketProtocol"))
                 return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error);
 
-        if ((ci = socket_exec_command_from_string(name)) >= 0)
-                return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error);
+        ci = socket_exec_command_from_string(name);
+        if (ci >= 0)
+                return bus_set_transient_exec_command(u, name,
+                                                      &s->exec_command[ci],
+                                                      message, flags, error);
+
 
         if (streq(name, "Symlinks")) {
                 _cleanup_strv_free_ char **l = NULL;
index b7fd35fc678ca206fe46e07d48602fc60f6078e7..e32db2bf630a489b1a9823c40dbfbebbbf9989c8 100644 (file)
@@ -1597,31 +1597,25 @@ static int mount_setup_unit(
 }
 
 static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
-        _cleanup_(mnt_free_tablep) struct libmnt_table *t = NULL;
-        _cleanup_(mnt_free_iterp) struct libmnt_iter *i = NULL;
+        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         int r;
 
         assert(m);
 
-        t = mnt_new_table();
-        i = mnt_new_iter(MNT_ITER_FORWARD);
-        if (!t || !i)
-                return log_oom();
-
-        r = mnt_table_parse_mtab(t, NULL);
+        r = libmount_parse(NULL, NULL, &table, &iter);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse /proc/self/mountinfo: %m");
 
         for (;;) {
                 struct libmnt_fs *fs;
                 const char *device, *path, *options, *fstype;
-                int k;
 
-                k = mnt_table_next_fs(t, i, &fs);
-                if (k == 1)
+                r = mnt_table_next_fs(table, iter, &fs);
+                if (r == 1)
                         break;
-                if (k < 0)
-                        return log_error_errno(k, "Failed to get next entry from /proc/self/mountinfo: %m");
+                if (r < 0)
+                        return log_error_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
 
                 device = mnt_fs_get_source(fs);
                 path = mnt_fs_get_target(fs);
index bd353eda964e2483dbcfda6dce028c986f90de65..9ab704e20762d439cf22d5bd09646ed0f6e017b4 100644 (file)
@@ -1036,10 +1036,7 @@ static int send_iovec(const struct iovec iovec[], size_t n_iovec, int input_fd)
                                          * (truncated) copy of what we want to send, and the second one
                                          * contains the trailing dots. */
                                         copy[0] = iovec[i];
-                                        copy[1] = (struct iovec) {
-                                                .iov_base = (char[]) { '.', '.', '.' },
-                                                .iov_len = 3,
-                                        };
+                                        copy[1] = IOVEC_MAKE(((char[]){'.', '.', '.'}), 3);
 
                                         mh.msg_iov = copy;
                                         mh.msg_iovlen = 2;
index 28ae48d551a87f476a3848b59337c87350fbe700..76270aec17f22ca4c284f699c9764b5e7738de1c 100644 (file)
@@ -463,7 +463,7 @@ static int add_mount(
                 if (r < 0)
                         return log_error_errno(r, "Failed to generate unit name: %m");
 
-                fclose(f);
+                f = safe_fclose(f);
 
                 r = generator_open_unit_file(dest, "/etc/fstab", automount_name, &f);
                 if (r < 0)
index 0d1ad2b1e1a4db1624f952a9d228a8650a348761..a6c6db372b170d75fd9d5e864d23f0dadb11b94b 100644 (file)
@@ -128,12 +128,12 @@ fuzzers += [
         [['src/fuzz/fuzz-nspawn-settings.c'],
          [libshared,
           libnspawn_core],
-         []],
+         [libseccomp]],
 
         [['src/fuzz/fuzz-nspawn-oci.c'],
          [libshared,
           libnspawn_core],
-         []],
+         [libseccomp]],
 
         [['src/fuzz/fuzz-calendarspec.c'],
          [libshared],
index 2426933558f3737e1192e9556b4d4da75f302b36..f4ca8f4f59438a80dbc5ecea341dd3e319cfdef3 100644 (file)
@@ -250,7 +250,7 @@ static void transfer_send_logs(Transfer *t, bool flush) {
                 n = strndup(t->log_message, e - t->log_message);
 
                 /* Skip over NUL and newlines */
-                while (e < t->log_message + t->log_message_size && (*e == 0 || *e == '\n'))
+                while (e < t->log_message + t->log_message_size && IN_SET(*e, 0, '\n'))
                         e++;
 
                 memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e);
index 04c66a29ce802e34fb1cb5cf2ed40c96570e6c7a..35efe7002b030dfb3987711f402413d24b75b2dd 100644 (file)
@@ -181,7 +181,7 @@ static int get_source_for_fd(RemoteServer *s,
                 return log_warning_errno(r, "Failed to get writer for source %s: %m",
                                          name);
 
-        if (s->sources[fd] == NULL) {
+        if (!s->sources[fd]) {
                 s->sources[fd] = source_new(fd, false, name, writer);
                 if (!s->sources[fd]) {
                         writer_unref(writer);
index 2154cf7eac4b1a6e426b1117ced511be9df79686..a112b9f70f98660a8234f165c9b29ef1e4d30202 100644 (file)
@@ -612,7 +612,7 @@ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t siz
         assert(data);
 
         hex_buf = hexmem(data, size);
-        if (hex_buf == NULL)
+        if (!hex_buf)
                 return -ENOMEM;
 
         fprintf(f, "%s=%s\n", key, hex_buf);
index 1759e13ca134ce79961e42fb007d92f647baebbf..774bf10219089ed4e8ffa74d72c743616c1411b4 100644 (file)
@@ -26,7 +26,7 @@ static int message_append_basic(sd_bus_message *m, char type, const void *p, con
 
 static void *adjust_pointer(const void *p, void *old_base, size_t sz, void *new_base) {
 
-        if (p == NULL)
+        if (!p)
                 return NULL;
 
         if (old_base == new_base)
index 2467da18eea4a6caf8aa43eb7229397154c23771..dacd3b3d9c0c0ce1c0e70a83f8194f238cd2e616 100644 (file)
@@ -693,8 +693,7 @@ bool manager_all_buttons_ignored(Manager *m) {
                 return false;
         if (m->handle_lid_switch != HANDLE_IGNORE)
                 return false;
-        if (m->handle_lid_switch_ep != _HANDLE_ACTION_INVALID &&
-            m->handle_lid_switch_ep != HANDLE_IGNORE)
+        if (!IN_SET(m->handle_lid_switch_ep, _HANDLE_ACTION_INVALID, HANDLE_IGNORE))
                 return false;
         if (m->handle_lid_switch_docked != HANDLE_IGNORE)
                 return false;
index 0a19cf8abcd3cb5aa447751fdc3c8bc6e92be95e..c5d442865cc39ec102c305cc463fe37d181db83e 100644 (file)
@@ -754,7 +754,7 @@ void user_update_last_session_timer(User *u) {
 
         assert(!u->timer_event_source);
 
-        if (u->manager->user_stop_delay == 0 || u->manager->user_stop_delay == USEC_INFINITY)
+        if (IN_SET(u->manager->user_stop_delay, 0, USEC_INFINITY))
                 return;
 
         if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) {
index b290095b0e95385c7acc15cf570f9bab45f9c46f..739f52c219cca57516b1d00ee2b11b54f2a5b7f9 100644 (file)
@@ -17,6 +17,7 @@
 #include "format-util.h"
 #include "fs-util.h"
 #include "fstab-util.h"
+#include "libmount-util.h"
 #include "main-func.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
@@ -713,9 +714,11 @@ static int start_transient_automount(
 }
 
 static int find_mount_points(const char *what, char ***list) {
-        _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
+        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         _cleanup_strv_free_ char **l = NULL;
         size_t bufsize = 0, n = 0;
+        int r;
 
         assert(what);
         assert(list);
@@ -723,55 +726,42 @@ static int find_mount_points(const char *what, char ***list) {
         /* Returns all mount points obtained from /proc/self/mountinfo in *list,
          * and the number of mount points as return value. */
 
-        proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
-        if (!proc_self_mountinfo)
-                return log_error_errno(errno, "Can't open /proc/self/mountinfo: %m");
+        r = libmount_parse(NULL, NULL, &table, &iter);
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse /proc/self/mountinfo: %m");
 
         for (;;) {
-                _cleanup_free_ char *path = NULL, *where = NULL, *dev = NULL;
-                int r;
+                struct libmnt_fs *fs;
+                const char *source, *target;
 
-                r = fscanf(proc_self_mountinfo,
-                           "%*s "       /* (1) mount id */
-                           "%*s "       /* (2) parent id */
-                           "%*s "       /* (3) major:minor */
-                           "%*s "       /* (4) root */
-                           "%ms "       /* (5) mount point */
-                           "%*s"        /* (6) mount options */
-                           "%*[^-]"     /* (7) optional fields */
-                           "- "         /* (8) separator */
-                           "%*s "       /* (9) file system type */
-                           "%ms"        /* (10) mount source */
-                           "%*s"        /* (11) mount options 2 */
-                           "%*[^\n]",   /* some rubbish at the end */
-                           &path, &dev);
-                if (r != 2) {
-                        if (r == EOF)
-                                break;
-
-                        continue;
-                }
+                r = mnt_table_next_fs(table, iter, &fs);
+                if (r == 1)
+                        break;
+                if (r < 0)
+                        return log_error_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
 
-                if (!streq(what, dev))
+                source = mnt_fs_get_source(fs);
+                target = mnt_fs_get_target(fs);
+                if (!source || !target)
                         continue;
 
-                r = cunescape(path, UNESCAPE_RELAX, &where);
-                if (r < 0)
+                if (!path_equal(source, what))
                         continue;
 
                 /* one extra slot is needed for the terminating NULL */
-                if (!GREEDY_REALLOC(l, bufsize, n + 2))
+                if (!GREEDY_REALLOC0(l, bufsize, n + 2))
                         return log_oom();
 
-                l[n++] = TAKE_PTR(where);
+                l[n] = strdup(target);
+                if (!l[n])
+                        return log_oom();
+                n++;
         }
 
-        if (!GREEDY_REALLOC(l, bufsize, n + 1))
+        if (!GREEDY_REALLOC0(l, bufsize, n + 1))
                 return log_oom();
 
-        l[n] = NULL;
         *list = TAKE_PTR(l);
-
         return n;
 }
 
index 90361c9f4a361e59195deea82290aa34d4c33e44..ba795decfecf61fb99cfa5fc6ddb425248d253ce 100644 (file)
@@ -229,7 +229,7 @@ static int dhcp6_pd_prefix_distribute(Link *dhcp6_link, Iterator *i,
                                              strnull(assigned_buf),
                                              strnull(buf), pd_prefix_len);
 
-                        if (assigned_link == NULL)
+                        if (!assigned_link)
                                 continue;
 
                 } else
index 8cb14b588cfbd5a7ab4f0c4e93e9697f5219c0e8..fdbf7cac62880f7105bfe5ca4e2b8576bf6d9ea6 100644 (file)
@@ -356,7 +356,7 @@ static int radv_set_dns(Link *link, Link *uplink) {
         if (link->network->router_dns) {
                 dns = newdup(struct in6_addr, link->network->router_dns,
                              link->network->n_router_dns);
-                if (dns == NULL)
+                if (!dns)
                         return -ENOMEM;
 
                 n_dns = link->network->n_router_dns;
@@ -372,7 +372,7 @@ static int radv_set_dns(Link *link, Link *uplink) {
                 goto set_dns;
 
         if (uplink) {
-                if (uplink->network == NULL) {
+                if (!uplink->network) {
                         log_link_debug(uplink, "Cannot fetch DNS servers as uplink interface is not managed by us");
                         return 0;
                 }
@@ -411,7 +411,7 @@ static int radv_set_domains(Link *link, Link *uplink) {
                 goto set_domains;
 
         if (uplink) {
-                if (uplink->network == NULL) {
+                if (!uplink->network) {
                         log_link_debug(uplink, "Cannot fetch DNS search domains as uplink interface is not managed by us");
                         return 0;
                 }
index 31217c7b4637daaf08b6f77feb86aec69acb87ac..c049ac6754113eee3fe2e12ec6ad07329f0b04bd 100644 (file)
@@ -48,7 +48,7 @@ tests += [
         [['src/nspawn/test-nspawn-tables.c'],
          [libnspawn_core,
           libshared],
-         []],
+         [libseccomp]],
 
         [['src/nspawn/test-patch-uid.c'],
          [libnspawn_core,
index 4b31cb36ede3790fc1cd760c1ad8ac9af37d561a..f62ad0a0f58aa7307df55d7e7208aeaac0dc68f9 100644 (file)
@@ -37,7 +37,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
         d = dest;
 
         for (;;) {
-                if (*n == 0 || *n == '.') {
+                if (IN_SET(*n, 0, '.')) {
                         if (FLAGS_SET(flags, DNS_LABEL_LDH) && last_char == '-')
                                 /* Trailing dash */
                                 return -EINVAL;
index fc884dedf06b38e4306a947ad2e25ee30834ee91..1bd8835633c2d31202ff53d080e8be56b2bb9a67 100644 (file)
@@ -514,7 +514,7 @@ int efi_get_boot_option(
         if (path)
                 *path = TAKE_PTR(p);
         if (active)
-                *active = !!(header->attr & LOAD_OPTION_ACTIVE);
+                *active = header->attr & LOAD_OPTION_ACTIVE;
 
         return 0;
 }
index 8638cd3cc98b07df2196b9dbfa7a1cd0d7acf87d..8dc2c42ad15d335c39100de5ccef14198f4a50e2 100644 (file)
@@ -94,7 +94,7 @@ static int get_line(JournalImporter *imp, char **line, size_t *size) {
 
                         c = memchr(imp->buf + start, '\n',
                                    imp->filled - start);
-                        if (c != NULL)
+                        if (c)
                                 break;
                 }
 
index 7d94468e52852aedff078bf0f790f1d1a7396a20..7c3b855df52056e1b1bb15f2dba7ad39b16bb930 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
+#include <stdio.h>
+
 /* This needs to be after sys/mount.h */
 #include <libmount.h>
 
@@ -8,3 +10,38 @@
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter);
+
+static inline int libmount_parse(
+                const char *path,
+                FILE *source,
+                struct libmnt_table **ret_table,
+                struct libmnt_iter **ret_iter) {
+
+        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
+        int r;
+
+        /* Older libmount seems to require this. */
+        assert(!source || path);
+
+        table = mnt_new_table();
+        iter = mnt_new_iter(MNT_ITER_FORWARD);
+        if (!table || !iter)
+                return -ENOMEM;
+
+        /* If source or path are specified, we use on the functions which ignore utab.
+         * Only if both are empty, we use mnt_table_parse_mtab(). */
+
+        if (source)
+                r = mnt_table_parse_stream(table, source, path);
+        else if (path)
+                r = mnt_table_parse_file(table, path);
+        else
+                r = mnt_table_parse_mtab(table, NULL);
+        if (r < 0)
+                return r;
+
+        *ret_table = TAKE_PTR(table);
+        *ret_iter = TAKE_PTR(iter);
+        return 0;
+}
index 4ad112740d41eaa11fb0acc231fe0a85787976fa..6b9d8fb97a6c494ea7ba80241bf39d890deaaab8 100644 (file)
@@ -395,7 +395,7 @@ static int image_make(
                 if (r < 0)
                         return r;
 
-                if (size != 0 && size != UINT64_MAX)
+                if (!IN_SET(size, 0, UINT64_MAX))
                         (*ret)->usage = (*ret)->usage_exclusive = (*ret)->limit = (*ret)->limit_exclusive = size;
 
                 return 0;
index 44c80f60ba063327195dde416a3b6fab2d3df7a0..9129ad5f6b851e5b6ba5c07dec053b369f051834 100644 (file)
@@ -8,16 +8,13 @@
 #include <sys/statvfs.h>
 #include <unistd.h>
 
-/* Include later */
-#include <libmount.h>
-
 #include "alloc-util.h"
-#include "escape.h"
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
 #include "hashmap.h"
+#include "libmount-util.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
 #include "parse-util.h"
@@ -36,52 +33,38 @@ int umount_recursive(const char *prefix, int flags) {
          * unmounting them until they are gone. */
 
         do {
-                _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
+                _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+                _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
 
                 again = false;
 
-                r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo);
+                r = libmount_parse("/proc/self/mountinfo", NULL, &table, &iter);
                 if (r < 0)
-                        return r;
+                        return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
 
                 for (;;) {
-                        _cleanup_free_ char *path = NULL, *p = NULL;
-                        int k;
-
-                        k = fscanf(proc_self_mountinfo,
-                                   "%*s "       /* (1) mount id */
-                                   "%*s "       /* (2) parent id */
-                                   "%*s "       /* (3) major:minor */
-                                   "%*s "       /* (4) root */
-                                   "%ms "       /* (5) mount point */
-                                   "%*s"        /* (6) mount options */
-                                   "%*[^-]"     /* (7) optional fields */
-                                   "- "         /* (8) separator */
-                                   "%*s "       /* (9) file system type */
-                                   "%*s"        /* (10) mount source */
-                                   "%*s"        /* (11) mount options 2 */
-                                   "%*[^\n]",   /* some rubbish at the end */
-                                   &path);
-                        if (k != 1) {
-                                if (k == EOF)
-                                        break;
+                        struct libmnt_fs *fs;
+                        const char *path;
 
-                                continue;
-                        }
+                        r = mnt_table_next_fs(table, iter, &fs);
+                        if (r == 1)
+                                break;
+                        if (r < 0)
+                                return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
 
-                        k = cunescape(path, UNESCAPE_RELAX, &p);
-                        if (k < 0)
-                                return k;
+                        path = mnt_fs_get_target(fs);
+                        if (!path)
+                                continue;
 
-                        if (!path_startswith(p, prefix))
+                        if (!path_startswith(path, prefix))
                                 continue;
 
-                        if (umount2(p, flags) < 0) {
-                                r = log_debug_errno(errno, "Failed to umount %s: %m", p);
+                        if (umount2(path, flags) < 0) {
+                                r = log_debug_errno(errno, "Failed to umount %s: %m", path);
                                 continue;
                         }
 
-                        log_debug("Successfully unmounted %s", p);
+                        log_debug("Successfully unmounted %s", path);
 
                         again = true;
                         n++;
@@ -91,7 +74,7 @@ int umount_recursive(const char *prefix, int flags) {
 
         } while (again);
 
-        return r < 0 ? r : n;
+        return n;
 }
 
 static int get_mount_flags(const char *path, unsigned long *flags) {
@@ -141,6 +124,8 @@ int bind_remount_recursive_with_mountinfo(
 
         for (;;) {
                 _cleanup_set_free_free_ Set *todo = NULL;
+                _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+                _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
                 bool top_autofs = false;
                 char *x;
                 unsigned long orig_flags;
@@ -151,56 +136,45 @@ int bind_remount_recursive_with_mountinfo(
 
                 rewind(proc_self_mountinfo);
 
-                for (;;) {
-                        _cleanup_free_ char *path = NULL, *p = NULL, *type = NULL;
-                        int k;
-
-                        k = fscanf(proc_self_mountinfo,
-                                   "%*s "       /* (1) mount id */
-                                   "%*s "       /* (2) parent id */
-                                   "%*s "       /* (3) major:minor */
-                                   "%*s "       /* (4) root */
-                                   "%ms "       /* (5) mount point */
-                                   "%*s"        /* (6) mount options (superblock) */
-                                   "%*[^-]"     /* (7) optional fields */
-                                   "- "         /* (8) separator */
-                                   "%ms "       /* (9) file system type */
-                                   "%*s"        /* (10) mount source */
-                                   "%*s"        /* (11) mount options (bind mount) */
-                                   "%*[^\n]",   /* some rubbish at the end */
-                                   &path,
-                                   &type);
-                        if (k != 2) {
-                                if (k == EOF)
-                                        break;
+                r = libmount_parse("/proc/self/mountinfo", proc_self_mountinfo, &table, &iter);
+                if (r < 0)
+                        return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
 
-                                continue;
-                        }
+                for (;;) {
+                        struct libmnt_fs *fs;
+                        const char *path, *type;
 
-                        r = cunescape(path, UNESCAPE_RELAX, &p);
+                        r = mnt_table_next_fs(table, iter, &fs);
+                        if (r == 1)
+                                break;
                         if (r < 0)
-                                return r;
+                                return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
 
-                        if (!path_startswith(p, cleaned))
+                        path = mnt_fs_get_target(fs);
+                        type = mnt_fs_get_fstype(fs);
+                        if (!path || !type)
                                 continue;
 
-                        /* Ignore this mount if it is blacklisted, but only if it isn't the top-level mount we shall
-                         * operate on. */
-                        if (!path_equal(cleaned, p)) {
+                        if (!path_startswith(path, cleaned))
+                                continue;
+
+                        /* Ignore this mount if it is blacklisted, but only if it isn't the top-level mount
+                         * we shall operate on. */
+                        if (!path_equal(path, cleaned)) {
                                 bool blacklisted = false;
                                 char **i;
 
                                 STRV_FOREACH(i, blacklist) {
-
                                         if (path_equal(*i, cleaned))
                                                 continue;
 
                                         if (!path_startswith(*i, cleaned))
                                                 continue;
 
-                                        if (path_startswith(p, *i)) {
+                                        if (path_startswith(path, *i)) {
                                                 blacklisted = true;
-                                                log_debug("Not remounting %s blacklisted by %s, called for %s", p, *i, cleaned);
+                                                log_debug("Not remounting %s blacklisted by %s, called for %s",
+                                                          path, *i, cleaned);
                                                 break;
                                         }
                                 }
@@ -215,15 +189,12 @@ int bind_remount_recursive_with_mountinfo(
                          * already triggered, then we will find
                          * another entry for this. */
                         if (streq(type, "autofs")) {
-                                top_autofs = top_autofs || path_equal(cleaned, p);
+                                top_autofs = top_autofs || path_equal(path, cleaned);
                                 continue;
                         }
 
-                        if (!set_contains(done, p)) {
-                                r = set_consume(todo, p);
-                                p = NULL;
-                                if (r == -EEXIST)
-                                        continue;
+                        if (!set_contains(done, path)) {
+                                r = set_put_strdup(todo, path);
                                 if (r < 0)
                                         return r;
                         }
index dbb4622312a079080ab3ae63720ce1cce4517abc..f721aff76071182940f5191f725ca6615463f1af 100644 (file)
@@ -120,10 +120,8 @@ int switch_root(const char *new_root,
 
                 if (fstat(old_root_fd, &rb) < 0)
                         log_warning_errno(errno, "Failed to stat old root directory, leaving: %m");
-                else {
-                        (void) rm_rf_children(old_root_fd, 0, &rb);
-                        old_root_fd = -1;
-                }
+                else
+                        (void) rm_rf_children(TAKE_FD(old_root_fd), 0, &rb); /* takes possession of the dir fd, even on failure */
         }
 
         return 0;
index e30b475c75d5cea783256ec13a9dbd75ce152954..c75be39fefc88c9a0fcf61452107e179b12630e2 100644 (file)
@@ -55,18 +55,13 @@ void mount_points_list_free(MountPoint **head) {
 }
 
 int mount_points_list_get(const char *mountinfo, MountPoint **head) {
-        _cleanup_(mnt_free_tablep) struct libmnt_table *t = NULL;
-        _cleanup_(mnt_free_iterp) struct libmnt_iter *i = NULL;
+        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         int r;
 
         assert(head);
 
-        t = mnt_new_table();
-        i = mnt_new_iter(MNT_ITER_FORWARD);
-        if (!t || !i)
-                return log_oom();
-
-        r = mnt_table_parse_mtab(t, mountinfo);
+        r = libmount_parse(mountinfo, NULL, &table, &iter);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse %s: %m", mountinfo);
 
@@ -79,7 +74,7 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 bool try_remount_ro;
                 _cleanup_free_ MountPoint *m = NULL;
 
-                r = mnt_table_next_fs(t, i, &fs);
+                r = mnt_table_next_fs(table, iter, &fs);
                 if (r == 1)
                         break;
                 if (r < 0)
index e58e1cc73d3f90729f0b1ae7e7f8d1bcfb8eebcc..c68229b536a9bb5f552f7650a22f28031874eba9 100644 (file)
@@ -269,6 +269,10 @@ tests += [
          [],
          []],
 
+        [['src/test/test-umask-util.c'],
+         [],
+         []],
+
         [['src/test/test-proc-cmdline.c'],
          [],
          []],
index fc28f27d53e6110500c533010c847a9e1926cbb1..c3395493d460b038c2f25996331a9be8384f97dc 100644 (file)
@@ -21,13 +21,10 @@ static void test_libmount_unescaping_one(
         _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         _cleanup_fclose_ FILE *f = NULL;
 
-        assert_se(table = mnt_new_table());
-        assert_se(iter = mnt_new_iter(MNT_ITER_FORWARD));
-
         f = fmemopen((char*) string, strlen(string), "re");
         assert_se(f);
 
-        assert_se(mnt_table_parse_stream(table, f, title) >= 0);
+        assert_se(libmount_parse(title, f, &table, &iter) >= 0);
 
         struct libmnt_fs *fs;
         const char *source, *target;
index f634ca28dbdf29e49c899390e3ad849024bbe036..7878512465ed0650d4ddb94bece7e50657d29563 100644 (file)
@@ -158,7 +158,7 @@ static int enumerate_print_list(struct udev_enumerate *enumerate) {
 
                 device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
                                                       udev_list_entry_get_name(list_entry));
-                if (device != NULL) {
+                if (device) {
                         log_info("device: '%s' (%s)",
                                  udev_device_get_syspath(device),
                                  udev_device_get_subsystem(device));
@@ -249,7 +249,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate '%s'", subsystem == NULL ? "<all>" : subsystem);
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_match_subsystem(udev_enumerate, subsystem);
         udev_enumerate_scan_devices(udev_enumerate);
@@ -258,7 +258,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'net' + duplicated scan + null + zero");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_match_subsystem(udev_enumerate, "net");
         udev_enumerate_scan_devices(udev_enumerate);
@@ -278,7 +278,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'block'");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_match_subsystem(udev_enumerate,"block");
         r = udev_enumerate_add_match_is_initialized(udev_enumerate);
@@ -292,7 +292,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'not block'");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
         udev_enumerate_scan_devices(udev_enumerate);
@@ -301,7 +301,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'pci, mem, vc'");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_match_subsystem(udev_enumerate, "pci");
         udev_enumerate_add_match_subsystem(udev_enumerate, "mem");
@@ -312,7 +312,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'subsystem'");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_scan_subsystems(udev_enumerate);
         enumerate_print_list(udev_enumerate);
@@ -320,7 +320,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
 
         log_info("enumerate 'property IF_FS_*=filesystem'");
         udev_enumerate = udev_enumerate_new(udev);
-        if (udev_enumerate == NULL)
+        if (!udev_enumerate)
                 return -1;
         udev_enumerate_add_match_property(udev_enumerate, "ID_FS*", "filesystem");
         udev_enumerate_scan_devices(udev_enumerate);
index 27afe36082f5a2660b78942fa0ac0a6c1ac85bb3..d0f989837866b7df170f1af597d4785f2d76db50 100644 (file)
@@ -88,7 +88,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
                 if (it->scopeid == 0)
                         goto numerical_index;
 
-                if (if_indextoname(it->scopeid, ifname) == NULL) {
+                if (!if_indextoname(it->scopeid, ifname)) {
                         log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid);
                 numerical_index:
                         xsprintf(ifname, "%i", it->scopeid);
diff --git a/src/test/test-umask-util.c b/src/test/test-umask-util.c
new file mode 100644 (file)
index 0000000..27f6b56
--- /dev/null
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "tests.h"
+#include "umask-util.h"
+
+int main(int argc, char *argv[]) {
+        size_t n;
+        mode_t u;
+
+        test_setup_logging(LOG_DEBUG);
+
+        u = umask(0111);
+
+        n = 0;
+        RUN_WITH_UMASK(0123) {
+                assert_se(umask(000) == 0123);
+                n++;
+        }
+
+        assert_se(n == 1);
+        assert_se(umask(u) == 0111);
+
+        RUN_WITH_UMASK(0135) {
+                assert_se(umask(000) == 0135);
+                n++;
+        }
+
+        assert_se(n == 2);
+        assert_se(umask(0111) == u);
+
+        RUN_WITH_UMASK(0315) {
+                assert_se(umask(000) == 0315);
+                n++;
+                break;
+        }
+
+        assert_se(n == 3);
+        assert_se(umask(u) == 0111);
+
+        return EXIT_SUCCESS;
+}
index 4c00fa409f04a48bfddc0d67d8a4c4b0923f34ed..3c3a7fe69aec049ca3fac7ccb0b27a174fd81f9c 100644 (file)
@@ -1024,7 +1024,7 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
         sd_network_monitor_flush(m->network_monitor);
 
         /* When manager_network_read_link_servers() failed, we assume that the servers are changed. */
-        changed = !!manager_network_read_link_servers(m);
+        changed = manager_network_read_link_servers(m);
 
         /* check if the machine is online */
         online = network_is_online();
index d9d1cc1c1a1c6cd3b9da0c3aeadc4ccee680b4c2..73e0e33d0a8f3709a6f5c2dfd948ffd45cf8c730 100644 (file)
@@ -2397,7 +2397,7 @@ static int specifier_expansion_from_arg(Item *i) {
 
         assert(i);
 
-        if (i->argument == NULL)
+        if (!i->argument)
                 return 0;
 
         switch (i->type) {
index 8ea2e1e327ed8e034020cb0462cd78eb0778a6da..9aca82b1fbde1e46815a84b906ae50a8a052baed 100644 (file)
@@ -381,7 +381,7 @@ static int disk_identify(int fd,
         }
 
 out:
-        if (out_is_packet_device != NULL)
+        if (out_is_packet_device)
                 *out_is_packet_device = is_packet_device;
         return ret;
 }
@@ -432,7 +432,7 @@ int main(int argc, char *argv[]) {
         }
 
         node = argv[optind];
-        if (node == NULL) {
+        if (!node) {
                 log_error("no node specified");
                 return 1;
         }
index ddcdbdaa18d6fde2b3607e36229a4dedfb4c75b1..a287901266baad43068fa335843353bcf1f0a3b1 100644 (file)
@@ -95,7 +95,7 @@ static bool is_mounted(const char *device) {
                 return false;
 
         fp = fopen("/proc/self/mountinfo", "re");
-        if (fp == NULL)
+        if (!fp)
                 return false;
         while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
                 if (makedev(maj, min) == statbuf.st_rdev) {
@@ -108,11 +108,10 @@ static bool is_mounted(const char *device) {
 }
 
 static void info_scsi_cmd_err(const char *cmd, int err) {
-        if (err == -1) {
+        if (err == -1)
                 log_debug("%s failed", cmd);
-                return;
-        }
-        log_debug("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh", cmd, SK(err), ASC(err), ASCQ(err));
+        else
+                log_debug("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh", cmd, SK(err), ASC(err), ASCQ(err));
 }
 
 struct scsi_cmd {
@@ -149,9 +148,9 @@ static int scsi_cmd_run(struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t
                 cmd->sg_io.dxferp = buf;
                 cmd->sg_io.dxfer_len = bufsize;
                 cmd->sg_io.dxfer_direction = SG_DXFER_FROM_DEV;
-        } else {
+        } else
                 cmd->sg_io.dxfer_direction = SG_DXFER_NONE;
-        }
+
         if (ioctl(fd, SG_IO, &cmd->sg_io))
                 return -1;
 
@@ -191,7 +190,7 @@ static int media_eject(int fd) {
         scsi_cmd_set(&sc, 4, 0x02);
         scsi_cmd_set(&sc, 5, 0);
         err = scsi_cmd_run(&sc, fd, NULL, 0);
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("START_STOP_UNIT", err);
                 return -1;
         }
@@ -202,10 +201,8 @@ static int cd_capability_compat(int fd) {
         int capability;
 
         capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
-        if (capability < 0) {
-                log_debug("CDROM_GET_CAPABILITY failed");
-                return -1;
-        }
+        if (capability < 0)
+                return log_debug_errno(errno, "CDROM_GET_CAPABILITY failed");
 
         if (capability & CDC_CD_R)
                 cd_cd_r = 1;
@@ -225,10 +222,9 @@ static int cd_capability_compat(int fd) {
 }
 
 static int cd_media_compat(int fd) {
-        if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
-                log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK");
-                return -1;
-        }
+        if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK)
+                return log_debug_errno(errno, "CDROM_DRIVE_STATUS != CDS_DISC_OK");
+
         cd_media = 1;
         return 0;
 }
@@ -243,15 +239,13 @@ static int cd_inquiry(int fd) {
         scsi_cmd_set(&sc, 4, 36);
         scsi_cmd_set(&sc, 5, 0);
         err = scsi_cmd_run(&sc, fd, inq, 36);
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("INQUIRY", err);
                 return -1;
         }
 
-        if ((inq[0] & 0x1F) != 5) {
-                log_debug("not an MMC unit");
-                return -1;
-        }
+        if ((inq[0] & 0x1F) != 5)
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "not an MMC unit");
 
         log_debug("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32);
         return 0;
@@ -465,7 +459,7 @@ static int cd_profiles_old_mmc(int fd) {
         scsi_cmd_set(&sc, 8, sizeof(header));
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, header, sizeof(header));
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("READ DISC INFORMATION", err);
                 if (cd_media == 1) {
                         log_debug("no current profile, but disc is present; assuming CD-ROM");
@@ -473,10 +467,9 @@ static int cd_profiles_old_mmc(int fd) {
                         cd_media_track_count = 1;
                         cd_media_track_count_data = 1;
                         return 0;
-                } else {
-                        log_debug("no current profile, assuming no media");
-                        return -1;
-                }
+                } else
+                        return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
+                                               "no current profile, assuming no media");
         };
 
         cd_media = 1;
@@ -512,7 +505,7 @@ static int cd_profiles(int fd) {
         scsi_cmd_set(&sc, 8, 8);
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, features, 8);
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("GET CONFIGURATION", err);
                 /* handle pre-MMC2 drives which do not support GET CONFIGURATION */
                 if (SK(err) == 0x5 && IN_SET(ASC(err), 0x20, 0x24)) {
@@ -528,9 +521,8 @@ static int cd_profiles(int fd) {
                 log_debug("current profile 0x%02x", cur_profile);
                 feature_profile_media(cur_profile);
                 ret = 0; /* we have media */
-        } else {
+        } else
                 log_debug("no current profile, assuming no media");
-        }
 
         len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
         log_debug("GET CONFIGURATION: size of features buffer 0x%04x", len);
@@ -548,7 +540,7 @@ static int cd_profiles(int fd) {
         scsi_cmd_set(&sc, 8, len & 0xff);
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, features, len);
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("GET CONFIGURATION", err);
                 return -1;
         }
@@ -598,7 +590,7 @@ static int cd_media_info(int fd) {
         scsi_cmd_set(&sc, 8, sizeof(header) & 0xff);
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, header, sizeof(header));
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("READ DISC INFORMATION", err);
                 return -1;
         };
@@ -637,7 +629,7 @@ static int cd_media_info(int fd) {
                         scsi_cmd_set(&sc, 9, sizeof(dvdstruct));
                         scsi_cmd_set(&sc, 11, 0);
                         err = scsi_cmd_run(&sc, fd, dvdstruct, sizeof(dvdstruct));
-                        if ((err != 0)) {
+                        if (err != 0) {
                                 info_scsi_cmd_err("READ DVD STRUCTURE", err);
                                 return -1;
                         }
@@ -653,16 +645,15 @@ static int cd_media_info(int fd) {
                         scsi_cmd_set(&sc, 8, sizeof(format));
                         scsi_cmd_set(&sc, 9, 0);
                         err = scsi_cmd_run(&sc, fd, format, sizeof(format));
-                        if ((err != 0)) {
+                        if (err != 0) {
                                 info_scsi_cmd_err("READ DVD FORMAT CAPACITIES", err);
                                 return -1;
                         }
 
                         len = format[3];
-                        if (len & 7 || len < 16) {
-                                log_debug("invalid format capacities length");
-                                return -1;
-                        }
+                        if (len & 7 || len < 16)
+                                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "invalid format capacities length");
 
                         switch(format[8] & 3) {
                             case 1:
@@ -680,8 +671,8 @@ static int cd_media_info(int fd) {
 
                             case 3:
                                 cd_media = 0; //return no media
-                                log_debug("format capacities returned no media");
-                                return -1;
+                                return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
+                                                       "format capacities returned no media");
                         }
                 }
 
@@ -695,7 +686,7 @@ static int cd_media_info(int fd) {
                 scsi_cmd_set(&sc, 8, 32);
                 scsi_cmd_set(&sc, 9, 0);
                 err = scsi_cmd_run(&sc, fd, buffer, sizeof(buffer));
-                if ((err != 0)) {
+                if (err != 0) {
                         cd_media = 0;
                         info_scsi_cmd_err("READ FIRST 32 BLOCKS", err);
                         return -1;
@@ -748,7 +739,7 @@ static int cd_media_toc(int fd) {
         scsi_cmd_set(&sc, 8, sizeof(header) & 0xff);
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, header, sizeof(header));
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("READ TOC", err);
                 return -1;
         }
@@ -773,7 +764,7 @@ static int cd_media_toc(int fd) {
         scsi_cmd_set(&sc, 8, len & 0xff);
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, toc, len);
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("READ TOC (tracks)", err);
                 return -1;
         }
@@ -803,7 +794,7 @@ static int cd_media_toc(int fd) {
         scsi_cmd_set(&sc, 8, sizeof(header));
         scsi_cmd_set(&sc, 9, 0);
         err = scsi_cmd_run(&sc, fd, header, sizeof(header));
-        if ((err != 0)) {
+        if (err != 0) {
                 info_scsi_cmd_err("READ TOC (multi session)", err);
                 return -1;
         }
@@ -1026,7 +1017,7 @@ work:
         if (cd_media_hddvd_rw)
                 printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
 
-        if (cd_media_state != NULL)
+        if (cd_media_state)
                 printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
         if (cd_media_session_next > 0)
                 printf("ID_CDROM_MEDIA_SESSION_NEXT=%u\n", cd_media_session_next);
index 2698cdd82fd9d8bb36103cd1601c79ced3957474..e1a8d7e3a9252819f3c8d28de8106549c738c4a9 100644 (file)
@@ -157,7 +157,7 @@ static int get_file_options(const char *vendor, const char *model,
         int retval = 0;
 
         f = fopen(config_file, "re");
-        if (f == NULL) {
+        if (!f) {
                 if (errno == ENOENT)
                         return 1;
                 else {
@@ -181,7 +181,7 @@ static int get_file_options(const char *vendor, const char *model,
                 vendor_in = model_in = options_in = NULL;
 
                 buf = fgets(buffer, MAX_BUFFER_LEN, f);
-                if (buf == NULL)
+                if (!buf)
                         break;
                 lineno++;
                 if (buf[strlen(buffer) - 1] != '\n') {
@@ -239,7 +239,7 @@ static int get_file_options(const char *vendor, const char *model,
                         break;
                 }
                 if (vendor == NULL) {
-                        if (vendor_in == NULL)
+                        if (!vendor_in)
                                 break;
                 } else if (vendor_in &&
                            startswith(vendor, vendor_in) &&
@@ -346,18 +346,18 @@ static int set_options(int argc, char **argv,
                                 default_page_code = PAGE_83;
                         else if (streq(optarg, "pre-spc3-83"))
                                 default_page_code = PAGE_83_PRE_SPC3;
-                        else {
-                                log_error("Unknown page code '%s'", optarg);
-                                return -1;
-                        }
+                        else
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Unknown page code '%s'",
+                                                       optarg);
                         break;
 
                 case 's':
                         sg_version = atoi(optarg);
-                        if (sg_version < 3 || sg_version > 4) {
-                                log_error("Unknown SG version '%s'", optarg);
-                                return -1;
-                        }
+                        if (sg_version < 3 || sg_version > 4)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "Unknown SG version '%s'",
+                                                       optarg);
                         break;
 
                 case 'u':
index 7ca01858d165ba58c8bae63e371320734d3abcbe..481c426618df08cea4ac693fed0a9ba9ba89ffe6 100644 (file)
@@ -168,10 +168,10 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
          * we'll retry the command.
          */
 
-        if (sb_len < 1) {
-                log_debug("%s: sense buffer empty", dev_scsi->kernel);
-                return -1;
-        }
+        if (sb_len < 1)
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s: sense buffer empty",
+                                       dev_scsi->kernel);
 
         sense_class = (sense_buffer[0] >> 4) & 0x07;
         code = sense_buffer[0] & 0xf;
@@ -181,40 +181,41 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
                  * extended sense data.
                  */
                 s = sense_buffer[7] + 8;
-                if (sb_len < s) {
-                        log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
-                                  dev_scsi->kernel, sb_len, s - sb_len);
-                        return -1;
-                }
+                if (sb_len < s)
+                        return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "%s: sense buffer too small %d bytes, %d bytes too short",
+                                               dev_scsi->kernel, sb_len,
+                                               s - sb_len);
+
                 if (IN_SET(code, 0x0, 0x1)) {
                         sense_key = sense_buffer[2] & 0xf;
-                        if (s < 14) {
+                        if (s < 14)
                                 /*
                                  * Possible?
                                  */
-                                log_debug("%s: sense result too" " small %d bytes",
-                                          dev_scsi->kernel, s);
-                                return -1;
-                        }
+                                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "%s: sense result too small %d bytes",
+                                                       dev_scsi->kernel, s);
+
                         asc = sense_buffer[12];
                         ascq = sense_buffer[13];
                 } else if (IN_SET(code, 0x2, 0x3)) {
                         sense_key = sense_buffer[1] & 0xf;
                         asc = sense_buffer[2];
                         ascq = sense_buffer[3];
-                } else {
-                        log_debug("%s: invalid sense code 0x%x",
-                                  dev_scsi->kernel, code);
-                        return -1;
-                }
+                } else
+                        return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "%s: invalid sense code 0x%x",
+                                               dev_scsi->kernel, code);
+
                 log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x",
                           dev_scsi->kernel, sense_key, asc, ascq);
         } else {
-                if (sb_len < 4) {
-                        log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
-                                  dev_scsi->kernel, sb_len, 4 - sb_len);
-                        return -1;
-                }
+                if (sb_len < 4)
+                        return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "%s: sense buffer too small %d bytes, %d bytes too short",
+                                               dev_scsi->kernel, sb_len,
+                                               4 - sb_len);
 
                 if (sense_buffer[0] < 15)
                         log_debug("%s: old sense key: 0x%x", dev_scsi->kernel, sense_buffer[0] & 0x0f);
@@ -231,13 +232,13 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
 
 static int scsi_dump(struct scsi_id_device *dev_scsi, struct sg_io_hdr *io) {
         if (!io->status && !io->host_status && !io->msg_status &&
-            !io->driver_status) {
+            !io->driver_status)
                 /*
                  * Impossible, should not be called.
                  */
-                log_debug("%s: called with no error", __FUNCTION__);
-                return -1;
-        }
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s: called with no error",
+                                       __FUNCTION__);
 
         log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x",
                   dev_scsi->kernel, io->driver_status, io->host_status, io->msg_status, io->status);
@@ -249,13 +250,13 @@ static int scsi_dump(struct scsi_id_device *dev_scsi, struct sg_io_hdr *io) {
 
 static int scsi_dump_v4(struct scsi_id_device *dev_scsi, struct sg_io_v4 *io) {
         if (!io->device_status && !io->transport_status &&
-            !io->driver_status) {
+            !io->driver_status)
                 /*
                  * Impossible, should not be called.
                  */
-                log_debug("%s: called with no error", __FUNCTION__);
-                return -1;
-        }
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s: called with no error",
+                                       __FUNCTION__);
 
         log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x",
                   dev_scsi->kernel, io->driver_status, io->transport_status, io->device_status);
@@ -278,10 +279,9 @@ static int scsi_inquiry(struct scsi_id_device *dev_scsi, int fd,
         int retry = 3; /* rather random */
         int retval;
 
-        if (buflen > SCSI_INQ_BUFF_LEN) {
-                log_debug("buflen %d too long", buflen);
-                return -1;
-        }
+        if (buflen > SCSI_INQ_BUFF_LEN)
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "buflen %d too long", buflen);
 
 resend:
         if (dev_scsi->use_sg == 4) {
@@ -411,11 +411,11 @@ static int prepend_vendor_model(struct scsi_id_device *dev_scsi, char *serial) {
          * This is not a complete check, since we are using strncat/cpy
          * above, ind will never be too large.
          */
-        if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
-                log_debug("%s: expected length %d, got length %d",
-                          dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
-                return -1;
-        }
+        if (ind != (VENDOR_LENGTH + MODEL_LENGTH))
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "%s: expected length %d, got length %d",
+                                       dev_scsi->kernel,
+                                       (VENDOR_LENGTH + MODEL_LENGTH), ind);
         return ind;
 }
 
@@ -524,7 +524,7 @@ static int check_fill_0x83_id(struct scsi_id_device *dev_scsi,
 
         if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) {
                 strncpy(wwn, &serial[s], 16);
-                if (wwn_vendor_extension != NULL)
+                if (wwn_vendor_extension)
                         strncpy(wwn_vendor_extension, &serial[s + 16], 16);
         }
 
@@ -729,7 +729,7 @@ static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
          * specific type where we prepend '0' + vendor + model.
          */
         len = buf[3];
-        if (serial != NULL) {
+        if (serial) {
                 serial[0] = 'S';
                 ser_ind = prepend_vendor_model(dev_scsi, &serial[1]);
                 if (ser_ind < 0)
@@ -738,7 +738,7 @@ static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
                 for (i = 4; i < len + 4; i++, ser_ind++)
                         serial[ser_ind] = buf[i];
         }
-        if (serial_short != NULL) {
+        if (serial_short) {
                 memcpy(serial_short, &buf[4], len);
                 serial_short[len] = '\0';
         }
index 7bdf6cfbb59613936cc3b9d60d5b2c245e992a89..58af63f11a6cbe8abdfb4e0c88662ef0162f93bf 100644 (file)
@@ -196,7 +196,7 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
                              desc->bInterfaceProtocol) != 7)
                         continue;
 
-                if (strstr(ifs_str, if_str) != NULL)
+                if (strstr(ifs_str, if_str))
                         continue;
 
                 memcpy(&ifs_str[strpos], if_str, 8),
index 4d60ee3c85909938adb3aae69678eb4c43837704..5de26b8062377ce96c34eaa5a74a30fa47affb93 100644 (file)
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
                 }
 
         device = argv[optind];
-        if (device == NULL)
+        if (!device)
                 return 2;
 
         fd = open(device, O_RDONLY);