Skip to content

Commit

Permalink
status: report errors from get_state_directory_status_file
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jan 28, 2025
1 parent 5dcdae0 commit 4d1ecdd
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/libcrun/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,24 @@ libcrun_get_state_directory (char **out, const char *state_root, const char *id,
return 0;
}

static char *
get_state_directory_status_file (const char *state_root, const char *id)
static int
get_state_directory_status_file (char **out, const char *state_root, const char *id, libcrun_error_t *err)
{
cleanup_free char *root = NULL;
libcrun_error_t *err = NULL;
char *path = NULL;
int ret;

ret = get_run_directory (&root, state_root, err);
if (UNLIKELY (ret < 0))
{
crun_error_release (err);
return NULL;
}
return ret;

ret = append_paths (&path, err, root, id, "status", NULL);
if (UNLIKELY (ret < 0))
{
crun_error_release (err);
return NULL;
}
return ret;

STEAL_POINTER (out, path);

return path;
return 0;
}

static int
Expand Down Expand Up @@ -188,15 +183,19 @@ libcrun_write_container_status (const char *state_root, const char *id, libcrun_
libcrun_error_t *err)
{
int r, ret;
cleanup_free char *file = get_state_directory_status_file (state_root, id);
cleanup_free char *file_tmp = NULL;
cleanup_free char *file = NULL;
size_t len;
cleanup_close int fd_write = -1;
const unsigned char *buf = NULL;
struct pid_stat st;
const char *tmp;
yajl_gen gen = NULL;

ret = get_state_directory_status_file (&file, state_root, id, err);
if (UNLIKELY (ret < 0))
return ret;

ret = read_pid_stat (status->pid, &st, err);
if (UNLIKELY (ret < 0))
return ret;
Expand Down Expand Up @@ -363,9 +362,13 @@ libcrun_read_container_status (libcrun_container_status_t *status, const char *s
cleanup_free char *buffer = NULL;
char err_buffer[256];
int ret;
cleanup_free char *file = get_state_directory_status_file (state_root, id);
cleanup_free char *file = NULL;
yajl_val tree, tmp;

ret = get_state_directory_status_file (&file, state_root, id, err);
if (UNLIKELY (ret < 0))
return ret;

ret = read_all_file (file, &buffer, NULL, err);
if (UNLIKELY (ret < 0))
return ret;
Expand Down

0 comments on commit 4d1ecdd

Please sign in to comment.