X Tutup
Skip to content

Commit 614b022

Browse files
committed
Move and rename parse_path_argument() function
This fits better in shared/, and the new parse-argument.c file is a good home for it.
1 parent 923e212 commit 614b022

File tree

18 files changed

+71
-60
lines changed

18 files changed

+71
-60
lines changed

src/basic/path-util.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -752,38 +752,6 @@ int fsck_exists(const char *fstype) {
752752
return executable_is_good(checker);
753753
}
754754

755-
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg) {
756-
char *p;
757-
int r;
758-
759-
/*
760-
* This function is intended to be used in command line
761-
* parsers, to handle paths that are passed in. It makes the
762-
* path absolute, and reduces it to NULL if omitted or
763-
* root (the latter optionally).
764-
*
765-
* NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON
766-
* SUCCESS! Hence, do not pass in uninitialized pointers.
767-
*/
768-
769-
if (isempty(path)) {
770-
*arg = mfree(*arg);
771-
return 0;
772-
}
773-
774-
r = path_make_absolute_cwd(path, &p);
775-
if (r < 0)
776-
return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
777-
778-
path_simplify(p, false);
779-
if (suppress_root && empty_or_root(p))
780-
p = mfree(p);
781-
782-
free_and_replace(*arg, p);
783-
784-
return 0;
785-
}
786-
787755
char* dirname_malloc(const char *path) {
788756
char *d, *dir, *dir2;
789757

src/basic/path-util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ int fsck_exists(const char *fstype);
144144
_ret; \
145145
})
146146

147-
int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg);
148-
149147
char* dirname_malloc(const char *path);
150148
const char *last_path_component(const char *path);
151149
int path_extract_filename(const char *p, char **ret);

src/core/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "mount-setup.h"
5959
#include "os-util.h"
6060
#include "pager.h"
61+
#include "parse-argument.h"
6162
#include "parse-util.h"
6263
#include "path-util.h"
6364
#include "pretty-print.h"
@@ -358,7 +359,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
358359
return 0;
359360

360361
if (path_is_absolute(value))
361-
(void) parse_path_argument_and_warn(value, false, &arg_early_core_pattern);
362+
(void) parse_path_argument(value, false, &arg_early_core_pattern);
362363
else
363364
log_warning("Specified core pattern '%s' is not an absolute path, ignoring.", value);
364365

@@ -498,7 +499,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
498499
if (proc_cmdline_value_missing(key, value))
499500
return 0;
500501

501-
(void) parse_path_argument_and_warn(value, false, &arg_watchdog_device);
502+
(void) parse_path_argument(value, false, &arg_watchdog_device);
502503

503504
} else if (proc_cmdline_key_streq(key, "systemd.clock_usec")) {
504505

src/cryptenroll/cryptenroll.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "libfido2-util.h"
1717
#include "main-func.h"
1818
#include "memory-util.h"
19+
#include "parse-argument.h"
1920
#include "parse-util.h"
2021
#include "path-util.h"
2122
#include "pkcs11-util.h"
@@ -323,7 +324,7 @@ static int parse_argv(int argc, char *argv[]) {
323324
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
324325
"Too many arguments, refusing.");
325326

326-
r = parse_path_argument_and_warn(argv[optind], false, &arg_node);
327+
r = parse_path_argument(argv[optind], false, &arg_node);
327328
if (r < 0)
328329
return r;
329330

src/dissect/dissect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mkdir.h"
2323
#include "mount-util.h"
2424
#include "namespace-util.h"
25+
#include "parse-argument.h"
2526
#include "parse-util.h"
2627
#include "path-util.h"
2728
#include "pretty-print.h"
@@ -245,7 +246,7 @@ static int parse_argv(int argc, char *argv[]) {
245246
}
246247

247248
case ARG_VERITY_DATA:
248-
r = parse_path_argument_and_warn(optarg, false, &arg_verity_settings.data_path);
249+
r = parse_path_argument(optarg, false, &arg_verity_settings.data_path);
249250
if (r < 0)
250251
return r;
251252
break;

src/firstboot/firstboot.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mkdir.h"
2525
#include "mount-util.h"
2626
#include "os-util.h"
27+
#include "parse-argument.h"
2728
#include "parse-util.h"
2829
#include "path-util.h"
2930
#include "pretty-print.h"
@@ -1046,13 +1047,13 @@ static int parse_argv(int argc, char *argv[]) {
10461047
return version();
10471048

10481049
case ARG_ROOT:
1049-
r = parse_path_argument_and_warn(optarg, true, &arg_root);
1050+
r = parse_path_argument(optarg, true, &arg_root);
10501051
if (r < 0)
10511052
return r;
10521053
break;
10531054

10541055
case ARG_IMAGE:
1055-
r = parse_path_argument_and_warn(optarg, false, &arg_image);
1056+
r = parse_path_argument(optarg, false, &arg_image);
10561057
if (r < 0)
10571058
return r;
10581059
break;

src/home/homectl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "main-func.h"
2424
#include "memory-util.h"
2525
#include "pager.h"
26+
#include "parse-argument.h"
2627
#include "parse-util.h"
2728
#include "path-util.h"
2829
#include "pkcs11-util.h"
@@ -2260,7 +2261,7 @@ static int parse_argv(int argc, char *argv[]) {
22602261
break;
22612262
}
22622263

2263-
r = parse_path_argument_and_warn(optarg, false, &hd);
2264+
r = parse_path_argument(optarg, false, &hd);
22642265
if (r < 0)
22652266
return r;
22662267

@@ -2481,7 +2482,7 @@ static int parse_argv(int argc, char *argv[]) {
24812482
break;
24822483
}
24832484

2484-
r = parse_path_argument_and_warn(optarg, false, &v);
2485+
r = parse_path_argument(optarg, false, &v);
24852486
if (r < 0)
24862487
return r;
24872488

src/journal/journalctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "mountpoint-util.h"
5656
#include "nulstr-util.h"
5757
#include "pager.h"
58+
#include "parse-argument.h"
5859
#include "parse-util.h"
5960
#include "path-util.h"
6061
#include "pcre2-dlopen.h"
@@ -719,13 +720,13 @@ static int parse_argv(int argc, char *argv[]) {
719720
break;
720721

721722
case ARG_ROOT:
722-
r = parse_path_argument_and_warn(optarg, /* suppress_root= */ true, &arg_root);
723+
r = parse_path_argument(optarg, /* suppress_root= */ true, &arg_root);
723724
if (r < 0)
724725
return r;
725726
break;
726727

727728
case ARG_IMAGE:
728-
r = parse_path_argument_and_warn(optarg, /* suppress_root= */ false, &arg_image);
729+
r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
729730
if (r < 0)
730731
return r;
731732
break;

src/machine-id-setup/machine-id-setup-main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "log.h"
1111
#include "machine-id-setup.h"
1212
#include "main-func.h"
13+
#include "parse-argument.h"
1314
#include "path-util.h"
1415
#include "pretty-print.h"
1516
#include "util.h"
@@ -76,7 +77,7 @@ static int parse_argv(int argc, char *argv[]) {
7677
return version();
7778

7879
case ARG_ROOT:
79-
r = parse_path_argument_and_warn(optarg, true, &arg_root);
80+
r = parse_path_argument(optarg, true, &arg_root);
8081
if (r < 0)
8182
return r;
8283
break;

src/nspawn/nspawn.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "nulstr-util.h"
7979
#include "os-util.h"
8080
#include "pager.h"
81+
#include "parse-argument.h"
8182
#include "parse-util.h"
8283
#include "path-util.h"
8384
#include "pretty-print.h"
@@ -791,31 +792,31 @@ static int parse_argv(int argc, char *argv[]) {
791792
return version();
792793

793794
case 'D':
794-
r = parse_path_argument_and_warn(optarg, false, &arg_directory);
795+
r = parse_path_argument(optarg, false, &arg_directory);
795796
if (r < 0)
796797
return r;
797798

798799
arg_settings_mask |= SETTING_DIRECTORY;
799800
break;
800801

801802
case ARG_TEMPLATE:
802-
r = parse_path_argument_and_warn(optarg, false, &arg_template);
803+
r = parse_path_argument(optarg, false, &arg_template);
803804
if (r < 0)
804805
return r;
805806

806807
arg_settings_mask |= SETTING_DIRECTORY;
807808
break;
808809

809810
case 'i':
810-
r = parse_path_argument_and_warn(optarg, false, &arg_image);
811+
r = parse_path_argument(optarg, false, &arg_image);
811812
if (r < 0)
812813
return r;
813814

814815
arg_settings_mask |= SETTING_DIRECTORY;
815816
break;
816817

817818
case ARG_OCI_BUNDLE:
818-
r = parse_path_argument_and_warn(optarg, false, &arg_oci_bundle);
819+
r = parse_path_argument(optarg, false, &arg_oci_bundle);
819820
if (r < 0)
820821
return r;
821822

@@ -934,7 +935,7 @@ static int parse_argv(int argc, char *argv[]) {
934935
break;
935936

936937
case ARG_NETWORK_NAMESPACE_PATH:
937-
r = parse_path_argument_and_warn(optarg, false, &arg_network_namespace_path);
938+
r = parse_path_argument(optarg, false, &arg_network_namespace_path);
938939
if (r < 0)
939940
return r;
940941

@@ -1386,7 +1387,7 @@ static int parse_argv(int argc, char *argv[]) {
13861387
}
13871388

13881389
case ARG_VERITY_DATA:
1389-
r = parse_path_argument_and_warn(optarg, false, &arg_verity_settings.data_path);
1390+
r = parse_path_argument(optarg, false, &arg_verity_settings.data_path);
13901391
if (r < 0)
13911392
return r;
13921393
break;

0 commit comments

Comments
 (0)
X Tutup