[CRIU] [PATCH 7/9] unit: don't check ui->ue->name.len twice in bind_unix_sk()
Andrei Vagin
avagin at virtuozzo.com
Fri Mar 16 20:24:28 MSK 2018
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/sk-unix.c | 62 ++++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 32 deletions(-)
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index af81a1d83..77c7b5606 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1349,51 +1349,49 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, ui->name, ui->ue->name.len);
- if (ui->ue->name.len) {
- if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd))
- return -1;
+ if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd))
+ return -1;
- ret = bind(sk, (struct sockaddr *)&addr,
- sizeof(addr.sun_family) + ui->ue->name.len);
- if (ret < 0) {
- if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) {
- if (bind_deleted_unix_sk(sk, ui, &addr))
- goto done;
- } else {
- pr_perror("Can't bind socket");
+ ret = bind(sk, (struct sockaddr *)&addr,
+ sizeof(addr.sun_family) + ui->ue->name.len);
+ if (ret < 0) {
+ if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) {
+ if (bind_deleted_unix_sk(sk, ui, &addr))
goto done;
- }
+ } else {
+ pr_perror("Can't bind socket");
+ goto done;
}
+ }
- if (*ui->name && ui->ue->file_perms) {
- FilePermsEntry *perms = ui->ue->file_perms;
- char fname[PATH_MAX];
-
- if (ui->ue->name.len >= sizeof(fname)) {
- pr_err("The file name is too long\n");
- goto done;
- }
+ if (*ui->name && ui->ue->file_perms) {
+ FilePermsEntry *perms = ui->ue->file_perms;
+ char fname[PATH_MAX];
- memcpy(fname, ui->name, ui->ue->name.len);
- fname[ui->ue->name.len] = '\0';
+ if (ui->ue->name.len >= sizeof(fname)) {
+ pr_err("The file name is too long\n");
+ goto done;
+ }
- if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
- pr_perror("Unable to change file owner and group");
- goto done;
- }
+ memcpy(fname, ui->name, ui->ue->name.len);
+ fname[ui->ue->name.len] = '\0';
- if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
- pr_perror("Unable to change file mode bits");
- goto done;
- }
+ if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
+ pr_perror("Unable to change file owner and group");
+ goto done;
}
- if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) {
- pr_perror("failed to unlink %s", ui->ue->name.data);
+ if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
+ pr_perror("Unable to change file mode bits");
goto done;
}
}
+ if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) {
+ pr_perror("failed to unlink %s", ui->ue->name.data);
+ goto done;
+ }
+
if (ui->ue->state != TCP_LISTEN) {
ui->bound = 1;
wake_connected_sockets(ui);
--
2.13.6
More information about the CRIU
mailing list