return executable_is_good(checker);
}
-int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
- char *p;
- int r;
-
- /*
- * This function is intended to be used in command line
- * parsers, to handle paths that are passed in. It makes the
- * path absolute, and reduces it to NULL if omitted or
- * root (the latter optionally).
- *
- * NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON
- * SUCCESS! Hence, do not pass in uninitialized pointers.
- */
-
- if (isempty(path)) {
- *arg = mfree(*arg);
- return 0;
- }
-
- r = path_make_absolute_cwd(path, &p);
- if (r < 0)
- return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
-
- path_simplify(p, false);
- if (suppress_root && empty_or_root(p))
- p = mfree(p);
-
- free_and_replace(*arg, p);
-
- return 0;
-}
-
char* dirname_malloc(const char *path) {
char *d, *dir, *dir2;
_ret; \
})
-int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg);
-
char* dirname_malloc(const char *path);
const char *last_path_component(const char *path);
int path_extract_filename(const char *p, char **ret);
#include "mount-setup.h"
#include "os-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
return 0;
if (path_is_absolute(value))
- (void) parse_path_argument_and_warn(value, false, &arg_early_core_pattern);
+ (void) parse_path_argument(value, false, &arg_early_core_pattern);
else
log_warning("Specified core pattern '%s' is not an absolute path, ignoring.", value);
if (proc_cmdline_value_missing(key, value))
return 0;
- (void) parse_path_argument_and_warn(value, false, &arg_watchdog_device);
+ (void) parse_path_argument(value, false, &arg_watchdog_device);
} else if (proc_cmdline_key_streq(key, "systemd.clock_usec")) {
#include "libfido2-util.h"
#include "main-func.h"
#include "memory-util.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pkcs11-util.h"
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many arguments, refusing.");
- r = parse_path_argument_and_warn(argv[optind], false, &arg_node);
+ r = parse_path_argument(argv[optind], false, &arg_node);
if (r < 0)
return r;
#include "mkdir.h"
#include "mount-util.h"
#include "namespace-util.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
}
case ARG_VERITY_DATA:
- r = parse_path_argument_and_warn(optarg, false, &arg_verity_settings.data_path);
+ r = parse_path_argument(optarg, false, &arg_verity_settings.data_path);
if (r < 0)
return r;
break;
#include "mkdir.h"
#include "mount-util.h"
#include "os-util.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
return version();
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, true, &arg_root);
+ r = parse_path_argument(optarg, true, &arg_root);
if (r < 0)
return r;
break;
case ARG_IMAGE:
- r = parse_path_argument_and_warn(optarg, false, &arg_image);
+ r = parse_path_argument(optarg, false, &arg_image);
if (r < 0)
return r;
break;
#include "main-func.h"
#include "memory-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pkcs11-util.h"
break;
}
- r = parse_path_argument_and_warn(optarg, false, &hd);
+ r = parse_path_argument(optarg, false, &hd);
if (r < 0)
return r;
break;
}
- r = parse_path_argument_and_warn(optarg, false, &v);
+ r = parse_path_argument(optarg, false, &v);
if (r < 0)
return r;
#include "mountpoint-util.h"
#include "nulstr-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pcre2-dlopen.h"
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ true, &arg_root);
+ r = parse_path_argument(optarg, /* suppress_root= */ true, &arg_root);
if (r < 0)
return r;
break;
case ARG_IMAGE:
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_image);
+ r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
if (r < 0)
return r;
break;
#include "log.h"
#include "machine-id-setup.h"
#include "main-func.h"
+#include "parse-argument.h"
#include "path-util.h"
#include "pretty-print.h"
#include "util.h"
return version();
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, true, &arg_root);
+ r = parse_path_argument(optarg, true, &arg_root);
if (r < 0)
return r;
break;
#include "nulstr-util.h"
#include "os-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
return version();
case 'D':
- r = parse_path_argument_and_warn(optarg, false, &arg_directory);
+ r = parse_path_argument(optarg, false, &arg_directory);
if (r < 0)
return r;
break;
case ARG_TEMPLATE:
- r = parse_path_argument_and_warn(optarg, false, &arg_template);
+ r = parse_path_argument(optarg, false, &arg_template);
if (r < 0)
return r;
break;
case 'i':
- r = parse_path_argument_and_warn(optarg, false, &arg_image);
+ r = parse_path_argument(optarg, false, &arg_image);
if (r < 0)
return r;
break;
case ARG_OCI_BUNDLE:
- r = parse_path_argument_and_warn(optarg, false, &arg_oci_bundle);
+ r = parse_path_argument(optarg, false, &arg_oci_bundle);
if (r < 0)
return r;
break;
case ARG_NETWORK_NAMESPACE_PATH:
- r = parse_path_argument_and_warn(optarg, false, &arg_network_namespace_path);
+ r = parse_path_argument(optarg, false, &arg_network_namespace_path);
if (r < 0)
return r;
}
case ARG_VERITY_DATA:
- r = parse_path_argument_and_warn(optarg, false, &arg_verity_settings.data_path);
+ r = parse_path_argument(optarg, false, &arg_verity_settings.data_path);
if (r < 0)
return r;
break;
#include "mkfs-util.h"
#include "mount-util.h"
#include "parse-util.h"
+#include "parse-argument.h"
#include "path-util.h"
#include "pretty-print.h"
#include "proc-cmdline.h"
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, false, &arg_root);
+ r = parse_path_argument(optarg, false, &arg_root);
if (r < 0)
return r;
break;
break;
case ARG_DEFINITIONS:
- r = parse_path_argument_and_warn(optarg, false, &arg_definitions);
+ r = parse_path_argument(optarg, false, &arg_definitions);
if (r < 0)
return r;
break;
#include "fd-util.h"
#include "format-util.h"
#include "main-func.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
break;
case ARG_WORKING_DIRECTORY:
- r = parse_path_argument_and_warn(optarg, true, &arg_working_directory);
+ r = parse_path_argument(optarg, true, &arg_working_directory);
if (r < 0)
return r;
#include "format-table.h"
#include "parse-argument.h"
+#include "path-util.h"
#include "signal-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
+/* All functions in this file emit warnigs. */
+
+int parse_path_argument(const char *path, bool suppress_root, char **arg) {
+ char *p;
+ int r;
+
+ /*
+ * This function is intended to be used in command line parsers, to handle paths that are passed
+ * in. It makes the path absolute, and reduces it to NULL if omitted or root (the latter optionally).
+ *
+ * NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON SUCCESS!
+ * Hence, do not pass in uninitialized pointers.
+ */
+
+ if (isempty(path)) {
+ *arg = mfree(*arg);
+ return 0;
+ }
+
+ r = path_make_absolute_cwd(path, &p);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
+
+ path_simplify(p, false);
+ if (suppress_root && empty_or_root(p))
+ p = mfree(p);
+
+ return free_and_replace(*arg, p);
+}
+
int parse_signal_argument(const char *s, int *ret) {
int r;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+int parse_path_argument(const char *path, bool suppress_root, char **arg);
int parse_signal_argument(const char *s, int *ret);
#include "mountpoint-util.h"
#include "os-util.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "process-util.h"
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, false, &arg_root);
+ r = parse_path_argument(optarg, false, &arg_root);
if (r < 0)
return r;
break;
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, false, &arg_root);
+ r = parse_path_argument(optarg, false, &arg_root);
if (r < 0)
return r;
break;
#include "mount-util.h"
#include "nscd-flush.h"
#include "pager.h"
+#include "parse-argument.h"
#include "path-util.h"
#include "pretty-print.h"
#include "selinux-util.h"
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_root);
+ r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_root);
if (r < 0)
return r;
break;
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"This systemd-sysusers version is compiled without support for --image=.");
#else
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_image);
+ r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
if (r < 0)
return r;
break;
#include "mountpoint-util.h"
#include "offline-passwd.h"
#include "pager.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "path-lookup.h"
#include "path-util.h"
break;
case ARG_ROOT:
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_root);
+ r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_root);
if (r < 0)
return r;
break;
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"This systemd-tmpfiles version is compiled without support for --image=.");
#else
- r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_image);
+ r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
if (r < 0)
return r;
#endif