Fix broken Batphone build

Recent changes such as the Makefile.in overhaul and the introduction of
feature-driven linking broke the Android build.  This commit fixes the
breakage:
- detects the presence of gettid() in configure.ac and only defines
  gettid() in serval.c if HAVE_GETTID is not defined
- builds libserval.so not libservald.so on Android, to avoid a conflict
  on the module name "servald" in Android.mk
- renames cli_cleanup() to command_cleanup(), defines it in
  commandline.h instead of cli.h, and supplies it in android.c
- supplies the 'keyring' global in android.c
- removes log_stderr.c from the Android build, since it conflicted with
  log.c
This commit is contained in:
Andrew Bettison 2016-10-17 17:40:28 +10:30
parent 6627c868d0
commit 8325aacc5d
12 changed files with 60 additions and 19 deletions

View File

@ -11,7 +11,7 @@ SERVALD_SRC_FILES = \
$(SERVAL_CLIENT_SOURCES) \
$(MDP_CLIENT_SOURCES) \
$(SERVAL_DAEMON_SOURCES) \
$(ANDROIDONLY_SOURCES)
$(ANDROID_SOURCES)
SQLITE3_INC := $(LOCAL_PATH)/$(SQLITE3_AMALGAMATION)
SERVALD_LOCAL_CFLAGS = \
@ -39,6 +39,7 @@ SERVALD_LOCAL_CFLAGS = \
-DHAVE_JNI_H=1 -DHAVE_STRUCT_UCRED=1 -DHAVE_CRYPTO_SIGN_NACL_GE25519_H=1 \
-DBYTE_ORDER=_BYTE_ORDER -DHAVE_LINUX_STRUCT_UCRED -DUSE_ABSTRACT_NAMESPACE \
-DHAVE_BCOPY -DHAVE_BZERO -DHAVE_NETINET_IN_H -DHAVE_LSEEK64 -DSIZEOF_OFF_T=4 \
-DHAVE_GETTID=1 \
-DHAVE_LINUX_IF_H -DHAVE_SYS_STAT_H -DHAVE_SYS_VFS_H -DHAVE_LINUX_NETLINK_H -DHAVE_LINUX_RTNETLINK_H \
-DSQLITE_OMIT_DATETIME_FUNCS -DSQLITE_OMIT_COMPILEOPTION_DIAGS -DSQLITE_OMIT_DEPRECATED \
-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_VIRTUALTABLE -DSQLITE_OMIT_AUTHORIZATION \
@ -50,11 +51,11 @@ SERVALD_LOCAL_STATIC_LIBRARIES += sodium
# Build libservald.so
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := $(SERVALD_LOCAL_STATIC_LIBRARIES)
LOCAL_SRC_FILES := $(SERVALD_SRC_FILES) version_servald.c android.c
LOCAL_SRC_FILES := $(SERVALD_SRC_FILES) version_servald.c
LOCAL_CFLAGS += $(SERVALD_LOCAL_CFLAGS)
LOCAL_C_INCLUDES += $(SODIUM_INCLUDE)
LOCAL_LDLIBS := $(SERVALD_LOCAL_LDLIBS)
LOCAL_MODULE := servald
LOCAL_MODULE := serval
include $(BUILD_SHARED_LIBRARY)
# Build servald executable, a wrapper around libservald.so

View File

@ -24,6 +24,7 @@ ALL_SOURCES = \
$(SERVAL_DAEMON_SOURCES) \
$(SERVAL_DAEMON_JNI_SOURCES) \
$(MONITOR_CLIENT_SRCS) \
$(CLIENT_ONLY_SOURCES) \
$(SIMULATOR_SOURCES) \
$(SQLITE3_SOURCES)
@ -42,9 +43,11 @@ SERVALD_OBJS = \
$(SERVAL_DAEMON_OBJS)
LIB_SERVAL_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MDP_CLIENT_SOURCES:.c=.o))
MONITOR_CLIENT_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MONITOR_CLIENT_SRCS:.c=.o))
SIMULATOR_OBJS = \
$(addprefix $(OBJSDIR_TOOLS)/, $(SIMULATOR_SOURCES:.c=.o))

View File

@ -20,6 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h>
#include "debug.h"
#include "conf.h"
#include "keyring.h"
#include "commandline.h"
__thread keyring_file *keyring = NULL;
// We don't want to call any at_exit functions from the dalvik VM
void _exit(int status);
@ -29,3 +33,11 @@ void exit(int status)
fflush(stdout);
_exit(status);
}
void command_cleanup()
{
// This function is called after every CLI command has finished.
rhizome_close_db();
free_subscribers();
assert(keyring==NULL);
}

3
cli.h
View File

@ -165,13 +165,10 @@ void cli_field_name(struct cli_context *context, const char *name, const char *d
*/
void cli_flush(struct cli_context *context);
void cli_cleanup();
/* CLI encapulation. Every interface that can encapsulate the CLI must provide
* a vtable of operations that realise the above output primitives in terms of
* its own data channel.
*/
struct cli_vtable {
void (*delim)(struct cli_context *context, const char *opt);
void (*write)(struct cli_context *context, const char *buf, size_t len);

View File

@ -47,7 +47,7 @@ int commandline_main(struct cli_context *context, const char *argv0, int argc, c
IN();
cf_init();
struct cli_parsed parsed;
int result = cli_parse(argc, args, SECTION_START(commands), SECTION_END(commands), &parsed);
switch (result) {
@ -74,10 +74,10 @@ int commandline_main(struct cli_context *context, const char *argv0, int argc, c
break;
}
cli_cleanup();
command_cleanup();
OUT();
if (IF_DEBUG(timing))
fd_showstats();
return result;

View File

@ -49,4 +49,9 @@ DECLARE_SECTION(struct cli_schema, commands);
int commandline_main(struct cli_context *context, const char *argv0, int argc, const char *const *args);
int commandline_main_stdio(FILE *output, const char *argv0, int argc, const char *const *args);
/* Called after every command has finished. Is not supplied by the
* command-line object; the caller must define this function.
*/
void command_cleanup();
#endif // __SERVAL_DNA__COMMANDLINE_H

View File

@ -170,8 +170,9 @@ AC_CHECK_HEADERS(
AC_CHECK_LIB(sodium, sodium_init,, [AC_MSG_ERROR([missing libsodium LIBSODIUM_MESSAGE([LIBRARY_PATH])])])
dnl Check if the Linux gettid() and tgkill() system calls are supported.
AC_CACHE_CHECK([Linux gettid() and tgkill()], ac_cv_have_linux_gettid_tgkill, [
ac_cv_have_linux_gettid_tgkill=no
AC_CHECK_FUNCS([gettid tgkill])
AC_CACHE_CHECK([Linux thread system calls], ac_cv_have_linux_threads, [
ac_cv_have_linux_threads=no
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
#include <unistd.h>
@ -180,10 +181,10 @@ AC_CACHE_CHECK([Linux gettid() and tgkill()], ac_cv_have_linux_gettid_tgkill, [
],
[syscall(SYS_tgkill, getpid(), syscall(SYS_gettid), SIGHUP)]
)],
[ac_cv_have_linux_gettid_tgkill=yes]
[ac_cv_have_linux_threads=yes]
)
])
AS_IF([test "x$ac_cv_have_linux_gettid_tgkill" = xyes], [AC_DEFINE([HAVE_LINUX_THREADS])])
AS_IF([test "x$ac_cv_have_linux_threads" = xyes], [AC_DEFINE([HAVE_LINUX_THREADS])])
dnl Lazy way of checking for Linux
AS_IF([test "x$ac_cv_header_linux_if_h" = xyes], [AC_DEFINE([USE_ABSTRACT_NAMESPACE])])

View File

@ -66,9 +66,9 @@ void servald_features()
__thread keyring_file *keyring = NULL;
void cli_cleanup()
void command_cleanup()
{
/* clean up after ourselves */
// This function is called after every CLI command has finished.
rhizome_close_db();
free_subscribers();
assert(keyring==NULL);

View File

@ -26,7 +26,7 @@ int main(int argc,char **argv)
{
const char *libservald_path =
#ifdef ANDROID
"/data/data/org.servalproject/lib/libservald.so"
"/data/data/org.servalproject/lib/libserval.so"
#else
"libservald.so"
#endif

View File

@ -74,6 +74,9 @@ static const char *_server_pidfile_path(struct __sourceloc __whence);
static int server_write_proc_state(const char *path, const char *fmt, ...);
static int server_get_proc_state(const char *path, char *buff, size_t buff_len);
// Define our own gettid() and tgkill() if <unistd.h> doesn't provide them (eg, it does on Android).
#ifndef HAVE_GETTID
static pid_t gettid()
{
#ifdef HAVE_LINUX_THREADS
@ -82,6 +85,16 @@ static pid_t gettid()
return getpid();
#endif
}
#endif // !HAVE_GETTID
#ifdef HAVE_LINUX_THREADS
#ifndef HAVE_TGKILL
static int tgkill(int tgid, int tid, int signum)
{
return syscall(SYS_tgkill, tgid, tid, signum);
}
#endif // !HAVE_TGKILL
#endif // HAVE_LINUX_THREADS
// Read the PID and TID from the given pidfile, returning a PID of 0 if the file does not exist, or
// a PID of -1 if the file exists but contains invalid content or is not locked by process PID,

View File

@ -19,7 +19,6 @@ SERVAL_CLIENT_SOURCES = \
logMessage.c \
log_cli.c \
log_context.c \
log_stderr.c \
log_util.c \
mem.c \
net.c \
@ -135,3 +134,13 @@ SIMULATOR_SOURCES = \
MONITOR_CLIENT_SRCS = \
monitor-client.c
# These source files must excluded from the Android.mk build, otherwise
# the libserval.so link fails.
# TODO: get rid of the need for this separate list by unifying the daemon
# and client logging.
CLIENT_ONLY_SOURCES = \
log_stderr.c
ANDROID_SOURCES = \
android.c

View File

@ -27,4 +27,4 @@ void test_features()
USE_FEATURE(cli_tests);
}
void cli_cleanup() {}
void command_cleanup() {}