summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp')
-rw-r--r--tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp63
1 files changed, 55 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp b/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp
index e701677403..42a173debe 100644
--- a/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp
+++ b/tests/auto/corelib/io/qprocess/testUnixProcessParameters/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2023 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <string_view>
@@ -29,18 +29,39 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
+ if (cmd == "reset-ids") {
+ if (getuid() == geteuid() && getgid() == getegid())
+ return EXIT_SUCCESS;
+ fprintf(stderr, "Real: %d %d; Effective: %d %d\n",
+ getuid(), getgid(), geteuid(), getegid());
+ return EXIT_FAILURE;
+ }
+
if (cmd == "reset-sighand") {
- // confirm it was not ignored
+ bool ok = true;
+
+ // confirm our signal block mask is empty
+ sigset_t set;
+ sigprocmask(SIG_SETMASK, nullptr, &set);
+ for (int signo = 1; signo < NSIG; ++signo) {
+ if (sigismember(&set, signo)) {
+ fprintf(stderr, "'%s' is blocked.\n", strsignal(signo));
+ ok = false;
+ }
+ }
+
+ // confirm SIGUSR1 was not ignored
struct sigaction action;
sigaction(SIGUSR1, nullptr, &action);
- if (action.sa_handler == SIG_DFL)
- return EXIT_SUCCESS;
- fprintf(stderr, "SIGUSR1 is SIG_IGN\n");
- return EXIT_FAILURE;
+ if (action.sa_handler != SIG_DFL) {
+ fprintf(stderr, "SIGUSR1 is SIG_IGN\n");
+ ok = false;
+ }
+ return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
if (cmd == "ignore-sigpipe") {
- // confirm it was ignored
+ // confirm SIGPIPE was ignored
struct sigaction action;
sigaction(SIGPIPE, nullptr, &action);
if (action.sa_handler == SIG_IGN)
@@ -49,7 +70,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- if (cmd == "std-file-descriptors") {
+ if (cmd == "file-descriptors") {
int fd = atoi(argv[2]);
if (close(fd) < 0 && errno == EBADF)
return EXIT_SUCCESS;
@@ -57,6 +78,32 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
+ if (cmd == "file-descriptors2") {
+ int fd1 = atoi(argv[2]); // should be open
+ int fd2 = atoi(argv[3]); // should be closed
+ if (close(fd1) < 0)
+ fprintf(stderr, "%d was not a valid file descriptor\n", fd1);
+ if (close(fd2) == 0 || errno != EBADF)
+ fprintf(stderr, "%d is a valid file descriptor\n", fd2);
+ return EXIT_SUCCESS;
+ }
+
+ if (cmd == "noctty") {
+ int fd = open("/dev/tty", O_RDONLY);
+ if (fd == -1)
+ return EXIT_SUCCESS;
+ fprintf(stderr, "Could open /dev/tty\n");
+ return EXIT_FAILURE;
+ }
+
+ if (cmd == "setsid") {
+ pid_t pgid = getpgrp();
+ if (pgid == getpid())
+ return EXIT_SUCCESS;
+ fprintf(stderr, "Process group was %d\n", pgid);
+ return EXIT_FAILURE;
+ }
+
fprintf(stderr, "Unknown command \"%s\"", cmd.data());
return EXIT_FAILURE;
}