move common sources to common/

This commit is contained in:
Nikos Mavrogiannopoulos
2015-11-11 14:59:12 +01:00
parent 2ef8d5a4c2
commit 3ba4c2b618
10 changed files with 131 additions and 19 deletions

View File

@@ -479,6 +479,7 @@ AC_CONFIG_FILES([
src/occtl/Makefile
src/ocpasswd/Makefile
src/ccan/Makefile
src/common/Makefile
src/pcl/Makefile
src/protobuf/Makefile
doc/Makefile

View File

@@ -1,8 +1,8 @@
SUBDIRS = ccan
SUBDIRS = ccan common
AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \
-I$(srcdir)/ -I$(builddir)/../ -I$(srcdir)/../ $(LIBOPTS_CFLAGS) \
$(LIBGNUTLS_CFLAGS) \
$(LIBGNUTLS_CFLAGS) -I$(srcdir)/common -I$(builddir)/common \
$(LIBPROTOBUF_C_CFLAGS) $(LIBLZ4_CFLAGS) \
$(LIBREADLINE_CFLAGS) \
$(LIBTALLOC_CFLAGS) $(LIBDBUS_CFLAGS) $(LIBOATH_CFLAGS) \
@@ -35,9 +35,6 @@ ocserv-args.c: $(srcdir)/ocserv-args.def $(builddir)/version.inc
$(AUTOGEN) $<
ocserv-args.h: ocserv-args.c
# Files common to ocserv and occtl.
COMMON_SOURCES=common.c common.h system.c system.h
# Authentication module sources
AUTH_SOURCES=auth/pam.c auth/pam.h auth/plain.c auth/plain.h auth/radius.c auth/radius.h \
auth/common.c auth/common.h auth/gssapi.h auth/gssapi.c auth-unix.c \
@@ -52,7 +49,7 @@ ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \
worker-extras.c html.c html.h worker-http.c \
main-user.c worker-misc.c route-add.c route-add.h worker-privs.c \
sec-mod.c sec-mod-db.c sec-mod-auth.c sec-mod-auth.h sec-mod.h \
script-list.h $(COMMON_SOURCES) $(AUTH_SOURCES) $(ACCT_SOURCES) \
script-list.h $(AUTH_SOURCES) $(ACCT_SOURCES) \
icmp-ping.c icmp-ping.h worker-kkdcp.c subconfig.c \
sec-mod-sup-config.c sec-mod-sup-config.h \
sup-config/file.c sup-config/file.h main-sec-mod-cmd.c \
@@ -72,9 +69,9 @@ if HAVE_GSSAPI
ocserv_SOURCES += kkdcp_asn1_tab.c kkdcp.asn
endif
ocserv_SOURCES += ipc.pb-c.h ipc.pb-c.c ctl.pb-c.c ctl.pb-c.h
ocserv_SOURCES += ipc.pb-c.h ipc.pb-c.c
ocserv_LDADD = ../gl/libgnu.a $(NEEDED_LIBOPTS) libcmd-ocserv.a ccan/libccan.a
ocserv_LDADD = ../gl/libgnu.a $(NEEDED_LIBOPTS) libcmd-ocserv.a ccan/libccan.a common/libcommon.a
ocserv_LDADD += $(LIBGNUTLS_LIBS) $(PAM_LIBS) $(LIBUTIL) \
$(LIBSECCOMP) $(LIBWRAP) $(LIBCRYPT) $(NEEDED_HTTP_PARSER_LIBS) \
$(LIBPROTOBUF_C_LIBS) $(LIBSYSTEMD) $(LIBTALLOC_LIBS) \
@@ -104,11 +101,6 @@ ipc.pb-c.c: ipc.proto
ipc.pb-c.h: ipc.pb-c.c
ctl.pb-c.c: ctl.proto
protoc-c --c_out=. --proto_path=$(srcdir) $<
ctl.pb-c.h: ctl.pb-c.c
http-heads.h: $(srcdir)/http-heads.gperf
-gperf --global-table -t $^ > $@-tmp && mv $@-tmp $@

83
src/common/cloexec.c Normal file
View File

@@ -0,0 +1,83 @@
/* closexec.c - set or clear the close-on-exec descriptor flag
Copyright (C) 1991, 2004-2006, 2009-2014 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
The code is taken from glibc/manual/llio.texi */
#include <config.h>
#include "cloexec.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
or clear the flag if VALUE is false.
Return 0 on success, or -1 on error with 'errno' set.
Note that on MingW, this function does NOT protect DESC from being
inherited into spawned children. Instead, either use dup_cloexec
followed by closing the original DESC, or use interfaces such as
open or pipe2 that accept flags like O_CLOEXEC to create DESC
non-inheritable in the first place. */
int
set_cloexec_flag (int desc, bool value)
{
#ifdef F_SETFD
int flags = fcntl (desc, F_GETFD, 0);
if (0 <= flags)
{
int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
if (flags == newflags
|| fcntl (desc, F_SETFD, newflags) != -1)
return 0;
}
return -1;
#else /* !F_SETFD */
/* Use dup2 to reject invalid file descriptors; the cloexec flag
will be unaffected. */
if (desc < 0)
{
errno = EBADF;
return -1;
}
if (dup2 (desc, desc) < 0)
/* errno is EBADF here. */
return -1;
/* There is nothing we can do on this kind of platform. Punt. */
return 0;
#endif /* !F_SETFD */
}
/* Duplicates a file handle FD, while marking the copy to be closed
prior to exec or spawn. Returns -1 and sets errno if FD could not
be duplicated. */
int
dup_cloexec (int fd)
{
return fcntl (fd, F_DUPFD_CLOEXEC, 0);
}

38
src/common/cloexec.h Normal file
View File

@@ -0,0 +1,38 @@
/* closexec.c - set or clear the close-on-exec descriptor flag
Copyright (C) 2004, 2009-2014 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
or clear the flag if VALUE is false.
Return 0 on success, or -1 on error with 'errno' set.
Note that on MingW, this function does NOT protect DESC from being
inherited into spawned children. Instead, either use dup_cloexec
followed by closing the original DESC, or use interfaces such as
open or pipe2 that accept flags like O_CLOEXEC to create DESC
non-inheritable in the first place. */
int set_cloexec_flag (int desc, bool value);
/* Duplicates a file handle FD, while marking the copy to be closed
prior to exec or spawn. Returns -1 and sets errno if FD could not
be duplicated. */
int dup_cloexec (int fd);

View File

@@ -1,6 +1,7 @@
AM_CPPFLAGS = -I$(srcdir)/../../gl/ -I$(builddir)/../../gl/ \
-I$(srcdir)/ -I$(srcdir)/../ -I$(builddir)/../../ -I$(builddir)/../ \
$(LIBNL3_CFLAGS) $(LIBPROTOBUF_C_CFLAGS) $(LIBTALLOC_CFLAGS)
$(LIBNL3_CFLAGS) $(LIBPROTOBUF_C_CFLAGS) $(LIBTALLOC_CFLAGS) \
-I$(srcdir)/../common/
if LOCAL_TALLOC
AM_CPPFLAGS += -I$(srcdir)/../ccan/talloc
@@ -10,12 +11,9 @@ EXTRA_DIST = args.def
bin_PROGRAMS = occtl
COMMON_SOURCES=../common.c ../common.h
occtl_SOURCES = occtl.c pager.c occtl.h time.c cache.c ip-cache.c \
nl.c ctl.h ../ctl.pb-c.c ../ctl.pb-c.h $(COMMON_SOURCES) \
print.c json.c json.h
occtl_LDADD = ../../gl/libgnu.a $(LIBREADLINE_LIBS) \
nl.c ctl.h print.c json.c json.h
occtl_LDADD = ../../gl/libgnu.a ../common/libcommon.a $(LIBREADLINE_LIBS) \
$(LIBNL3_LIBS) $(LIBPROTOBUF_C_LIBS) $(LIBTALLOC_LIBS) ../ccan/libccan.a
if LOCAL_PROTOBUF_C