Archived
3
0

v0.7.2: ipcd indicates if it successfully contacted the service.

This commit is contained in:
Karchnu 2020-11-05 14:15:39 +01:00
parent c69ce64273
commit 825e0c1b2c
3 changed files with 32 additions and 14 deletions

View File

@ -1,5 +1,5 @@
PACKAGE = 'libipc' PACKAGE = 'libipc'
VERSION = '0.7.1' VERSION = '0.7.2'
PREFIX := /usr/local PREFIX := /usr/local
BINDIR := $(PREFIX)/bin 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 $(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 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)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' @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' @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' @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: libipc.so.clean:
@echo ' RM > libipc.so' @echo ' RM > libipc.so'
$(Q)rm -f libipc.so $(Q)rm -f libipc.so
libipc.so.uninstall: libipc.so.uninstall:
@echo ' RM > $(LIBDIR)/libipc.so.0.7.1' @echo ' RM > $(LIBDIR)/libipc.so.0.7.2'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.1' $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7.2'
@echo ' RM > $(LIBDIR)/libipc.so.0.7' @echo ' RM > $(LIBDIR)/libipc.so.0.7'
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7' $(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so.0.7'
@echo ' RM > $(LIBDIR)/libipc.so.0' @echo ' RM > $(LIBDIR)/libipc.so.0'
@ -327,7 +327,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
$(PACKAGE)-$(VERSION)/src/utils.h $(PACKAGE)-$(VERSION)/src/utils.h
help: help:
@echo ' :: libipc-0.7.1' @echo ' :: libipc-0.7.2'
@echo '' @echo ''
@echo 'Generic targets:' @echo 'Generic targets:'
@echo ' - help  Prints this help message.' @echo ' - help  Prints this help message.'

View File

@ -1,6 +1,6 @@
package=libipc # Package name. package=libipc # Package name.
version=0.7.1 # Package version. version=0.7.2 # Package version.
# Our targets are the library and its documentation. # Our targets are the library and its documentation.
targets=(libipc man/libipc.7) targets=(libipc man/libipc.7)

View File

@ -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 ((pfd == NULL), IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM);
T_R ((sname == NULL), IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_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"); char *ipcd_var = getenv ("IPC_NETWORK");
if (ipcd_var == NULL) { if (ipcd_var == NULL) {
*pfd = 0;
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }
// TODO: is there another, more interesting way to do this? // 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)); memcpy (columnthensname + 1, sname, strlen (sname));
if (strncmp (ipcd_var, sname, strlen (sname)) != 0 && strstr (ipcd_var, columnthensname) == NULL) { if (strncmp (ipcd_var, sname, strlen (sname)) != 0 && strstr (ipcd_var, columnthensname) == NULL) {
*pfd = 0;
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }
@ -95,7 +96,24 @@ struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname)
msg.length = strlen (content); msg.length = strlen (content);
msg.payload = 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); struct ipc_error ret = ipc_receive_fd (ipcd_fd, pfd);
if (ret.error_code == IPC_ERROR_NONE) { 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); SECURE_DECLARATION(struct pollfd, pollfd);
pollfd.events = POLLIN; 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 ipcd did not initiate the connection
if (pollfd.fd <= 0) { if (pollfd.fd <= 0) {