1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

Merge pull request #19317 from keszybz/check-return-values-from-log_errno-functions

Check return values from log_errno functions
This commit is contained in:
Luca Boccassi 2021-04-15 20:33:54 +01:00 committed by GitHub
commit 2d8c8549ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 264 additions and 192 deletions

View File

@ -38,7 +38,7 @@ relative_source_path = run_command('realpath',
project_source_root).stdout().strip()
conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path)
conf.set('BUILD_MODE', 'BUILD_MODE_' + get_option('mode').to_upper(),
conf.set10('BUILD_MODE_DEVELOPER', get_option('mode') == 'developer',
description : 'tailor build to development or release builds')
want_ossfuzz = get_option('oss-fuzz')
@ -1117,7 +1117,7 @@ else
libcurl = []
endif
conf.set10('HAVE_LIBCURL', have)
conf.set10('CURL_NO_OLDIES', get_option('mode') == 'developer')
conf.set10('CURL_NO_OLDIES', conf.get('BUILD_MODE_DEVELOPER') == 1)
want_libidn = get_option('libidn')
want_libidn2 = get_option('libidn2')
@ -3318,11 +3318,15 @@ custom_target(
'} >@OUTPUT@'],
build_by_default : true)
# We intentionally do not do inline initializations with definitions for
# a bunch of _cleanup_ variables in tests, to ensure valgrind is triggered.
# This triggers a lot of maybe-uninitialized false positives when the
# combination of -O2 and -flto is used. Suppress them.
no_uninit = '-O2' in get_option('c_args') and '-flto=auto' in get_option('c_args') ? cc.first_supported_argument('-Wno-maybe-uninitialized') : []
test_cflags = ['-DTEST_CODE=1']
# We intentionally do not do inline initializations with definitions for a
# bunch of _cleanup_ variables in tests, to ensure valgrind is triggered if we
# use the variable unexpectedly. This triggers a lot of maybe-uninitialized
# false positives when the combination of -O2 and -flto is used. Suppress them.
if '-O2' in get_option('c_args') and '-flto=auto' in get_option('c_args')
test_cflags += cc.first_supported_argument('-Wno-maybe-uninitialized')
endif
foreach tuple : tests
sources = tuple[0]
link_with = tuple.length() > 1 and tuple[1].length() > 0 ? tuple[1] : [libshared]
@ -3331,7 +3335,7 @@ foreach tuple : tests
condition = tuple.length() > 4 ? tuple[4] : ''
type = tuple.length() > 5 ? tuple[5] : ''
defs = tuple.length() > 6 ? tuple[6] : []
defs += no_uninit
defs += test_cflags
parallel = tuple.length() > 7 ? tuple[7] : true
timeout = 30
@ -3399,7 +3403,7 @@ exe = executable(
'test-libudev-sym',
test_libudev_sym_c,
include_directories : libudev_includes,
c_args : ['-Wno-deprecated-declarations'] + no_uninit,
c_args : ['-Wno-deprecated-declarations'] + test_cflags,
link_with : [libudev],
build_by_default : want_tests != 'false',
install : install_tests,
@ -3412,7 +3416,7 @@ exe = executable(
'test-libudev-static-sym',
test_libudev_sym_c,
include_directories : libudev_includes,
c_args : ['-Wno-deprecated-declarations'] + no_uninit,
c_args : ['-Wno-deprecated-declarations'] + test_cflags,
link_with : [install_libudev_static],
build_by_default : want_tests != 'false' and static_libudev_pic,
install : install_tests and static_libudev_pic,
@ -3453,7 +3457,7 @@ foreach tuple : fuzzers
include_directories : [incs, include_directories('src/fuzz')],
link_with : link_with,
dependencies : dependencies,
c_args : defs,
c_args : defs + test_cflags,
link_args: link_args,
install : false,
build_by_default : fuzz_tests or fuzzer_build)
@ -3640,7 +3644,7 @@ if dbus_docs.length() > 0
'@INPUT@'],
input : dbus_docs)
if conf.get('BUILD_MODE') == 'BUILD_MODE_DEVELOPER'
if conf.get('BUILD_MODE_DEVELOPER') == 1
test('dbus-docs-fresh',
update_dbus_docs_py,
args : ['--build-dir=@0@'.format(project_build_root),

View File

@ -15,7 +15,6 @@
#include "analyze-condition.h"
#include "analyze-security.h"
#include "analyze-verify.h"
#include "build.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
@ -53,6 +52,7 @@
#include "unit-name.h"
#include "util.h"
#include "verbs.h"
#include "version.h"
#define SCALE_X (0.1 / 1000.0) /* pixels per us */
#define SCALE_Y (20.0)

View File

@ -4,8 +4,3 @@
#include "version.h"
extern const char* const systemd_features;
enum {
BUILD_MODE_DEVELOPER,
BUILD_MODE_RELEASE,
};

View File

@ -4,6 +4,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "macro.h"
@ -188,20 +189,39 @@ void log_assert_failed_return(
log_dispatch_internal(level, error, PROJECT_FILE, __LINE__, __func__, NULL, NULL, NULL, NULL, buffer)
/* Logging with level */
#define log_full_errno(level, error, ...) \
#define log_full_errno_zerook(level, error, ...) \
({ \
int _level = (level), _e = (error); \
(log_get_max_level() >= LOG_PRI(_level)) \
_e = (log_get_max_level() >= LOG_PRI(_level)) \
? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \
: -ERRNO_VALUE(_e); \
_e < 0 ? _e : -EIO; \
})
#define log_full(level, ...) (void) log_full_errno((level), 0, __VA_ARGS__)
#if BUILD_MODE_DEVELOPER && !defined(TEST_CODE)
# define ASSERT_NON_ZERO(x) assert((x) != 0)
#else
# define ASSERT_NON_ZERO(x)
#endif
#define log_full_errno(level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_full_errno_zerook(level, _error, __VA_ARGS__); \
})
#define log_full(level, fmt, ...) \
({ \
if (BUILD_MODE_DEVELOPER) \
assert(!strstr(fmt, "%m")); \
(void) log_full_errno_zerook(level, 0, fmt, ##__VA_ARGS__); \
})
int log_emergency_level(void);
/* Normal logging */
#define log_debug(...) log_full_errno(LOG_DEBUG, 0, __VA_ARGS__)
#define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__)
#define log_info(...) log_full(LOG_INFO, __VA_ARGS__)
#define log_notice(...) log_full(LOG_NOTICE, __VA_ARGS__)
#define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)

View File

@ -27,7 +27,7 @@
#ifdef CAP_LAST_CAP
# if CAP_LAST_CAP > SYSTEMD_CAP_LAST_CAP
# if BUILD_MODE == BUILD_MODE_DEVELOPER && defined(TEST_CAPABILITY_C)
# if BUILD_MODE_DEVELOPER && defined(TEST_CAPABILITY_C)
# warning "The capability list here is outdated"
# endif
# else

View File

@ -216,7 +216,7 @@ int bpf_devices_apply_policy(
_cleanup_free_ char *controller_path = NULL;
int r;
/* This will assign *keep_program if everything goes well. */
/* This will assign *prog_installed if everything goes well. */
if (!prog)
goto finish;

View File

@ -273,7 +273,8 @@ int mac_selinux_generic_access_check(
sd_bus_error_set(error, SD_BUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
}
log_debug_errno(r, "SELinux access check scon=%s tcon=%s tclass=%s perm=%s state=%s path=%s cmdline=%s: %m",
log_full_errno_zerook(LOG_DEBUG, r,
"SELinux access check scon=%s tcon=%s tclass=%s perm=%s state=%s path=%s cmdline=%s: %m",
scon, fcon, tclass, permission, enforce ? "enforcing" : "permissive", path, cl);
return enforce ? r : 0;
}

View File

@ -3,11 +3,11 @@
#include <fcntl.h>
#include "alloc-util.h"
#include "build.h"
#include "curl-util.h"
#include "fd-util.h"
#include "locale-util.h"
#include "string-util.h"
#include "version.h"
static void curl_glue_check_finished(CurlGlue *g) {
CURLMsg *msg;

View File

@ -9,7 +9,6 @@
#include "sd-daemon.h"
#include "alloc-util.h"
#include "build.h"
#include "conf-parser.h"
#include "daemon-util.h"
#include "def.h"
@ -34,6 +33,7 @@
#include "strv.h"
#include "tmpfile-util.h"
#include "util.h"
#include "version.h"
#define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
#define CERT_FILE CERTIFICATE_ROOT "/certs/journal-upload.pem"

View File

@ -376,8 +376,8 @@ int server_open_dev_kmsg(Server *s) {
s->dev_kmsg_fd = open("/dev/kmsg", mode);
if (s->dev_kmsg_fd < 0) {
log_full(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
"Failed to open /dev/kmsg, ignoring: %m");
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
errno, "Failed to open /dev/kmsg, ignoring: %m");
return 0;
}

View File

@ -67,14 +67,12 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, ui
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
#define log_dhcp_client_errno(client, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"DHCPv4 client: ", \
sd_dhcp_client_get_ifname(client), \
LOG_DEBUG, _e, "DHCPv4 client: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_dhcp_client(client, fmt, ...) \
log_dhcp_client_errno(client, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"DHCPv4 client: ", \
sd_dhcp_client_get_ifname(client), \
0, fmt, ##__VA_ARGS__)

View File

@ -99,14 +99,12 @@ void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);
#define log_dhcp_server_errno(server, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"DHCPv4 server: ", \
sd_dhcp_server_get_ifname(server), \
LOG_DEBUG, _e, "DHCPv4 server: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_dhcp_server(server, fmt, ...) \
log_dhcp_server_errno(server, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"DHCPv4 server: ", \
sd_dhcp_server_get_ifname(server), \
0, fmt, ##__VA_ARGS__)

View File

@ -120,14 +120,12 @@ const char *dhcp6_message_status_to_string(int s) _const_;
int dhcp6_message_status_from_string(const char *s) _pure_;
#define log_dhcp6_client_errno(client, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"DHCPv6 client: ", \
sd_dhcp6_client_get_ifname(client), \
LOG_DEBUG, _e, "DHCPv6 client: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_dhcp6_client(client, fmt, ...) \
log_dhcp6_client_errno(client, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"DHCPv6 client: ", \
sd_dhcp6_client_get_ifname(client), \
0, fmt, ##__VA_ARGS__)

View File

@ -37,14 +37,12 @@ const char* lldp_event_to_string(sd_lldp_event_t e) _const_;
sd_lldp_event_t lldp_event_from_string(const char *s) _pure_;
#define log_lldp_errno(lldp, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"LLDP: ", \
sd_lldp_get_ifname(lldp), \
LOG_DEBUG, _e, "LLDP: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_lldp(lldp, fmt, ...) \
log_lldp_errno(lldp, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"LLDP: ", \
sd_lldp_get_ifname(lldp), \
0, fmt, ##__VA_ARGS__)

View File

@ -42,14 +42,12 @@ const char* ndisc_event_to_string(sd_ndisc_event_t e) _const_;
sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_;
#define log_ndisc_errno(ndisc, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"NDISC: ", \
sd_ndisc_get_ifname(ndisc), \
LOG_DEBUG, _e, "NDISC: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_ndisc(ndisc, fmt, ...) \
log_ndisc_errno(ndisc, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"NDISC: ", \
sd_ndisc_get_ifname(ndisc), \
0, fmt, ##__VA_ARGS__)

View File

@ -126,14 +126,12 @@ struct sd_radv_route_prefix {
};
#define log_radv_errno(radv, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"RADV: ", \
sd_radv_get_ifname(radv), \
LOG_DEBUG, _e, "RADV: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_radv(radv, fmt, ...) \
log_radv_errno(radv, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"RADV: ", \
sd_radv_get_ifname(radv), \
0, fmt, ##__VA_ARGS__)

View File

@ -76,17 +76,15 @@ struct sd_ipv4acd {
};
#define log_ipv4acd_errno(acd, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"IPv4ACD: ", \
sd_ipv4acd_get_ifname(acd), \
LOG_DEBUG, _e, "IPv4ACD: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_ipv4acd(acd, fmt, ...) \
log_ipv4acd_errno(acd, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"IPv4ACD: ", \
sd_ipv4acd_get_ifname(acd), \
0, fmt, ##__VA_ARGS__)
static const char * const ipv4acd_state_table[_IPV4ACD_STATE_MAX] = {
[IPV4ACD_STATE_INIT] = "init",

View File

@ -50,17 +50,15 @@ struct sd_ipv4ll {
};
#define log_ipv4ll_errno(ll, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno( \
log_interface_prefix_full_errno( \
"IPv4LL: ", \
sd_ipv4ll_get_ifname(ll), \
LOG_DEBUG, _e, "IPv4LL: " fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
error, fmt, ##__VA_ARGS__)
#define log_ipv4ll(ll, fmt, ...) \
log_ipv4ll_errno(ll, 0, fmt, ##__VA_ARGS__)
log_interface_prefix_full_errno_zerook( \
"IPv4LL: ", \
sd_ipv4ll_get_ifname(ll), \
0, fmt, ##__VA_ARGS__)
static void ipv4ll_on_acd(sd_ipv4acd *ll, int event, void *userdata);

View File

@ -45,22 +45,29 @@
device; \
device = sd_device_enumerator_get_subsystem_next(enumerator))
#define log_device_full_errno(device, level, error, ...) \
#define log_device_full_errno_zerook(device, level, error, ...) \
({ \
const char *_sysname = NULL; \
sd_device *_d = (device); \
int _level = (level), _error = (error); \
int _level = (level), _e = (error); \
\
if (_d && _unlikely_(log_get_max_level() >= LOG_PRI(_level))) \
(void) sd_device_get_sysname(_d, &_sysname); \
log_object_internal(_level, _error, PROJECT_FILE, __LINE__, __func__, \
log_object_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, \
_sysname ? "DEVICE=" : NULL, _sysname, \
NULL, NULL, __VA_ARGS__); \
})
#define log_device_full(device, level, ...) (void) log_device_full_errno(device, level, 0, __VA_ARGS__)
#define log_device_full_errno(device, level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_device_full_errno_zerook(device, level, _error, __VA_ARGS__); \
})
#define log_device_debug(device, ...) log_device_full_errno(device, LOG_DEBUG, 0, __VA_ARGS__)
#define log_device_full(device, level, ...) (void) log_device_full_errno_zerook(device, level, 0, __VA_ARGS__)
#define log_device_debug(device, ...) log_device_full(device, LOG_DEBUG, __VA_ARGS__)
#define log_device_info(device, ...) log_device_full(device, LOG_INFO, __VA_ARGS__)
#define log_device_notice(device, ...) log_device_full(device, LOG_NOTICE, __VA_ARGS__)
#define log_device_warning(device, ...) log_device_full(device, LOG_WARNING, __VA_ARGS__)

View File

@ -178,13 +178,12 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
/* all 'devices' require an 'uevent' file */
path = strjoina(syspath, "/uevent");
r = access(path, F_OK);
if (r < 0) {
if (access(path, F_OK) < 0) {
if (errno == ENOENT)
/* this is not a valid device */
return -ENODEV;
return log_debug_errno(errno, "sd-device: %s does not have an uevent file: %m", syspath);
return log_debug_errno(errno, "sd-device: cannot access uevent file for %s: %m", syspath);
}
} else {
/* everything else just needs to be a directory */

View File

@ -6,7 +6,6 @@
#include <unistd.h>
#include "alloc-util.h"
#include "build.h"
#include "fd-util.h"
#include "libudev-list-internal.h"
#include "libudev-util.h"
@ -15,6 +14,7 @@
#include "stdio-util.h"
#include "string-util.h"
#include "tests.h"
#include "version.h"
static bool arg_monitor = false;

View File

@ -268,7 +268,7 @@ static int manager_enumerate_seats(Manager *m) {
s = hashmap_get(m->seats, de->d_name);
if (!s) {
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
log_warning("Failed to remove /run/systemd/seats/%s: %m",
log_warning_errno(errno, "Failed to remove /run/systemd/seats/%s: %m",
de->d_name);
continue;
}

View File

@ -208,8 +208,10 @@ int link_set_bridge_mdb(Link *link) {
if (hashmap_isempty(link->network->mdb_entries_by_section))
goto finish;
if (!link_has_carrier(link))
return log_link_debug(link, "Link does not have carrier yet, setting MDB entries later.");
if (!link_has_carrier(link)) {
log_link_debug(link, "Link does not have carrier yet, setting MDB entries later.");
return 0;
}
if (link->network->bridge) {
Link *master;
@ -218,8 +220,10 @@ int link_set_bridge_mdb(Link *link) {
if (r < 0)
return log_link_error_errno(link, r, "Failed to get Link object for Bridge=%s", link->network->bridge->ifname);
if (!link_has_carrier(master))
return log_link_debug(link, "Bridge interface %s does not have carrier yet, setting MDB entries later.", link->network->bridge->ifname);
if (!link_has_carrier(master)) {
log_link_debug(link, "Bridge interface %s does not have carrier yet, setting MDB entries later.", link->network->bridge->ifname);
return 0;
}
} else if (!streq_ptr(link->kind, "bridge")) {
log_link_warning(link, "Link is neither a bridge master nor a bridge port, ignoring [BridgeMDB] sections.");

View File

@ -711,8 +711,10 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: could not get nexthop family, ignoring: %m");
return 0;
} else if (!IN_SET(tmp->family, AF_INET, AF_INET6))
return log_link_debug(link, "rtnl: received nexthop message with invalid family %d, ignoring.", tmp->family);
} else if (!IN_SET(tmp->family, AF_INET, AF_INET6)) {
log_link_debug(link, "rtnl: received nexthop message with invalid family %d, ignoring.", tmp->family);
return 0;
}
r = sd_rtnl_message_nexthop_get_protocol(message, &tmp->protocol);
if (r < 0) {

View File

@ -3830,7 +3830,7 @@ static int parse_efi_variable_factory_reset(void) {
arg_factory_reset = r;
if (r)
log_notice("Honouring factory reset requested via EFI variable FactoryReset: %m");
log_notice("Factory reset requested via EFI variable FactoryReset.");
return 0;
}

View File

@ -262,7 +262,7 @@ static int run(int argc, char *argv[]) {
if (k < 0)
log_debug_errno(errno, "Failed to read random data with getrandom(), falling back to /dev/urandom: %m");
else if ((size_t) k < buf_size)
log_debug("Short read from getrandom(), falling back to /dev/urandom: %m");
log_debug("Short read from getrandom(), falling back to /dev/urandom.");
else
getrandom_worked = true;

View File

@ -306,7 +306,8 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_ar
if (q < 0 && r == 0)
r = q;
log_debug_errno(q, "Got result %s/%m for job %s", d->result, d->name);
log_full_errno_zerook(LOG_DEBUG, q,
"Got result %s/%m for job %s", d->result, d->name);
}
d->name = mfree(d->name);

View File

@ -3,13 +3,38 @@
#include "log.h"
#define log_interface_full_errno(ifname, level, error, ...) \
#define log_interface_full_errno_zerook(ifname, level, error, ...) \
({ \
const char *_ifname = (ifname); \
_ifname ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, "INTERFACE=", _ifname, NULL, NULL, ##__VA_ARGS__) : \
log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
})
#define log_interface_full_errno(ifname, level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_interface_full_errno_zerook(ifname, level, _error, __VA_ARGS__); \
})
#define log_interface_prefix_full_errno_zerook(prefix, ifname_expr, error, fmt, ...) \
({ \
int _e = (error); \
if (DEBUG_LOGGING) \
log_interface_full_errno_zerook( \
ifname_expr, \
LOG_DEBUG, _e, prefix fmt, \
##__VA_ARGS__); \
-ERRNO_VALUE(_e); \
})
#define log_interface_prefix_full_errno(prefix, ifname_expr, error, fmt, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_interface_prefix_full_errno_zerook(prefix, ifname_expr, _error, fmt, ##__VA_ARGS__); \
})
/*
* The following macros append INTERFACE= to the message.
* The macros require a struct named 'Link' which contains 'char *ifname':
@ -21,15 +46,22 @@
* See, network/networkd-link.h for example.
*/
#define log_link_full_errno(link, level, error, ...) \
#define log_link_full_errno_zerook(link, level, error, ...) \
({ \
const Link *_l = (link); \
log_interface_full_errno(_l ? _l->ifname : NULL, level, error, ##__VA_ARGS__); \
log_interface_full_errno_zerook(_l ? _l->ifname : NULL, level, error, __VA_ARGS__); \
})
#define log_link_full(link, level, ...) (void) log_link_full_errno(link, level, 0, __VA_ARGS__)
#define log_link_full_errno(link, level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_link_full_errno_zerook(link, level, _error, __VA_ARGS__); \
})
#define log_link_debug(link, ...) log_link_full_errno(link, LOG_DEBUG, 0, __VA_ARGS__)
#define log_link_full(link, level, ...) (void) log_link_full_errno_zerook(link, level, 0, __VA_ARGS__)
#define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, __VA_ARGS__)
#define log_link_info(link, ...) log_link_full(link, LOG_INFO, __VA_ARGS__)
#define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, __VA_ARGS__)
#define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, __VA_ARGS__)

View File

@ -20,11 +20,10 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose)
return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
"Failed to look up module alias '%s': %m", module);
if (!modlist) {
log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
if (!modlist)
return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG,
SYNTHETIC_ERRNO(ENOENT),
"Failed to find module '%s'", module);
return -ENOENT;
}
kmod_list_foreach(itr, modlist) {
_cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;

View File

@ -163,10 +163,10 @@ static int lock_all_homes(void) {
if (!bus_error_is_unknown_service(&error))
return log_error_errno(r, "Failed to lock home directories: %s", bus_error_message(&error, r));
return log_debug("systemd-homed is not running, locking of home directories skipped.");
}
return log_debug("Successfully requested locking of all home directories.");
log_debug("systemd-homed is not running, locking of home directories skipped.");
} else
log_debug("Successfully requested locking of all home directories.");
return 0;
}
static int execute(char **modes, char **states, const char *action) {

View File

@ -10,7 +10,6 @@
#include "sd-daemon.h"
#include "alloc-util.h"
#include "build.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "errno-util.h"
@ -18,6 +17,7 @@
#include "log.h"
#include "main-func.h"
#include "util.h"
#include "version.h"
#define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket"

View File

@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
r = cg_all_unified();
if (r <= 0)
return log_tests_skipped_errno(r, "Unified hierarchy is required, skipping.");
return log_tests_skipped("Unified hierarchy is required, skipping.");
r = enter_cgroup_subroot(NULL);
if (r == -ENOMEDIUM)

View File

@ -3,13 +3,13 @@
#include <unistd.h>
#include "alloc-util.h"
#include "build.h"
#include "cgroup-setup.h"
#include "errno-util.h"
#include "log.h"
#include "proc-cmdline.h"
#include "string-util.h"
#include "tests.h"
#include "version.h"
static void test_is_wanted_print(bool header) {
_cleanup_free_ char *cmdline = NULL;

View File

@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "build.h"
#include "cgroup-util.h"
#include "dirent-util.h"
#include "errno-util.h"
@ -17,6 +16,7 @@
#include "tests.h"
#include "user-util.h"
#include "util.h"
#include "version.h"
static void check_p_d_u(const char *path, int code, const char *result) {
_cleanup_free_ char *unit = NULL;

View File

@ -11,7 +11,6 @@
#include <sys/signalfd.h>
#include <unistd.h>
#include "build.h"
#include "device-private.h"
#include "fs-util.h"
#include "log.h"
@ -24,6 +23,7 @@
#include "string-util.h"
#include "tests.h"
#include "udev-event.h"
#include "version.h"
static int fake_filesystems(void) {
static const struct fakefs {

View File

@ -302,10 +302,23 @@ static int cd_capability_compat(Context *c) {
}
static int cd_media_compat(Context *c) {
int r;
assert(c);
if (ioctl(c->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK)
return log_debug_errno(errno, "CDROM_DRIVE_STATUS != CDS_DISC_OK");
r = ioctl(c->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
if (r < 0)
return log_debug_errno(errno, "ioctl(CDROM_DRIVE_STATUS) failed: m");
if (r != CDS_DISC_OK) {
log_debug("ioctl(CDROM_DRIVE_STATUS) → %d (%s), ignoring",
r,
r == CDS_NO_INFO ? "no info" :
r == CDS_NO_DISC ? "no disc" :
r == CDS_TRAY_OPEN ? "tray open" :
r == CDS_DRIVE_NOT_READY ? "drive not ready" :
"unkown status");
return -ENOMEDIUM;
}
c->has_media = true;
return 0;
@ -730,25 +743,23 @@ static int cd_media_toc(Context *c) {
}
static int open_drive(Context *c) {
_cleanup_close_ int fd = -1;
int fd;
assert(c);
assert(c->fd < 0);
for (int cnt = 0; cnt < 20; cnt++) {
if (cnt != 0)
(void) usleep(100 * USEC_PER_MSEC + random_u64() % (100 * USEC_PER_MSEC));
for (int cnt = 0;; cnt++) {
fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
if (fd >= 0 || errno != EBUSY)
if (fd >= 0)
break;
if (++cnt >= 20 || errno != EBUSY)
return log_debug_errno(errno, "Unable to open '%s': %m", arg_node);
(void) usleep(100 * USEC_PER_MSEC + random_u64() % (100 * USEC_PER_MSEC));
}
if (fd < 0)
return log_debug_errno(errno, "Unable to open '%s'", arg_node);
log_debug("probing: '%s'", arg_node);
c->fd = TAKE_FD(fd);
c->fd = fd;
return 0;
}
@ -939,7 +950,7 @@ static int parse_argv(int argc, char *argv[]) {
arg_node = argv[optind];
if (!arg_node)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No device is specified.");
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No device specified.");
return 1;
}

View File

@ -45,12 +45,12 @@
#include <getopt.h>
#include "alloc-util.h"
#include "build.h"
#include "fileio.h"
#include "main-func.h"
#include "string-util.h"
#include "udev-util.h"
#include "unaligned.h"
#include "version.h"
#define SUPPORTED_SMBIOS_VER 0x030300

View File

@ -364,9 +364,11 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
return r;
switch (addr_type) {
case NET_ADDR_SET:
return log_device_debug(device, "MAC on the device already set by userspace");
log_device_debug(device, "MAC on the device already set by userspace");
return 0;
case NET_ADDR_STOLEN:
return log_device_debug(device, "MAC on the device already set based on another device");
log_device_debug(device, "MAC on the device already set based on another device");
return 0;
case NET_ADDR_RANDOM:
case NET_ADDR_PERM:
break;
@ -375,9 +377,11 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
return 0;
}
if (want_random == (addr_type == NET_ADDR_RANDOM))
return log_device_debug(device, "MAC on the device already matches policy *%s*",
if (want_random == (addr_type == NET_ADDR_RANDOM)) {
log_device_debug(device, "MAC on the device already matches policy *%s*",
mac_address_policy_to_string(policy));
return 0;
}
if (want_random) {
log_device_debug(device, "Using random bytes to generate MAC");

View File

@ -17,7 +17,6 @@
#include <unistd.h>
#include "alloc-util.h"
#include "build.h"
#include "device-nodes.h"
#include "extract-word.h"
#include "fd-util.h"
@ -27,6 +26,7 @@
#include "strv.h"
#include "strxcpyx.h"
#include "udev-util.h"
#include "version.h"
static const struct option options[] = {
{ "device", required_argument, NULL, 'd' },

View File

@ -184,21 +184,30 @@ struct UdevRules {
/*** Logging helpers ***/
#define log_rule_full_errno(device, rules, level, error, fmt, ...) \
#define log_rule_full_errno_zerook(device, rules, level, error, fmt, ...) \
({ \
UdevRules *_r = (rules); \
UdevRuleFile *_f = _r ? _r->current_file : NULL; \
UdevRuleLine *_l = _f ? _f->current_line : NULL; \
const char *_n = _f ? _f->filename : NULL; \
\
log_device_full_errno(device, level, error, "%s:%u " fmt, \
log_device_full_errno_zerook( \
device, level, error, "%s:%u " fmt, \
strna(_n), _l ? _l->line_number : 0, \
##__VA_ARGS__); \
})
#define log_rule_full(device, rules, level, ...) (void) log_rule_full_errno(device, rules, level, 0, __VA_ARGS__)
#define log_rule_full_errno(device, rules, level, error, fmt, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_rule_full_errno_zerook( \
device, rules, level, _error, fmt, ##__VA_ARGS__); \
})
#define log_rule_debug(device, rules, ...) log_rule_full_errno(device, rules, LOG_DEBUG, 0, __VA_ARGS__)
#define log_rule_full(device, rules, level, ...) (void) log_rule_full_errno_zerook(device, rules, level, 0, __VA_ARGS__)
#define log_rule_debug(device, rules, ...) log_rule_full(device, rules, LOG_DEBUG, __VA_ARGS__)
#define log_rule_info(device, rules, ...) log_rule_full(device, rules, LOG_INFO, __VA_ARGS__)
#define log_rule_notice(device, rules, ...) log_rule_full(device, rules, LOG_NOTICE, __VA_ARGS__)
#define log_rule_warning(device, rules, ...) log_rule_full(device, rules, LOG_WARNING, __VA_ARGS__)
@ -210,10 +219,11 @@ struct UdevRules {
#define log_rule_warning_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_WARNING, error, __VA_ARGS__)
#define log_rule_error_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_ERR, error, __VA_ARGS__)
#define log_token_full_errno_zerook(rules, level, error, ...) log_rule_full_errno_zerook(NULL, rules, level, error, __VA_ARGS__)
#define log_token_full_errno(rules, level, error, ...) log_rule_full_errno(NULL, rules, level, error, __VA_ARGS__)
#define log_token_full(rules, level, ...) (void) log_token_full_errno(rules, level, 0, __VA_ARGS__)
#define log_token_full(rules, level, ...) (void) log_token_full_errno_zerook(rules, level, 0, __VA_ARGS__)
#define log_token_debug(rules, ...) log_token_full_errno(rules, LOG_DEBUG, 0, __VA_ARGS__)
#define log_token_debug(rules, ...) log_token_full(rules, LOG_DEBUG, __VA_ARGS__)
#define log_token_info(rules, ...) log_token_full(rules, LOG_INFO, __VA_ARGS__)
#define log_token_notice(rules, ...) log_token_full(rules, LOG_NOTICE, __VA_ARGS__)
#define log_token_warning(rules, ...) log_token_full(rules, LOG_WARNING, __VA_ARGS__)

View File

@ -3,7 +3,6 @@
#include <stdio.h>
#include "build.h"
#include "macro.h"
int info_main(int argc, char *argv[], void *userdata);

View File

@ -28,7 +28,6 @@
#include "sd-event.h"
#include "alloc-util.h"
#include "build.h"
#include "cgroup-util.h"
#include "cpu-set-util.h"
#include "dev-setup.h"
@ -65,6 +64,7 @@
#include "udev-util.h"
#include "udev-watch.h"
#include "user-util.h"
#include "version.h"
#define WORKER_NUM_MAX 2048U