From b6f32819e513ecc93f4b6bbb1966802e91dc76a7 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Wed, 1 Jul 2020 14:24:45 +0200 Subject: [PATCH] networkd -> ipcd --- src/communication.c | 36 ++++++++++++++++++------------------ src/error.c | 6 +++--- src/ipc.h | 21 ++++++++------------- src/network.c | 10 +++++----- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/communication.c b/src/communication.c index 1cc6485..94b2ef1 100644 --- a/src/communication.c +++ b/src/communication.c @@ -43,14 +43,14 @@ struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname) IPC_RETURN_NO_ERROR; } -// when networkd is not working properly (or do not retrieve the service): srv->fd = 0 -struct ipc_error ipc_contact_networkd (int *pfd, const char *sname) +// when ipcd is not working properly (or do not retrieve the service): srv->fd = 0 +struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname) { - T_R ((pfd == NULL), IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM); - T_R ((sname == NULL), IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM); + T_R ((pfd == NULL), IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM); + T_R ((sname == NULL), IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM); - char *networkvar = getenv ("IPC_NETWORK"); - if (networkvar == NULL) { + char *ipcd_var = getenv ("IPC_NETWORK"); + if (ipcd_var == NULL) { *pfd = 0; IPC_RETURN_NO_ERROR; } @@ -63,7 +63,7 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname) columnthensname[0] = ';'; memcpy (columnthensname + 1, sname, strlen (sname)); - if (strncmp (networkvar, sname, strlen (sname)) != 0 && strstr (networkvar, columnthensname) == NULL) { + if (strncmp (ipcd_var, sname, strlen (sname)) != 0 && strstr (ipcd_var, columnthensname) == NULL) { *pfd = 0; IPC_RETURN_NO_ERROR; } @@ -72,31 +72,31 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname) SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX); TEST_IPC_RR (service_path (buf, "network"), "cannot get network service path"); - int networkdfd = 0; + int ipcd_fd = 0; - TEST_IPC_RETURN_ON_ERROR (usock_connect (&networkdfd, buf)); + TEST_IPC_RETURN_ON_ERROR (usock_connect (&ipcd_fd, buf)); SECURE_DECLARATION (struct ipc_message, msg); msg.type = MSG_TYPE_NETWORK_LOOKUP; msg.user_type = MSG_TYPE_NETWORK_LOOKUP; SECURE_BUFFER_DECLARATION (char, content, BUFSIZ); - snprintf (content, BUFSIZ, "%s;%s", sname, networkvar); + snprintf (content, BUFSIZ, "%s;%s", sname, ipcd_var); msg.length = strlen (content); msg.payload = content; - TEST_IPC_RR (ipc_write_fd (networkdfd, &msg), "cannot send a message to networkd"); + TEST_IPC_RR (ipc_write_fd (ipcd_fd, &msg), "cannot send a message to networkd"); - struct ipc_error ret = ipc_receive_fd (networkdfd, pfd); + struct ipc_error ret = ipc_receive_fd (ipcd_fd, pfd); if (ret.error_code == IPC_ERROR_NONE) { - usock_close (networkdfd); + usock_close (ipcd_fd); } return ret; } -// Create context, contact networkd, connects to the service. +// Create context, contact ipcd, connects to the service. struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname) { T_R ((ctx == NULL), IPC_ERROR_CONNECTION__NO_CTX); @@ -107,9 +107,9 @@ struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname) SECURE_DECLARATION(struct pollfd, pollfd); pollfd.events = POLLIN; - TEST_IPC_P (ipc_contact_networkd (&pollfd.fd, sname), "error during networkd connection"); + TEST_IPC_P (ipc_contact_ipcd (&pollfd.fd, sname), "error during networkd connection"); - // if networkd did not initiate the connection + // if ipcd did not initiate the connection if (pollfd.fd <= 0) { // gets the service path SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX); @@ -336,7 +336,7 @@ struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ctx, int index) { - // If the socket is associated to another one for networkd: + // If the socket is associated to another one for ipcd: // read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch. if (ctx->switchdb.collection != NULL) { int talkingfd = ctx->pollfd[index].fd; @@ -370,7 +370,7 @@ struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ct if (buf != NULL) free (buf); - // Everything is OK: inform networkd of a successful transfer. + // Everything is OK: inform ipcd of a successful transfer. IPC_EVENT_SET (event, IPC_EVENT_TYPE_SWITCH, index, ctx->pollfd[index].fd, NULL); IPC_RETURN_NO_ERROR; } else if (msize == 0) { diff --git a/src/error.c b/src/error.c index b573c9b..a26e7ec 100644 --- a/src/error.c +++ b/src/error.c @@ -40,8 +40,8 @@ static struct ipc_errors_verbose ipc_errors_verbose[] = { , {IPC_ERROR_WAIT_EVENT__NO_CLIENTS_PARAM, "ipc_wait_event: no clients param"} , {IPC_ERROR_WAIT_EVENT__NO_EVENT_PARAM , "ipc_wait_event: no event param"} - , {IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM, "ipc_contact_networkd: no service name param"} - , {IPC_ERROR_CONTACT_NETWORKD__NO_SERVER_PARAM , "ipc_contact_networkd: no server param"} + , {IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM, "ipc_contact_ipcd: no service name param"} + , {IPC_ERROR_CONTACT_IPCD__NO_SERVER_PARAM , "ipc_contact_ipcd: no server param"} , {IPC_ERROR_HANDLE_NEW_CONNECTION__MALLOC, "ipc_handle_new_connection: error on malloc function"} @@ -133,7 +133,7 @@ static struct ipc_errors_verbose ipc_errors_verbose[] = { , {IPC_ERROR_CONNECTION__NO_CTX, "IPC_ERROR_CONNECTION__NO_CTX"} , {IPC_ERROR_CTX_INIT__MALLOC_CTX, "IPC_ERROR_CTX_INIT__MALLOC_CTX"} , {IPC_ERROR_CTX_INIT__MALLOC_POLLFD, "IPC_ERROR_CTX_INIT__MALLOC_POLLFD"} - , {IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM, "IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM"} + , {IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM, "IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM"} , {IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX, "IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX"} , {IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES, "IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES"} , {IPC_ERROR_MESSAGE_DEL__INDEX_ERROR, "IPC_ERROR_MESSAGE_DEL__INDEX_ERROR"} diff --git a/src/ipc.h b/src/ipc.h index c8763d9..27da563 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -122,8 +122,8 @@ enum ipc_error_code { , IPC_ERROR_DEL_FD__EMPTIED_LIST = 33 , IPC_ERROR_DEL_FD__EMPTY_LIST = 34 , IPC_ERROR_DEL_FD__CANNOT_FIND_CLIENT = 35 - , IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM = 36 - , IPC_ERROR_CONTACT_NETWORKD__NO_SERVER_PARAM = 37 + , IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM = 36 + , IPC_ERROR_CONTACT_IPCD__NO_SERVER_PARAM = 37 , IPC_ERROR_DEL__EMPTY_LIST = 38 , IPC_ERROR_DEL__EMPTIED_LIST = 39 , IPC_ERROR_DEL__CANNOT_FIND_CLIENT = 40 @@ -185,7 +185,7 @@ enum ipc_error_code { , IPC_ERROR_CONNECTION__NO_CTX = 95 , IPC_ERROR_CTX_INIT__MALLOC_CTX = 96 , IPC_ERROR_CTX_INIT__MALLOC_POLLFD = 97 - , IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM = 98 + , IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM = 98 , IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX = 99 , IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100 , IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101 @@ -351,29 +351,24 @@ void ipc_messages_free (struct ipc_messages *); **/ struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m); +struct ipc_error ipc_ctx_init (struct ipc_ctx **); struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx); struct ipc_error service_path (char *path, const char *sname); - struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); -/** - * Used by ipc_server_init and ipc_connection - */ -struct ipc_error ipc_ctx_init (struct ipc_ctx **); - void ipc_connection_print (struct ipc_connection_info *cinfo); void ipc_connections_print (struct ipc_ctx *cinfos); // Last parameter is the index for the server fd in the context structure. struct ipc_error ipc_accept_add (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); -struct ipc_error ipc_contact_networkd (int *pfd, const char *sname); +struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname); struct ipc_error service_path (char *path, const char *sname); /*** - * networkd enumerations, structures and functions + * ipcd enumerations, structures and functions **/ -struct networkd { +struct ipcd { int cpt; struct ipc_connection_info *srv; struct ipc_ctx *clients; @@ -381,7 +376,7 @@ struct networkd { }; struct ipc_error -ipc_wait_event_networkd (struct ipc_ctx *cinfos +ipc_wait_event_ipcd (struct ipc_ctx *cinfos , struct ipc_connection_info *cinfo // cinfo is NULL for clients , struct ipc_event *event, struct ipc_switchings *switchdb, int *timer); diff --git a/src/network.c b/src/network.c index a54a290..fc88a02 100644 --- a/src/network.c +++ b/src/network.c @@ -20,12 +20,12 @@ /** * TODO: - * describe a protocol to get this working into networkd - * asking networkd for a fd with an URI + * describe a protocol to get this working into ipcd + * asking ipcd for a fd with an URI * URI should contain: who (the service name), where (destination), how (protocol) - * networkd initiates a communication with the requested service - * networkd sends the fd - * get a networkd working with this + * ipcd initiates a communication with the requested service + * ipcd sends the fd + * get a ipcd working with this */ struct ipc_error ipc_receive_fd (int sock, int *fd)