Skip to content

Fixes to enable building on FreeBSD #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Run this to generate all the initial makefiles, etc.

: ${AUTOCONF=autoconf}
Expand Down
4 changes: 2 additions & 2 deletions common/obj-backend-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ obj_backend_fs_read (ObjBackend *bend,
static int
fsync_obj_contents (int fd)
{
#ifdef __linux__
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* Some file systems may not support fsync().
* In this case, just skip the error.
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ fsync_obj_contents (int fd)
static int
rename_and_sync (const char *tmp_path, const char *obj_path)
{
#ifdef __linux__
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
char *parent_dir;
int ret = 0;

Expand Down
50 changes: 49 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ else
AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for BSD)
if test `uname | grep -e BSD -e DragonFly | wc -l` = "1"; then
bbsd=true
AC_MSG_RESULT(compile in BSD)
else
AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for Linux)
if test "$bmac" != "true" -a "$bwin32" != "true"; then
if test "$bmac" != "true" -a "$bwin32" != "true" -a "$bbsd" != "true"; then
blinux=true
AC_MSG_RESULT(compile in linux)
else
Expand All @@ -78,6 +86,11 @@ if test "$bwin32" != true; then
[compile_fuse=$enableval],[compile_fuse="yes"])
fi

if test "$bbsd" = true; then
AC_ARG_ENABLE(fuse, AC_HELP_STRING([--enable-fuse], [enable fuse virtual file system]),
[compile_fuse=$enableval],[compile_fuse="no"])
fi

AC_ARG_ENABLE(python,
AC_HELP_STRING([--enable-python],[build seafile python binding]),
[compile_python=$enableval],
Expand All @@ -89,6 +102,7 @@ AM_CONDITIONAL([COMPILE_FUSE], [test "${compile_fuse}" = "yes"])

AM_CONDITIONAL([WIN32], [test "$bwin32" = "true"])
AM_CONDITIONAL([MACOS], [test "$bmac" = "true"])
AM_CONDITIONAL([BSD], [test "$bbsd" = "true"])
AM_CONDITIONAL([LINUX], [test "$blinux" = "true"])


Expand Down Expand Up @@ -134,6 +148,8 @@ if test "$bwin32" = true; then
LIB_MAC=
MSVC_CFLAGS="-D__MSVCRT__ -D__MSVCRT_VERSION__=0x0601"
LIB_CRYPT32=-lcrypt32
LIB_INOTIFY=
LIB_KVM=
LIB_ICONV=-liconv
elif test "$bmac" = true ; then
LIB_WS32=
Expand All @@ -149,6 +165,24 @@ elif test "$bmac" = true ; then
LIB_MAC="-framework CoreServices"
LIB_CRYPT32=
LIB_ICONV=-liconv
LIB_INOTIFY=
LIB_KVM=
elif test "$bbsd" = true ; then
LIB_WS32=
LIB_GDI32=
LIB_RT=
LIB_INTL=
LIB_RESOLV=
LIB_UUID=-luuid
LIB_IPHLPAPI=
LIB_SHELL32=
LIB_PSAPI=
LIB_MAC=
MSVC_CFLAGS=
LIB_CRYPT32=
LIB_ICONV=-liconv
LIB_INOTIFY=-linotify
LIB_KVM=-lkvm
else
LIB_WS32=
LIB_GDI32=
Expand All @@ -162,6 +196,8 @@ else
LIB_MAC=
MSVC_CFLAGS=
LIB_CRYPT32=
LIB_INOTIFY=-linotify
LIB_KVM=
fi

AC_SUBST(LIB_WS32)
Expand All @@ -174,6 +210,8 @@ AC_SUBST(LIB_IPHLPAPI)
AC_SUBST(LIB_SHELL32)
AC_SUBST(LIB_PSAPI)
AC_SUBST(LIB_MAC)
AC_SUBST(LIB_INOTIFY)
AC_SUBST(LIB_KVM)
AC_SUBST(MSVC_CFLAGS)
AC_SUBST(LIB_CRYPT32)
AC_SUBST(LIB_ICONV)
Expand All @@ -189,6 +227,8 @@ ZDB_REQUIRED=2.10
CURL_REQUIRED=7.17
FUSE_REQUIRED=2.7.3
ZLIB_REQUIRED=1.2.0
LIBEVHTP_REQUIRED=1.2.10
ONIGURUMA_REQUIRED=5.9.2

PKG_CHECK_MODULES(SSL, [openssl])
AC_SUBST(SSL_CFLAGS)
Expand Down Expand Up @@ -222,6 +262,14 @@ PKG_CHECK_MODULES(ZLIB, [zlib >= $ZLIB_REQUIRED])
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_LIBS)

PKG_CHECK_MODULES(LIBEVHTP, [evhtp >= $LIBEVHTP_REQUIRED])
AC_SUBST(LIBEVHTP_CFLAGS)
AC_SUBST(LIBEVHTP_LIBS)

PKG_CHECK_MODULES(ONIGURUMA, [oniguruma >= $ONIGURUMA_REQUIRED])
AC_SUBST(ONIGURUMA_CFLAGS)
AC_SUBST(ONIGURUMA_LIBS)

if test x${compile_python} = xyes; then
AM_PATH_PYTHON([2.6])
if test "$bwin32" = true; then
Expand Down
129 changes: 61 additions & 68 deletions controller/seafile-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
#include "log.h"
#include "seafile-controller.h"

#define CHECK_PROCESS_INTERVAL 10 /* every 10 seconds */
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
#include <limits.h>

#if defined(__sun)
#define PROC_SELF_PATH "/proc/self/path/a.out"
#else
#define PROC_SELF_PATH "/proc/self/exe"
#ifndef WITH_PROC_FS
#define WITH_PROC_FS g_file_test("/proc/curproc", G_FILE_TEST_EXISTS)
#endif

static char *command_name = NULL;
#endif

#define CHECK_PROCESS_INTERVAL 10 /* every 10 seconds */

SeafileController *ctl;

static char *controller_pidfile = NULL;
Expand Down Expand Up @@ -265,7 +272,20 @@ static void
init_seafile_path ()
{
GError *error = NULL;
char *binary = g_file_read_link (PROC_SELF_PATH, &error);
#if defined(__linux__)
char *binary = g_file_read_link ("/proc/self/exe", &error);
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
/*
* seafile.sh starts the process using abs path
*/
char binary[_POSIX_PATH_MAX];
memset(binary, 0, _POSIX_PATH_MAX);
char * rc = realpath(command_name, binary);
if (!rc) {
seaf_warning ("failed to readpath: %s\n", binary);
return;
}
#endif
char *tmp = NULL;
if (error != NULL) {
seaf_warning ("failed to readlink: %s\n", error->message);
Expand All @@ -279,7 +299,9 @@ init_seafile_path ()

topdir = g_path_get_dirname (installpath);

#if defined(__linux__)
g_free (binary);
#endif
g_free (tmp);
}

Expand Down Expand Up @@ -348,42 +370,6 @@ setup_env ()
setup_python_path();
}

static int
start_seafevents() {
if (!ctl->has_seafevents)
return 0;

static char *seafevents_config_file = NULL;
static char *seafevents_log_file = NULL;

if (seafevents_config_file == NULL)
seafevents_config_file = g_build_filename (topdir,
"conf/seafevents.conf",
NULL);
if (seafevents_log_file == NULL)
seafevents_log_file = g_build_filename (ctl->logdir,
"seafevents.log",
NULL);

char *argv[] = {
(char *)get_python_executable(),
"-m", "seafevents.main",
"--config-file", seafevents_config_file,
"--logfile", seafevents_log_file,
"-P", ctl->pidfile[PID_SEAFEVENTS],
NULL
};

int pid = spawn_process (argv);

if (pid <= 0) {
seaf_warning ("Failed to spawn seafevents.\n");
return -1;
}

return 0;
}

static int
start_seafdav() {
static char *seafdav_log_file = NULL;
Expand Down Expand Up @@ -457,12 +443,41 @@ need_restart (int which)
return FALSE;
} else {
char buf[256];
gboolean with_procfs;
#if defined(__linux__)
with_procfs = g_file_test("/proc/self", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
with_procfs = g_file_test("/proc/curproc", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
#else
with_procfs = FALSE;
#endif
if (with_procfs) {
snprintf (buf, sizeof(buf), "/proc/%d", pid);
if (g_file_test (buf, G_FILE_TEST_IS_DIR)) {
return FALSE;
} else {
seaf_warning ("path /proc/%d doesn't exist, restart progress [%d]\n", pid, which);
return TRUE;
}

} else {
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
#ifdef __OpenBSD__
int min[6] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), 1};
#else
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
#endif
size_t len = sizeof(struct kinfo_proc);
struct kinfo_proc kp;
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0) != -1 &&
len == sizeof(struct kinfo_proc)) {
return FALSE;
} else {
return TRUE;
}
#else
return FALSE;
#endif
}
}
}
Expand All @@ -482,11 +497,6 @@ check_process (void *data)
}
}

if (ctl->has_seafevents && need_restart(PID_SEAFEVENTS)) {
seaf_message ("seafevents need restart...\n");
start_seafevents ();
}

return TRUE;
}

Expand Down Expand Up @@ -582,11 +592,6 @@ on_ccnet_connected ()
if (start_seaf_server () < 0)
controller_exit(1);

if (ctl->has_seafevents && need_restart(PID_SEAFEVENTS)) {
if (start_seafevents() < 0)
controller_exit(1);
}

if (ctl->seafdav_config.enabled) {
if (need_restart(PID_SEAFDAV)) {
if (start_seafdav() < 0)
Expand Down Expand Up @@ -638,8 +643,6 @@ stop_ccnet_server ()
kill_by_force(PID_CCNET);
kill_by_force(PID_SERVER);
kill_by_force(PID_SEAFDAV);
if (ctl->has_seafevents)
kill_by_force(PID_SEAFEVENTS);
}

static void
Expand All @@ -656,7 +659,6 @@ init_pidfile_path (SeafileController *ctl)
ctl->pidfile[PID_CCNET] = g_build_filename (pid_dir, "ccnet.pid", NULL);
ctl->pidfile[PID_SERVER] = g_build_filename (pid_dir, "seaf-server.pid", NULL);
ctl->pidfile[PID_SEAFDAV] = g_build_filename (pid_dir, "seafdav.pid", NULL);
ctl->pidfile[PID_SEAFEVENTS] = g_build_filename (pid_dir, "seafevents.pid", NULL);
}

static int
Expand Down Expand Up @@ -710,18 +712,6 @@ seaf_controller_init (SeafileController *ctl,
return -1;
}

char *seafevents_config_file = g_build_filename (topdir,
"conf/seafevents.conf",
NULL);

if (!g_file_test (seafevents_config_file, G_FILE_TEST_EXISTS)) {
seaf_message ("No seafevents.\n");
ctl->has_seafevents = FALSE;
} else {
ctl->has_seafevents = TRUE;
}
g_free (seafevents_config_file);

init_pidfile_path (ctl);
setup_env ();

Expand Down Expand Up @@ -980,6 +970,9 @@ int main (int argc, char **argv)
exit (1);
}

#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
command_name = argv[0];
#endif
char *config_dir = DEFAULT_CONFIG_DIR;
char *central_config_dir = NULL;
char *seafile_dir = NULL;
Expand Down Expand Up @@ -1016,7 +1009,7 @@ int main (int argc, char **argv)
case 'f':
daemon_mode = 0;
break;
case 'L':
case 'l':
logdir = g_strdup(optarg);
break;
case 'g':
Expand Down
7 changes: 6 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ libseafile_common_la_SOURCES = ${seafile_object_gen} ${utils_srcs}
libseafile_common_la_LDFLAGS = -no-undefined
libseafile_common_la_LIBADD = @GLIB2_LIBS@ @GOBJECT_LIBS@ @SSL_LIBS@ -lcrypto @LIB_GDI32@ \
@LIB_UUID@ @LIB_WS32@ @LIB_PSAPI@ -lsqlite3 \
@LIB_KVM@ \
@LIBEVENT_LIBS@ @SEARPC_LIBS@ @LIB_SHELL32@ \
@ZLIB_LIBS@

Expand All @@ -66,7 +67,7 @@ vala.stamp: ${seafile_object_define}
rm -f ${seafile_object_gen}
@rm -f vala.tmp
@touch vala.tmp
valac -C --pkg posix $^
valac -C --pkg posix ${seafile_object_define}
@mv -f vala.tmp $@

${seafile_object_gen}: vala.stamp
Expand All @@ -81,6 +82,10 @@ clean-local:
install-data-local:
if MACOS
sed -i '' -e "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)
else
if BSD
sed -i '' "s|(DESTDIR)|${PREFIX}|g" $(pcfiles)
else
${SED} -i "s|(DESTDIR)|${DESTDIR}|g" $(pcfiles)
endif
endif
Loading