Merge pull request #23645 from DaanDeMeyer/journalctl-static-destructor
journalctl: Use STATIC_DESTRUCTOR_REGISTER()
This commit is contained in:
+17
-21
@@ -58,13 +58,14 @@
|
||||
#include "parse-argument.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "pcre2-dlopen.h"
|
||||
#include "pcre2-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "qrcode-util.h"
|
||||
#include "random-util.h"
|
||||
#include "rlimit-util.h"
|
||||
#include "set.h"
|
||||
#include "sigbus.h"
|
||||
#include "static-destruct.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-table.h"
|
||||
#include "strv.h"
|
||||
@@ -138,6 +139,19 @@ static pcre2_code *arg_compiled_pattern = NULL;
|
||||
static int arg_case_sensitive = -1; /* -1 means be smart */
|
||||
#endif
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_file, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_facilities, set_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_verify_key, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_syslog_identifier, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_system_units, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_user_units, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_output_fields, strv_freep);
|
||||
#if HAVE_PCRE2
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_compiled_pattern, sym_pcre2_code_freep);
|
||||
#endif
|
||||
|
||||
static enum {
|
||||
ACTION_SHOW,
|
||||
ACTION_NEW_ID128,
|
||||
@@ -167,9 +181,6 @@ typedef struct BootId {
|
||||
} BootId;
|
||||
|
||||
#if HAVE_PCRE2
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_match_data*, sym_pcre2_match_data_free, NULL);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_code*, sym_pcre2_code_free, NULL);
|
||||
|
||||
static int pattern_compile(const char *pattern, unsigned flags, pcre2_code **out) {
|
||||
int errorcode, r;
|
||||
PCRE2_SIZE erroroffset;
|
||||
@@ -2817,28 +2828,13 @@ int main(int argc, char *argv[]) {
|
||||
finish:
|
||||
pager_close();
|
||||
|
||||
strv_free(arg_file);
|
||||
|
||||
set_free(arg_facilities);
|
||||
strv_free(arg_syslog_identifier);
|
||||
strv_free(arg_system_units);
|
||||
strv_free(arg_user_units);
|
||||
strv_free(arg_output_fields);
|
||||
|
||||
free(arg_root);
|
||||
free(arg_verify_key);
|
||||
|
||||
#if HAVE_PCRE2
|
||||
if (arg_compiled_pattern) {
|
||||
sym_pcre2_code_free(arg_compiled_pattern);
|
||||
|
||||
if (arg_compiled_pattern && r == 0 && n_shown == 0)
|
||||
/* --grep was used, no error was thrown, but the pattern didn't
|
||||
* match anything. Let's mimic grep's behavior here and return
|
||||
* a non-zero exit code, so journalctl --grep can be used
|
||||
* in scripts and such */
|
||||
if (r == 0 && n_shown == 0)
|
||||
r = -ENOENT;
|
||||
}
|
||||
r = -ENOENT;
|
||||
#endif
|
||||
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
@@ -247,8 +247,8 @@ shared_sources = files(
|
||||
'parse-argument.h',
|
||||
'parse-helpers.c',
|
||||
'parse-helpers.h',
|
||||
'pcre2-dlopen.c',
|
||||
'pcre2-dlopen.h',
|
||||
'pcre2-util.c',
|
||||
'pcre2-util.h',
|
||||
'pe-header.h',
|
||||
'pkcs11-util.c',
|
||||
'pkcs11-util.h',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "dlfcn-util.h"
|
||||
#include "log.h"
|
||||
#include "pcre2-dlopen.h"
|
||||
#include "pcre2-util.h"
|
||||
|
||||
#if HAVE_PCRE2
|
||||
static void *pcre2_dl = NULL;
|
||||
@@ -1,6 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
#if HAVE_PCRE2
|
||||
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
@@ -13,6 +15,9 @@ extern pcre2_code* (*sym_pcre2_compile)(PCRE2_SPTR, PCRE2_SIZE, uint32_t, int *,
|
||||
extern int (*sym_pcre2_get_error_message)(int, PCRE2_UCHAR *, PCRE2_SIZE);
|
||||
extern int (*sym_pcre2_match)(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, uint32_t, pcre2_match_data *, pcre2_match_context *);
|
||||
extern PCRE2_SIZE* (*sym_pcre2_get_ovector_pointer)(pcre2_match_data *);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_match_data*, sym_pcre2_match_data_free, NULL);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pcre2_code*, sym_pcre2_code_free, NULL);
|
||||
#endif
|
||||
|
||||
int dlopen_pcre2(void);
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "libfido2-util.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
#include "pcre2-dlopen.h"
|
||||
#include "pcre2-util.h"
|
||||
#include "pwquality-util.h"
|
||||
#include "qrcode-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
Reference in New Issue
Block a user