]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
enosys: improve checks for EXIT_NOTSUPP
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 11 May 2023 10:48:33 +0000 (12:48 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 16 May 2023 20:32:25 +0000 (22:32 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
misc-utils/enosys.c

index 88e7af3b02feef8388d22ceedc477e33ab6184f0..bf104876cd554d5fa02a1eb0179e85746149069e 100644 (file)
@@ -132,11 +132,17 @@ int main(int argc, char **argv)
                .filter = filter,
        };
 
+       /* *SET* below will return EINVAL when either the filter is invalid or
+        * seccomp is not supported. To distinguish those cases do a *GET* here
+        */
+       if (prctl(PR_GET_SECCOMP) == -1 && errno == EINVAL)
+               err(EXIT_NOTSUPP, "Seccomp non-functional");
+
        if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
-               err(EXIT_NOTSUPP, "prctl(PR_SET_NO_NEW_PRIVS)");
+               err_nosys(EXIT_FAILURE, "prctl(PR_SET_NO_NEW_PRIVS)");
 
        if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog))
-               err(EXIT_NOTSUPP, "prctl(PR_SET_SECCOMP)");
+               err_nosys(EXIT_FAILURE, "prctl(PR_SET_SECCOMP)");
 
        if (execvp(argv[optind], argv + optind))
                err(EXIT_NOTSUPP, "Could not exec");