summaryrefslogtreecommitdiff
path: root/src/test/test-process-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-11-06 16:45:48 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-11-08 18:21:10 +0100
commitee617a4e5ca5828cabd46f3bb1d9ffc0dd3db9e5 (patch)
tree4c87c8db4af1a2bbe5678c3c965a33a90682dd41 /src/test/test-process-util.c
parentc47511da7e2bab1a429fc1958a73d3f426ebb3da (diff)
downloadsystemd-ee617a4e5ca5828cabd46f3bb1d9ffc0dd3db9e5.tar.gz
basic: move a bunch of cmdline-related funcs to new argv-util.c+h
I wanted to move saved_arg[cv] to process-util.c+h, but this causes problems: process-util.h includes format-util.h which includes net/if.h, which conflicts with linux/if.h. So we can't include process-util.h in some files. But process-util.c is very long anyway, so it seems nice to create a new file. rename_process(), invoked_as(), invoked_by_systemd(), and argv_looks_like_help() which lived in process-util.c refer to saved_argc and saved_argv, so it seems reasonable to move them to the new file too. util.c is now empty, so it is removed. util.h remains.
Diffstat (limited to 'src/test/test-process-util.c')
-rw-r--r--src/test/test-process-util.c102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 990eb1e2b6..a9b2f537ca 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -524,108 +524,6 @@ TEST(get_process_cmdline_harder) {
_exit(EXIT_SUCCESS);
}
-static void test_rename_process_now(const char *p, int ret) {
- _cleanup_free_ char *comm = NULL, *cmdline = NULL;
- int r;
-
- log_info("/* %s(%s) */", __func__, p);
-
- r = rename_process(p);
- assert_se(r == ret ||
- (ret == 0 && r >= 0) ||
- (ret > 0 && r > 0));
-
- log_debug_errno(r, "rename_process(%s): %m", p);
-
- if (r < 0)
- return;
-
-#if HAVE_VALGRIND_VALGRIND_H
- /* see above, valgrind is weird, we can't verify what we are doing here */
- if (RUNNING_ON_VALGRIND)
- return;
-#endif
-
- assert_se(get_process_comm(0, &comm) >= 0);
- log_debug("comm = <%s>", comm);
- assert_se(strneq(comm, p, TASK_COMM_LEN-1));
- /* We expect comm to be at most 16 bytes (TASK_COMM_LEN). The kernel may raise this limit in the
- * future. We'd only check the initial part, at least until we recompile, but this will still pass. */
-
- r = get_process_cmdline(0, SIZE_MAX, 0, &cmdline);
- assert_se(r >= 0);
- /* we cannot expect cmdline to be renamed properly without privileges */
- if (geteuid() == 0) {
- if (r == 0 && detect_container() > 0)
- log_info("cmdline = <%s> (not verified, Running in unprivileged container?)", cmdline);
- else {
- log_info("cmdline = <%s> (expected <%.*s>)", cmdline, (int) strlen("test-process-util"), p);
-
- bool skip = cmdline[0] == '"'; /* A shortcut to check if the string is quoted */
-
- assert_se(strneq(cmdline + skip, p, strlen("test-process-util")));
- assert_se(startswith(cmdline + skip, p));
- }
- } else
- log_info("cmdline = <%s> (not verified)", cmdline);
-}
-
-static void test_rename_process_one(const char *p, int ret) {
- siginfo_t si;
- pid_t pid;
-
- log_info("/* %s(%s) */", __func__, p);
-
- pid = fork();
- assert_se(pid >= 0);
-
- if (pid == 0) {
- /* child */
- test_rename_process_now(p, ret);
- _exit(EXIT_SUCCESS);
- }
-
- assert_se(wait_for_terminate(pid, &si) >= 0);
- assert_se(si.si_code == CLD_EXITED);
- assert_se(si.si_status == EXIT_SUCCESS);
-}
-
-TEST(rename_process_invalid) {
- assert_se(rename_process(NULL) == -EINVAL);
- assert_se(rename_process("") == -EINVAL);
-}
-
-TEST(rename_process_multi) {
- pid_t pid;
-
- pid = fork();
- assert_se(pid >= 0);
-
- if (pid > 0) {
- siginfo_t si;
-
- assert_se(wait_for_terminate(pid, &si) >= 0);
- assert_se(si.si_code == CLD_EXITED);
- assert_se(si.si_status == EXIT_SUCCESS);
-
- return;
- }
-
- /* child */
- test_rename_process_now("one", 1);
- test_rename_process_now("more", 0); /* longer than "one", hence truncated */
- (void) setresuid(99, 99, 99); /* change uid when running privileged */
- test_rename_process_now("time!", 0);
- test_rename_process_now("0", 1); /* shorter than "one", should fit */
- _exit(EXIT_SUCCESS);
-}
-
-TEST(rename_process) {
- test_rename_process_one("foo", 1); /* should always fit */
- test_rename_process_one("this is a really really long process name, followed by some more words", 0); /* unlikely to fit */
- test_rename_process_one("1234567", 1); /* should always fit */
-}
-
TEST(getpid_cached) {
siginfo_t si;
pid_t a, b, c, d, e, f, child;