[CRIU] [PATCHv2 2/5] service: set one exit point
Ruslan Kuprieiev
kupruser at gmail.com
Fri Sep 20 18:19:15 EDT 2013
On 09/19/2013 02:37 PM, Andrey Vagin wrote:
> Cc: Ruslan Kuprieiev<kupruser at gmail.com>
> Signed-off-by: Andrey Vagin<avagin at openvz.org>
Original-patch-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
-------------- next part --------------
diff --git a/cr-service.c b/cr-service.c
index 8e2fc1b..1762a95 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -206,7 +206,7 @@ err:
int cr_service(bool daemon_mode)
{
- int server_fd;
+ int server_fd = -1;
int child_pid;
struct sockaddr_un server_addr;
@@ -220,7 +220,7 @@ int cr_service(bool daemon_mode)
server_fd = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
if (server_fd == -1) {
pr_perror("Can't initialize service socket.");
- return -1;
+ goto err;
}
memset(&server_addr, 0, sizeof(server_addr));
@@ -241,7 +241,7 @@ int cr_service(bool daemon_mode)
if (bind(server_fd, (struct sockaddr *) &server_addr,
server_addr_len) == -1) {
pr_perror("Can't bind.");
- return -1;
+ goto err;
}
pr_info("The service socket is bound to %s\n", server_addr.sun_path);
@@ -249,25 +249,25 @@ int cr_service(bool daemon_mode)
/* change service socket permissions, so anyone can connect to it */
if (chmod(server_addr.sun_path, 0666)) {
pr_perror("Can't change permissions of the service socket.");
- return -1;
+ goto err;
}
if (listen(server_fd, 16) == -1) {
pr_perror("Can't listen for socket connections.");
- return -1;
+ goto err;
}
if (daemon_mode) {
if (daemon(1, 1) == -1) {
pr_perror("Can't run service server in the background");
- return -errno;
+ goto err;
}
}
if (opts.pidfile) {
if (write_pidfile(opts.pidfile, getpid()) == -1) {
pr_perror("Can't write pidfile");
- return -1;
+ goto err;
}
}
@@ -299,5 +299,7 @@ int cr_service(bool daemon_mode)
}
}
- return 0;
+err:
+ close_safe(&server_fd);
+ exit(1);
}
More information about the CRIU
mailing list