mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
nss: move definition of NSS_ENTRYPOINT_BEGIN to nss-util.h
Then, also make nss modules parse $SYSTEMD_ASSERT_RETURN_IS_CRITICAL environment variable. This also moves nss-util.c and nss-util.h from src/basic/ to src/shared/, as they are not used by libsystemd.
This commit is contained in:
@@ -43,7 +43,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
|
||||
char *r_name;
|
||||
|
||||
PROTECT_ERRNO;
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
|
||||
NSS_ENTRYPOINT_BEGIN;
|
||||
|
||||
assert(name);
|
||||
assert(pat);
|
||||
@@ -326,7 +326,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
|
||||
int n_addresses = 0;
|
||||
|
||||
PROTECT_ERRNO;
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
|
||||
NSS_ENTRYPOINT_BEGIN;
|
||||
|
||||
assert(name);
|
||||
assert(host);
|
||||
@@ -425,7 +425,7 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
|
||||
unsigned n;
|
||||
|
||||
PROTECT_ERRNO;
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
|
||||
NSS_ENTRYPOINT_BEGIN;
|
||||
|
||||
assert(addr);
|
||||
assert(host);
|
||||
|
||||
@@ -17,15 +17,6 @@
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
static void setup_logging_once(void) {
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
|
||||
}
|
||||
|
||||
#define NSS_ENTRYPOINT_BEGIN \
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); \
|
||||
setup_logging_once()
|
||||
|
||||
NSS_GETHOSTBYNAME_PROTOTYPES(mymachines);
|
||||
NSS_GETPW_PROTOTYPES(mymachines);
|
||||
NSS_GETGR_PROTOTYPES(mymachines);
|
||||
|
||||
@@ -19,24 +19,6 @@
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
|
||||
static sd_json_dispatch_flags_t json_dispatch_flags = SD_JSON_ALLOW_EXTENSIONS;
|
||||
|
||||
static void setup_logging(void) {
|
||||
log_parse_environment_variables();
|
||||
|
||||
if (DEBUG_LOGGING)
|
||||
json_dispatch_flags = SD_JSON_LOG;
|
||||
}
|
||||
|
||||
static void setup_logging_once(void) {
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
assert_se(pthread_once(&once, setup_logging) == 0);
|
||||
}
|
||||
|
||||
#define NSS_ENTRYPOINT_BEGIN \
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); \
|
||||
setup_logging_once()
|
||||
|
||||
NSS_GETHOSTBYNAME_PROTOTYPES(resolve);
|
||||
NSS_GETHOSTBYADDR_PROTOTYPES(resolve);
|
||||
|
||||
@@ -258,7 +240,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
r = sd_json_dispatch(rparams, resolve_hostname_reply_dispatch_table, json_dispatch_flags, &p);
|
||||
r = sd_json_dispatch(rparams, resolve_hostname_reply_dispatch_table, nss_json_dispatch_flags, &p);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (sd_json_variant_is_blank_object(p.addresses))
|
||||
@@ -268,7 +250,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
|
||||
AddressParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -306,7 +288,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
|
||||
AddressParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -422,7 +404,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
r = sd_json_dispatch(rparams, resolve_hostname_reply_dispatch_table, json_dispatch_flags, &p);
|
||||
r = sd_json_dispatch(rparams, resolve_hostname_reply_dispatch_table, nss_json_dispatch_flags, &p);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (sd_json_variant_is_blank_object(p.addresses))
|
||||
@@ -432,7 +414,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
|
||||
AddressParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -478,7 +460,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
|
||||
AddressParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, address_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -640,7 +622,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
|
||||
goto not_found;
|
||||
}
|
||||
|
||||
r = sd_json_dispatch(rparams, resolve_address_reply_dispatch_table, json_dispatch_flags, &p);
|
||||
r = sd_json_dispatch(rparams, resolve_address_reply_dispatch_table, nss_json_dispatch_flags, &p);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (sd_json_variant_is_blank_object(p.names))
|
||||
@@ -651,7 +633,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.names) {
|
||||
_cleanup_(name_parameters_destroy) NameParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, name_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, name_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -692,7 +674,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
|
||||
JSON_VARIANT_ARRAY_FOREACH(entry, p.names) {
|
||||
_cleanup_(name_parameters_destroy) NameParameters q = {};
|
||||
|
||||
r = sd_json_dispatch(entry, name_parameters_dispatch_table, json_dispatch_flags, &q);
|
||||
r = sd_json_dispatch(entry, name_parameters_dispatch_table, nss_json_dispatch_flags, &q);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -122,15 +122,6 @@ static GetentData getsgent_data = {
|
||||
};
|
||||
REENABLE_WARNING;
|
||||
|
||||
static void setup_logging_once(void) {
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
|
||||
}
|
||||
|
||||
#define NSS_ENTRYPOINT_BEGIN \
|
||||
BLOCK_SIGNALS(NSS_SIGNALS_BLOCK); \
|
||||
setup_logging_once()
|
||||
|
||||
NSS_GETPW_PROTOTYPES(systemd);
|
||||
NSS_GETSP_PROTOTYPES(systemd);
|
||||
NSS_GETGR_PROTOTYPES(systemd);
|
||||
|
||||
@@ -137,6 +137,7 @@ shared_sources = files(
|
||||
'notify-recv.c',
|
||||
'nsflags.c',
|
||||
'nsresource.c',
|
||||
'nss-util.c',
|
||||
'numa-util.c',
|
||||
'open-file.c',
|
||||
'openssl-util.c',
|
||||
|
||||
23
src/shared/nss-util.c
Normal file
23
src/shared/nss-util.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "log.h"
|
||||
#include "nss-util.h"
|
||||
|
||||
sd_json_dispatch_flags_t nss_json_dispatch_flags = SD_JSON_ALLOW_EXTENSIONS;
|
||||
|
||||
static void log_setup_nss_internal(void) {
|
||||
log_set_assert_return_is_critical_from_env();
|
||||
log_parse_environment_variables();
|
||||
if (DEBUG_LOGGING)
|
||||
nss_json_dispatch_flags = SD_JSON_LOG;
|
||||
}
|
||||
|
||||
void log_setup_nss(void) {
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
assert_se(pthread_once(&once, log_setup_nss_internal) == 0);
|
||||
}
|
||||
@@ -7,7 +7,27 @@
|
||||
#include <pwd.h>
|
||||
#include <resolv.h>
|
||||
|
||||
#define NSS_SIGNALS_BLOCK SIGALRM,SIGVTALRM,SIGPIPE,SIGCHLD,SIGTSTP,SIGIO,SIGHUP,SIGUSR1,SIGUSR2,SIGPROF,SIGURG,SIGWINCH
|
||||
#include "forward.h"
|
||||
#include "signal-util.h"
|
||||
|
||||
extern sd_json_dispatch_flags_t nss_json_dispatch_flags;
|
||||
|
||||
void log_setup_nss(void);
|
||||
|
||||
#define NSS_ENTRYPOINT_BEGIN \
|
||||
log_setup_nss(); \
|
||||
BLOCK_SIGNALS(SIGALRM, \
|
||||
SIGVTALRM, \
|
||||
SIGPIPE, \
|
||||
SIGCHLD, \
|
||||
SIGTSTP, \
|
||||
SIGIO, \
|
||||
SIGHUP, \
|
||||
SIGUSR1, \
|
||||
SIGUSR2, \
|
||||
SIGPROF, \
|
||||
SIGURG, \
|
||||
SIGWINCH)
|
||||
|
||||
#ifndef DEPRECATED_RES_USE_INET6
|
||||
# define DEPRECATED_RES_USE_INET6 0x00002000
|
||||
Reference in New Issue
Block a user