Browse Source

Setting the configuration files.

master
Aitor 10 months ago
parent
commit
d809e20dfb
  1. 3
      Makefile.am
  2. 3
      autogen.sh
  3. 23
      conf/Makefile.am
  4. 0
      conf/snetaid.conf
  5. 28
      conf/snetaid.init.in
  6. 50
      configure.ac
  7. 4
      src/Makefile.am
  8. 8
      src/config.c
  9. 27
      src/util.c

3
Makefile.am

@ -6,7 +6,6 @@ CLEANFILES =
SUBDIRS = \
src \
conf \
po
DISTCLEANFILES = \
$(desktop_DATA)

3
autogen.sh

@ -7,8 +7,7 @@ autoreconf --force --install --verbose --warnings=all "$srcdir"
echo "Setting up Intltool"
intltoolize --copy --force --automake || exit 1
test -n "$NOCONFIGURE" || "$srcdir/configure" \
--program-suffix=${SUFFIX} \
--prefix= \
--enable-manpages \
--disable-dependency-tracking \
"$@"

23
conf/Makefile.am

@ -0,0 +1,23 @@
# This file is part of snetaid.
#
#
sysinitdir = @SYSINITDIR@
noinst_DATA = snetaid.init snetaid.conf
EXTRA_DIST = snetaid.init.in snetaid.conf
CLEANFILES = snetaid.init
snetaid.init: snetaid.init.in Makefile
sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' $< > $@
chmod 755 $@
install-data-local: snetaid.init
$(INSTALL) -b -D -m755 snetaid.init ${DESTDIR}${sysinitdir}/snetaid
$(INSTALL) -b -D -m644 $(srcdir)/snetaid.conf ${DESTDIR}${sysconfdir}/simple-netaid/snetaid.conf
uninstall-local:
rm -f ${DESTDIR}${sysconfdir}/simple-netaid/snetaid.conf ${DESTDIR}${sysinitdir}/snetaid

0
snetaid.conf → conf/snetaid.conf

28
snetaid.init → conf/snetaid.init.in

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# snetaid /etc/init.d initscript for snetaid
#
@ -20,33 +20,35 @@ set -e
# Import LSB funcions:
. /lib/lsb/init-functions
NAME=snetaid
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
DAEMON_OPTS="-b -s -p$PIDFILE"
SNETAID=@sbindir@/snetaid
PIDFILE=/run/snetaid/snetaid.pid
test -x $SNETAID || exit 5
##proguser=root
if [ `id -u` != "0" ] && [ "$1" = "start" -o "$1" = "stop" ] ; then
echo "You must be root to start, stop or restart snetaid."
exit 1
fi
test -x $DAEMON || {
DAEMON=/usr/sbin/$NAME
test -x $DAEMON || exit 5
}
DAEMON_OPTS="-b -p$PIDFILE"
start() {
log_action_begin_msg "Starting $NAME"
start_daemon -- $DAEMON $DAEMON_OPTS
start_daemon -- $SNETAID $DAEMON_OPTS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $PIDFILE
return $RETVAL
}
stop() {
OUTPUT=`$DAEMON -c -p$PIDFILE`
OUTPUT=`$SNETAID -c -p$PIDFILE`
RETVAL=$?
[ $RETVAL -eq 0 ] && {
if test "${OUTPUT#*'running as pid'}" != "$OUTPUT"; then
log_action_begin_msg "Stopping $NAME"
$DAEMON -k -p$PIDFILE
$SNETAID -k -p$PIDFILE
else
log_action_begin_msg "$NAME not running"
fi
@ -65,7 +67,7 @@ case "$1" in
log_action_end_msg 0
;;
status)
$DAEMON -c
$SNETAID -c
;;
restart|reload|force-reload)
stop

50
configure.ac

@ -41,6 +41,45 @@ AC_PROG_LIBTOOL
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
# Init script location
AC_ARG_WITH(initdir, AS_HELP_STRING(--with-initdir=DIR,Install init script in DIR (system dependent default)))
test "x$with_initdir" = xyes -o "x$with_initdir" = xno && with_initdir=
if test "x$with_initdir" = x ; then
if test -d /etc/init.d ; then
SYSINITDIR=/etc/init.d
else
if test -d /etc/rc.d/init.d ; then
SYSINITDIR=/etc/rc.d/init.d
else
AC_MSG_ERROR([missing --with-initdir=DIR])
fi
fi
else
SYSINITDIR="$with_initdir"
fi
AC_MSG_NOTICE([*** Init sript will be installed in $SYSINITDIR ***])
AC_SUBST(SYSINITDIR)
# Set paths here
AC_ARG_WITH(
[rootprefix],
[AS_HELP_STRING(
[--with-rootprefix=DIR],
[rootfs directory prefix for config files and kernel modules])],
[],
[with_rootprefix="\${prefix}"]
)
# Configured paths
AC_SUBST([rootprefix], [${with_rootprefix}])
# sysconfdir paths
AC_SUBST([snetaidconfdir],[${sysconfdir}/simple-netaid])
AC_SUBST([snetaidconffile],[${snetaidconfdir}/snetaid.conf])
# ------------------------------------------------------------------------------
AC_ARG_ENABLE([manpages], AS_HELP_STRING([--disable-manpages],[disable manpages]),[],[enable_manpages=no])
AM_CONDITIONAL(ENABLE_MANPAGES, [test "x$enable_manpages" = "xyes"])
@ -60,9 +99,18 @@ AS_IF([test "x$enable_debug" = "xyes"],
CFLAGS="-Wall $cflags_add $CFLAGS"
AC_CONFIG_FILES([Makefile
src/Makefile]
src/Makefile
conf/Makefile]
po/Makefile.in)
AC_OUTPUT
# ------------------------------------------------------------------------------
AC_MSG_RESULT([
prefix: ${prefix}
snetaidconfdir: ${snetaidconfdir}
snetaidconffile: ${snetaidconffile}
])
# ------------------------------------------------------------------------------

4
src/Makefile.am

@ -38,8 +38,8 @@ snetaid_CFLAGS = \
snetaid_LDFLAGS = \
$(AM_LDFLAGS)
install-data-local:
$(MKDIR_P) /etc/network/wifi

8
src/config.c

@ -335,7 +335,7 @@ int config_load_from_args(config_t* config, int argc, char** argv)
{"foreground", no_argument, 0, 'f'},
{"kill", no_argument, 0, 'k'},
{"stop", no_argument, 0, 's'},
{"verbose-level", required_argument, 0, 'v'},
{"verbose-level", required_argument, 0, 'v'},
{"config_path", required_argument, 0, 'a'},
{"logfile_path", required_argument, 0, 'l'},
{"pidfile_path", required_argument, 0, 'p'},
@ -402,7 +402,7 @@ int config_load_from_args(config_t* config, int argc, char** argv)
if(m_config->pidfile_path != NULL) {
free(m_config->pidfile_path);
}
m_config->pidfile_path = strdup_or_null(optarg);
m_config->pidfile_path = strdup_or_null(optarg);
break;
case 'k':
@ -426,10 +426,6 @@ int config_load_from_args(config_t* config, int argc, char** argv)
printf("Failed to kill daemon: %s with SIGTERM , rc = %d\n", strerror(errno), rc);
exit(1);
}
/* Try to delete lockfile */
if (m_config->pidfile_path)
unlink(m_config->pidfile_path);
exit(EXIT_SUCCESS);
}

27
src/util.c

@ -34,30 +34,6 @@
#define MAX_SIZE 256
int lock_file(int fd, int enable)
{
struct flock f;
memset(&f, 0, sizeof(f));
f.l_type = enable ? F_WRLCK : F_UNLCK;
f.l_whence = SEEK_SET;
f.l_start = 0;
f.l_len = 0;
if (fcntl(fd, F_SETLKW, &f) < 0) {
if (enable && errno == EBADF) {
f.l_type = F_RDLCK;
if (fcntl(fd, F_SETLKW, &f) >= 0)
return 0;
}
log_warn("fcntl(F_SETLKW) failed: %s", strerror(errno));
return -1;
}
return 0;
}
/**
* \brief Get the PID of the process.
*/
@ -79,9 +55,6 @@ pid_t get_pid_t(void)
}
}
if ((locked = lock_file(fd, 1)) < 0)
goto finish;
if ((l = read(fd, txt, MAX_SIZE-1)) < 0) {
int saved_errno = errno;
log_error("read(): %s , errno=%d", strerror(errno), errno);

Loading…
Cancel
Save