Skip to content

Commit

Permalink
ipcc: Return dup of socket fd to user application
Browse files Browse the repository at this point in the history
This will protect library from closing fd returned to user application.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
jfriesse committed Jan 15, 2013
1 parent b6aabed commit 28c5907
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/coroipcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

struct ipc_instance {
int fd;
int user_app_fd;
struct control_buffer *control_buffer;
char *request_buffer;
char *response_buffer;
Expand Down Expand Up @@ -611,6 +612,11 @@ coroipcc_service_connect (
if (request_fd == -1) {
return (CS_ERR_LIBRARY);
}
ipc_instance->user_app_fd = dup(request_fd);
if (ipc_instance->user_app_fd == -1) {
close(request_fd);
return (CS_ERR_LIBRARY);
}
#ifdef SO_NOSIGPIPE
socket_nosigpipe (request_fd);
#endif
Expand Down Expand Up @@ -810,6 +816,7 @@ coroipcc_service_disconnect (

shutdown (ipc_instance->fd, SHUT_RDWR);
close (ipc_instance->fd);
close (ipc_instance->user_app_fd);
hdb_handle_destroy (&ipc_hdb, handle);
hdb_handle_put (&ipc_hdb, handle);
return (CS_OK);
Expand Down Expand Up @@ -847,7 +854,7 @@ coroipcc_fd_get (
return (res);
}

*fd = ipc_instance->fd;
*fd = ipc_instance->user_app_fd;

hdb_handle_put (&ipc_hdb, handle);
return (res);
Expand Down

0 comments on commit 28c5907

Please sign in to comment.