summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-29 21:40:54 +0200
committerLennart Poettering <lennart@poettering.net>2015-04-29 21:45:58 +0200
commitcfeaa44a09756a93a881f786678973d9b1e382db (patch)
treec86172a848d4ca1716e1b2b82427e819f025e51c /src/test
parentcfa9677bd164574600d29a9bf99f9d1f28a7a170 (diff)
sd-bus: properly handle creds that are known but undefined for a process
A number of fields do not apply to all processes, including: there a processes without a controlling tty, without parent process, without service, user services or session. To distuingish these cases from the case where we simply don't have the data, always return ENXIO for them, while returning ENODATA for the case where we really lack the information. Also update the credentials dumping code to show this properly. Fields that are known but do not apply are now shown as "n/a". Note that this also changes some of the calls in process-util.c and cgroup-util.c to return ENXIO for these cases.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-cgroup-util.c26
-rw-r--r--src/test/test-process-util.c5
2 files changed, 15 insertions, 16 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index aca4f868a1..fff9ec22cf 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -40,11 +40,11 @@ static void test_path_decode_unit(void) {
check_p_d_u("getty@tty2.service", 0, "getty@tty2.service");
check_p_d_u("getty@tty2.service/", 0, "getty@tty2.service");
check_p_d_u("getty@tty2.service/xxx", 0, "getty@tty2.service");
- check_p_d_u("getty@.service/", -EINVAL, NULL);
- check_p_d_u("getty@.service", -EINVAL, NULL);
+ check_p_d_u("getty@.service/", -ENXIO, NULL);
+ check_p_d_u("getty@.service", -ENXIO, NULL);
check_p_d_u("getty.service", 0, "getty.service");
- check_p_d_u("getty", -EINVAL, NULL);
- check_p_d_u("getty/waldo", -EINVAL, NULL);
+ check_p_d_u("getty", -ENXIO, NULL);
+ check_p_d_u("getty/waldo", -ENXIO, NULL);
check_p_d_u("_cpu.service", 0, "cpu.service");
}
@@ -64,12 +64,12 @@ static void test_path_get_unit(void) {
check_p_g_u("/system.slice/getty@tty5.service/aaa/bbb", 0, "getty@tty5.service");
check_p_g_u("/system.slice/getty@tty5.service/", 0, "getty@tty5.service");
check_p_g_u("/system.slice/getty@tty6.service/tty5", 0, "getty@tty6.service");
- check_p_g_u("sadfdsafsda", -EINVAL, NULL);
- check_p_g_u("/system.slice/getty####@tty6.service/xxx", -EINVAL, NULL);
+ check_p_g_u("sadfdsafsda", -ENXIO, NULL);
+ check_p_g_u("/system.slice/getty####@tty6.service/xxx", -ENXIO, NULL);
check_p_g_u("/system.slice/system-waldo.slice/foobar.service/sdfdsaf", 0, "foobar.service");
check_p_g_u("/system.slice/system-waldo.slice/_cpu.service/sdfdsaf", 0, "cpu.service");
check_p_g_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "user@1000.service");
- check_p_g_u("/user.slice/user-1000.slice/user@.service/server.service", -EINVAL, NULL);
+ check_p_g_u("/user.slice/user-1000.slice/user@.service/server.service", -ENXIO, NULL);
}
static void check_p_g_u_u(const char *path, int code, const char *result) {
@@ -87,15 +87,15 @@ static void test_path_get_user_unit(void) {
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo.slice/foobar.service", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service/waldo/uuuux", 0, "foobar.service");
- check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo/waldo/uuuux", -EINVAL, NULL);
+ check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo/waldo/uuuux", -ENXIO, NULL);
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/session-2.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar@pie.service/pa/po", 0, "foobar@pie.service");
- check_p_g_u_u("/meh.service", -ENOENT, NULL);
+ check_p_g_u_u("/meh.service", -ENXIO, NULL);
check_p_g_u_u("/session-3.scope/_cpu.service", 0, "cpu.service");
check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/server.service", 0, "server.service");
check_p_g_u_u("/user.slice/user-1000.slice/user@1000.service/foobar.slice/foobar@pie.service", 0, "foobar@pie.service");
- check_p_g_u_u("/user.slice/user-1000.slice/user@.service/server.service", -ENOENT, NULL);
+ check_p_g_u_u("/user.slice/user-1000.slice/user@.service/server.service", -ENXIO, NULL);
}
static void check_p_g_s(const char *path, int code, const char *result) {
@@ -108,8 +108,8 @@ static void check_p_g_s(const char *path, int code, const char *result) {
static void test_path_get_session(void) {
check_p_g_s("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "2");
check_p_g_s("/session-3.scope", 0, "3");
- check_p_g_s("/session-.scope", -ENOENT, NULL);
- check_p_g_s("", -ENOENT, NULL);
+ check_p_g_s("/session-.scope", -ENXIO, NULL);
+ check_p_g_s("", -ENXIO, NULL);
}
static void check_p_g_o_u(const char *path, int code, uid_t result) {
@@ -122,7 +122,7 @@ static void check_p_g_o_u(const char *path, int code, uid_t result) {
static void test_path_get_owner_uid(void) {
check_p_g_o_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, 1000);
check_p_g_o_u("/user.slice/user-1006.slice", 0, 1006);
- check_p_g_o_u("", -ENOENT, 0);
+ check_p_g_o_u("", -ENXIO, 0);
}
static void test_get_paths(void) {
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 1de100cdae..e4e2efecd5 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -44,9 +44,8 @@ static void test_get_process_comm(void) {
if (stat("/proc/1/comm", &st) == 0) {
assert_se(get_process_comm(1, &a) >= 0);
log_info("pid1 comm: '%s'", a);
- } else {
+ } else
log_warning("/proc/1/comm does not exist.");
- }
assert_se(get_process_cmdline(1, 0, true, &c) >= 0);
log_info("pid1 cmdline: '%s'", c);
@@ -87,7 +86,7 @@ static void test_get_process_comm(void) {
log_info("self strlen(environ): '%zu'", strlen(env));
if (!detect_container(NULL))
- assert_se(get_ctty_devnr(1, &h) == -ENOENT);
+ assert_se(get_ctty_devnr(1, &h) == -ENXIO);
getenv_for_pid(1, "PATH", &i);
log_info("pid1 $PATH: '%s'", strna(i));