summaryrefslogtreecommitdiff
path: root/src/firstboot/firstboot.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-13 17:42:10 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-13 17:42:10 +0200
commit1d13f648d0fade38194db74b4f82ca68c8a26856 (patch)
treeb85c22b0007e0c8c6e612b8c9f5606bcd84f0451 /src/firstboot/firstboot.c
parent8b44a3d22c1fdfc5ce5fcb77e38a90ec02ba8019 (diff)
util: add generic calls for prefixing a root directory to a path
So far a number of utilities implemented their own calls for this, unify them in prefix_root() and prefix_roota(). The former uses heap memory, the latter allocates from the stack via alloca(). Port over most users of a --root= logic.
Diffstat (limited to 'src/firstboot/firstboot.c')
-rw-r--r--src/firstboot/firstboot.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 37326df008..d156d57caf 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -52,8 +52,6 @@ static bool arg_copy_locale = false;
static bool arg_copy_timezone = false;
static bool arg_copy_root_password = false;
-#define prefix_roota(p) (arg_root ? (const char*) strjoina(arg_root, p) : (const char*) p)
-
static void clear_string(char *x) {
if (!x)
@@ -87,13 +85,13 @@ static void print_welcome(void) {
if (done)
return;
- os_release = prefix_roota("/etc/os-release");
+ os_release = prefix_roota(arg_root, "/etc/os-release");
r = parse_env_file(os_release, NEWLINE,
"PRETTY_NAME", &pretty_name,
NULL);
if (r == -ENOENT) {
- os_release = prefix_roota("/usr/lib/os-release");
+ os_release = prefix_roota(arg_root, "/usr/lib/os-release");
r = parse_env_file(os_release, NEWLINE,
"PRETTY_NAME", &pretty_name,
NULL);
@@ -251,7 +249,7 @@ static int process_locale(void) {
unsigned i = 0;
int r;
- etc_localeconf = prefix_roota("/etc/locale.conf");
+ etc_localeconf = prefix_roota(arg_root, "/etc/locale.conf");
if (faccessat(AT_FDCWD, etc_localeconf, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;
@@ -325,7 +323,7 @@ static int process_timezone(void) {
const char *etc_localtime, *e;
int r;
- etc_localtime = prefix_roota("/etc/localtime");
+ etc_localtime = prefix_roota(arg_root, "/etc/localtime");
if (faccessat(AT_FDCWD, etc_localtime, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;
@@ -404,7 +402,7 @@ static int process_hostname(void) {
const char *etc_hostname;
int r;
- etc_hostname = prefix_roota("/etc/hostname");
+ etc_hostname = prefix_roota(arg_root, "/etc/hostname");
if (faccessat(AT_FDCWD, etc_hostname, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;
@@ -429,7 +427,7 @@ static int process_machine_id(void) {
char id[SD_ID128_STRING_MAX];
int r;
- etc_machine_id = prefix_roota("/etc/machine-id");
+ etc_machine_id = prefix_roota(arg_root, "/etc/machine-id");
if (faccessat(AT_FDCWD, etc_machine_id, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;
@@ -455,7 +453,7 @@ static int prompt_root_password(void) {
if (!arg_prompt_root_password)
return 0;
- etc_shadow = prefix_roota("/etc/shadow");
+ etc_shadow = prefix_roota(arg_root, "/etc/shadow");
if (faccessat(AT_FDCWD, etc_shadow, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;
@@ -544,7 +542,7 @@ static int process_root_password(void) {
const char *etc_shadow;
int r;
- etc_shadow = prefix_roota("/etc/shadow");
+ etc_shadow = prefix_roota(arg_root, "/etc/shadow");
if (faccessat(AT_FDCWD, etc_shadow, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
return 0;