Merge pull request #43 from BjoernSch/master

Bind to localhost only/ Make the installation directory changeable
This commit is contained in:
joan2937 2015-12-28 10:42:24 +00:00
commit 0549fcc2af
5 changed files with 81 additions and 54 deletions

View File

@ -8,6 +8,13 @@ CFLAGS += -O3 -Wall -pthread
ALL = libpigpiod_if.so libpigpiod_if2.so pigs x_pigpiod_if x_pigpiod_if2 ALL = libpigpiod_if.so libpigpiod_if2.so pigs x_pigpiod_if x_pigpiod_if2
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
includedir = $(prefix)/include
libdir = $(prefix)/lib
mandir = $(prefix)/man
all: $(ALL) pigpio.py setup.py all: $(ALL) pigpio.py setup.py
pigpiod_if.o: pigpiod_if.c pigpio.h command.h pigpiod_if.h pigpiod_if.o: pigpiod_if.c pigpio.h command.h pigpiod_if.h
@ -32,37 +39,37 @@ clean:
rm -f *.o *.i *.s *~ $(ALL) rm -f *.o *.i *.s *~ $(ALL)
install: $(LIB1) $(LIB2) install: $(LIB1) $(LIB2)
install -m 0755 -d /usr/local/include install -m 0755 -d $(DESTDIR)$(includedir)
install -m 0644 pigpio.h /usr/local/include install -m 0644 pigpio.h $(DESTDIR)$(includedir)
install -m 0644 pigpiod_if.h /usr/local/include install -m 0644 pigpiod_if.h $(DESTDIR)$(includedir)
install -m 0644 pigpiod_if2.h /usr/local/include install -m 0644 pigpiod_if2.h $(DESTDIR)$(includedir)
install -m 0755 -d /usr/local/lib install -m 0755 -d $(DESTDIR)$(libdir)
install -m 0644 libpigpiod_if.so /usr/local/lib install -m 0644 libpigpiod_if.so $(DESTDIR)$(libdir)
install -m 0644 libpigpiod_if2.so /usr/local/lib install -m 0644 libpigpiod_if2.so $(DESTDIR)$(libdir)
install -m 0755 -d /usr/local/bin install -m 0755 -d $(DESTDIR)$(bindir)
install -m 0755 pigs /usr/local/bin install -m 0755 pigs $(DESTDIR)$(bindir)
python2 setup.py install python2 setup.py install
python3 setup.py install python3 setup.py install
install -m 0755 -d /usr/local/man/man1 install -m 0755 -d $(DESTDIR)$(mandir)/man1
install -m 0644 *.1 /usr/local/man/man1 install -m 0644 *.1 $(DESTDIR)$(mandir)/man1
install -m 0755 -d /usr/local/man/man3 install -m 0755 -d $(DESTDIR)$(mandir)/man3
install -m 0644 *.3 /usr/local/man/man3 install -m 0644 *.3 $(DESTDIR)$(mandir)/man3
uninstall: uninstall:
rm -f /usr/local/include/pigpio.h rm -f $(DESTDIR)$(includedir)/pigpio.h
rm -f /usr/local/include/pigpiod_if.h rm -f $(DESTDIR)$(includedir)/pigpiod_if.h
rm -f /usr/local/include/pigpiod_if2.h rm -f $(DESTDIR)$(includedir)/pigpiod_if2.h
rm -f /usr/local/lib/libpigpiod_if.so rm -f $(DESTDIR)$(libdir)/libpigpiod_if.so
rm -f /usr/local/lib/libpigpiod_if2.so rm -f $(DESTDIR)$(libdir)/libpigpiod_if2.so
echo removing python2 files echo removing python2 files
python2 setup.py install --record /tmp/pigpio >/dev/null python2 setup.py install --record /tmp/pigpio >/dev/null
xargs rm -f < /tmp/pigpio >/dev/null xargs rm -f < /tmp/pigpio >/dev/null
echo removing python3 files echo removing python3 files
python3 setup.py install --record /tmp/pigpio >/dev/null python3 setup.py install --record /tmp/pigpio >/dev/null
xargs rm -f < /tmp/pigpio >/dev/null xargs rm -f < /tmp/pigpio >/dev/null
rm -f /usr/local/bin/pigs rm -f $(DESTDIR)$(bindir)/pigs
rm -f /usr/local/man/man1/pig*.1 rm -f $(DESTDIR)$(mandir)/man1/pig*.1
rm -f /usr/local/man/man3/pig*.3 rm -f $(DESTDIR)$(mandir)/man3/pig*.3
LL1 = -L. -lpigpiod_if -pthread -lrt LL1 = -L. -lpigpiod_if -pthread -lrt
LL2 = -L. -lpigpiod_if2 -pthread -lrt LL2 = -L. -lpigpiod_if2 -pthread -lrt

View File

@ -27,6 +27,13 @@ LL2 = -L. -lpigpiod_if -pthread -lrt
LL3 = -L. -lpigpiod_if2 -pthread -lrt LL3 = -L. -lpigpiod_if2 -pthread -lrt
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
includedir = $(prefix)/include
libdir = $(prefix)/lib
mandir = $(prefix)/man
all: $(ALL) all: $(ALL)
pigpio.o: pigpio.c pigpio.h command.h custom.cext pigpio.o: pigpio.c pigpio.h command.h custom.cext
@ -63,41 +70,41 @@ clean:
rm -f *.o *.i *.s *~ $(ALL) rm -f *.o *.i *.s *~ $(ALL)
install: $(ALL) install: $(ALL)
install -m 0755 -d /opt/pigpio/cgi install -m 0755 -d $(DESTDIR)/opt/pigpio/cgi
install -m 0755 -d /usr/local/include install -m 0755 -d $(DESTDIR)$(includedir)
install -m 0644 pigpio.h /usr/local/include install -m 0644 pigpio.h $(DESTDIR)$(includedir)
install -m 0644 pigpiod_if.h /usr/local/include install -m 0644 pigpiod_if.h $(DESTDIR)$(includedir)
install -m 0644 pigpiod_if2.h /usr/local/include install -m 0644 pigpiod_if2.h $(DESTDIR)$(includedir)
install -m 0755 -d /usr/local/lib install -m 0755 -d $(DESTDIR)$(libdir)
install -m 0755 libpigpio.so /usr/local/lib install -m 0755 libpigpio.so $(DESTDIR)$(libdir)
install -m 0755 libpigpiod_if.so /usr/local/lib install -m 0755 libpigpiod_if.so $(DESTDIR)$(libdir)
install -m 0755 libpigpiod_if2.so /usr/local/lib install -m 0755 libpigpiod_if2.so $(DESTDIR)$(libdir)
install -m 0755 -d /usr/local/bin install -m 0755 -d $(DESTDIR)$(bindir)
install -m 0755 -s pig2vcd /usr/local/bin install -m 0755 -s pig2vcd $(DESTDIR)$(bindir)
install -m 0755 -s pigpiod /usr/local/bin install -m 0755 -s pigpiod $(DESTDIR)$(bindir)
install -m 0755 -s pigs /usr/local/bin install -m 0755 -s pigs $(DESTDIR)$(bindir)
if which python2; then python2 setup.py install; fi if which python2; then python2 setup.py install; fi
if which python3; then python3 setup.py install; fi if which python3; then python3 setup.py install; fi
install -m 0755 -d /usr/local/man/man1 install -m 0755 -d $(DESTDIR)$(mandir)/man1
install -m 0644 *.1 /usr/local/man/man1 install -m 0644 *.1 $(DESTDIR)$(mandir)/man1
install -m 0755 -d /usr/local/man/man3 install -m 0755 -d $(DESTDIR)$(mandir)/man3
install -m 0644 *.3 /usr/local/man/man3 install -m 0644 *.3 $(DESTDIR)$(mandir)/man3
ldconfig ldconfig
uninstall: uninstall:
rm -f /usr/local/include/pigpio.h rm -f $(DESTDIR)$(includedir)/pigpio.h
rm -f /usr/local/include/pigpiod_if.h rm -f $(DESTDIR)$(includedir)/pigpiod_if.h
rm -f /usr/local/include/pigpiod_if2.h rm -f $(DESTDIR)$(includedir)/pigpiod_if2.h
rm -f /usr/local/lib/libpigpio.so rm -f $(DESTDIR)$(libdir)/libpigpio.so
rm -f /usr/local/lib/libpigpiod_if.so rm -f $(DESTDIR)$(libdir)/libpigpiod_if.so
rm -f /usr/local/lib/libpigpiod_if2.so rm -f $(DESTDIR)$(libdir)/libpigpiod_if2.so
rm -f /usr/local/bin/pig2vcd rm -f $(DESTDIR)$(bindir)/pig2vcd
rm -f /usr/local/bin/pigpiod rm -f $(DESTDIR)$(bindir)/pigpiod
rm -f /usr/local/bin/pigs rm -f $(DESTDIR)$(bindir)/pigs
if which python2; then python2 setup.py install --record /tmp/pigpio >/dev/null; xargs rm -f < /tmp/pigpio >/dev/null; fi if which python2; then python2 setup.py install --record /tmp/pigpio >/dev/null; xargs rm -f < /tmp/pigpio >/dev/null; fi
if which python3; then python3 setup.py install --record /tmp/pigpio >/dev/null; xargs rm -f < /tmp/pigpio >/dev/null; fi if which python3; then python3 setup.py install --record /tmp/pigpio >/dev/null; xargs rm -f < /tmp/pigpio >/dev/null; fi
rm -f /usr/local/man/man1/pig*.1 rm -f $(DESTDIR)$(mandir)/man1/pig*.1
rm -f /usr/local/man/man3/pig*.3 rm -f $(DESTDIR)$(mandir)/man3/pig*.3
ldconfig ldconfig
$(LIB1): $(OBJ1) $(LIB1): $(OBJ1)

View File

@ -7496,7 +7496,14 @@ int initInitialise(void)
if (portStr) port = atoi(portStr); else port = gpioCfg.socketPort; if (portStr) port = atoi(portStr); else port = gpioCfg.socketPort;
server.sin_family = AF_INET; server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY; if (gpioCfg.ifFlags & PI_LOCALHOST_SOCK_IF)
{
server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
}
else
{
server.sin_addr.s_addr = htonl(INADDR_ANY);
}
server.sin_port = htons(port); server.sin_port = htons(port);
if (bind(fdSock,(struct sockaddr *)&server , sizeof(server)) < 0) if (bind(fdSock,(struct sockaddr *)&server , sizeof(server)) < 0)
@ -11508,7 +11515,7 @@ int gpioCfgInterfaces(unsigned ifFlags)
CHECK_NOT_INITED; CHECK_NOT_INITED;
if (ifFlags > 3) if (ifFlags > 7)
SOFT_ERROR(PI_BAD_IF_FLAGS, "bad ifFlags (%X)", ifFlags); SOFT_ERROR(PI_BAD_IF_FLAGS, "bad ifFlags (%X)", ifFlags);
gpioCfg.ifFlags = ifFlags; gpioCfg.ifFlags = ifFlags;

View File

@ -731,8 +731,9 @@ typedef void *(gpioThreadFunc_t) (void *);
/* ifFlags: */ /* ifFlags: */
#define PI_DISABLE_FIFO_IF 1 #define PI_DISABLE_FIFO_IF 1
#define PI_DISABLE_SOCK_IF 2 #define PI_DISABLE_SOCK_IF 2
#define PI_LOCALHOST_SOCK_IF 4
/* memAllocMode */ /* memAllocMode */

View File

@ -93,6 +93,7 @@ void usage()
" -e value, secondary DMA channel, 0-6, default 5\n" \ " -e value, secondary DMA channel, 0-6, default 5\n" \
" -f, disable fifo interface, default enabled\n" \ " -f, disable fifo interface, default enabled\n" \
" -k, disable socket interface, default enabled\n" \ " -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default all interfaces\n" \
" -p value, socket port, 1024-32000, default 8888\n" \ " -p value, socket port, 1024-32000, default 8888\n" \
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \ " -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \ " -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
@ -120,7 +121,7 @@ static void initOpts(int argc, char *argv[])
int opt, err, i; int opt, err, i;
int64_t mask; int64_t mask;
while ((opt = getopt(argc, argv, "a:b:c:d:e:fkp:s:t:x:")) != -1) while ((opt = getopt(argc, argv, "a:b:c:d:e:fklp:s:t:x:")) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -167,6 +168,10 @@ static void initOpts(int argc, char *argv[])
ifFlags |= PI_DISABLE_SOCK_IF; ifFlags |= PI_DISABLE_SOCK_IF;
break; break;
case 'l':
ifFlags |= PI_LOCALHOST_SOCK_IF;
break;
case 'p': case 'p':
i = getNum(optarg, &err); i = getNum(optarg, &err);
if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT)) if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT))