Skip to content

Commit 830d73c

Browse files
committedNov 21, 2024
login,libblkid: use econf_readConfig rather than deprecated econf_readDirs
Fixes: lib/logindefs.c: In function ‘load_defaults’: lib/logindefs.c:257:9: warning: ‘econf_readDirs’ is deprecated: Use the econf_readConfig/econf_readConfigWithCallback instead [-Wdeprecated-declarations] 257 | error = econf_readDirs(&file, | ^~~~~ libblkid/src/config.c: In function 'blkid_read_config': libblkid/src/config.c:164:17: error: 'econf_readDirs' is deprecated: Use the econf_readConfig/econf_readConfigWithCallback instead [-Werror=deprecated-declarations] 164 | error = econf_readDirs(&file, | ^~~~~ * check for econf_readConfig() by ./configure and moson * add UL_VENDORDIR_PATH into pathnames.h to avoid #ifdef in code * use #ifdef HAVE_ECONF_READCONFIG to switch between econf_readDirs() and the econf_readConfig() Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 23a4dc0 commit 830d73c

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed
 

‎configure.ac

+9-2
Original file line numberDiff line numberDiff line change
@@ -2723,8 +2723,15 @@ AC_ARG_WITH([econf],
27232723

27242724
have_econf=no
27252725
AS_IF([test "x$with_econf" != xno], [
2726-
PKG_CHECK_MODULES([ECONF], [libeconf], [have_econf=yes], [have_econf=no])
2727-
AS_CASE([$with_econf:$have_econf],
2726+
PKG_CHECK_MODULES([ECONF], [libeconf],
2727+
[have_econf=yes
2728+
AC_CHECK_LIB([econf], [econf_readConfig], [
2729+
AC_DEFINE([HAVE_ECONF_READCONFIG], [1], [Define if econf_readConfig exist in -leconf])
2730+
])
2731+
],
2732+
[have_econf=no]
2733+
)
2734+
AS_CASE([$with_econf:$have_econf],
27282735
[yes:no],
27292736
[AC_MSG_ERROR([libeconf expected but libeconf not found])],
27302737
[*:yes],

‎include/pathnames.h

+7
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,11 @@
236236
/* Maximum number of PIDs system supports */
237237
#define _PATH_PROC_PIDMAX "/proc/sys/kernel/pid_max"
238238

239+
/* econf path */
240+
#if USE_VENDORDIR
241+
# define UL_VENDORDIR_PATH _PATH_VENDORDIR
242+
#else
243+
# define UL_VENDORDIR_PATH NULL
244+
#endif
245+
239246
#endif /* PATHNAMES_H */

‎lib/logindefs.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,13 @@ static void load_defaults(void)
254254
if (file != NULL)
255255
free_getlogindefs_data();
256256

257-
error = econf_readDirs(&file,
258-
#if USE_VENDORDIR
259-
_PATH_VENDORDIR,
257+
#ifdef HAVE_ECONF_READCONFIG
258+
error = econf_readConfig(&file, NULL,
259+
UL_VENDORDIR_PATH, "login", "defs", "= \t", "#");
260260
#else
261-
NULL,
261+
error = econf_readDirs(&file,
262+
UL_VENDORDIR_PATH, "/etc", "login", "defs", "= \t", "#");
262263
#endif
263-
"/etc", "login", "defs", "= \t", "#");
264-
265264
if (error)
266265
syslog(LOG_NOTICE, _("Error reading login.defs: %s"),
267266
econf_errString(error));

‎libblkid/src/config.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include <stdint.h>
2424
#include <stdarg.h>
2525
#if defined (HAVE_LIBECONF)
26-
#include <libeconf.h>
26+
# include <libeconf.h>
27+
# include "pathnames.h"
2728
#endif
2829

2930
#include "blkidP.h"
@@ -161,13 +162,13 @@ struct blkid_config *blkid_read_config(const char *filename)
161162
DBG(CONFIG, ul_debug("reading config file: %s.", filename));
162163
error = econf_readFile(&file, filename, "= \t", "#");
163164
} else {
164-
error = econf_readDirs(&file,
165-
#if USE_VENDORDIR
166-
_PATH_VENDORDIR,
165+
#ifdef HAVE_ECONF_READCONFIG
166+
error = econf_readConfig(&file, NULL,
167+
UL_VENDORDIR_PATH, "blkid", "conf", "= \t", "#");
167168
#else
168-
NULL,
169+
error = econf_readDirs(&file,
170+
UL_VENDORDIR_PATH, "/etc", "blkid", "conf", "= \t", "#");
169171
#endif
170-
"/etc", "blkid", "conf", "= \t", "#");
171172
}
172173

173174
if (error) {

‎meson.build

+5
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ lib_econf = dependency(
431431
required : get_option('econf'))
432432
conf.set('HAVE_LIBECONF', lib_econf.found() ? 1 : false)
433433

434+
have = cc.has_function(
435+
'econf_readConfig',
436+
dependencies : lib_econf)
437+
conf.set('HAVE_ECONF_READCONFIG', have ? 1 : false)
438+
434439
lib_audit = dependency(
435440
'audit',
436441
required : get_option('audit'))

0 commit comments

Comments
 (0)