executor: do not abort on invalid serialization fd
E.g. --deserialize=15 would cause the program to abrt in safe_close. But in fact, we shouldn't try to do the close in any case: if the fd is not valid, we should return an error without modifying state. And if it _is_ valid, we set O_CLOEXEC on it, so it'll be closed automatically later.
This commit is contained in:
+5
-6
@@ -16,7 +16,6 @@
|
||||
#include "exit-status.h"
|
||||
#include "fd-util.h"
|
||||
#include "fdset.h"
|
||||
#include "fileio.h"
|
||||
#include "format-table.h"
|
||||
#include "label-util.h"
|
||||
#include "log.h"
|
||||
@@ -106,19 +105,19 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
OPTION_LONG("deserialize", "FD", "Deserialize process config from FD"): {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
FILE *f;
|
||||
|
||||
fd = parse_fd(arg);
|
||||
int fd = parse_fd(arg);
|
||||
if (fd < 0)
|
||||
return log_error_errno(fd, "Failed to parse serialization fd \"%s\": %m", arg);
|
||||
|
||||
/* Set O_CLOEXEC and as a side effect, verify that the fd is valid. */
|
||||
r = fd_cloexec(fd, /* cloexec= */ true);
|
||||
if (r == -EBADF)
|
||||
return log_error_errno(r, "Serialization fd %d is not valid.", fd);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set serialization fd %d to close-on-exec: %m",
|
||||
fd);
|
||||
|
||||
f = take_fdopen(&fd, "r");
|
||||
FILE *f = fdopen(fd, "r");
|
||||
if (!f)
|
||||
return log_error_errno(errno, "Failed to open serialization fd %d: %m", fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user