]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Fix error message handling in sample/test code
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 18 Apr 2026 08:24:04 +0000 (10:24 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 21 Apr 2026 12:32:44 +0000 (14:32 +0200)
- Remove extra newline in errx messages
- Use fprintf/exit for usage to avoid repeated program name
- Improve signal safety by using appropriate functions

This code is not installed, thus no functional change in final
installation of util-linux.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libblkid/samples/partitions.c
libmount/src/lock.c
login-utils/sulogin-consoles.c

index c5830e657139cd688e671c2eb8053abd41c0a176..7830aa224c9d670271ccba00ae88455806794b12 100644 (file)
@@ -38,15 +38,15 @@ int main(int argc, char *argv[])
        /* Binary interface */
        ls = blkid_probe_get_partitions(pr);
        if (!ls)
-               errx(EXIT_FAILURE, "%s: failed to read partitions\n", devname);
+               errx(EXIT_FAILURE, "%s: failed to read partitions", devname);
 
        /*
         * Print info about the primary (root) partition table
         */
        root_tab = blkid_partlist_get_table(ls);
        if (!root_tab)
-               errx(EXIT_FAILURE, "%s: does not contains any "
-                                "known partition table\n", devname);
+               errx(EXIT_FAILURE, "%s: does not contain any "
+                                "known partition table", devname);
 
        printf("size: %jd, sector size: %u, PT: %s, offset: %jd, id=%s\n---\n",
                (intmax_t)blkid_probe_get_size(pr),
index d5c68b1792649210f9c0711ec269e02c1feb0880..3880f47c0646fa0ab4cdd2e82c345bc623b22f80 100644 (file)
@@ -332,7 +332,8 @@ static void clean_lock(void)
 
 static void __attribute__((__noreturn__)) sig_handler(int sig)
 {
-       errx(EXIT_FAILURE, "\n%d: catch signal: %s\n", getpid(), strsignal(sig));
+       ul_sig_printf("\n%d: caught signal %d\n", getpid(), sig);
+       _exit(EXIT_FAILURE);
 }
 
 static int test_lock(struct libmnt_test *ts __attribute__((unused)),
index 721650df97f2694d83956682f12da34812a42e64..c35922ff11c85f462c784a89b33e1db31126c0e2 100644 (file)
@@ -815,8 +815,10 @@ int main(int argc, char *argv[])
                fd = STDIN_FILENO;
        }
 
-       if (!name)
-               errx(EXIT_FAILURE, "usage: %s [<tty>]\n", program_invocation_short_name);
+       if (!name) {
+               fprintf(stderr, "usage: %s [<tty>]\n", program_invocation_short_name);
+               return EXIT_FAILURE;
+       }
 
        INIT_LIST_HEAD(&consoles);
        re = detect_consoles(name, fd, &consoles);