Subversion Repositories plscnt

Compare Revisions

Ignore whitespace Rev 90 → Rev 91

/texinfo.tex
File deleted
\ No newline at end of file
/configure.ac
7,7 → 7,7
AM_INIT_AUTOMAKE([dist-bzip2])
AM_MAINTAINER_MODE
 
AC_PREFIX_DEFAULT(/usr/local)
AC_PREFIX_DEFAULT(/opt/emg/usr/local)
 
# Files to configure
AC_CONFIG_MACRO_DIR([m4])
43,19 → 43,16
dnl Checks for header files.
AC_HEADER_MAJOR
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/param.h sys/time.h sys/types.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h)
AC_CHECK_HEADERS(time.h signal.h fcntl.h unistd.h)
AC_CHECK_HEADERS(syslog.h stdarg.h errno.h)
AC_CHECK_HEADERS(mman.h poll.h)
AC_CHECK_HEADER(sys/ioctl.h linux/i2c-dev.h)
AC_CHECK_HEADERS(errno.h fcntl.h getopt.h signal.h socket.h stdarg.h stdio.h stdlib.h string.h syslog.h system.h time.h unistd.h)
AC_CHECK_HEADERS(sys/ioctl.h sys/mman.h sys/socket.h sys/stat.h sys/types.h sys/in.h arpa/inet.h)
AC_CHECK_HEADER(linux/i2c-dev.h)
AC_CHECK_HEADER(pthread.h)
 
# Check for functions
AC_FUNC_ALLOCA
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_CLOSEDIR_VOID
AC_CHECK_FUNCS(fork pause usleep)
AC_CHECK_FUNC(getcwd memchr memset strrchr strstr)
AC_CHECK_FUNCS(getcwd memchr memset strrchr strstr)
 
# Check for types
AC_TYPE_OFF_T
65,6 → 62,10
 
dnl Checks for typedefs, structures, and compiler characteristics.
 
dnl Check for library functions
AC_CHECK_LIB(sock, bind)
AC_CHECK_LIB(pthread, pthread_create)
 
dnl Check for pkg modules
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6.0)
/emg_install.sh
0,0 → 1,28
#!/bin/sh
 
prefix=/opt/emg
program=`cat configure.ac | grep AC_INIT | cut -d '(' -f 2 | cut -d ',' -f 1`
group="emg"
user="emg"
 
echo $program
 
if getent group $group > /dev/null; then
echo "emg group already exists."
else
groupadd -f $group
echo "emg group has been created."
fi
 
if getent passwd $user > /dev/null; then
echo "emg user already exists."
else
useradd -M -N -r -s /bin/false -c "Disabled emg member" $user
echo "emg user has been created (no shell)."
fi
 
#./configure --prefix=$prefix
#make install
 
ln -sf $prefix/etc/init.d/$program.sh /etc/init.d/$program.sh
cd $prefix/etc/init.d; update-rc.d $program.sh defaults
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: man/commands.txt
===================================================================
--- man/commands.txt (nonexistent)
+++ man/commands.txt (revision 91)
@@ -0,0 +1,10 @@
+List of TCP/IP commands:
+
+-> LIST
+<- 8
+
+-> GET COUNTER01
+<- 12345677
+
+-> PUT COUNTER08 87654321
+<- 87654321
Index: man/Makefile.in
===================================================================
--- man/Makefile.in (revision 90)
+++ man/Makefile.in (revision 91)
@@ -99,7 +99,6 @@
MANS = $(man_MANS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
-ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
Index: autoheader.h.in
===================================================================
--- autoheader.h.in (revision 90)
+++ autoheader.h.in (revision 91)
@@ -1,27 +1,8 @@
/* autoheader.h.in. Generated from configure.ac by autoheader. */
-/* Define to 1 if the `closedir' function returns void instead of `int'. */
-#undef CLOSEDIR_VOID
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#undef HAVE_ARPA_INET_H
-/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
- systems. This function is required for `alloca.c' support on those systems.
- */
-#undef CRAY_STACKSEG_END
-
-/* Define to 1 if using `alloca.c'. */
-#undef C_ALLOCA
-
-/* Define to 1 if you have `alloca', as a function or macro. */
-#undef HAVE_ALLOCA
-
-/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
- */
-#undef HAVE_ALLOCA_H
-
-/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
- */
-#undef HAVE_DIRENT_H
-
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
@@ -31,31 +12,31 @@
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
+/* Define to 1 if you have the `getcwd' function. */
+#undef HAVE_GETCWD
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#undef HAVE_GETOPT_H
+
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
-/* Define to 1 if you have the <locale.h> header file. */
-#undef HAVE_LOCALE_H
-
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
+/* Define to 1 if you have the `memchr' function. */
+#undef HAVE_MEMCHR
+
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
-/* Define to 1 if you have the <mman.h> header file. */
-#undef HAVE_MMAN_H
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
-/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
-#undef HAVE_NDIR_H
-
/* Define to 1 if you have the `pause' function. */
#undef HAVE_PAUSE
-/* Define to 1 if you have the <poll.h> header file. */
-#undef HAVE_POLL_H
-
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
@@ -63,6 +44,9 @@
/* Define to 1 if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H
+/* Define to 1 if you have the <socket.h> header file. */
+#undef HAVE_SOCKET_H
+
/* Define to 1 if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H
@@ -69,6 +53,9 @@
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
+
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
@@ -78,6 +65,12 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
+/* Define to 1 if you have the `strrchr' function. */
+#undef HAVE_STRRCHR
+
+/* Define to 1 if you have the `strstr' function. */
+#undef HAVE_STRSTR
+
/* Define to 1 if `st_blocks' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BLOCKS
@@ -88,29 +81,24 @@
/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
-/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
- */
-#undef HAVE_SYS_DIR_H
+/* Define to 1 if you have the <system.h> header file. */
+#undef HAVE_SYSTEM_H
-/* Define to 1 if you have the <sys/mkdev.h> header file. */
-#undef HAVE_SYS_MKDEV_H
+/* Define to 1 if you have the <sys/in.h> header file. */
+#undef HAVE_SYS_IN_H
-/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
- */
-#undef HAVE_SYS_NDIR_H
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
-/* Define to 1 if you have the <sys/param.h> header file. */
-#undef HAVE_SYS_PARAM_H
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#undef HAVE_SYS_MMAN_H
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
-/* Define to 1 if you have the <sys/sysmacros.h> header file. */
-#undef HAVE_SYS_SYSMACROS_H
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#undef HAVE_SYS_TIME_H
-
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
@@ -155,14 +143,6 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION
-/* If using the C implementation of alloca, define if you know the
- direction of stack growth for your system; otherwise it will be
- automatically deduced at runtime.
- STACK_DIRECTION > 0 => grows toward higher addresses
- STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown */
-#undef STACK_DIRECTION
-
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/pirtc/Makefile.in
68,7 → 68,6
esac
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
/configure
585,7 → 585,7
PACKAGE_BUGREPORT='rlievin@emgbox.org'
PACKAGE_URL=''
 
ac_default_prefix=/usr/local
ac_default_prefix=/opt/emg/usr/local
ac_unique_file="src/main.c"
# Factoring default headers for most tests.
ac_includes_default="\
634,7 → 634,6
PKG_CONFIG_PATH
PKG_CONFIG
LIBOBJS
ALLOCA
EGREP
GREP
CPP
1741,60 → 1740,6
 
} # ac_fn_c_check_header_compile
 
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
# variable VAR accordingly.
ac_fn_c_check_type ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
eval "$3=no"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof ($2))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof (($2)))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
 
else
eval "$3=yes"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
} # ac_fn_c_check_type
 
# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
1862,6 → 1807,60
 
} # ac_fn_c_check_func
 
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
# variable VAR accordingly.
ac_fn_c_check_type ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
eval "$3=no"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof ($2))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$4
int
main ()
{
if (sizeof (($2)))
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
 
else
eval "$3=yes"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
} # ac_fn_c_check_type
 
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
# ----------------------------------------------------
# Tries to find if the field MEMBER exists in type AGGR, after including
4529,7 → 4528,7
 
fi
 
for ac_header in sys/param.h sys/time.h sys/types.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h
for ac_header in errno.h fcntl.h getopt.h signal.h socket.h stdarg.h stdio.h stdlib.h string.h syslog.h system.h time.h unistd.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
4542,7 → 4541,7
 
done
 
for ac_header in time.h signal.h fcntl.h unistd.h
for ac_header in sys/ioctl.h sys/mman.h sys/socket.h sys/stat.h sys/types.h sys/in.h arpa/inet.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
4555,237 → 4554,20
 
done
 
for ac_header in syslog.h stdarg.h errno.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
ac_fn_c_check_header_mongrel "$LINENO" "linux/i2c-dev.h" "ac_cv_header_linux_i2c_dev_h" "$ac_includes_default"
if test "x$ac_cv_header_linux_i2c_dev_h" = xyes; then :
 
fi
 
done
 
for ac_header in mman.h poll.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default"
if test "x$ac_cv_header_pthread_h" = xyes; then :
 
fi
 
done
 
ac_fn_c_check_header_mongrel "$LINENO" "sys/ioctl.h linux/i2c-dev.h" "ac_cv_header_sys_ioctl_h_linux_i2c_dev_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_ioctl_h_linux_i2c_dev_h" = xyes; then :
 
fi
 
 
 
# Check for functions
ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
if test "x$ac_cv_type_size_t" = xyes; then :
 
else
 
cat >>confdefs.h <<_ACEOF
#define size_t unsigned int
_ACEOF
 
fi
 
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless!
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
$as_echo_n "checking for working alloca.h... " >&6; }
if ${ac_cv_working_alloca_h+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <alloca.h>
int
main ()
{
char *p = (char *) alloca (2 * sizeof (int));
if (p) return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_working_alloca_h=yes
else
ac_cv_working_alloca_h=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5
$as_echo "$ac_cv_working_alloca_h" >&6; }
if test $ac_cv_working_alloca_h = yes; then
 
$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h
 
fi
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5
$as_echo_n "checking for alloca... " >&6; }
if ${ac_cv_func_alloca_works+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#ifdef __GNUC__
# define alloca __builtin_alloca
#else
# ifdef _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
void *alloca (size_t);
# endif
# endif
# endif
# endif
#endif
 
int
main ()
{
char *p = (char *) alloca (1);
if (p) return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_func_alloca_works=yes
else
ac_cv_func_alloca_works=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5
$as_echo "$ac_cv_func_alloca_works" >&6; }
 
if test $ac_cv_func_alloca_works = yes; then
 
$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h
 
else
# The SVR3 libPW and SVR4 libucb both contain incompatible functions
# that cause trouble. Some versions do not even contain alloca or
# contain a buggy version. If you still want to use their alloca,
# use ar to extract alloca.o from them instead of compiling alloca.c.
 
ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
 
$as_echo "#define C_ALLOCA 1" >>confdefs.h
 
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5
$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; }
if ${ac_cv_os_cray+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#if defined CRAY && ! defined CRAY2
webecray
#else
wenotbecray
#endif
 
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "webecray" >/dev/null 2>&1; then :
ac_cv_os_cray=yes
else
ac_cv_os_cray=no
fi
rm -f conftest*
 
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5
$as_echo "$ac_cv_os_cray" >&6; }
if test $ac_cv_os_cray = yes; then
for ac_func in _getb67 GETB67 getb67; do
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
 
cat >>confdefs.h <<_ACEOF
#define CRAY_STACKSEG_END $ac_func
_ACEOF
 
break
fi
 
done
fi
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5
$as_echo_n "checking stack direction for C alloca... " >&6; }
if ${ac_cv_c_stack_direction+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
ac_cv_c_stack_direction=0
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$ac_includes_default
int
find_stack_direction (int *addr, int depth)
{
int dir, dummy = 0;
if (! addr)
addr = &dummy;
*addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
dir = depth ? find_stack_direction (addr, depth - 1) : 0;
return dir + dummy;
}
 
int
main (int argc, char **argv)
{
return find_stack_direction (0, argc + !argv + 20) < 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
ac_cv_c_stack_direction=1
else
ac_cv_c_stack_direction=-1
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
 
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5
$as_echo "$ac_cv_c_stack_direction" >&6; }
cat >>confdefs.h <<_ACEOF
#define STACK_DIRECTION $ac_cv_c_stack_direction
_ACEOF
 
 
fi
 
for ac_header in stdlib.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
4920,207 → 4702,19
fi
 
 
ac_header_dirent=no
for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
as_ac_Header=`$as_echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_hdr that defines DIR" >&5
$as_echo_n "checking for $ac_hdr that defines DIR... " >&6; }
if eval \${$as_ac_Header+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <sys/types.h>
#include <$ac_hdr>
 
int
main ()
{
if ((DIR *) 0)
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$as_ac_Header=yes"
else
eval "$as_ac_Header=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$as_ac_Header
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
for ac_func in fork pause usleep
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_hdr" | $as_tr_cpp` 1
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
 
ac_header_dirent=$ac_hdr; break
fi
 
done
# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
if test $ac_header_dirent = dirent.h; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
$as_echo_n "checking for library containing opendir... " >&6; }
if ${ac_cv_search_opendir+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
 
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char opendir ();
int
main ()
{
return opendir ();
;
return 0;
}
_ACEOF
for ac_lib in '' dir; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_opendir=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_opendir+:} false; then :
break
fi
done
if ${ac_cv_search_opendir+:} false; then :
 
else
ac_cv_search_opendir=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
$as_echo "$ac_cv_search_opendir" >&6; }
ac_res=$ac_cv_search_opendir
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
fi
 
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing opendir" >&5
$as_echo_n "checking for library containing opendir... " >&6; }
if ${ac_cv_search_opendir+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
 
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char opendir ();
int
main ()
{
return opendir ();
;
return 0;
}
_ACEOF
for ac_lib in '' x; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_opendir=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_opendir+:} false; then :
break
fi
done
if ${ac_cv_search_opendir+:} false; then :
 
else
ac_cv_search_opendir=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_opendir" >&5
$as_echo "$ac_cv_search_opendir" >&6; }
ac_res=$ac_cv_search_opendir
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
fi
 
fi
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether closedir returns void" >&5
$as_echo_n "checking whether closedir returns void... " >&6; }
if ${ac_cv_func_closedir_void+:} false; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
ac_cv_func_closedir_void=yes
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
$ac_includes_default
#include <$ac_header_dirent>
#ifndef __cplusplus
int closedir ();
#endif
 
int
main ()
{
return closedir (opendir (".")) != 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
ac_cv_func_closedir_void=no
else
ac_cv_func_closedir_void=yes
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
 
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_closedir_void" >&5
$as_echo "$ac_cv_func_closedir_void" >&6; }
if test $ac_cv_func_closedir_void = yes; then
 
$as_echo "#define CLOSEDIR_VOID 1" >>confdefs.h
 
fi
 
for ac_func in fork pause usleep
for ac_func in getcwd memchr memset strrchr strstr
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
5132,12 → 4726,7
fi
done
 
ac_fn_c_check_func "$LINENO" "getcwd memchr memset strrchr strstr" "ac_cv_func_getcwd_memchr_memset_strrchr_strstr"
if test "x$ac_cv_func_getcwd_memchr_memset_strrchr_strstr" = xyes; then :
 
fi
 
 
# Check for types
ac_fn_c_check_type "$LINENO" "off_t" "ac_cv_type_off_t" "$ac_includes_default"
if test "x$ac_cv_type_off_t" = xyes; then :
5218,13 → 4807,104
 
 
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for bind in -lsock" >&5
$as_echo_n "checking for bind in -lsock... " >&6; }
if ${ac_cv_lib_sock_bind+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lsock $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
 
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char bind ();
int
main ()
{
return bind ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_sock_bind=yes
else
ac_cv_lib_sock_bind=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_sock_bind" >&5
$as_echo "$ac_cv_lib_sock_bind" >&6; }
if test "x$ac_cv_lib_sock_bind" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBSOCK 1
_ACEOF
 
LIBS="-lsock $LIBS"
 
fi
 
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
 
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pthread_pthread_create=yes
else
ac_cv_lib_pthread_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBPTHREAD 1
_ACEOF
 
LIBS="-lpthread $LIBS"
 
fi
 
 
 
 
 
 
 
 
 
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
/Makefile.in
54,7 → 54,7
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/autoheader.h.in $(top_srcdir)/configure AUTHORS \
COPYING ChangeLog INSTALL NEWS compile config.guess config.sub \
depcomp install-sh ltmain.sh missing texinfo.tex
depcomp install-sh ltmain.sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
158,7 → 158,6
| sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
distcleancheck_listfiles = find . -type f -print
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
/src/Makefile.am
8,7 → 8,6
plscnt_CPPFLAGS = @GLIB_CFLAGS@
 
plscnt_LDFLAGS = @GLIB_LIBS@
#-export-dynamic
 
plscnt_LDADD =
 
23,10 → 22,12
inputs.c inputs.h \
outputs.c outputs.h \
logging.c logging.h \
tcp_socket.c tcp_socket.h \
tcp_server.c tcp_server.h \
nvram.c nvram.h \
xmalloc.c system.h aclocal.m4 getopt.c getopt1.c getopt.h
 
EXTRA_DIST=plscnt.lsm.in plscnt.spec.in
EXTRA_DIST=client
 
# if you write a self-test script named `chk', uncomment the
# following and add `chk' to the EXTRA_DIST list
/src/main.h
48,6 → 48,8
 
char pulses[MAX_STR_SIZE];
int button;
 
int port;
} GlobalOptions;
 
typedef struct
57,7 → 59,7
char* var; // "/var" or "@prefix@/var"
char* data; // "/var/lib/plscnt" or "@prefix@/var/lib/eon"
char* run; // "/var/run" or "@prefix@/var/run"
char *lock; // "/var/lock" or "@prefix@/var/lock"
char* lock; // "/var/lock" or "@prefix@/var/lock"
} GlobalPaths;
 
/* Variables */
/src/Makefile.in
68,7 → 68,8
plscnt-daemon.$(OBJEXT) plscnt-signals.$(OBJEXT) \
plscnt-gpio_sysfs.$(OBJEXT) plscnt-gpio_mmap.$(OBJEXT) \
plscnt-inputs.$(OBJEXT) plscnt-outputs.$(OBJEXT) \
plscnt-logging.$(OBJEXT) plscnt-nvram.$(OBJEXT) \
plscnt-logging.$(OBJEXT) plscnt-tcp_socket.$(OBJEXT) \
plscnt-tcp_server.$(OBJEXT) plscnt-nvram.$(OBJEXT) \
plscnt-xmalloc.$(OBJEXT) plscnt-getopt.$(OBJEXT) \
plscnt-getopt1.$(OBJEXT)
plscnt_OBJECTS = $(am_plscnt_OBJECTS)
94,7 → 95,6
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
194,7 → 194,6
 
plscnt_CPPFLAGS = @GLIB_CFLAGS@
plscnt_LDFLAGS = @GLIB_LIBS@
#-export-dynamic
plscnt_LDADD =
plscnt_SOURCES = main.c indep.h \
autosave.c autosave.h \
207,10 → 206,12
inputs.c inputs.h \
outputs.c outputs.h \
logging.c logging.h \
tcp_socket.c tcp_socket.h \
tcp_server.c tcp_server.h \
nvram.c nvram.h \
xmalloc.c system.h aclocal.m4 getopt.c getopt1.c getopt.h
 
EXTRA_DIST = plscnt.lsm.in plscnt.spec.in
EXTRA_DIST = client
all: all-am
 
.SUFFIXES:
309,6 → 310,8
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-nvram.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-outputs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-signals.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-tcp_server.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-tcp_socket.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plscnt-xmalloc.Po@am__quote@
 
.c.o:
479,6 → 482,34
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o plscnt-logging.obj `if test -f 'logging.c'; then $(CYGPATH_W) 'logging.c'; else $(CYGPATH_W) '$(srcdir)/logging.c'; fi`
 
plscnt-tcp_socket.o: tcp_socket.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT plscnt-tcp_socket.o -MD -MP -MF $(DEPDIR)/plscnt-tcp_socket.Tpo -c -o plscnt-tcp_socket.o `test -f 'tcp_socket.c' || echo '$(srcdir)/'`tcp_socket.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/plscnt-tcp_socket.Tpo $(DEPDIR)/plscnt-tcp_socket.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tcp_socket.c' object='plscnt-tcp_socket.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o plscnt-tcp_socket.o `test -f 'tcp_socket.c' || echo '$(srcdir)/'`tcp_socket.c
 
plscnt-tcp_socket.obj: tcp_socket.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT plscnt-tcp_socket.obj -MD -MP -MF $(DEPDIR)/plscnt-tcp_socket.Tpo -c -o plscnt-tcp_socket.obj `if test -f 'tcp_socket.c'; then $(CYGPATH_W) 'tcp_socket.c'; else $(CYGPATH_W) '$(srcdir)/tcp_socket.c'; fi`
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/plscnt-tcp_socket.Tpo $(DEPDIR)/plscnt-tcp_socket.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tcp_socket.c' object='plscnt-tcp_socket.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o plscnt-tcp_socket.obj `if test -f 'tcp_socket.c'; then $(CYGPATH_W) 'tcp_socket.c'; else $(CYGPATH_W) '$(srcdir)/tcp_socket.c'; fi`
 
plscnt-tcp_server.o: tcp_server.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT plscnt-tcp_server.o -MD -MP -MF $(DEPDIR)/plscnt-tcp_server.Tpo -c -o plscnt-tcp_server.o `test -f 'tcp_server.c' || echo '$(srcdir)/'`tcp_server.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/plscnt-tcp_server.Tpo $(DEPDIR)/plscnt-tcp_server.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tcp_server.c' object='plscnt-tcp_server.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o plscnt-tcp_server.o `test -f 'tcp_server.c' || echo '$(srcdir)/'`tcp_server.c
 
plscnt-tcp_server.obj: tcp_server.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT plscnt-tcp_server.obj -MD -MP -MF $(DEPDIR)/plscnt-tcp_server.Tpo -c -o plscnt-tcp_server.obj `if test -f 'tcp_server.c'; then $(CYGPATH_W) 'tcp_server.c'; else $(CYGPATH_W) '$(srcdir)/tcp_server.c'; fi`
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/plscnt-tcp_server.Tpo $(DEPDIR)/plscnt-tcp_server.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tcp_server.c' object='plscnt-tcp_server.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o plscnt-tcp_server.obj `if test -f 'tcp_server.c'; then $(CYGPATH_W) 'tcp_server.c'; else $(CYGPATH_W) '$(srcdir)/tcp_server.c'; fi`
 
plscnt-nvram.o: nvram.c
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(plscnt_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT plscnt-nvram.o -MD -MP -MF $(DEPDIR)/plscnt-nvram.Tpo -c -o plscnt-nvram.o `test -f 'nvram.c' || echo '$(srcdir)/'`nvram.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/plscnt-nvram.Tpo $(DEPDIR)/plscnt-nvram.Po
/src/config.c
155,6 → 155,12
ret = sscanf(p, "%i", &options.button);
if(ret != 1) stop(l, buffer);
}
 
if ((p = find_token(buffer, "port=")))
{
ret = sscanf(p, "%i", &options.port);
if(ret != 1) stop(l, buffer);
}
if ((p = find_token(buffer, "verbosity=")))
{
/src/tcp_server.c
0,0 → 1,141
/* Hey EMACS -*- linux-c -*- */
/* $Id$ */
 
/* plscnt - Energy Monitoring & Graphing
* Copyright (C) 2006-2012 Romain Lievin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
 
#ifdef HAVE_CONFIG_H
#include <autoheader.h>
#endif
 
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <glib.h>
#include <pthread.h>
 
#include "logging.h"
#include "timeout.h"
#include "tcp_socket.h"
#include "tcp_server.h"
 
/*
The server is responsible of:
- listening incoming commands
- reply to requests
 
Format is the following:
- LIST
- GET COUNTER07
- PUT COUNTER06
*/
 
#ifndef __WIN32__
 
int sfd;
//int sd[TCP_SOCKET_CONN_MAX] = { -1 };
int nsd = -1;
 
static void recv_handler (int signum)
{
int ret = 0;
char buf[TCP_SOCKET_BUFSIZE-2];
int size;
char addr[17];
int port;
 
printf("Entering recv_handler!\n");
 
/* Accept incoming connection */
ret = socket_accept(sfd, &nsd);
if(ret < 0)
{
return ret;
}
 
/* Data is ready, get it from addr:port to host:1234 */
size = sizeof(buf);
ret = socket_recv(nsd, addr, &port, buf, &size);
printf("buf=<%s>\n", buf);
 
/* Parse command and execute */
if(!strncmp(buf, "LST", 3))
{
ret = socket_send(nsd, addr, TCP_SOCKET_PORT, "echo", strlen("echo"));
}
else if(!strncmp(buf, "GET", 3))
{
ret = socket_send(nsd, addr, TCP_SOCKET_PORT, "echo", strlen("echo"));
}
else if(!strncmp(buf, "PUT", 3))
{
ret = socket_send(nsd, addr, TCP_SOCKET_PORT, "echo", strlen("echo"));
}
else
{
printl(LVL_DBG, "Received bad TCP command: <%s>.\n", buf);
}
ret = ret;
return;
}
 
int server_enable(void)
{
int oflags;
 
/* Create socket */
sfd = socket_open();
 
/* Bind socket */
socket_bind(sfd, "", TCP_SOCKET_PORT);
 
/* Listen for incoming connection */
nsd = socket_listen(sfd);
 
/* Install signal handler for data retrieval */
signal(SIGIO, &recv_handler);
fcntl(nsd, F_SETOWN, getpid());
oflags = fcntl(nsd, F_GETFL);
fcntl(nsd, F_SETFL, oflags | FASYNC);
 
return 0;
}
 
int server_disable(void)
{
int ret = 0;
 
/* Close connection */
if(sfd != -1)
{
ret = socket_close(sfd);
}
return ret;
}
 
#endif
/src/tcp_server.h
0,0 → 1,36
/* Hey EMACS -*- linux-c -*- */
/* $Id$ */
 
/*
plscnt - Energy Monitoring and Graphing
 
Copyright (C) 2006-2012 Romain Liévin
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
 
#ifndef __TCP_SERVER_H__
#define __TCP_SERVER_H__
 
/* Defines */
 
/* Externs */
 
int server_enable(void);
int server_disable(void);
 
/* Enums */
 
#endif
/src/inputs.c
182,8 → 182,9
//printl(LVL_DBG, "ret = %i\n", ret);
 
/*
{ int k; for(k = 0; k < gpio_size; k++)
printf("%i ", gpio_fdset[k].revents);
{ int k;
for(k = 0; k < gpio_size; k++)
printf("%i ", gpio_fdset[k].revents);
printf("\n"); }
*/
// Remark: we are using SIGALRM which makes poll() returns immediately.
/src/tcp_socket.c
0,0 → 1,303
/* Hey EMACS -*- linux-c -*- */
/* $Id$ */
 
/* plscnt - Energy Monitoring & Graphing
* Copyright (C) 2006-2012 Romain Lievin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
 
#ifdef HAVE_CONFIG_H
#include <autoheader.h>
#endif
 
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <glib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
 
#include "logging.h"
#include "timeout.h"
#include "tcp_socket.h"
 
/* Create new socket (addr = "" -> INADDR_ANY) */
int socket_open(void)
{
int sd;
#ifdef TCP_SOCKET_NONBLOCK
int ret;
long cmd;
#endif
 
printl(LVL_INFO, "Opening TCP connection...\n");
 
/* Create an TCP socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd < 0)
{
debug_context();
printl(LVL_ERR, "socket() failed: %s\n", strerr);
return -1;
}
printl(LVL_DEBUG, "socket created\n");
/* Use asynchronous mode */
#ifdef TCP_SOCKET_NONBLOCK
ret = cmd = fcntl(sd, F_GETFL, 0);
if(ret == -1)
{
debug_context();
printl(LVL_ERR, "fcntl() failed: %s\n", strerr);
return -1;
}
cmd |= O_NONBLOCK;
ret = fcntl(sd, F_SETFL, cmd);
if(cmd == -1)
{
debug_context();
printl(LVL_ERR, "fcntl failed: %s\n", strerr);
return -1;
}
#endif
 
return sd;
}
int socket_bind(int sfd, char *addr, int port)
{
struct sockaddr_in local;
int ret;
 
printl(LVL_INFO, "Binding TCP connection on %s:%d...\n",
strlen(addr) ? addr : "ANY", port);
/* Prepare host and port */
memset((char *)&local, 0, sizeof(local));
local.sin_family = AF_INET;
if(!addr || !strlen(addr))
{
local.sin_addr.s_addr = htonl(INADDR_ANY);
}
else
{
if(inet_aton(addr, &local.sin_addr) == 0)
{
debug_context();
printl(LVL_ERR, "inet_aton() failed: %s\n", "bad IP address syntax");
return -1;
}
}
local.sin_port = htons(port);
 
/* Bind socket to server */
ret = bind(sfd, (struct sockaddr *)&local, sizeof(local));
if(ret == -1)
{
debug_context();
printl(LVL_ERR, "bind() failed: %s\n", strerr);
return -1;
}
 
return 0;
}
 
int socket_listen(int sfd)
{
int ret;
 
/* Listen for connection */
ret = listen(sfd, TCP_SOCKET_CONN_MAX);
if(ret == -1)
{
debug_context();
printl(LVL_ERR, "listen() failed: %s\n", strerr);
return -1;
}
else
{
printl(LVL_INFO, "Listening up to %d connections...\n",
TCP_SOCKET_CONN_MAX);
}
 
return 0;
}
 
int socket_accept(int sfd, int *nsd)
{
struct sockaddr_in remote;
int len;
int ret;
 
/* Accept connection */
ret = accept(sfd, (struct sockaddr *)&remote, (socklen_t *)&len);
if(ret == -1)
{
debug_context();
printl(LVL_ERR, "bind() failed: %s\n", strerr);
return -1;
}
else
{
printl(LVL_INFO, "Connection accepted from %s:%d...\n",
remote.sin_addr.s_addr,
ntohs(remote.sin_port));
if(nsd != NULL)
{
*nsd = ret;
}
}
 
return 0;
}
 
/* Send a buffer to socket */
int socket_send(int nsd, char *addr, int port, const char* buf, int len)
{
struct sockaddr_in remote;
tiTIME ref;
int ret = -1;
int slen;
printl(LVL_INFO, "Sending %d bytes to %s:%d...\n", len, addr, port);
//printf("buf = <%s> (%i)\n", buf, len);
 
/* Prepare connection */
memset((char *)&remote, 0, sizeof(remote));
remote.sin_family = AF_INET;
remote.sin_port = htons(port);
if(inet_aton(addr, &remote.sin_addr) == 0)
{
debug_context();
printl(LVL_ERR, "inet_aton() failed: %s\n",
"bad IP address syntax");
return -1;
}
 
/* Send data */
TO_START(ref);
 
do
{
slen = sizeof(remote);
ret = sendto(nsd, buf, len, 0, (struct sockaddr *)&remote, slen);
 
#ifdef TCP_SOCKET_NONBLOCK
if(TO_ELAPSED(ref, TCP_SOCKET_TIMEOUT))
break;
#endif
 
//printf("'''%i %i'''\n", ret, errno);
if(ret == -1 && errno != EAGAIN &&
errno != EALREADY && errno != EINPROGRESS)
break;
}
while(ret < 0);
 
if(ret < 0)
{
debug_context();
printl(LVL_DEBUG, "send() failed: %s", strerr);
printl(LVL_ERR, "socket send failed.\n");
return -1;
}
else
{
printl(LVL_DEBUG, "Packet sent (%d bytes).\n", ret);
}
printl(LVL_INFO, "Packet sent (%d bytes).\n", ret);
 
return 0;
}
 
int socket_recv(int nsd, char *addr, int *port, char *buf, int *len)
{
struct sockaddr_in remote;
#ifdef TCP_SOCKET_NONBLOCK
tiTIME ref;
#endif
int ret;
int slen;
 
printl(LVL_INFO, "Waiting for data...\n");
/* Receiving data from socket */
#ifdef TCP_SOCKET_NONBLOCK
TO_START(ref);
#endif
do
{
slen = sizeof(remote);
ret = recvfrom(nsd, buf, TCP_SOCKET_BUFSIZE, 0,
(struct sockaddr *)&remote, (socklen_t *)&slen);
#ifdef TCP_SOCKET_NONBLOCK
if(TO_ELAPSED(ref, TCP_SOCKET_TIMEOUT))
break;
#endif
//printf("<%i> %i\n", ret, errno); // -1 11 = EAGAIN
if(ret == -1 && errno != EAGAIN &&
errno != EALREADY && errno != EINPROGRESS)
break;
}
while(ret < 0);
if(ret < 0)
{
debug_context();
printl(LVL_DEBUG, "recv() failed: %s", strerr);
printl(LVL_ERR, "receive from socket failed.\n");
return -1;
}
else
{
*len = ret;
printl(LVL_DEBUG, "Received packet from %s:%d\nData: %s\n",
inet_ntoa(remote.sin_addr), ntohs(remote.sin_port), buf);
strcpy(addr, inet_ntoa(remote.sin_addr));
*port = ntohs(remote.sin_port);
}
printl(LVL_INFO, "Packet received (%d bytes).\n", *len);
buf[*len] = '\0';
return 0;
}
 
int socket_close(int sd)
{
/* Close socket */
if(sd != -1)
close(sd);
sd = -1;
 
printl(LVL_INFO, "Connection closed.\n");
 
return 0;
}
 
/src/tcp_socket.h
0,0 → 1,48
/* Hey EMACS -*- linux-c -*- */
/* $Id$ */
 
/*
emg - Energy Monitoring and Graphing
 
Copyright (C) 2006-2012 Romain Liévin
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
 
#ifndef __TCP_SOCKET_H__
#define __TCP_SOCKET_H__
 
/* Defines */
 
#define TCP_SOCKET_PORT 333
#define TCP_SOCKET_BUFSIZE 256 // 256 bytes per chunk
#define TCP_SOCKET_TIMEOUT (5 * 1000) // 5 seconds
#define TCP_SOCKET_CONN_MAX 4 // unused
 
#define TCP_SOCKET_NONBLOCK
 
/* Externs */
 
int socket_open(void);
int socket_bind(int sfd, char *addr, int port);
int socket_listen(int sfd);
int socket_accept(int sfd, int *nsd);
int socket_send(int nsd, char *addr, int port, const char* buf, int len);
int socket_recv(int nsd, char *addr, int *port, char* buf, int *len);
int socket_close(int sd);
 
/* Enums */
 
#endif
/src/main.c
44,6 → 44,7
#include "nvram.h"
#include "autosave.h"
#include "signals.h"
#include "tcp_server.h"
 
#include "getopt.h"
 
300,6 → 301,14
// Capture Ctrl+C
signals_catch();
 
server_enable();
while(1)
{
 
}
server_disable();
 
if(outputs_init() < 0)
exit(-1);
307,7 → 316,7
exit(-1);
outputs_set(LED_1G, LED_ON);
 
while(1)
{
outputs_run();
/misc/plscnt.conf
18,3 → 18,5
# Logging mode
logging=syslog
 
# Server port
port=333
/misc/Makefile.am
15,6 → 15,3
@INSTALL@ -d $(localstatedir)/lib/plscnt
 
@INSTALL@ -d $(localstatedir)/run
 
ln -sf $(sysconfdir)/init.d/plscnt.sh /etc/init.d/plscnt.sh
cd $(sysconfdir)/init.d; update-rc.d plscnt.sh defaults
/misc/Makefile.in
69,7 → 69,6
esac
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
365,9 → 364,6
 
@INSTALL@ -d $(localstatedir)/run
 
ln -sf $(sysconfdir)/init.d/plscnt.sh /etc/init.d/plscnt.sh
cd $(sysconfdir)/init.d; update-rc.d plscnt.sh defaults
 
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT: