diff --git a/src/libcrun/cgroup-utils.c b/src/libcrun/cgroup-utils.c index 5256b4c714..1653ef49f7 100644 --- a/src/libcrun/cgroup-utils.c +++ b/src/libcrun/cgroup-utils.c @@ -347,7 +347,9 @@ rmdir_all_fd (int dfd) dir = fdopendir (dfd); if (dir == NULL) { + int saved_errno = errno; TEMP_FAILURE_RETRY (close (dfd)); + errno = saved_errno; return -1; } diff --git a/src/libcrun/container.c b/src/libcrun/container.c index c2f50a9b9e..01a91a9760 100644 --- a/src/libcrun/container.c +++ b/src/libcrun/container.c @@ -3968,7 +3968,7 @@ libcrun_container_exec_with_options (libcrun_context_t *context, const char *id, process = make_runtime_spec_schema_config_schema_process (tree, &ctx, &parser_err); if (UNLIKELY (process == NULL)) { - ret = crun_make_error (err, errno, "cannot parse process file: `%s`", parser_err); + ret = crun_make_error (err, 0, "cannot parse process file: `%s`", parser_err); free (parser_err); if (tree) yajl_tree_free (tree); @@ -4177,7 +4177,7 @@ libcrun_container_update (libcrun_context_t *context, const char *id, const char resources = make_runtime_spec_schema_config_linux_resources (tree, &ctx, &parser_err); if (UNLIKELY (resources == NULL)) { - ret = crun_make_error (err, errno, "cannot parse resources: %s", parser_err); + ret = crun_make_error (err, 0, "cannot parse resources: %s", parser_err); goto cleanup; } diff --git a/src/libcrun/criu.c b/src/libcrun/criu.c index 9737c00fb0..bebaabaa4b 100644 --- a/src/libcrun/criu.c +++ b/src/libcrun/criu.c @@ -1217,7 +1217,7 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru } out: ret_out = rmdir (root); - if (UNLIKELY (ret == -1)) + if (UNLIKELY (ret < 0)) return ret; if (UNLIKELY (ret_out == -1)) return crun_make_error (err, errno, "error removing restore directory `%s`", root); diff --git a/src/libcrun/linux.c b/src/libcrun/linux.c index 3b09966292..1c27563994 100644 --- a/src/libcrun/linux.c +++ b/src/libcrun/linux.c @@ -3969,7 +3969,7 @@ expect_success_from_sync_socket (int sync_fd, libcrun_error_t *err) ret = TEMP_FAILURE_RETRY (read (sync_fd, &res, sizeof (res))); if (UNLIKELY (ret != sizeof (res))) - return crun_make_error (err, errno, "read status from sync socket"); + return crun_make_error (err, ret < 0 ? errno : 0, "read status from sync socket"); if (res == 0) return 0; @@ -5171,7 +5171,7 @@ libcrun_run_linux_container (libcrun_container_t *container, container_entrypoin ret = TEMP_FAILURE_RETRY (read (sync_socket_host, &new_pid, sizeof (new_pid))); if (UNLIKELY (ret != sizeof (new_pid))) - return crun_make_error (err, errno, "read pid from sync socket"); + return crun_make_error (err, ret < 0 ? errno : 0, "read pid from sync socket"); /* Cleanup the first process. */ ret = waitpid_ignore_stopped (pid, NULL, 0);