communication.c => proc supprimé, déplacement de fichiers, suppression code mort
parent
250e06190d
commit
044e8d034e
318
Makefile
318
Makefile
|
@ -1,318 +0,0 @@
|
|||
PACKAGE = 'perfect-os-junk'
|
||||
VERSION = '0.0.1'
|
||||
|
||||
PREFIX := /usr/local
|
||||
BINDIR := $(PREFIX)/bin
|
||||
LIBDIR := $(PREFIX)/lib
|
||||
SHAREDIR := $(PREFIX)/share
|
||||
INCLUDEDIR := $(PREFIX)/include
|
||||
|
||||
CC := cc
|
||||
AR := ar
|
||||
RANLIB := ranlib
|
||||
CFLAGS := -O2 -Wall -Wextra -Wshadow -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L
|
||||
LDFLAGS :=
|
||||
|
||||
Q := @
|
||||
|
||||
all: libposj pingpong/pingpong pubsub/pubsub pubsub/pubsub-test-send
|
||||
|
||||
libposj: libposj.so libposj.a
|
||||
@:
|
||||
libposj.install: libposj.so.install libposj.a.install
|
||||
|
||||
libposj.clean: libposj.so.clean libposj.a.clean
|
||||
|
||||
libposj.uninstall: libposj.so.uninstall libposj.a.uninstall
|
||||
|
||||
pingpong/pingpong: pingpong/pingpong.o libposj.a
|
||||
@echo '[01;32m [LD] [01;37mpingpong/pingpong[00m'
|
||||
$(Q)$(CC) -o pingpong/pingpong $(LDFLAGS) pingpong/pingpong.o libposj.a -lpthread
|
||||
|
||||
pingpong/pingpong.install: pingpong/pingpong
|
||||
@echo '[01;31m [IN] [01;37m$(BINDIR)/pingpong[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)'
|
||||
$(Q)install -m0755 pingpong/pingpong $(DESTDIR)$(BINDIR)/pingpong
|
||||
|
||||
pingpong/pingpong.clean: pingpong/pingpong.o.clean
|
||||
@echo '[01;37m [RM] [01;37mpingpong/pingpong[00m'
|
||||
$(Q)rm -f pingpong/pingpong
|
||||
|
||||
pingpong/pingpong.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/pingpong[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/pingpong'
|
||||
|
||||
pubsub/pubsub: pubsub/pubsubd.o libposj.a
|
||||
@echo '[01;32m [LD] [01;37mpubsub/pubsub[00m'
|
||||
$(Q)$(CC) -o pubsub/pubsub $(LDFLAGS) pubsub/pubsubd.o libposj.a -lpthread
|
||||
|
||||
pubsub/pubsub.install: pubsub/pubsub
|
||||
@echo '[01;31m [IN] [01;37m$(BINDIR)/pubsub[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)'
|
||||
$(Q)install -m0755 pubsub/pubsub $(DESTDIR)$(BINDIR)/pubsub
|
||||
|
||||
pubsub/pubsub.clean: pubsub/pubsubd.o.clean
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsub[00m'
|
||||
$(Q)rm -f pubsub/pubsub
|
||||
|
||||
pubsub/pubsub.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/pubsub[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/pubsub'
|
||||
|
||||
pubsub/pubsub-test-send: pubsub/pubsub-test-send.o libposj.a
|
||||
@echo '[01;32m [LD] [01;37mpubsub/pubsub-test-send[00m'
|
||||
$(Q)$(CC) -o pubsub/pubsub-test-send $(LDFLAGS) pubsub/pubsub-test-send.o libposj.a -lpthread
|
||||
|
||||
pubsub/pubsub-test-send.install: pubsub/pubsub-test-send
|
||||
@echo '[01;31m [IN] [01;37m$(BINDIR)/pubsub-test-send[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)'
|
||||
$(Q)install -m0755 pubsub/pubsub-test-send $(DESTDIR)$(BINDIR)/pubsub-test-send
|
||||
|
||||
pubsub/pubsub-test-send.clean: pubsub/pubsub-test-send.o.clean
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsub-test-send[00m'
|
||||
$(Q)rm -f pubsub/pubsub-test-send
|
||||
|
||||
pubsub/pubsub-test-send.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/pubsub-test-send[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/pubsub-test-send'
|
||||
|
||||
libposj.so: lib/communication.o lib/process.o lib/pubsubd.o
|
||||
@echo '[01;32m [LD] [01;37mlibposj.so[00m'
|
||||
$(Q)$(CC) -o libposj.so -shared $(LDFLAGS) lib/communication.o lib/process.o lib/pubsubd.o
|
||||
|
||||
libposj.so.install: libposj.so
|
||||
@echo '[01;31m [IN] [01;37m$(LIBDIR)/libposj.so.0.0.1[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(LIBDIR)'
|
||||
$(Q)install -m0755 libposj.so $(DESTDIR)$(LIBDIR)/libposj.so.0.0.1
|
||||
@echo '[01;33m [LN] [01;37m$(LIBDIR)/libposj.so.0.0[00m'
|
||||
$(Q)ln -sf '$(LIBDIR)/libposj.so.0.0.1' '$(DESTDIR)/$(LIBDIR)/libposj.so.0.0'
|
||||
@echo '[01;33m [LN] [01;37m$(LIBDIR)/libposj.so.0[00m'
|
||||
$(Q)ln -sf '$(LIBDIR)/libposj.so.0.0.1' '$(DESTDIR)/$(LIBDIR)/libposj.so.0'
|
||||
@echo '[01;33m [LN] [01;37m$(LIBDIR)/libposj.so[00m'
|
||||
$(Q)ln -sf '$(LIBDIR)/libposj.so.0.0.1' '$(DESTDIR)/$(LIBDIR)/libposj.so'
|
||||
|
||||
libposj.so.clean:
|
||||
@echo '[01;37m [RM] [01;37mlibposj.so[00m'
|
||||
$(Q)rm -f libposj.so
|
||||
|
||||
libposj.so.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(LIBDIR)/libposj.so.0.0.1[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libposj.so.0.0.1'
|
||||
@echo '[01;37m [RM] [01;37m$(LIBDIR)/libposj.so.0.0[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libposj.so.0.0'
|
||||
@echo '[01;37m [RM] [01;37m$(LIBDIR)/libposj.so.0[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libposj.so.0'
|
||||
@echo '[01;37m [RM] [01;37m$(LIBDIR)/libposj.so[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libposj.so'
|
||||
|
||||
libposj.a: lib/communication.o lib/process.o lib/pubsubd.o
|
||||
@echo '[01;32m [LD] [01;37mlibposj.a[00m'
|
||||
$(Q)$(AR) rc 'libposj.a' lib/communication.o lib/process.o lib/pubsubd.o
|
||||
|
||||
libposj.a.install: libposj.a
|
||||
@echo '[01;31m [IN] [01;37m$(LIBDIR)/libposj.a[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(LIBDIR)'
|
||||
$(Q)install -m0755 libposj.a $(DESTDIR)$(LIBDIR)/libposj.a
|
||||
|
||||
libposj.a.clean:
|
||||
@echo '[01;37m [RM] [01;37mlibposj.a[00m'
|
||||
$(Q)rm -f libposj.a
|
||||
|
||||
libposj.a.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(LIBDIR)/libposj.a[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libposj.a'
|
||||
|
||||
pingpong/pingpong.o: pingpong/pingpong.c pingpong/../lib/communication.h
|
||||
@echo '[01;34m [CC] [01;37mpingpong/pingpong.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -c pingpong/pingpong.c -o pingpong/pingpong.o
|
||||
|
||||
pingpong/pingpong.o.install:
|
||||
|
||||
pingpong/pingpong.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mpingpong/pingpong.o[00m'
|
||||
$(Q)rm -f pingpong/pingpong.o
|
||||
|
||||
pingpong/pingpong.o.uninstall:
|
||||
|
||||
pubsub/pubsubd.o: pubsub/pubsubd.c pubsub/../lib/pubsubd.h
|
||||
@echo '[01;34m [CC] [01;37mpubsub/pubsubd.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -c pubsub/pubsubd.c -o pubsub/pubsubd.o
|
||||
|
||||
pubsub/pubsubd.o.install:
|
||||
|
||||
pubsub/pubsubd.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsubd.o[00m'
|
||||
$(Q)rm -f pubsub/pubsubd.o
|
||||
|
||||
pubsub/pubsubd.o.uninstall:
|
||||
|
||||
pubsub/pubsub-test-send.o: pubsub/pubsub-test-send.c pubsub/../lib/pubsubd.h
|
||||
@echo '[01;34m [CC] [01;37mpubsub/pubsub-test-send.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -c pubsub/pubsub-test-send.c -o pubsub/pubsub-test-send.o
|
||||
|
||||
pubsub/pubsub-test-send.o.install:
|
||||
|
||||
pubsub/pubsub-test-send.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsub-test-send.o[00m'
|
||||
$(Q)rm -f pubsub/pubsub-test-send.o
|
||||
|
||||
pubsub/pubsub-test-send.o.uninstall:
|
||||
|
||||
lib/communication.o: lib/communication.c lib/communication.h
|
||||
@echo '[01;34m [CC] [01;37mlib/communication.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -fPIC -c lib/communication.c -fPIC -o lib/communication.o
|
||||
|
||||
lib/communication.o.install:
|
||||
|
||||
lib/communication.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mlib/communication.o[00m'
|
||||
$(Q)rm -f lib/communication.o
|
||||
|
||||
lib/communication.o.uninstall:
|
||||
|
||||
lib/process.o: lib/process.c lib/process.h
|
||||
@echo '[01;34m [CC] [01;37mlib/process.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -fPIC -c lib/process.c -fPIC -o lib/process.o
|
||||
|
||||
lib/process.o.install:
|
||||
|
||||
lib/process.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mlib/process.o[00m'
|
||||
$(Q)rm -f lib/process.o
|
||||
|
||||
lib/process.o.uninstall:
|
||||
|
||||
lib/pubsubd.o: lib/pubsubd.c lib/pubsubd.h
|
||||
@echo '[01;34m [CC] [01;37mlib/pubsubd.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -fPIC -c lib/pubsubd.c -fPIC -o lib/pubsubd.o
|
||||
|
||||
lib/pubsubd.o.install:
|
||||
|
||||
lib/pubsubd.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mlib/pubsubd.o[00m'
|
||||
$(Q)rm -f lib/pubsubd.o
|
||||
|
||||
lib/pubsubd.o.uninstall:
|
||||
|
||||
$(DESTDIR)$(PREFIX):
|
||||
@echo '[01;35m [DIR] [01;37m$(PREFIX)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(PREFIX)
|
||||
$(DESTDIR)$(BINDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(BINDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(BINDIR)
|
||||
$(DESTDIR)$(LIBDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(LIBDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(LIBDIR)
|
||||
$(DESTDIR)$(SHAREDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(SHAREDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(SHAREDIR)
|
||||
$(DESTDIR)$(INCLUDEDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(INCLUDEDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
install: subdirs.install libposj.install pingpong/pingpong.install pubsub/pubsub.install pubsub/pubsub-test-send.install libposj.so.install libposj.a.install pingpong/pingpong.o.install pubsub/pubsubd.o.install pubsub/pubsub-test-send.o.install lib/communication.o.install lib/process.o.install lib/pubsubd.o.install lib/communication.o.install lib/process.o.install lib/pubsubd.o.install
|
||||
@:
|
||||
|
||||
subdirs.install:
|
||||
|
||||
uninstall: subdirs.uninstall libposj.uninstall pingpong/pingpong.uninstall pubsub/pubsub.uninstall pubsub/pubsub-test-send.uninstall libposj.so.uninstall libposj.a.uninstall pingpong/pingpong.o.uninstall pubsub/pubsubd.o.uninstall pubsub/pubsub-test-send.o.uninstall lib/communication.o.uninstall lib/process.o.uninstall lib/pubsubd.o.uninstall lib/communication.o.uninstall lib/process.o.uninstall lib/pubsubd.o.uninstall
|
||||
@:
|
||||
|
||||
subdirs.uninstall:
|
||||
|
||||
test: all subdirs subdirs.test
|
||||
@:
|
||||
|
||||
subdirs.test:
|
||||
|
||||
clean: libposj.clean pingpong/pingpong.clean pubsub/pubsub.clean pubsub/pubsub-test-send.clean libposj.so.clean libposj.a.clean pingpong/pingpong.o.clean pubsub/pubsubd.o.clean pubsub/pubsub-test-send.o.clean lib/communication.o.clean lib/process.o.clean lib/pubsubd.o.clean lib/communication.o.clean lib/process.o.clean lib/pubsubd.o.clean
|
||||
|
||||
distclean: clean
|
||||
|
||||
dist: dist-gz dist-xz dist-bz2
|
||||
$(Q)rm -- $(PACKAGE)-$(VERSION)
|
||||
|
||||
distdir:
|
||||
$(Q)rm -rf -- $(PACKAGE)-$(VERSION)
|
||||
$(Q)ln -s -- . $(PACKAGE)-$(VERSION)
|
||||
|
||||
dist-gz: $(PACKAGE)-$(VERSION).tar.gz
|
||||
$(PACKAGE)-$(VERSION).tar.gz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.gz[00m'
|
||||
$(Q)tar czf $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/pingpong/pingpong.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsub-test-send.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.h
|
||||
|
||||
dist-xz: $(PACKAGE)-$(VERSION).tar.xz
|
||||
$(PACKAGE)-$(VERSION).tar.xz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.xz[00m'
|
||||
$(Q)tar cJf $(PACKAGE)-$(VERSION).tar.xz \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/pingpong/pingpong.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsub-test-send.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.h
|
||||
|
||||
dist-bz2: $(PACKAGE)-$(VERSION).tar.bz2
|
||||
$(PACKAGE)-$(VERSION).tar.bz2: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.bz2[00m'
|
||||
$(Q)tar cjf $(PACKAGE)-$(VERSION).tar.bz2 \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/pingpong/pingpong.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsub-test-send.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/process.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/pubsubd.h
|
||||
|
||||
help:
|
||||
@echo '[01;37m :: perfect-os-junk-0.0.1[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mGeneric targets:[00m'
|
||||
@echo '[00m - [01;32mhelp [37m Prints this help message.[00m'
|
||||
@echo '[00m - [01;32mall [37m Builds all targets.[00m'
|
||||
@echo '[00m - [01;32mdist [37m Creates tarballs of the files of the project.[00m'
|
||||
@echo '[00m - [01;32minstall [37m Installs the project.[00m'
|
||||
@echo '[00m - [01;32mclean [37m Removes compiled files.[00m'
|
||||
@echo '[00m - [01;32muninstall [37m Deinstalls the project.[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mCLI-modifiable variables:[00m'
|
||||
@echo ' - [01;34mCC [37m ${CC}[00m'
|
||||
@echo ' - [01;34mCFLAGS [37m ${CFLAGS}[00m'
|
||||
@echo ' - [01;34mLDFLAGS [37m ${LDFLAGS}[00m'
|
||||
@echo ' - [01;34mDESTDIR [37m ${DESTDIR}[00m'
|
||||
@echo ' - [01;34mPREFIX [37m ${PREFIX}[00m'
|
||||
@echo ' - [01;34mBINDIR [37m ${BINDIR}[00m'
|
||||
@echo ' - [01;34mLIBDIR [37m ${LIBDIR}[00m'
|
||||
@echo ' - [01;34mSHAREDIR [37m ${SHAREDIR}[00m'
|
||||
@echo ' - [01;34mINCLUDEDIR [37m ${INCLUDEDIR}[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mProject targets: [00m'
|
||||
@echo ' - [01;33mlibposj [37m library[00m'
|
||||
@echo ' - [01;33mpingpong/pingpong[37m binary[00m'
|
||||
@echo ' - [01;33mpubsub/pubsub [37m binary[00m'
|
||||
@echo ' - [01;33mpubsub/pubsub-test-send[37m binary[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mMakefile options:[00m'
|
||||
@echo ' - gnu: true'
|
||||
@echo ' - colors: true'
|
||||
@echo ''
|
||||
@echo '[01;37mRebuild the Makefile with:[00m'
|
||||
@echo ' zsh ./build.zsh -c -g'
|
||||
.PHONY: all subdirs clean distclean dist install uninstall help
|
||||
|
|
@ -32,7 +32,8 @@ int msg_recv (const int fd, char **buf)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int close_socket(int fd) {
|
||||
int close_socket (int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = close (fd);
|
||||
|
@ -44,7 +45,10 @@ int close_socket(int fd) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int srv_init (int argc, char **argv, char **env, struct service *srv, const char *sname, int (*cb)(int argc, char **argv, char **env, struct service *srv, const char *sname))
|
||||
// SERVICE
|
||||
|
||||
// init unix socket + srv->spath filled
|
||||
int srv_init (int argc, char **argv, char **env, struct service *srv, const char *sname)
|
||||
{
|
||||
if (srv == NULL)
|
||||
return ER_PARAMS;
|
||||
|
@ -59,62 +63,47 @@ int srv_init (int argc, char **argv, char **env, struct service *srv, const char
|
|||
argv = argv;
|
||||
env = env;
|
||||
|
||||
// gets the service path, such as /tmp/<service>
|
||||
// srv->version => already set
|
||||
// srv->index => already set
|
||||
|
||||
// gets the service path, such as /tmp/ipc/<service>
|
||||
memset (srv->spath, 0, PATH_MAX);
|
||||
strncat (srv->spath, TMPDIR, PATH_MAX -1);
|
||||
strncat (srv->spath, sname, PATH_MAX -1);
|
||||
snprintf (srv->spath, PATH_MAX, "%s/%s-%d-%d"
|
||||
, TMPDIR, sname, srv->index, srv->version);
|
||||
|
||||
srv->version = COMMUNICATION_VERSION;
|
||||
srv->index = 0; // TODO
|
||||
// TODO TEST create a unix socket
|
||||
int sfd;
|
||||
struct sockaddr_un my_addr;
|
||||
|
||||
if (cb != NULL) {
|
||||
int ret = (*cb) (argc, argv, env, srv, sname);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sfd == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
// clear structure
|
||||
memset(&my_addr, 0, sizeof(struct sockaddr_un));
|
||||
|
||||
// SERVICE
|
||||
my_addr.sun_family = AF_UNIX;
|
||||
strncpy(my_addr.sun_path, srv->spath, strlen (srv->spath)); // TODO check size
|
||||
|
||||
int srv_create (struct service *srv)
|
||||
{
|
||||
int ret;
|
||||
if ((ret = mkfifo (srv->spath, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) {
|
||||
switch (errno) {
|
||||
case EACCES :
|
||||
printf ("file %s : EACCES\n", srv->spath);
|
||||
return 1;
|
||||
case EEXIST :
|
||||
printf ("file %s : EEXIST\n", srv->spath);
|
||||
break;
|
||||
case ENAMETOOLONG :
|
||||
printf ("file %s : ENAMETOOLONG\n", srv->spath);
|
||||
return 2;
|
||||
case ENOENT :
|
||||
printf ("file %s : ENOENT\n", srv->spath);
|
||||
return 3;
|
||||
case ENOSPC :
|
||||
printf ("file %s : ENOSPC\n", srv->spath);
|
||||
return 4;
|
||||
case ENOTDIR :
|
||||
printf ("file %s : ENOTDIR\n", srv->spath);
|
||||
return 5;
|
||||
case EROFS :
|
||||
printf ("file %s : EROFS\n", srv->spath);
|
||||
return 6;
|
||||
default :
|
||||
printf ("err file %s unknown\n", srv->spath);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
// delete the unix socket if already created
|
||||
// TODO FIXME
|
||||
unlink(my_addr.sun_path);
|
||||
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
|
||||
return -1;
|
||||
|
||||
if (listen(sfd, LISTEN_BACKLOG) == -1)
|
||||
return -1;
|
||||
|
||||
srv->service_fd = sfd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int srv_close (struct service *srv)
|
||||
{
|
||||
close_socket (srv->service_fd);
|
||||
|
||||
// TODO FIXME is unlink really necessary
|
||||
if (unlink (srv->spath)) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -122,35 +111,6 @@ int srv_close (struct service *srv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int srv_get_new_process (char *buf, struct process *p)
|
||||
{
|
||||
char *token = NULL, *saveptr = NULL;
|
||||
char *str = NULL;
|
||||
int i = 0;
|
||||
|
||||
int index = 0;
|
||||
int version = 0;
|
||||
|
||||
for (str = buf, i = 1; ; str = NULL, i++) {
|
||||
token = strtok_r(str, " ", &saveptr);
|
||||
if (token == NULL)
|
||||
break;
|
||||
|
||||
if (i == 1) {
|
||||
index = strtoul(token, NULL, 10);
|
||||
}
|
||||
else if (i == 2) {
|
||||
version = strtoul(token, NULL, 10);
|
||||
}
|
||||
}
|
||||
|
||||
//if (buf != NULL)
|
||||
// free (buf);
|
||||
srv_process_gen (p, index, version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int srv_read (const struct service *srv, char ** buf)
|
||||
{
|
||||
//printf("---%s\n", srv->spath);
|
||||
|
@ -165,14 +125,25 @@ int srv_write (const struct service *srv, const char * buf, size_t msize)
|
|||
|
||||
// APPLICATION
|
||||
|
||||
//Init connection with unix socket
|
||||
// Initialize connection with unix socket
|
||||
// send the connection string to $TMP/<service>
|
||||
int app_srv_connection (struct service *srv, const char *connectionstr, size_t msize)
|
||||
|
||||
// fill srv->spath && srv->service_fd
|
||||
int app_connection (struct service *srv, const char *sname
|
||||
, const char *connectionstr, size_t msize)
|
||||
{
|
||||
if (srv == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// srv->version => already set
|
||||
// srv->index => already set
|
||||
|
||||
// gets the service path, such as /tmp/ipc/<service>
|
||||
memset (srv->spath, 0, PATH_MAX);
|
||||
snprintf (srv->spath, PATH_MAX, "%s/%s-%d-%d"
|
||||
, TMPDIR, sname, srv->index, srv->version);
|
||||
|
||||
int sfd;
|
||||
struct sockaddr_un my_addr;
|
||||
socklen_t peer_addr_size;
|
||||
|
@ -181,103 +152,38 @@ int app_srv_connection (struct service *srv, const char *connectionstr, size_t m
|
|||
if (sfd == -1)
|
||||
return -1;
|
||||
|
||||
// clear structure
|
||||
memset(&my_addr, 0, sizeof(struct sockaddr_un));
|
||||
// Clear structure
|
||||
|
||||
my_addr.sun_family = AF_UNIX;
|
||||
strncpy(my_addr.sun_path, srv->spath, sizeof(my_addr.sun_path) - 1);
|
||||
strncpy(my_addr.sun_path, srv->spath, strlen (srv->spath)); // TODO check size
|
||||
|
||||
peer_addr_size = sizeof(struct sockaddr_un);
|
||||
if(connect(sfd,(struct sockaddr *) &my_addr, peer_addr_size) == -1)
|
||||
if(connect(sfd, (struct sockaddr *) &my_addr, peer_addr_size) == -1)
|
||||
{
|
||||
perror("connect()");
|
||||
exit(errno);
|
||||
}
|
||||
srv->service_fd = sfd;
|
||||
|
||||
return srv_write(srv, connectionstr, msize);
|
||||
|
||||
}
|
||||
|
||||
int proc_connection(struct process *p) {
|
||||
int sfd;
|
||||
struct sockaddr_un my_addr;
|
||||
socklen_t peer_addr_size;
|
||||
|
||||
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sfd == -1)
|
||||
return -1;
|
||||
|
||||
memset(&my_addr, 0, sizeof(struct sockaddr_un));
|
||||
// Clear structure
|
||||
my_addr.sun_family = AF_UNIX;
|
||||
strncpy(my_addr.sun_path, p->path_proc, sizeof(my_addr.sun_path) - 1);
|
||||
|
||||
peer_addr_size = sizeof(struct sockaddr_un);
|
||||
if(connect(sfd,(struct sockaddr *) &my_addr, peer_addr_size) == -1)
|
||||
{
|
||||
perror("connect()");
|
||||
exit(errno);
|
||||
}
|
||||
p->proc_fd = sfd;
|
||||
// TODO FIXME
|
||||
// send connection string and receive acknowledgement
|
||||
srv_write(srv, connectionstr, msize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_create (struct process *p, int index, int version)
|
||||
int app_close (struct service *srv)
|
||||
{
|
||||
if (version == 0) {
|
||||
version = COMMUNICATION_VERSION;
|
||||
}
|
||||
|
||||
// then creates the structure
|
||||
srv_process_gen (p, index, version);
|
||||
|
||||
return 0;
|
||||
return close_socket (srv->service_fd);
|
||||
}
|
||||
|
||||
int app_destroy (struct process *p)
|
||||
{
|
||||
if (unlink (p->path_proc)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_read (struct process *p, char ** buf)
|
||||
int app_read (struct service *srv, char ** buf)
|
||||
{
|
||||
//printf("---%s\n", p->path_proc);
|
||||
return msg_recv (p->proc_fd, buf);
|
||||
return msg_recv (srv->service_fd, buf);
|
||||
}
|
||||
|
||||
int app_write (struct process *p, char * buf, size_t msize)
|
||||
int app_write (struct service *srv, char * buf, size_t msize)
|
||||
{
|
||||
//printf("---%s\n", p->path_proc);
|
||||
return msg_send (p->proc_fd, buf, msize);
|
||||
}
|
||||
|
||||
/*init a unix socket : bind, listen
|
||||
*and return a socket
|
||||
*/
|
||||
int set_listen_socket(const char *path) {
|
||||
int sfd;
|
||||
struct sockaddr_un my_addr;
|
||||
|
||||
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sfd == -1)
|
||||
return -1;
|
||||
|
||||
memset(&my_addr, 0, sizeof(struct sockaddr_un));
|
||||
/* Clear structure */
|
||||
my_addr.sun_family = AF_UNIX;
|
||||
strncpy(my_addr.sun_path, path, sizeof(my_addr.sun_path) - 1);
|
||||
|
||||
unlink(my_addr.sun_path);
|
||||
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
|
||||
return -1;
|
||||
|
||||
if (listen(sfd, LISTEN_BACKLOG) == -1)
|
||||
return -1;
|
||||
|
||||
return sfd;
|
||||
return msg_send (srv->service_fd, buf, msize);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <string.h>
|
||||
//#include <cbor.h>
|
||||
|
||||
#include "process.h"
|
||||
#include <unistd.h> // unlink
|
||||
|
||||
#include <sys/types.h> // mkfifo
|
||||
|
@ -33,21 +32,16 @@ struct service {
|
|||
int service_fd;
|
||||
};
|
||||
|
||||
// wrappers
|
||||
int msg_recv (int fd, char **buf);
|
||||
int msg_send (int fd, const char *buf, const int m_size);
|
||||
int close_socket (int fd);
|
||||
|
||||
|
||||
// SERVICE
|
||||
|
||||
int srv_init (int argc, char **argv, char **env
|
||||
, struct service *srv, const char *sname
|
||||
, int (*cb)(int argc, char **argv, char **env
|
||||
, struct service *srv, const char *sname));
|
||||
|
||||
int srv_get_new_process (char *buf, struct process *proc);
|
||||
|
||||
/*
|
||||
* returns
|
||||
* 0 : ok
|
||||
* 1 : no service name
|
||||
* 2 : service name too long
|
||||
* 3 : unable to create fifo
|
||||
*/
|
||||
int srv_create (struct service *srv);
|
||||
, struct service *srv, const char *sname);
|
||||
int srv_close (struct service *srv);
|
||||
|
||||
int srv_read (const struct service *, char ** buf);
|
||||
|
@ -56,27 +50,10 @@ int srv_write (const struct service *, const char * buf, size_t);
|
|||
// APPLICATION
|
||||
|
||||
// send the connection string to $TMP/<service>
|
||||
int app_srv_connection (struct service *, const char *, size_t);
|
||||
int app_connection (struct service *, const char *, const char *, size_t);
|
||||
int app_close (struct service *);
|
||||
|
||||
int app_create (struct process *, pid_t pid, int index, int version);
|
||||
int app_destroy (struct process *);
|
||||
|
||||
int app_read (struct process *, char ** buf);
|
||||
int app_write (struct process *, char * buf, size_t);
|
||||
|
||||
// wrappers
|
||||
int file_read (int fd, char **buf);
|
||||
int file_write (int fd, const char *buf, const int m_size);
|
||||
|
||||
//close socket
|
||||
int close_socket(int fd);
|
||||
|
||||
//set and return a listen socket
|
||||
int set_listen_socket(const char *path);
|
||||
|
||||
//init a proc connection
|
||||
int proc_connection(struct process *p);
|
||||
|
||||
//open, close, read, write
|
||||
int app_read (struct service *, char ** buf);
|
||||
int app_write (struct service *, char * buf, size_t);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,6 @@ void srv_process_gen (struct process *p
|
|||
{
|
||||
p->version = version;
|
||||
p->index = index;
|
||||
snprintf(p->path_proc, PATH_MAX, "%s%d-%d", TMPDIR, index, version);
|
||||
}
|
||||
|
||||
void srv_process_print (struct process *p)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
struct process {
|
||||
unsigned int version;
|
||||
unsigned int index;
|
||||
char path_proc [PATH_MAX];
|
||||
int proc_fd;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "../lib/communication.h"
|
||||
#include "../../lib/communication.h"
|
||||
#include <pthread.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -22,23 +22,7 @@ void * pongd_thread(void * pdata) {
|
|||
memset(buf, 0, BUFSIZ);
|
||||
int nbytes;
|
||||
|
||||
//init unix socket
|
||||
/*int sfd, cfd;
|
||||
struct sockaddr_un peer_addr;
|
||||
socklen_t peer_addr_size;
|
||||
printf("%s\n", proc->path_proc);
|
||||
//app_create(proc, proc->pid, proc->index, proc->version);
|
||||
|
||||
sfd = set_listen_socket(proc->path_proc);
|
||||
if (sfd == -1){
|
||||
handle_error("set_listen_socket");
|
||||
}
|
||||
peer_addr_size = sizeof(struct sockaddr_un);
|
||||
|
||||
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
|
||||
if (cfd == -1)
|
||||
handle_error("accept");
|
||||
proc->proc_fd = cfd;*/
|
||||
// init unix socket
|
||||
|
||||
while (1) {
|
||||
if ((nbytes = file_read (*sockclient, &buf)) == -1) {
|
||||
|
@ -252,6 +236,9 @@ void main_loop (struct service *srv)
|
|||
int main(int argc, char * argv[], char **env)
|
||||
{
|
||||
struct service srv;
|
||||
memset (&srv, 0, sizeof (struct service));
|
||||
srv->index = 0;
|
||||
srv->version = 0;
|
||||
srv_init (argc, argv, env, &srv, PONGD_SERVICE_NAME, NULL);
|
||||
printf ("Listening on %s.\n", srv.spath);
|
||||
|
|
@ -14,6 +14,8 @@ main(int argc, char **argv, char **env)
|
|||
{
|
||||
struct service srv;
|
||||
memset (&srv, 0, sizeof (struct service));
|
||||
srv->index = 0;
|
||||
srv->version = 0;
|
||||
srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
|
||||
printf ("Listening on %s.\n", srv.spath);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ main(int argc, char **argv, char **env)
|
|||
{
|
||||
struct service srv;
|
||||
memset (&srv, 0, sizeof (struct service));
|
||||
srv->index = 0;
|
||||
srv->version = 0;
|
||||
srv_init (argc, argv, env, &srv, TEST_NAME, NULL);
|
||||
printf ("Listening on %s.\n", srv.spath);
|
||||
|
||||
|
|
|
@ -124,6 +124,9 @@ void * service_thread(void * c_data) {
|
|||
makePivMessage(&piv, getpid(), cda->index, version);
|
||||
|
||||
struct service srv;
|
||||
memset (&srv, 0, sizeof (struct service));
|
||||
srv->index = 0;
|
||||
srv->version = 0;
|
||||
srv_init (0, NULL, NULL, &srv, service, NULL);
|
||||
if (app_srv_connection(&srv, piv, strlen(piv)) == -1) {
|
||||
handle_error("app_srv_connection\n");
|
||||
|
|
Reference in New Issue