Skip to content

Commit

Permalink
utils: add errno logs for exception case
Browse files Browse the repository at this point in the history
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
  • Loading branch information
2xsec authored and Christian Brauner committed Nov 22, 2018
1 parent f00d856 commit 669ffcf
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/lxc/utils.c
Expand Up @@ -1410,8 +1410,10 @@ static int lxc_get_unused_loop_dev_legacy(char *loop_name)
int dfd = -1, fd = -1, ret = -1;

dir = opendir("/dev");
if (!dir)
if (!dir) {
SYSERROR("Failed to open \"/dev\"");
return -1;
}

while ((dp = readdir(dir))) {
if (strncmp(dp->d_name, "loop", 4) != 0)
Expand Down Expand Up @@ -1459,20 +1461,24 @@ static int lxc_get_unused_loop_dev(char *name_loop)
int fd_ctl = -1, fd_tmp = -1;

fd_ctl = open("/dev/loop-control", O_RDWR | O_CLOEXEC);
if (fd_ctl < 0)
if (fd_ctl < 0) {
SYSERROR("Failed to open loop control");
return -ENODEV;
}

loop_nr = ioctl(fd_ctl, LOOP_CTL_GET_FREE);
if (loop_nr < 0)
if (loop_nr < 0) {
SYSERROR("Failed to get loop control");
goto on_error;
}

ret = snprintf(name_loop, LO_NAME_SIZE, "/dev/loop%d", loop_nr);
if (ret < 0 || ret >= LO_NAME_SIZE)
goto on_error;

fd_tmp = open(name_loop, O_RDWR | O_CLOEXEC);
if (fd_tmp < 0)
goto on_error;
SYSERROR("Failed to open loop \"%s\"", name_loop);

on_error:
close(fd_ctl);
Expand All @@ -1487,26 +1493,34 @@ int lxc_prepare_loop_dev(const char *source, char *loop_dev, int flags)

fd_loop = lxc_get_unused_loop_dev(loop_dev);
if (fd_loop < 0) {
if (fd_loop == -ENODEV)
fd_loop = lxc_get_unused_loop_dev_legacy(loop_dev);
else
if (fd_loop != -ENODEV)
goto on_error;

fd_loop = lxc_get_unused_loop_dev_legacy(loop_dev);
if (fd_loop < 0)
goto on_error;
}

fd_img = open(source, O_RDWR | O_CLOEXEC);
if (fd_img < 0)
if (fd_img < 0) {
SYSERROR("Failed to open source \"%s\"", source);
goto on_error;
}

ret = ioctl(fd_loop, LOOP_SET_FD, fd_img);
if (ret < 0)
if (ret < 0) {
SYSERROR("Failed to set loop fd");
goto on_error;
}

memset(&lo64, 0, sizeof(lo64));
lo64.lo_flags = flags;

ret = ioctl(fd_loop, LOOP_SET_STATUS64, &lo64);
if (ret < 0)
if (ret < 0) {
SYSERROR("Failed to set loop status64");
goto on_error;
}

fret = 0;

Expand Down Expand Up @@ -1673,10 +1687,8 @@ int lxc_set_death_signal(int signal, pid_t parent)
return -1;
}

if (ret < 0) {
SYSERROR("Failed to set PR_SET_PDEATHSIG to %d", signal);
if (ret < 0)
return -1;
}

return 0;
}
Expand Down

0 comments on commit 669ffcf

Please sign in to comment.