1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

Merge pull request #17407 from keszybz/test-ipcrm

Make test-ipcrm not fail cryptically
This commit is contained in:
Lennart Poettering 2020-10-21 09:04:12 +02:00 committed by GitHub
commit 0393e6a274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 14 deletions

View File

@ -218,7 +218,7 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid, bool rm) {
return ret;
}
static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) {
static int clean_posix_shm_internal(const char *dirname, DIR *dir, uid_t uid, gid_t gid, bool rm) {
struct dirent *de;
int ret = 0, r;
@ -234,7 +234,8 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) {
if (errno == ENOENT)
continue;
ret = log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s: %m", de->d_name);
ret = log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s/%s: %m",
dirname, de->d_name);
continue;
}
@ -244,9 +245,10 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) {
kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) {
if (errno != ENOENT)
ret = log_warning_errno(errno, "Failed to enter shared memory directory %s: %m", de->d_name);
ret = log_warning_errno(errno, "Failed to enter shared memory directory %s/%s: %m",
dirname, de->d_name);
} else {
r = clean_posix_shm_internal(kid, uid, gid, rm);
r = clean_posix_shm_internal(de->d_name, kid, uid, gid, rm);
if (r < 0)
ret = r;
}
@ -262,7 +264,8 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) {
if (errno == ENOENT)
continue;
ret = log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s: %m", de->d_name);
ret = log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s/%s: %m",
dirname, de->d_name);
} else {
log_debug("Removed POSIX shared memory directory %s", de->d_name);
if (ret == 0)
@ -307,7 +310,7 @@ static int clean_posix_shm(uid_t uid, gid_t gid, bool rm) {
return log_warning_errno(errno, "Failed to open /dev/shm: %m");
}
return clean_posix_shm_internal(dir, uid, gid, rm);
return clean_posix_shm_internal("/dev/shm", dir, uid, gid, rm);
}
static int clean_posix_mq(uid_t uid, gid_t gid, bool rm) {

View File

@ -1,11 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "clean-ipc.h"
#include "user-util.h"
#include "errno-util.h"
#include "main-func.h"
#include "tests.h"
#include "util.h"
#include "user-util.h"
int main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
uid_t uid;
int r;
const char* name = argv[1] ?: NOBODY_USER_NAME;
@ -15,11 +16,14 @@ int main(int argc, char *argv[]) {
r = get_user_creds(&name, &uid, NULL, NULL, NULL, 0);
if (r == -ESRCH)
return log_tests_skipped("Failed to resolve user");
if (r < 0) {
log_error_errno(r, "Failed to resolve \"%s\": %m", name);
return EXIT_FAILURE;
}
if (r < 0)
return log_error_errno(r, "Failed to resolve \"%s\": %m", name);
r = clean_ipc_by_uid(uid);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
if (ERRNO_IS_PRIVILEGE(r))
return log_tests_skipped("No privileges");
return r;
}
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);