2014-07-22 12:55:23 -05:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2015-09-16 15:49:02 +02:00
|
|
|
* Copyright (C) 2014 - 2015 Red Hat, Inc.
|
2014-07-22 12:55:23 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef NM_SD_ADAPT_H
|
|
|
|
|
#define NM_SD_ADAPT_H
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-07-22 12:55:23 -05:00
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <syslog.h>
|
2015-03-02 20:23:27 +01:00
|
|
|
#include <sys/resource.h>
|
2015-11-13 17:03:51 +01:00
|
|
|
#include <time.h>
|
2015-03-02 15:58:15 +01:00
|
|
|
|
2015-09-16 15:49:02 +02:00
|
|
|
#define noreturn G_GNUC_NORETURN
|
2015-05-15 16:38:10 +02:00
|
|
|
|
2015-11-13 17:03:51 +01:00
|
|
|
#ifndef CLOCK_BOOTTIME
|
|
|
|
|
#define CLOCK_BOOTTIME 7
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-10-11 11:39:50 +02:00
|
|
|
#if defined(HAVE_DECL_EXPLICIT_BZERO) && HAVE_DECL_EXPLICIT_BZERO == 1
|
|
|
|
|
#define HAVE_EXPLICIT_BZERO 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_EXPLICIT_BZERO 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG_HASHMAP 0
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_SYS_AUXV_H
|
|
|
|
|
#define HAVE_SYS_AUXV_H 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static inline NMLogLevel
|
2014-07-22 12:55:23 -05:00
|
|
|
_slog_level_to_nm (int slevel)
|
|
|
|
|
{
|
2017-06-14 12:07:26 +02:00
|
|
|
switch (LOG_PRI (slevel)) {
|
2014-07-22 12:55:23 -05:00
|
|
|
case LOG_DEBUG: return LOGL_DEBUG;
|
|
|
|
|
case LOG_WARNING: return LOGL_WARN;
|
2015-01-10 14:51:41 +01:00
|
|
|
case LOG_CRIT:
|
2014-07-22 12:55:23 -05:00
|
|
|
case LOG_ERR: return LOGL_ERR;
|
|
|
|
|
case LOG_INFO:
|
|
|
|
|
case LOG_NOTICE:
|
|
|
|
|
default: return LOGL_INFO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 12:07:26 +02:00
|
|
|
#define log_get_max_level_realm(realm) (LOG_DEBUG)
|
|
|
|
|
|
|
|
|
|
#define log_internal_realm(level, error, file, line, func, format, ...) \
|
2015-01-10 14:51:41 +01:00
|
|
|
({ \
|
2015-09-23 16:02:35 +02:00
|
|
|
const int _nm_e = (error); \
|
|
|
|
|
const NMLogLevel _nm_l = _slog_level_to_nm ((level)); \
|
|
|
|
|
\
|
2016-03-11 16:11:04 +01:00
|
|
|
if (nm_logging_enabled (_nm_l, LOGD_SYSTEMD)) { \
|
2015-01-10 14:51:41 +01:00
|
|
|
const char *_nm_location = strrchr ((""file), '/'); \
|
2014-11-11 22:26:00 +01:00
|
|
|
\
|
2017-03-01 10:20:01 +00:00
|
|
|
_nm_log_impl (_nm_location ? _nm_location + 1 : (""file), (line), (func), _nm_l, LOGD_DHCP, _nm_e, NULL, NULL, ("%s"format), "libsystemd: ", ## __VA_ARGS__); \
|
2014-11-11 22:26:00 +01:00
|
|
|
} \
|
2015-01-10 14:51:41 +01:00
|
|
|
(_nm_e > 0 ? -_nm_e : _nm_e); \
|
|
|
|
|
})
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
#define log_assert_failed(text, file, line, func) \
|
2014-07-22 12:55:23 -05:00
|
|
|
G_STMT_START { \
|
2015-01-10 14:51:41 +01:00
|
|
|
log_internal (LOG_CRIT, 0, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.", text, file, line, func); \
|
|
|
|
|
g_assert_not_reached (); \
|
2014-07-22 12:55:23 -05:00
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-10-07 10:07:17 +02:00
|
|
|
#define log_assert_failed_unreachable(text, file, line, func) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
log_internal (LOG_CRIT, 0, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.", text, file, line, func); \
|
|
|
|
|
g_assert_not_reached (); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
#define log_assert_failed_return(text, file, line, func) \
|
2015-07-05 12:04:21 +02:00
|
|
|
({ \
|
2015-01-10 14:51:41 +01:00
|
|
|
log_internal (LOG_DEBUG, 0, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Ignoring.", text, file, line, func); \
|
|
|
|
|
g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, text); \
|
2015-07-05 12:04:21 +02:00
|
|
|
(void) 0; \
|
|
|
|
|
})
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2015-09-16 15:49:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* The remainder of the header is only enabled when building the systemd code
|
|
|
|
|
* itself.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#if (NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_SYSTEMD
|
|
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <elf.h>
|
|
|
|
|
#ifdef HAVE_SYS_AUXV_H
|
|
|
|
|
#include <sys/auxv.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/syscall.h>
|
2016-02-29 14:30:15 +01:00
|
|
|
#include <sys/ioctl.h>
|
2015-09-16 15:49:02 +02:00
|
|
|
|
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
|
|
|
|
|
|
/* Missing in Linux 3.2.0, in Ubuntu 12.04 */
|
|
|
|
|
#ifndef BPF_XOR
|
|
|
|
|
#define BPF_XOR 0xa0
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-29 14:30:15 +01:00
|
|
|
#ifndef ETHERTYPE_LLDP
|
|
|
|
|
#define ETHERTYPE_LLDP 0x88cc
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-03-09 12:27:56 +01:00
|
|
|
#ifndef HAVE_SECURE_GETENV
|
|
|
|
|
# ifdef HAVE___SECURE_GETENV
|
|
|
|
|
# define secure_getenv __secure_getenv
|
|
|
|
|
# else
|
|
|
|
|
# error neither secure_getenv nor __secure_getenv is available
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
/*****************************************************************************/
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2016-02-12 17:02:13 +01:00
|
|
|
/* work around missing uchar.h */
|
|
|
|
|
typedef guint16 char16_t;
|
|
|
|
|
typedef guint32 char32_t;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-03-09 12:27:56 +01:00
|
|
|
#define PID_TO_PTR(p) ((void*) ((uintptr_t) p))
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
sd_notify (int unset_environment, const char *state)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 12:55:23 -05:00
|
|
|
/* Can't include both net/if.h and linux/if.h; so have to define this here */
|
2016-08-11 13:05:14 +02:00
|
|
|
#ifndef IF_NAMESIZE
|
|
|
|
|
#define IF_NAMESIZE 16
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-22 12:55:23 -05:00
|
|
|
#ifndef IFNAMSIZ
|
2016-08-11 13:05:14 +02:00
|
|
|
#define IFNAMSIZ IF_NAMESIZE
|
2014-07-22 12:55:23 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MAX_HANDLE_SZ
|
|
|
|
|
#define MAX_HANDLE_SZ 128
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2015-05-19 16:02:28 -05:00
|
|
|
/*
|
|
|
|
|
* Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export
|
|
|
|
|
* CLOCK_BOOTTIME even though the kernel supports it, so provide a
|
|
|
|
|
* local definition
|
|
|
|
|
*/
|
|
|
|
|
#ifndef CLOCK_BOOTTIME
|
|
|
|
|
#define CLOCK_BOOTTIME 7
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-22 12:55:23 -05:00
|
|
|
#include "sd-id128.h"
|
|
|
|
|
#include "sparse-endian.h"
|
|
|
|
|
#include "async.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
static inline pid_t gettid(void) {
|
|
|
|
|
return (pid_t) syscall(SYS_gettid);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 15:49:02 +02:00
|
|
|
#endif /* (NETWORKMANAGER_COMPILATION) == NM_NETWORKMANAGER_COMPILATION_SYSTEMD */
|
|
|
|
|
|
2014-07-22 12:55:23 -05:00
|
|
|
#endif /* NM_SD_ADAPT_H */
|
|
|
|
|
|