From 825e0c1b2cafe8fecd722a1f316bd7c2167c5505 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Thu, 5 Nov 2020 14:15:39 +0100 Subject: [PATCH] v0.7.2: ipcd indicates if it successfully contacted the service. --- Makefile | 18 +++++++++--------- project.zsh | 2 +- src/communication.c | 26 ++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index bc90896..cab2717 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PACKAGE = 'libipc' -VERSION = '0.7.1' +VERSION = '0.7.2' PREFIX := /usr/local BINDIR := $(PREFIX)/bin @@ -50,23 +50,23 @@ libipc.so: src/communication.o src/context.o src/error.o src/fs.o src/message.o $(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o libipc.so.install: libipc.so - @echo ' IN > $(LIBDIR)/libipc.so.0.7.1' + @echo ' IN > $(LIBDIR)/libipc.so.0.7.2' $(Q)mkdir -p '$(DESTDIR)$(LIBDIR)' - $(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.7.1 + $(Q)install -m0755 libipc.so $(DESTDIR)$(LIBDIR)/libipc.so.0.7.2 @echo ' LN > $(LIBDIR)/libipc.so.0.7' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.7' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.2' '$(DESTDIR)/$(LIBDIR)/libipc.so.0.7' @echo ' LN > $(LIBDIR)/libipc.so.0' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so.0' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.2' '$(DESTDIR)/$(LIBDIR)/libipc.so.0' @echo ' LN > $(LIBDIR)/libipc.so' - $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.1' '$(DESTDIR)/$(LIBDIR)/libipc.so' + $(Q)ln -sf '$(LIBDIR)/libipc.so.0.7.2' '$(DESTDIR)/$(LIBDIR)/libipc.so' libipc.so.clean: @echo ' RM > libipc.so' $(Q)rm -f libipc.so libipc.so.uninstall: - @echo ' RM > $(LIBDIR)/libipc.so.0.7.1' - $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.1' + @echo ' RM > $(LIBDIR)/libipc.so.0.7.2' + $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.2' @echo ' RM > $(LIBDIR)/libipc.so.0.7' $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7' @echo ' RM > $(LIBDIR)/libipc.so.0' @@ -327,7 +327,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir $(PACKAGE)-$(VERSION)/src/utils.h help: - @echo ' :: libipc-0.7.1' + @echo ' :: libipc-0.7.2' @echo '' @echo 'Generic targets:' @echo ' - help  Prints this help message.' diff --git a/project.zsh b/project.zsh index 2b99d0a..79b7121 100644 --- a/project.zsh +++ b/project.zsh @@ -1,6 +1,6 @@ package=libipc # Package name. -version=0.7.1 # Package version. +version=0.7.2 # Package version. # Our targets are the library and its documentation. targets=(libipc man/libipc.7) diff --git a/src/communication.c b/src/communication.c index 4efece3..b8e8d51 100644 --- a/src/communication.c +++ b/src/communication.c @@ -58,9 +58,11 @@ struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname) T_R ((pfd == NULL), IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM); T_R ((sname == NULL), IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM); + // In case there is a problem with ipcd. + *pfd = 0; + char *ipcd_var = getenv ("IPC_NETWORK"); if (ipcd_var == NULL) { - *pfd = 0; IPC_RETURN_NO_ERROR; } // TODO: is there another, more interesting way to do this? @@ -73,7 +75,6 @@ struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname) memcpy (columnthensname + 1, sname, strlen (sname)); if (strncmp (ipcd_var, sname, strlen (sname)) != 0 && strstr (ipcd_var, columnthensname) == NULL) { - *pfd = 0; IPC_RETURN_NO_ERROR; } @@ -95,7 +96,24 @@ struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname) msg.length = strlen (content); msg.payload = content; - TEST_IPC_RR (ipc_write_fd (ipcd_fd, &msg), "cannot send a message to networkd"); + TEST_IPC_RR (ipc_write_fd (ipcd_fd, &msg), "cannot send a message to ipcd"); + + memset (&msg, 0, sizeof(struct ipc_message)); + + // ipcd successfully contacted the service or failed. + // ipcd will tell either OK or NOT OK. + TEST_IPC_RR (ipc_read_fd (ipcd_fd, &msg), "cannot read the ipcd response"); + + // In case ipcd failed. + if (msg.length != 2) { + printf ("ipcd failed to contact service: (%d bytes) %s\n" + , msg.length + , msg.payload); + SECURE_DECLARATION(struct ipc_error, ret); + ret.error_code = IPC_ERROR_CLOSED_RECIPIENT; + usock_close (ipcd_fd); + return ret; + } struct ipc_error ret = ipc_receive_fd (ipcd_fd, pfd); if (ret.error_code == IPC_ERROR_NONE) { @@ -116,7 +134,7 @@ struct ipc_error ipc_connection_ (struct ipc_ctx *ctx, const char *sname, enum i SECURE_DECLARATION(struct pollfd, pollfd); pollfd.events = POLLIN; - TEST_IPC_P (ipc_contact_ipcd (&pollfd.fd, sname), "error during networkd connection"); + TEST_IPC_P (ipc_contact_ipcd (&pollfd.fd, sname), "error during ipcd connection"); // if ipcd did not initiate the connection if (pollfd.fd <= 0) {