]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl,elsewhere: make sure --file=foo fails with sane error msg if foo is not...
authorLennart Poettering <lennart@poettering.net>
Tue, 12 May 2020 21:36:27 +0000 (23:36 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 May 2020 13:26:51 +0000 (15:26 +0200)
It annoyed me for quite a while that running "journalctl --file=…" on a
file that is not readable failed with a "File not found" error instead
of a permission error. Let's fix that.

We make this work by using the GLOB_NOCHECK flag for glob() which means
that files are not accessible will be returned in the array as they are
instead of being filtered away. This then means that our later attemps
to open the files will fail cleanly with a good error message.

src/basic/glob-util.c
src/basic/glob-util.h
src/basic/path-util.c
src/coredump/coredumpctl.c
src/journal-remote/journal-upload.c
src/journal/journalctl.c
src/sysctl/sysctl.c

index e3aa6c2e152b4f9d7ecbb583770b02145188a838..1e7e301e09875d0e72579d45a03d895e3c29135d 100644 (file)
@@ -61,11 +61,11 @@ int glob_exists(const char *path) {
         return true;
 }
 
-int glob_extend(char ***strv, const char *path) {
+int glob_extend(char ***strv, const char *path, int flags) {
         _cleanup_globfree_ glob_t g = {};
         int k;
 
-        k = safe_glob(path, GLOB_NOSORT|GLOB_BRACE, &g);
+        k = safe_glob(path, GLOB_NOSORT|GLOB_BRACE|flags, &g);
         if (k < 0)
                 return k;
 
index 8b1bb02be138471ef399b6a2442f9ff177b671aa..3d5f5435085aca376f0362fdad86c8fe8f673d3f 100644 (file)
@@ -11,7 +11,7 @@
 int safe_glob(const char *path, int flags, glob_t *pglob);
 
 int glob_exists(const char *path);
-int glob_extend(char ***strv, const char *path);
+int glob_extend(char ***strv, const char *path, int flags);
 
 #define _cleanup_globfree_ _cleanup_(globfree)
 
index ba13de01ff0b194f6cc9925fe0fcd6e7078458d4..986dfe94a4b719b16e13c50b94bf6d041887c42d 100644 (file)
@@ -1051,7 +1051,7 @@ int systemd_installation_has_version(const char *root, unsigned minimal_version)
                 if (!path)
                         return -ENOMEM;
 
-                r = glob_extend(&names, path);
+                r = glob_extend(&names, path, 0);
                 if (r == -ENOENT)
                         continue;
                 if (r < 0)
index 60a02b770bee060810b4fdf1a20e23eca343a82d..ed4d06e9866dd1e4af044bc99d33e4d3b1b10139 100644 (file)
@@ -237,7 +237,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_FILE:
-                        r = glob_extend(&arg_file, optarg);
+                        r = glob_extend(&arg_file, optarg, GLOB_NOCHECK);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to add paths: %m");
                         break;
index 2f9585df564220f51a59d224ba72198ce550690b..bf656ac670617c7ff740450c73ef30d168b1ee0d 100644 (file)
@@ -720,7 +720,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_FILE:
-                        r = glob_extend(&arg_file, optarg);
+                        r = glob_extend(&arg_file, optarg, GLOB_NOCHECK);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to add paths: %m");
                         break;
index 01d75b0e24d0f5687d7eac87b8108777f6f98c45..a082995498f993e07b269a0fb26291ed22e9e5b9 100644 (file)
@@ -705,7 +705,7 @@ static int parse_argv(int argc, char *argv[]) {
                                  * STDIN. To avoid confusion we hence don't document this feature. */
                                 arg_file_stdin = true;
                         else {
-                                r = glob_extend(&arg_file, optarg);
+                                r = glob_extend(&arg_file, optarg, GLOB_NOCHECK);
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to add paths: %m");
                         }
index 3b3305d7f68a849f1b6bf49b9cf6b0abaccb04c6..5274cd24b38704f22d0e2de18d113d2e557f8c54 100644 (file)
@@ -138,7 +138,7 @@ static int apply_all(OrderedHashmap *sysctl_options) {
                         if (!pattern)
                                 return log_oom();
 
-                        k = glob_extend(&paths, pattern);
+                        k = glob_extend(&paths, pattern, GLOB_NOCHECK);
                         if (k < 0) {
                                 if (option->ignore_failure || ERRNO_IS_PRIVILEGE(k))
                                         log_debug_errno(k, "Failed to resolve glob '%s', ignoring: %m",