cg_path_get_user_unit(): Did not correctly parse user-unit templates.
It ran either skip_session() or skip_user_manager(), then ran skip_slices() iff skip_session() ran. It needs to run skip_slices() in either case. Included is a test case demonstrating why.
This commit is contained in:
parent
5e07a79e84
commit
3208148114
|
@ -1251,17 +1251,15 @@ int cg_path_get_user_unit(const char *path, char **unit) {
|
||||||
/* Skip slices, if there are any */
|
/* Skip slices, if there are any */
|
||||||
e = skip_slices(path);
|
e = skip_slices(path);
|
||||||
|
|
||||||
/* Skip the session scope... */
|
/* Skip the session scope or user manager... */
|
||||||
t = skip_session(e);
|
t = skip_session(e);
|
||||||
if (t)
|
if (!t)
|
||||||
/* ... and skip more slices if there's one */
|
t = skip_user_manager(e);
|
||||||
e = skip_slices(t);
|
if (!t)
|
||||||
else {
|
return -ENOENT;
|
||||||
/* ... or require a user manager unit to be there */
|
|
||||||
e = skip_user_manager(e);
|
/* ... and skip more slices if there are any */
|
||||||
if (!e)
|
e = skip_slices(t);
|
||||||
return -ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cg_path_decode_unit(e, unit);
|
return cg_path_decode_unit(e, unit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ static void test_path_get_user_unit(void) {
|
||||||
check_p_g_u_u("/meh.service", -ENOENT, NULL);
|
check_p_g_u_u("/meh.service", -ENOENT, NULL);
|
||||||
check_p_g_u_u("/session-3.scope/_cpu.service", 0, "cpu.service");
|
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/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", -ENOENT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue