Compare commits

...

4 Commits

Author SHA1 Message Date
Lennart Poettering 0393e6a274
Merge pull request #17407 from keszybz/test-ipcrm
Make test-ipcrm not fail cryptically
2020-10-21 09:04:12 +02:00
Lennart Poettering 141261f127 dhcp-server: make parameter const 2020-10-21 15:02:16 +09:00
Zbigniew Jędrzejewski-Szmek bb4febf4c1 test-ipcrm: modernize, skip test on permission errors
I now get:
$ build/test-ipcrm
Failed to enter shared memory directory /dev/shm/multipath: Permission denied
test-ipcrm: No privileges, skipping tests.
2020-10-20 18:06:28 +02:00
Zbigniew Jędrzejewski-Szmek aecdef08be shared/clean-ipc: improve error message a bit
Failed to enter shared memory directory multipath: Permission denied
→
Failed to enter shared memory directory /dev/shm/multipath: Permission denied

When looking at nested directories, we will print only the final two elements
of the path. That is still more useful than just the last component of the
path. To print the full path, we'd have to allocate the string, and since the
error occurs so very rarely, I think the current best-effort approach is
enough.
2020-10-20 18:06:28 +02:00
3 changed files with 22 additions and 15 deletions

View File

@ -566,7 +566,7 @@ static int server_send_nak(sd_dhcp_server *server, DHCPRequest *req) {
} }
static int server_send_forcerenew(sd_dhcp_server *server, be32_t address, static int server_send_forcerenew(sd_dhcp_server *server, be32_t address,
be32_t gateway, uint8_t chaddr[]) { be32_t gateway, const uint8_t chaddr[]) {
_cleanup_free_ DHCPPacket *packet = NULL; _cleanup_free_ DHCPPacket *packet = NULL;
size_t optoffset = 0; size_t optoffset = 0;
int r; int r;

View File

@ -218,7 +218,7 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid, bool rm) {
return ret; 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; struct dirent *de;
int ret = 0, r; 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) if (errno == ENOENT)
continue; 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; 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); kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) { if (!kid) {
if (errno != ENOENT) 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 { } 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) if (r < 0)
ret = r; 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) if (errno == ENOENT)
continue; 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 { } else {
log_debug("Removed POSIX shared memory directory %s", de->d_name); log_debug("Removed POSIX shared memory directory %s", de->d_name);
if (ret == 0) 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 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) { 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+ */ /* SPDX-License-Identifier: LGPL-2.1+ */
#include "clean-ipc.h" #include "clean-ipc.h"
#include "user-util.h" #include "errno-util.h"
#include "main-func.h"
#include "tests.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; uid_t uid;
int r; int r;
const char* name = argv[1] ?: NOBODY_USER_NAME; 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); r = get_user_creds(&name, &uid, NULL, NULL, NULL, 0);
if (r == -ESRCH) if (r == -ESRCH)
return log_tests_skipped("Failed to resolve user"); return log_tests_skipped("Failed to resolve user");
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to resolve \"%s\": %m", name); return log_error_errno(r, "Failed to resolve \"%s\": %m", name);
return EXIT_FAILURE;
}
r = clean_ipc_by_uid(uid); 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);