mirror of
https://github.com/systemd/systemd
synced 2024-10-04 15:21:01 +00:00
core/exec-invoke: clean up OpenFile= logging
Make collect_open_file_fds() the only logging function, and downgrade various usual errors to debug level if OPENFILE_GRACEFUL is set. Fixes #33458
This commit is contained in:
parent
b9c5d812d5
commit
c24ac9b97b
|
@ -3717,7 +3717,7 @@ static int connect_unix_harder(const ExecContext *c, const ExecParameters *p, co
|
||||||
|
|
||||||
r = sockaddr_un_set_path(&addr.un, FORMAT_PROC_FD_PATH(ofd));
|
r = sockaddr_un_set_path(&addr.un, FORMAT_PROC_FD_PATH(ofd));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_exec_error_errno(c, p, r, "Failed to set sockaddr for '%s': %m", of->path);
|
return log_exec_debug_errno(c, p, r, "Failed to set sockaddr for '%s': %m", of->path);
|
||||||
sa_len = r;
|
sa_len = r;
|
||||||
|
|
||||||
FOREACH_ELEMENT(i, socket_types) {
|
FOREACH_ELEMENT(i, socket_types) {
|
||||||
|
@ -3725,7 +3725,7 @@ static int connect_unix_harder(const ExecContext *c, const ExecParameters *p, co
|
||||||
|
|
||||||
fd = socket(AF_UNIX, *i|SOCK_CLOEXEC, 0);
|
fd = socket(AF_UNIX, *i|SOCK_CLOEXEC, 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_exec_error_errno(c, p,
|
return log_exec_debug_errno(c, p,
|
||||||
errno, "Failed to create socket for '%s': %m",
|
errno, "Failed to create socket for '%s': %m",
|
||||||
of->path);
|
of->path);
|
||||||
|
|
||||||
|
@ -3733,12 +3733,12 @@ static int connect_unix_harder(const ExecContext *c, const ExecParameters *p, co
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
return TAKE_FD(fd);
|
return TAKE_FD(fd);
|
||||||
if (r != -EPROTOTYPE)
|
if (r != -EPROTOTYPE)
|
||||||
return log_exec_error_errno(c, p,
|
return log_exec_debug_errno(c, p,
|
||||||
r, "Failed to connect to socket for '%s': %m",
|
r, "Failed to connect to socket for '%s': %m",
|
||||||
of->path);
|
of->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return log_exec_error_errno(c, p,
|
return log_exec_debug_errno(c, p,
|
||||||
SYNTHETIC_ERRNO(EPROTOTYPE), "No suitable socket type to connect to socket '%s'.",
|
SYNTHETIC_ERRNO(EPROTOTYPE), "No suitable socket type to connect to socket '%s'.",
|
||||||
of->path);
|
of->path);
|
||||||
}
|
}
|
||||||
|
@ -3753,10 +3753,10 @@ static int get_open_file_fd(const ExecContext *c, const ExecParameters *p, const
|
||||||
|
|
||||||
ofd = open(of->path, O_PATH | O_CLOEXEC);
|
ofd = open(of->path, O_PATH | O_CLOEXEC);
|
||||||
if (ofd < 0)
|
if (ofd < 0)
|
||||||
return log_exec_error_errno(c, p, errno, "Failed to open '%s' as O_PATH: %m", of->path);
|
return log_exec_debug_errno(c, p, errno, "Failed to open '%s' as O_PATH: %m", of->path);
|
||||||
|
|
||||||
if (fstat(ofd, &st) < 0)
|
if (fstat(ofd, &st) < 0)
|
||||||
return log_exec_error_errno(c, p, errno, "Failed to stat '%s': %m", of->path);
|
return log_exec_debug_errno(c, p, errno, "Failed to stat '%s': %m", of->path);
|
||||||
|
|
||||||
if (S_ISSOCK(st.st_mode)) {
|
if (S_ISSOCK(st.st_mode)) {
|
||||||
fd = connect_unix_harder(c, p, of, ofd);
|
fd = connect_unix_harder(c, p, of, ofd);
|
||||||
|
@ -3764,7 +3764,7 @@ static int get_open_file_fd(const ExecContext *c, const ExecParameters *p, const
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
if (FLAGS_SET(of->flags, OPENFILE_READ_ONLY) && shutdown(fd, SHUT_WR) < 0)
|
if (FLAGS_SET(of->flags, OPENFILE_READ_ONLY) && shutdown(fd, SHUT_WR) < 0)
|
||||||
return log_exec_error_errno(c, p,
|
return log_exec_debug_errno(c, p,
|
||||||
errno, "Failed to shutdown send for socket '%s': %m",
|
errno, "Failed to shutdown send for socket '%s': %m",
|
||||||
of->path);
|
of->path);
|
||||||
|
|
||||||
|
@ -3778,7 +3778,7 @@ static int get_open_file_fd(const ExecContext *c, const ExecParameters *p, const
|
||||||
|
|
||||||
fd = fd_reopen(ofd, flags|O_NOCTTY|O_CLOEXEC);
|
fd = fd_reopen(ofd, flags|O_NOCTTY|O_CLOEXEC);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_exec_error_errno(c, p, fd, "Failed to reopen file '%s': %m", of->path);
|
return log_exec_debug_errno(c, p, fd, "Failed to reopen file '%s': %m", of->path);
|
||||||
|
|
||||||
log_exec_debug(c, p, "Opened file '%s' as fd %d.", of->path, fd);
|
log_exec_debug(c, p, "Opened file '%s' as fd %d.", of->path, fd);
|
||||||
}
|
}
|
||||||
|
@ -3787,8 +3787,6 @@ static int get_open_file_fd(const ExecContext *c, const ExecParameters *p, const
|
||||||
}
|
}
|
||||||
|
|
||||||
static int collect_open_file_fds(const ExecContext *c, ExecParameters *p, size_t *n_fds) {
|
static int collect_open_file_fds(const ExecContext *c, ExecParameters *p, size_t *n_fds) {
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(c);
|
assert(c);
|
||||||
assert(p);
|
assert(p);
|
||||||
assert(n_fds);
|
assert(n_fds);
|
||||||
|
@ -3799,21 +3797,24 @@ static int collect_open_file_fds(const ExecContext *c, ExecParameters *p, size_t
|
||||||
fd = get_open_file_fd(c, p, of);
|
fd = get_open_file_fd(c, p, of);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (FLAGS_SET(of->flags, OPENFILE_GRACEFUL)) {
|
if (FLAGS_SET(of->flags, OPENFILE_GRACEFUL)) {
|
||||||
log_exec_warning_errno(c, p, fd,
|
log_exec_full_errno(c, p,
|
||||||
|
fd == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(fd) ? LOG_DEBUG : LOG_WARNING,
|
||||||
|
fd,
|
||||||
"Failed to get OpenFile= file descriptor for '%s', ignoring: %m",
|
"Failed to get OpenFile= file descriptor for '%s', ignoring: %m",
|
||||||
of->path);
|
of->path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return log_exec_error_errno(c, p, fd,
|
||||||
|
"Failed to get OpenFile= file descriptor for '%s': %m",
|
||||||
|
of->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GREEDY_REALLOC(p->fds, *n_fds + 1))
|
if (!GREEDY_REALLOC(p->fds, *n_fds + 1))
|
||||||
return -ENOMEM;
|
return log_oom();
|
||||||
|
|
||||||
r = strv_extend(&p->fd_names, of->fdname);
|
if (strv_extend(&p->fd_names, of->fdname) < 0)
|
||||||
if (r < 0)
|
return log_oom();
|
||||||
return r;
|
|
||||||
|
|
||||||
p->fds[(*n_fds)++] = TAKE_FD(fd);
|
p->fds[(*n_fds)++] = TAKE_FD(fd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue