Skip to content

Commit

Permalink
Merge pull request #289 from MrAnno/macos-fixes
Browse files Browse the repository at this point in the history
macOS-related fixes and improvements
  • Loading branch information
alltilla authored Sep 18, 2024
2 parents 39f9b3d + b1b49a7 commit 96ade8d
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 59 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jobs:
--disable-smtp
--disable-java
--disable-java-modules
--disable-mqtt
--disable-pacct
"
CMAKE_CONFIGURE_FLAGS="
Expand All @@ -74,7 +73,6 @@ jobs:
-DENABLE_GRPC=OFF
-DENABLE_JAVA=OFF
-DENABLE_JAVA_MODULES=OFF
-DENABLE_MQTT=OFF
-DENABLE_PACCT=OFF
"
PATH="${HOMEBREW_PREFIX}/opt/bison/bin:${HOMEBREW_PREFIX}/opt/libnet/bin:${HOMEBREW_PREFIX}/opt/net-snmp/bin:${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:${PYTHONUSERBASE}/bin:${PATH}"
Expand Down
24 changes: 12 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ project(axosyslog C)

option(ENABLE_CPP "Enable C++" ON)

if (ENABLE_CPP)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED OFF CACHE BOOL "C++ standard is a requirement")
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "C++ compiler specific extensions")
set(SYSLOG_NG_ENABLE_CPP ${ENABLE_CPP})
endif()

if(APPLE)
option(ENABLE_OBJC "Enable OSLog" ENABLE_DARWIN_OSL)
endif()

if(ENABLE_OBJC)
# Turned out that even the latest gcc has no proper support of the required ObjC version
# Once gcc was able to compile our ObjC modules properly this requirement could be removed again
set(CMAKE_OBJC_COMPILER clang)
Expand All @@ -27,14 +39,6 @@ if(APPLE)
set_property(GLOBAL PROPERTY OBJC_STANDARD_REQUIRED ON)
endif()

if (ENABLE_CPP)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED OFF CACHE BOOL "C++ standard is a requirement")
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "C++ compiler specific extensions")
set(SYSLOG_NG_ENABLE_CPP ${ENABLE_CPP})
endif()

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${PROJECT_SOURCE_DIR}/cmake/)
set(CMAKE_POSITION_INDEPENDENT_CODE 1)
set(BISON_FLAGS "-Wno-other -Werror=conflicts-sr -Werror=conflicts-rr -Wcounterexamples")
Expand Down Expand Up @@ -142,10 +146,6 @@ if (HAVE_TCP_KEEPIDLE AND HAVE_TCP_KEEPINTVL AND HAVE_TCP_KEEPCNT)
set(SYSLOG_NG_HAVE_TCP_KEEPALIVE_TIMERS 1)
endif()

if (NOT APPLE)
set(SYSLOG_NG_HAVE_ENVIRON 1)
endif()

option(ENV_LD_LIBRARY_PATH "Set LD_LIBRARY_PATH during runtime to the value given" "")
if (ENV_LD_LIBRARY_PATH)
set(SYSLOG_NG_ENABLE_ENV_WRAPPER 1)
Expand Down
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,6 @@ if test "x$blb_cv_keepcaps" = "xyes"; then
AC_DEFINE(HAVE_PR_SET_KEEPCAPS, 1, [have PR_SET_KEEPCAPS])
fi

if test "$ostype" != "Darwin" ; then
AC_DEFINE(HAVE_ENVIRON, [1], [Specifies whether the environ global variable exists])
fi

AC_CACHE_CHECK(for modern utmp,
blb_cv_c_modern_utmp,
[AC_TRY_COMPILE([
Expand Down
3 changes: 2 additions & 1 deletion contrib/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ brew "ivykis"
brew "json-c"
brew "libtool"
brew "openssl@3"
brew "pcre"
brew "pcre2"
brew "pkg-config"

brew "curl"
Expand All @@ -25,6 +25,7 @@ brew "net-snmp"
brew "python@3", link: true, force: true
brew "rabbitmq-c"
brew "riemann-client"
brew "libpaho-mqtt"

brew "grpc"

Expand Down
1 change: 1 addition & 0 deletions lib/compat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(COMPAT_HEADERS
compat/cpp-end.h
compat/curl.h
compat/json.h
compat/inttypes.h
PARENT_SCOPE)

set(COMPAT_SOURCES
Expand Down
3 changes: 2 additions & 1 deletion lib/compat/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ compatinclude_HEADERS = \
lib/compat/un.h \
lib/compat/cpp-start.h \
lib/compat/cpp-end.h \
lib/compat/curl.h
lib/compat/curl.h \
lib/compat/inttypes.h

compat_sources = \
lib/compat/getutent.c \
Expand Down
34 changes: 34 additions & 0 deletions lib/compat/inttypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2002-2014 Balabit
* Copyright (c) 2024 Sergey Fedorov
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/

#ifndef COMPAT_INTTYPES_H_INCLUDED
#define COMPAT_INTTYPES_H_INCLUDED

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>

#endif
11 changes: 4 additions & 7 deletions lib/gprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static gboolean stderr_present = TRUE;
static int have_capsyslog = FALSE;
static cap_value_t cap_syslog;
#endif
#ifdef SYSLOG_NG_HAVE_ENVIRON
#ifdef __APPLE__
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
#else
extern char **environ;
#endif

Expand Down Expand Up @@ -553,7 +556,6 @@ g_process_set_caps(const gchar *caps)
void
g_process_set_argv_space(gint argc, gchar **argv)
{
#ifdef SYSLOG_NG_HAVE_ENVIRON
gchar *lastargv = NULL;
gchar **envp = environ;
gint i;
Expand Down Expand Up @@ -595,7 +597,6 @@ g_process_set_argv_space(gint argc, gchar **argv)
for (i = 0; envp[i] != NULL; i++)
environ[i] = g_strdup(envp[i]);
environ[i] = NULL;
#endif
}

/**
Expand Down Expand Up @@ -1132,15 +1133,13 @@ g_process_perform_startup(void)
static void
g_process_setproctitle(const gchar *proc_title)
{
#ifdef SYSLOG_NG_HAVE_ENVIRON
size_t len;

g_assert(process_opts.argv_start != NULL);

len = g_strlcpy(process_opts.argv_start, proc_title, process_opts.argv_env_len);
for (; len < process_opts.argv_env_len; ++len)
process_opts.argv_start[len] = SPT_PADCHAR;
#endif
}


Expand Down Expand Up @@ -1526,7 +1525,6 @@ g_process_startup_ok(void)
void
g_process_finish(void)
{
#ifdef SYSLOG_NG_HAVE_ENVIRON
/**
* There is a memory leak for **environ and elements that should be
* freed here theoretically.
Expand All @@ -1548,7 +1546,6 @@ g_process_finish(void)
* As this leak does not cause any real problem like accumulating over
* time, it is safe to leave it as it is.
*/
#endif

g_process_remove_pidfile();
}
Expand Down
62 changes: 32 additions & 30 deletions modules/darwinosl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(APPLE)
if(ENABLE_OBJC AND ENABLE_DARWIN_OSL)
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-arc")

# Take care, this must follow any compiler setting overrides! (e.g. set(CMAKE_OBJC_COMPILER clang) etc.)
Expand All @@ -19,35 +19,37 @@ if(APPLE)
${CMAKE_CURRENT_BINARY_DIR}/darwinosl-grammar.h
)

include(CheckOBJCSourceCompiles)

# TODO: Once gcc was able to compile our ObjC code correctly we should add here a more sopgisticated check
check_objc_source_compiles("
#include <OSLog/OSLog.h>
int main(int, char**)
{ return 0; }
" HAVE_OSLLOG)

module_switch(ENABLE_DARWIN_OSL "Enable Darwin OSLog source" HAVE_OSLLOG)

if(ENABLE_DARWIN_OSL)
generate_y_from_ym(modules/darwinosl/darwinosl-grammar)

bison_target(DarwinOSLGrammar
${CMAKE_CURRENT_BINARY_DIR}/darwinosl-grammar.y
${CMAKE_CURRENT_BINARY_DIR}/darwinosl-grammar.c
COMPILE_FLAGS ${BISON_FLAGS})

add_module(
TARGET darwinosl
GRAMMAR darwinosl-grammar
SOURCES ${DARWINOSL_SOURCES}
)

target_link_libraries(darwinosl PRIVATE
"-framework Foundation"
"-framework OSLog"
)
target_link_options(darwinosl PRIVATE -ObjC)
include(CheckOBJCSourceCompiles)

# TODO: Once gcc was able to compile our ObjC code correctly we should add here a more sopgisticated check
check_objc_source_compiles("
#include <OSLog/OSLog.h>
int main(int, char**)
{ return 0; }
" HAVE_OSLOG)

if(HAVE_OSLOG)
generate_y_from_ym(modules/darwinosl/darwinosl-grammar)

bison_target(DarwinOSLGrammar
${CMAKE_CURRENT_BINARY_DIR}/darwinosl-grammar.y
${CMAKE_CURRENT_BINARY_DIR}/darwinosl-grammar.c
COMPILE_FLAGS ${BISON_FLAGS})

add_module(
TARGET darwinosl
GRAMMAR darwinosl-grammar
SOURCES ${DARWINOSL_SOURCES}
)

target_link_libraries(darwinosl PRIVATE
"-framework Foundation"
"-framework OSLog"
)
target_link_options(darwinosl PRIVATE -ObjC)
else()
message(STATUS "OSLog is not supported on this system")
endif()
endif()
endif()
1 change: 1 addition & 0 deletions modules/geoip2/maxminddb-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "maxminddb-helper.h"
#include "scratch-buffers.h"
#include "compat/inttypes.h"
#include <logmsg/logmsg.h>
#include <messages.h>

Expand Down
1 change: 1 addition & 0 deletions modules/grpc/otel/otel-protobuf-formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "value-pairs/value-pairs.h"
#include "scanner/list-scanner/list-scanner.h"
#include "compat/cpp-end.h"
#include "compat/inttypes.h"

#include <syslog.h>

Expand Down
3 changes: 1 addition & 2 deletions modules/grpc/otel/otel-protobuf-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "str-repr/encode.h"
#include "scratch-buffers.h"
#include "compat/cpp-end.h"

#include <inttypes.h>
#include "compat/inttypes.h"

using namespace syslogng::grpc::otel;
using namespace google::protobuf;
Expand Down
1 change: 1 addition & 0 deletions packaging/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Files: lib/cache.*
lib/compat/socket.h
lib/compat/string.h
lib/compat/strtok_r.c
lib/compat/inttypes.h
lib/control/control-server.*
lib/control/control-server-unix.c
lib/hostname.h
Expand Down

0 comments on commit 96ade8d

Please sign in to comment.