Skip to content

Commit d80d6e7

Browse files
codypssofar
authored andcommitted
support compilation & use without libsystemd
Allows us to run on travis more easily, but also potentially allows slightly greater portability. Default is to require libsystemd unless the --without-libsystemd flag is passed to configure (ie: default behaivor stays the same without extra flag). Could be relaxed to auto-select in the future if desired.
1 parent 56dffdd commit d80d6e7

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

configure.ac

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,16 @@ AC_CHECK_DECLS([gettid, getrandom], [], [], [[
6262
#include <linux/random.h>
6363
]])
6464

65-
PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd >= 221],
66-
[], [AC_MSG_ERROR([*** libsystemd library not found])])
65+
AC_ARG_WITH(libsystemd,
66+
AS_HELP_STRING([--without-libsystemd], [Disable use of libsystemd for journal output]),
67+
[], [with_libsystemd=yes])
68+
69+
AS_IF([test "x$with_libsystemd" != xno],
70+
[PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd >= 221],
71+
[AC_DEFINE([HAVE_LIBSYSTEMD],[1],[Define if you have libsystemd])],
72+
[AC_MSG_ERROR([*** libsystemd library not found])]
73+
)]
74+
)
6775

6876
CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
6977
-pipe \

src/bootchart.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include <time.h>
4646
#include <unistd.h>
4747

48+
#ifdef HAVE_LIBSYSTEMD
4849
#include <systemd/sd-journal.h>
50+
#endif
4951

5052
#include "alloc-util.h"
5153
#include "bootchart.h"
@@ -258,6 +260,7 @@ static int parse_argv(int argc, char *argv[]) {
258260
}
259261

260262
static int do_journal_append(char *file) {
263+
#ifdef HAVE_LIBSYSTEMD
261264
_cleanup_free_ char *bootchart_message = NULL;
262265
_cleanup_free_ char *bootchart_file = NULL;
263266
_cleanup_free_ char *p = NULL;
@@ -301,6 +304,9 @@ static int do_journal_append(char *file) {
301304
if (r < 0)
302305
log_error_errno(r, "Failed to send bootchart: %m");
303306

307+
#else
308+
(void)file;
309+
#endif
304310
return 0;
305311
}
306312

src/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ int log_syntax_internal(
323323
r = log_struct_internal(
324324
level, error,
325325
file, line, func,
326+
#ifdef HAVE_LIBSYSTEMD
326327
LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
328+
#endif
327329
"CONFIG_FILE=%s", config_file,
328330
"CONFIG_LINE=%u", config_line,
329331
LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),

src/log.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <stdlib.h>
2525
#include <syslog.h>
2626

27-
#include <systemd/sd-id128.h>
28-
2927
#include "alloc-util.h"
3028
#include "attributes.h"
3129

src/sd-messages.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
along with systemd; If not, see <http://www.gnu.org/licenses/>.
2121
***/
2222

23+
#ifdef HAVE_LIBSYSTEMD
2324
#include <systemd/sd-id128.h>
2425

2526
#include "_sd-common.h"
@@ -30,5 +31,6 @@ _SD_BEGIN_DECLARATIONS;
3031
#define SD_MESSAGE_BOOTCHART SD_ID128_MAKE(9f,26,aa,56,2c,f4,40,c2,b1,6c,77,3d,04,79,b5,18)
3132

3233
_SD_END_DECLARATIONS;
34+
#endif
3335

3436
#endif

0 commit comments

Comments
 (0)