uhub: 0.4.1 -> 0.5.0 (fixes build)

@ehmry: please have a look so that we can cherry-pick in release-16.09
and move forward on #18209
This commit is contained in:
obadz 2016-09-07 02:27:39 +01:00
parent 1c7270f001
commit 39e197ab1c
3 changed files with 23 additions and 184 deletions

View file

@ -3,13 +3,13 @@
assert tlsSupport -> openssl != null;
let version = "0.4.1"; in
stdenv.mkDerivation {
stdenv.mkDerivation rec {
name = "uhub-${version}";
version = "0.5.0";
src = fetchurl {
url = "http://www.extatic.org/downloads/uhub/uhub-${version}-src.tar.bz2";
sha256 = "1q0n74fb0h5w0k9fhfkznxb4r46qyfb8g2ss3wflivx4l0m1f9x2";
sha256 = "1xcqjz20lxikzn96f4f69mqyl9y985h9g0gyc9f7ckj18q22b5j5";
};
buildInputs = [ cmake sqlite pkgconfig systemd ] ++ stdenv.lib.optional tlsSupport openssl;
@ -19,14 +19,21 @@ stdenv.mkDerivation {
"mod_welcome"
"mod_logging"
"mod_auth_simple"
"mod_auth_sqlite"
"mod_chat_history"
"mod_chat_only"
"mod_topic"
"mod_no_guest_downloads"
];
patches = [ ./plugin-dir.patch ./systemd.patch ];
patches = [
./plugin-dir.patch
# Fixed compilation on systemd > 210
(fetchurl {
url = "https://github.com/janvidar/uhub/commit/70f2a43f676cdda5961950a8d9a21e12d34993f8.diff";
sha256 = "1jp8fvw6f9jh0sdjml9mahkk6p6b96p6rzg2y601mnnbcdj8y8xp";
})
];
cmakeFlags = ''
-DSYSTEMD_SUPPORT=ON
@ -40,4 +47,4 @@ stdenv.mkDerivation {
maintainers = [ maintainers.ehmry ];
platforms = platforms.unix;
};
}
}

View file

@ -1,23 +1,19 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40e996e..d3b7e6d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,10 +185,16 @@ else()
# add_definitions(-DDEBUG)
endif()
@@ -241,8 +241,14 @@
+set( PLUGINS mod_example mod_welcome mod_logging mod_auth_simple mod_auth_sqlite mod_chat_history mod_chat_only mod_topic mod_no_guest_downloads )
+
if (UNIX)
install( TARGETS uhub RUNTIME DESTINATION bin )
- install( TARGETS mod_example mod_welcome mod_logging mod_auth_simple mod_auth_sqlite mod_chat_history mod_chat_only mod_topic mod_no_guest_downloads DESTINATION /usr/lib/uhub/ OPTIONAL )
install( TARGETS uhub uhub-passwd RUNTIME DESTINATION bin )
- install( TARGETS mod_example mod_welcome mod_logging mod_auth_simple mod_auth_sqlite mod_chat_history mod_chat_history_sqlite mod_chat_only mod_topic mod_no_guest_downloads DESTINATION /usr/lib/uhub/ OPTIONAL )
- install( FILES ${CMAKE_SOURCE_DIR}/doc/uhub.conf ${CMAKE_SOURCE_DIR}/doc/plugins.conf ${CMAKE_SOURCE_DIR}/doc/rules.txt ${CMAKE_SOURCE_DIR}/doc/motd.txt DESTINATION /etc/uhub OPTIONAL )
+
+ foreach( PLUGIN ${PLUGINS} )
+ install( TARGETS ${PLUGIN} DESTINATION $ENV{${PLUGIN}} OPTIONAL )
+ endforeach( PLUGIN )
+ set( PLUGINS mod_example mod_welcome mod_logging mod_auth_simple mod_chat_history mod_chat_only mod_topic mod_no_guest_downloads )
+
+ foreach( PLUGIN ${PLUGINS} )
+ install( TARGETS ${PLUGIN} DESTINATION $ENV{${PLUGIN}} OPTIONAL )
+ endforeach( PLUGIN )
+
+ install( FILES ${CMAKE_SOURCE_DIR}/doc/uhub.conf ${CMAKE_SOURCE_DIR}/doc/plugins.conf ${CMAKE_SOURCE_DIR}/doc/rules.txt ${CMAKE_SOURCE_DIR}/doc/motd.txt DESTINATION doc/ OPTIONAL )
endif()
if (SQLITE_SUPPORT)
install( TARGETS uhub-passwd RUNTIME DESTINATION bin )

View file

@ -1,164 +0,0 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40e996e..fc4fb01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@ option(LINK_SUPPORT "Allow hub linking" OFF)
option(SSL_SUPPORT "Enable SSL support" ON)
option(USE_OPENSSL "Use OpenSSL's SSL support" ON )
option(SQLITE_SUPPORT "Enable SQLite support" ON)
+option(SYSTEMD_SUPPORT "Enable systemd notify and journal logging" OFF)
option(ADC_STRESS "Enable the stress tester client" OFF)
find_package(Git)
@@ -34,6 +35,12 @@ if (SSL_SUPPORT)
endif()
endif()
+if (SYSTEMD_SUPPORT)
+ INCLUDE(FindPkgConfig)
+ pkg_search_module(SD_DAEMON REQUIRED libsystemd-daemon)
+ pkg_search_module(SD_JOURNAL REQUIRED libsystemd-journal)
+endif()
+
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
@@ -175,6 +182,18 @@ if(SSL_SUPPORT)
endif()
endif()
+if (SYSTEMD_SUPPORT)
+ target_link_libraries(uhub ${SD_DAEMON_LIBRARIES})
+ target_link_libraries(uhub ${SD_JOURNAL_LIBRARIES})
+ target_link_libraries(test ${SD_DAEMON_LIBRARIES})
+ target_link_libraries(test ${SD_JOURNAL_LIBRARIES})
+ target_link_libraries(uhub-passwd ${SD_JOURNAL_LIBRARIES})
+ target_link_libraries(uhub-admin ${SD_JOURNAL_LIBRARIES})
+ include_directories(${SD_DAEMON_INCLUDE_DIRS})
+ include_directories(${SD_JOURNAL_INCLUDE_DIRS})
+ add_definitions(-DSYSTEMD)
+endif()
+
configure_file ("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_SOURCE_DIR}/version.h")
mark_as_advanced(FORCE CMAKE_BUILD_TYPE)
diff --git a/src/core/main.c b/src/core/main.c
index bb78672..ac2d2a8 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -19,6 +19,10 @@
#include "uhub.h"
+#ifdef SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
static int arg_verbose = 5;
static int arg_fork = 0;
static int arg_check_config = 0;
@@ -145,7 +149,16 @@ int main_loop()
}
#if !defined(WIN32)
setup_signal_handlers(hub);
-#endif
+#ifdef SYSTEMD
+ /* Notify the service manager that this daemon has
+ * been successfully initalized and shall enter the
+ * main loop.
+ */
+ sd_notifyf(0, "READY=1\n"
+ "MAINPID=%lu", (unsigned long) getpid());
+#endif /* SYSTEMD */
+
+#endif /* ! WIN32 */
}
hub_set_variables(hub, &acl);
@@ -216,13 +229,17 @@ void print_usage(char* program)
" -q Quiet mode - no output\n"
" -f Fork to background\n"
" -l <file> Log messages to given file (default: stderr)\n"
- " -L Log messages to syslog\n"
" -c <file> Specify configuration file (default: " SERVER_CONFIG ")\n"
" -C Check configuration and return\n"
" -s Show configuration parameters\n"
" -S Show configuration parameters, but ignore defaults\n"
" -h This message\n"
#ifndef WIN32
+#ifdef SYSTEMD
+ " -L Log messages to journal\n"
+#else
+ " -L Log messages to syslog\n"
+#endif
" -u <user> Run as given user\n"
" -g <group> Run with given group permissions\n"
" -p <file> Store pid in file (process id)\n"
diff --git a/src/util/log.c b/src/util/log.c
index 42badb3..2d97528 100644
--- a/src/util/log.c
+++ b/src/util/log.c
@@ -21,7 +21,15 @@
#include <locale.h>
#ifndef WIN32
+
+#ifdef SYSTEMD
+#define SD_JOURNAL_SUPPRESS_LOCATION
+#include <systemd/sd-journal.h>
+
+#else
#include <syslog.h>
+#endif
+
static int use_syslog = 0;
#endif
@@ -83,7 +91,9 @@ void hub_log_initialize(const char* file, int syslog)
if (syslog)
{
use_syslog = 1;
+ #ifndef SYSTEMD
openlog("uhub", LOG_PID, LOG_USER);
+ #endif
}
#endif
@@ -132,7 +142,9 @@ void hub_log_shutdown()
if (use_syslog)
{
use_syslog = 0;
+ #ifndef SYSTEMD
closelog();
+ #endif
}
#endif
}
@@ -212,7 +224,12 @@ void hub_log(int log_verbosity, const char *format, ...)
case log_fatal: level = LOG_CRIT; break;
case log_error: level = LOG_ERR; break;
case log_warning: level = LOG_WARNING; break;
- case log_user: level = LOG_INFO | LOG_AUTH; break;
+ #ifdef SYSTEMD
+ case log_user: level = LOG_INFO; break;
+
+ #else
+ case log_user: level = LOG_INFO | LOG_AUTH; break;
+ #endif
case log_info: level = LOG_INFO; break;
case log_debug: level = LOG_DEBUG; break;
@@ -224,8 +241,13 @@ void hub_log(int log_verbosity, const char *format, ...)
if (level == 0)
return;
+ #ifdef SYSTEMD
+ sd_journal_print(level, "%s", logmsg);
+
+ #else
level |= (LOG_USER | LOG_DAEMON);
syslog(level, "%s", logmsg);
+ #endif
}
#endif