From 18f1997118817a3f1482445c296ba404a99c39da Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 1 Sep 2020 21:34:18 -0400 Subject: Use HOME_OLD set by the init script for update mode instead. More robust --- multihome.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/multihome.c b/multihome.c index 77ab821..f5a7aae 100644 --- a/multihome.c +++ b/multihome.c @@ -624,9 +624,13 @@ int main(int argc, char *argv[]) { // Determine the user's home directory char *path_old; - path_old = getenv("HOME"); + if (!arguments.update) { + path_old = getenv("HOME"); + } else { // Update mode requires the original home path + path_old = getenv("HOME_OLD"); + } - // Handle legitimate case where HOME is undefined. Use the system's records instead... + // Handle legitimate case where HOME (or HOME_OLD) is undefined. Use the system's records instead... // i.e. The user wiped the environment with `env -i` prior to executing multihome if (path_old == NULL) { path_old = user_info->pw_dir; @@ -644,14 +648,7 @@ int main(int argc, char *argv[]) { sprintf(multihome.config_init, "%s/init", multihome.config_dir); sprintf(multihome.config_transfer, "%s/transfer", multihome.config_dir); sprintf(multihome.config_skeleton, "%s/skel/", multihome.config_dir); - - // Update mode uses the current $HOME, so set .path_new to .path_old - if (arguments.update) { - strcpy(multihome.path_new, multihome.path_old); - } else { // Construct .path_new normally - sprintf(multihome.path_new, "%s/%s/%s", multihome.path_old, multihome.path_root, nodename); - } - + sprintf(multihome.path_new, "%s/%s/%s", multihome.path_old, multihome.path_root, nodename); sprintf(multihome.path_topdir, "%s/topdir", multihome.path_new); sprintf(multihome.marker, "%s/.multihome_controlled", multihome.path_new); -- cgit