Skip to content

Commit

Permalink
fixed testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Oct 5, 2023
1 parent 2ed14c1 commit 72eef22
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
26 changes: 13 additions & 13 deletions lib/libeconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,22 @@ econf_err econf_readConfigWithCallback(econf_file **key_file,
bool (*callback)(const char *filename, const void *data),
const void *callback_data)
{
char *run_dir = DEFAULT_RUN_SUBDIR;
char *etc_dir = DEFAULT_ETC_SUBDIR;
char usr_dir[PATH_MAX];
char run_dir[PATH_MAX];
char etc_dir[PATH_MAX];

if (project != NULL) {
if (asprintf(&run_dir, "%s/%s", DEFAULT_RUN_SUBDIR, project) < 0) {
return ECONF_NOMEM;
}
if (asprintf(&etc_dir, "%s/%s", DEFAULT_ETC_SUBDIR, project) < 0) {
free(run_dir);
return ECONF_NOMEM;
}
}
snprintf(usr_dir, sizeof(usr_dir),"%s/%s", usr_subdir, project);
snprintf(run_dir, sizeof(run_dir), "%s/%s", DEFAULT_RUN_SUBDIR, project);
snprintf(etc_dir, sizeof(etc_dir), "%s/%s", DEFAULT_ETC_SUBDIR, project);
} else {
snprintf(usr_dir, sizeof(usr_dir),"%s", usr_subdir);
snprintf(run_dir, sizeof(run_dir), "%s", DEFAULT_RUN_SUBDIR);
snprintf(etc_dir, sizeof(etc_dir), "%s", DEFAULT_ETC_SUBDIR);
}

econf_err ret = readConfigWithCallback(key_file,
usr_subdir,
usr_dir,
run_dir,
etc_dir,
config_name,
Expand All @@ -306,8 +308,6 @@ econf_err econf_readConfigWithCallback(econf_file **key_file,
conf_count,
callback,
callback_data);
free(run_dir);
free(etc_dir);
return ret;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/libeconf.map
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ LIBECONF_0.5 {
econf_readDirsWithCallback;
econf_readDirsHistoryWithCallback;
econf_set_conf_dirs;
} LIBECONF_0.4;
} LIBECONF_0.4;
LIBECONF_0.6 {
global:
econf_readConfigWithCallback;
econf_readConfig;
} LIBECONF_0.5;
4 changes: 2 additions & 2 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ tst_getconfdirs7_exe = executable('tst-getconfdirs7', 'tst-getconfdirs7.c', c_ar
test('tst-getconfdirs7', tst_getconfdirs7_exe)
tst_getconfdirs8_exe = executable('tst-getconfdirs8', 'tst-getconfdirs8.c', c_args: ['-DSUFFIX="conf"', test_args], dependencies : libeconf_dep)
test('tst-getconfdirs8', tst_getconfdirs8_exe)
tst_getconfdirs9_exe = executable('tst-getconfdirs9', 'tst-getconfdirs9.c', c_args: test_args, dependencies : libeconf_dep)
test('tst-getconfdirs9', tst_getconfdirs9_exe)
tst_uapi_1_exe = executable('tst-uapi-1', sources: ['tst-uapi-1.c', '../lib/helpers.c', '../lib/readconfig.c', '../lib/mergefiles.c'], c_args: test_args, dependencies : libeconf_dep)
test('tst-uapi-1', tst_uapi_1_exe)

tst_parse_error_exe = executable('tst-parse-error', 'tst-parse-error.c', c_args: test_args, dependencies : libeconf_dep)
test('tst-parse-error', tst_parse_error_exe)
Expand Down
23 changes: 14 additions & 9 deletions tests/tst-getconfdirs9.c → tests/tst-uapi-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#include <string.h>

#include "libeconf.h"
#include "../lib/helpers.h"
#include "../lib/mergefiles.h"
#include "../lib/readconfig.h"

/* Test case:
Test the systemd like behavior:
/usr/etc/getconfdir.conf exists
/run/getconfdir.conf exists
/etc/getconfidr.conf.d/<files>.conf exists
/usr/foo/etc/getconfdir.conf exists
/run/foo/getconfdir.conf exists
/etc/foo/getconfidr.conf.d/<files>.conf exists
libeconf should ignore /usr/etc/getconfdir.conf, as this contains
libeconf should ignore /usr/foo/etc/getconfdir.conf, as this contains
*/

static int
Expand Down Expand Up @@ -53,13 +56,15 @@ main(void)
int retval = 0;
econf_err error;

error = econf_readDirs (&key_file,
TESTSDIR"tst-getconfdirs1-data/usr/etc",
TESTSDIR"tst-getconfdirs1-data/etc",
"getconfdir", "conf", "=", "#");
error = readConfigWithCallback (&key_file,
TESTSDIR"tst-uapi-1-data/usr/etc/foo",
TESTSDIR"tst-uapi-1-data/run/foo",
TESTSDIR"tst-uapi-1-data/etc/foo",
"getconfdir", "conf", "=", "#",
NULL, 0, NULL, NULL);
if (error)
{
fprintf (stderr, "ERROR: econf_readDirs: %s\n",
fprintf (stderr, "ERROR: econf_readConfig: %s\n",
econf_errString(error));
return 1;
}
Expand Down

0 comments on commit 72eef22

Please sign in to comment.