sync: switch to new error helpers

parent 8d3bcf63
...@@ -23,30 +23,21 @@ static int __sync_wait(int fd, int sequence) ...@@ -23,30 +23,21 @@ static int __sync_wait(int fd, int sequence)
ssize_t ret; ssize_t ret;
ret = lxc_read_nointr(fd, &sync, sizeof(sync)); ret = lxc_read_nointr(fd, &sync, sizeof(sync));
if (ret < 0) { if (ret < 0)
SYSERROR("Sync wait failure"); return log_error_errno(-1, errno, "Sync wait failure");
return -1;
}
if (!ret) if (!ret)
return 0; return 0;
if ((size_t)ret != sizeof(sync)) { if ((size_t)ret != sizeof(sync))
ERROR("Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync)); return log_error(-1, "Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync));
return -1;
}
if (sync == LXC_SYNC_ERROR) { if (sync == LXC_SYNC_ERROR)
ERROR("An error occurred in another process " return log_error(-1, "An error occurred in another process (expected sequence number %d)", sequence);
"(expected sequence number %d)", sequence);
return -1; if (sync != sequence)
} return log_error(-1, "Invalid sequence number %d. Expected sequence number %d", sync, sequence);
if (sync != sequence) {
ERROR("Invalid sequence number %d. Expected sequence number %d",
sync, sequence);
return -1;
}
return 0; return 0;
} }
...@@ -54,10 +45,9 @@ static int __sync_wake(int fd, int sequence) ...@@ -54,10 +45,9 @@ static int __sync_wake(int fd, int sequence)
{ {
int sync = sequence; int sync = sequence;
if (lxc_write_nointr(fd, &sync, sizeof(sync)) < 0) { if (lxc_write_nointr(fd, &sync, sizeof(sync)) < 0)
SYSERROR("Sync wake failure"); return log_error_errno(-1, errno, "Sync wake failure");
return -1;
}
return 0; return 0;
} }
...@@ -65,6 +55,7 @@ static int __sync_barrier(int fd, int sequence) ...@@ -65,6 +55,7 @@ static int __sync_barrier(int fd, int sequence)
{ {
if (__sync_wake(fd, sequence)) if (__sync_wake(fd, sequence))
return -1; return -1;
return __sync_wait(fd, sequence+1); return __sync_wait(fd, sequence+1);
} }
...@@ -103,31 +94,25 @@ int lxc_sync_init(struct lxc_handler *handler) ...@@ -103,31 +94,25 @@ int lxc_sync_init(struct lxc_handler *handler)
int ret; int ret;
ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, handler->sync_sock); ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, handler->sync_sock);
if (ret) { if (ret)
SYSERROR("failed to create synchronization socketpair"); return log_error_errno(-1, errno, "failed to create synchronization socketpair");
return -1;
}
/* Be sure we don't inherit this after the exec */ /* Be sure we don't inherit this after the exec */
fcntl(handler->sync_sock[0], F_SETFD, FD_CLOEXEC); ret = fcntl(handler->sync_sock[0], F_SETFD, FD_CLOEXEC);
if (ret < 0)
return log_error_errno(-1, errno, "Failed to make socket close-on-exec");
return 0; return 0;
} }
void lxc_sync_fini_child(struct lxc_handler *handler) void lxc_sync_fini_child(struct lxc_handler *handler)
{ {
if (handler->sync_sock[0] != -1) { close_prot_errno_disarm(handler->sync_sock[0]);
close(handler->sync_sock[0]);
handler->sync_sock[0] = -1;
}
} }
void lxc_sync_fini_parent(struct lxc_handler *handler) void lxc_sync_fini_parent(struct lxc_handler *handler)
{ {
if (handler->sync_sock[1] != -1) { close_prot_errno_disarm(handler->sync_sock[1]);
close(handler->sync_sock[1]);
handler->sync_sock[1] = -1;
}
} }
void lxc_sync_fini(struct lxc_handler *handler) void lxc_sync_fini(struct lxc_handler *handler)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment