From 327f620ea51a132122c03eeb3475332119be1396 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 17 Apr 2014 21:58:36 +0900 Subject: [PATCH] Add new method to get the PID of client process. Only if the client is in same host (localhost), Get the PID from socket and deliever it to the service core. Change-Id: I79c2aafe4ab5c2480a29a413701058ce92999c99 --- include/service_common.h | 11 +++++++++++ packaging/data-provider-master.spec | 2 +- src/service_common.c | 26 ++++++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/service_common.h b/include/service_common.h index f6ca153..f0dbf96 100644 --- a/include/service_common.h +++ b/include/service_common.h @@ -29,6 +29,17 @@ struct service_context; struct service_event_item; extern int tcb_fd(struct tcb *tcb); + +/*! + * \remarks This function will return valid pid only after it gets the packet from a client. + * or it will returns -1. + * \param[in] Thread Control Block + * \return pid Process Id + * \retval -1 TCB is not valid or the client is remote host. so we cannot get the PID of it. + * \retval >0 Process Id (PID) + */ +extern int tcb_pid(struct tcb *tcb); + extern struct service_context *tcb_svc_ctx(struct tcb *tcb); extern int tcb_client_type(struct tcb *tcb); extern int tcb_client_type_set(struct tcb *tcb, enum tcb_type type); diff --git a/packaging/data-provider-master.spec b/packaging/data-provider-master.spec index 57fe444..b0e04a9 100755 --- a/packaging/data-provider-master.spec +++ b/packaging/data-provider-master.spec @@ -2,7 +2,7 @@ Name: data-provider-master Summary: Master service provider for liveboxes -Version: 0.41.3 +Version: 0.42.0 Release: 1 Group: HomeTF/Livebox License: Flora diff --git a/src/service_common.c b/src/service_common.c index 4de77e1..9ddd002 100644 --- a/src/service_common.c +++ b/src/service_common.c @@ -105,6 +105,7 @@ struct tcb { /* Thread controll block */ int fd; /*!< Connection handle */ enum tcb_type type; int ctrl_pipe[PIPE_MAX]; + pid_t pid; /*!< Keep the PID of client, if the client is remote one, this will be -1 */ }; /*! @@ -122,7 +123,6 @@ static void *client_packet_pump_main(void *data) int size = 0; int packet_offset = 0; int recv_offset = 0; - int pid; long ret; int fd; char evt_ch = EVT_CH; @@ -181,7 +181,7 @@ static void *client_packet_pump_main(void *data) ptr = NULL; break; } - + /*! * \TODO * Service!!! Receive packet & route packet @@ -201,7 +201,7 @@ static void *client_packet_pump_main(void *data) recv_state = RECV_HEADER; /* Go through, don't break from here */ case RECV_HEADER: - ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid); + ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); if (ret <= 0) { if (ret == 0) { ret = -ECANCELED; @@ -243,7 +243,7 @@ static void *client_packet_pump_main(void *data) } break; case RECV_PAYLOAD: - ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid); + ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); if (ret <= 0) { if (ret == 0) { ret = -ECANCELED; @@ -436,6 +436,7 @@ static inline struct tcb *tcb_create(struct service_context *svc_ctx, int fd) tcb->fd = fd; tcb->svc_ctx = svc_ctx; tcb->type = TCB_CLIENT_TYPE_APP; + tcb->pid = -1; DbgPrint("Create a new service thread [%d]\n", fd); status = pthread_create(&tcb->thid, NULL, client_packet_pump_main, tcb); @@ -694,7 +695,7 @@ static void *server_main(void *data) ErrPrint("Failed to create a new TCB: %d (%d)\n", client_fd, svc_ctx->fd); secure_socket_destroy_handle(client_fd); } - } + } if (FD_ISSET(svc_ctx->evt_pipe[PIPE_READ], &set)) { if (read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) { @@ -784,7 +785,7 @@ static void *server_main(void *data) * how can I protect this TCB from deletion without disturbing the server thread? */ tcb_destroy(svc_ctx, tcb); - } + } /* If there is no such triggered FD? */ } @@ -982,6 +983,19 @@ HAPI int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb) * \note * SERVER THREAD */ +HAPI int tcb_pid(struct tcb *tcb) +{ + if (!tcb) { + return -1; + } + + return tcb->pid; +} + +/*! + * \note + * SERVER THREAD + */ HAPI int tcb_fd(struct tcb *tcb) { if (!tcb) { -- 2.7.4