From 8d98da3f1107529d5ba49aea1fa285f7264b7cba Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 5 Jun 2013 19:30:17 -0400 Subject: journalctl: allow the user to specify the file(s) to use This is useful for debugging and feels pretty natural. For example answering the question "is this big .journal file worth keeping?" is made easier. --- src/shared/util.c | 34 ++++++++++++++++++++++++++++------ src/shared/util.h | 1 + 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src/shared') diff --git a/src/shared/util.c b/src/shared/util.c index 17928ec36e..04811ff26b 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -4353,7 +4353,7 @@ int in_group(const char *name) { int glob_exists(const char *path) { _cleanup_globfree_ glob_t g = {}; - int r, k; + int k; assert(path); @@ -4361,15 +4361,37 @@ int glob_exists(const char *path) { k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); if (k == GLOB_NOMATCH) - r = 0; + return 0; else if (k == GLOB_NOSPACE) - r = -ENOMEM; + return -ENOMEM; else if (k == 0) - r = !strv_isempty(g.gl_pathv); + return !strv_isempty(g.gl_pathv); else - r = errno ? -errno : -EIO; + return errno ? -errno : -EIO; +} - return r; +int glob_extend(char ***strv, const char *path) { + _cleanup_globfree_ glob_t g = {}; + int k; + char **p; + + errno = 0; + k = glob(optarg, GLOB_NOSORT|GLOB_BRACE, NULL, &g); + + if (k == GLOB_NOMATCH) + return -ENOENT; + else if (k == GLOB_NOSPACE) + return -ENOMEM; + else if (k != 0 || strv_isempty(g.gl_pathv)) + return errno ? -errno : -EIO; + + STRV_FOREACH(p, g.gl_pathv) { + k = strv_extend(strv, *p); + if (k < 0) + break; + } + + return k; } int dirent_ensure_type(DIR *d, struct dirent *de) { diff --git a/src/shared/util.h b/src/shared/util.h index e6f9312e95..ddb21b4a9c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -439,6 +439,7 @@ char* uid_to_name(uid_t uid); char* gid_to_name(gid_t gid); int glob_exists(const char *path); +int glob_extend(char ***strv, const char *path); int dirent_ensure_type(DIR *d, struct dirent *de); -- cgit v1.2.3-54-g00ecf