5656#include "pager.h"
5757#include "parse-util.h"
5858#include "path-util.h"
59+ #include "pcre2-dlopen.h"
5960#include "pretty-print.h"
6061#include "rlimit-util.h"
6162#include "set.h"
@@ -160,20 +161,20 @@ typedef struct BootId {
160161} BootId ;
161162
162163#if HAVE_PCRE2
163- DEFINE_TRIVIAL_CLEANUP_FUNC (pcre2_match_data * , pcre2_match_data_free );
164- DEFINE_TRIVIAL_CLEANUP_FUNC (pcre2_code * , pcre2_code_free );
164+ DEFINE_TRIVIAL_CLEANUP_FUNC (pcre2_match_data * , sym_pcre2_match_data_free );
165+ DEFINE_TRIVIAL_CLEANUP_FUNC (pcre2_code * , sym_pcre2_code_free );
165166
166167static int pattern_compile (const char * pattern , unsigned flags , pcre2_code * * out ) {
167168 int errorcode , r ;
168169 PCRE2_SIZE erroroffset ;
169170 pcre2_code * p ;
170171
171- p = pcre2_compile ((PCRE2_SPTR8 ) pattern ,
172- PCRE2_ZERO_TERMINATED , flags , & errorcode , & erroroffset , NULL );
172+ p = sym_pcre2_compile ((PCRE2_SPTR8 ) pattern ,
173+ PCRE2_ZERO_TERMINATED , flags , & errorcode , & erroroffset , NULL );
173174 if (!p ) {
174175 unsigned char buf [LINE_MAX ];
175176
176- r = pcre2_get_error_message (errorcode , buf , sizeof buf );
177+ r = sym_pcre2_get_error_message (errorcode , buf , sizeof buf );
177178
178179 return log_error_errno (SYNTHETIC_ERRNO (EINVAL ),
179180 "Bad pattern \"%s\": %s" , pattern ,
@@ -183,7 +184,6 @@ static int pattern_compile(const char *pattern, unsigned flags, pcre2_code **out
183184 * out = p ;
184185 return 0 ;
185186}
186-
187187#endif
188188
189189static int add_matches_for_device (sd_journal * j , const char * devpath ) {
@@ -1087,22 +1087,26 @@ static int parse_argv(int argc, char *argv[]) {
10871087 if (arg_pattern ) {
10881088 unsigned flags ;
10891089
1090+ r = dlopen_pcre2 ();
1091+ if (r < 0 )
1092+ return r ;
1093+
10901094 if (arg_case_sensitive >= 0 )
10911095 flags = !arg_case_sensitive * PCRE2_CASELESS ;
10921096 else {
1093- _cleanup_ (pcre2_match_data_freep ) pcre2_match_data * md = NULL ;
1097+ _cleanup_ (sym_pcre2_match_data_freep ) pcre2_match_data * md = NULL ;
10941098 bool has_case ;
1095- _cleanup_ (pcre2_code_freep ) pcre2_code * cs = NULL ;
1099+ _cleanup_ (sym_pcre2_code_freep ) pcre2_code * cs = NULL ;
10961100
1097- md = pcre2_match_data_create (1 , NULL );
1101+ md = sym_pcre2_match_data_create (1 , NULL );
10981102 if (!md )
10991103 return log_oom ();
11001104
11011105 r = pattern_compile ("[[:upper:]]" , 0 , & cs );
11021106 if (r < 0 )
11031107 return r ;
11041108
1105- r = pcre2_match (cs , (PCRE2_SPTR8 ) arg_pattern , PCRE2_ZERO_TERMINATED , 0 , 0 , md , NULL );
1109+ r = sym_pcre2_match (cs , (PCRE2_SPTR8 ) arg_pattern , PCRE2_ZERO_TERMINATED , 0 , 0 , md , NULL );
11061110 has_case = r >= 0 ;
11071111
11081112 flags = !has_case * PCRE2_CASELESS ;
@@ -2630,12 +2634,12 @@ int main(int argc, char *argv[]) {
26302634
26312635#if HAVE_PCRE2
26322636 if (arg_compiled_pattern ) {
2633- _cleanup_ (pcre2_match_data_freep ) pcre2_match_data * md = NULL ;
2637+ _cleanup_ (sym_pcre2_match_data_freep ) pcre2_match_data * md = NULL ;
26342638 const void * message ;
26352639 size_t len ;
26362640 PCRE2_SIZE * ovec ;
26372641
2638- md = pcre2_match_data_create (1 , NULL );
2642+ md = sym_pcre2_match_data_create (1 , NULL );
26392643 if (!md )
26402644 return log_oom ();
26412645
@@ -2652,13 +2656,13 @@ int main(int argc, char *argv[]) {
26522656
26532657 assert_se (message = startswith (message , "MESSAGE=" ));
26542658
2655- r = pcre2_match (arg_compiled_pattern ,
2656- message ,
2657- len - strlen ("MESSAGE=" ),
2658- 0 , /* start at offset 0 in the subject */
2659- 0 , /* default options */
2660- md ,
2661- NULL );
2659+ r = sym_pcre2_match (arg_compiled_pattern ,
2660+ message ,
2661+ len - strlen ("MESSAGE=" ),
2662+ 0 , /* start at offset 0 in the subject */
2663+ 0 , /* default options */
2664+ md ,
2665+ NULL );
26622666 if (r == PCRE2_ERROR_NOMATCH ) {
26632667 need_seek = true;
26642668 continue ;
@@ -2667,14 +2671,14 @@ int main(int argc, char *argv[]) {
26672671 unsigned char buf [LINE_MAX ];
26682672 int r2 ;
26692673
2670- r2 = pcre2_get_error_message (r , buf , sizeof buf );
2674+ r2 = sym_pcre2_get_error_message (r , buf , sizeof buf );
26712675 log_error ("Pattern matching failed: %s" ,
26722676 r2 < 0 ? "unknown error" : (char * ) buf );
26732677 r = - EINVAL ;
26742678 goto finish ;
26752679 }
26762680
2677- ovec = pcre2_get_ovector_pointer (md );
2681+ ovec = sym_pcre2_get_ovector_pointer (md );
26782682 highlight [0 ] = ovec [0 ];
26792683 highlight [1 ] = ovec [1 ];
26802684 }
@@ -2766,7 +2770,7 @@ int main(int argc, char *argv[]) {
27662770
27672771#if HAVE_PCRE2
27682772 if (arg_compiled_pattern ) {
2769- pcre2_code_free (arg_compiled_pattern );
2773+ sym_pcre2_code_free (arg_compiled_pattern );
27702774
27712775 /* --grep was used, no error was thrown, but the pattern didn't
27722776 * match anything. Let's mimic grep's behavior here and return
0 commit comments