diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-01 21:34:18 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-01 21:36:11 -0400 |
commit | 18f1997118817a3f1482445c296ba404a99c39da (patch) | |
tree | 125697a0e94e202d1b4a1c6f236dc65c5b8f82f0 | |
parent | cf7cab4ede7d84ce110248de1606805b8c593da7 (diff) | |
download | multihome-18f1997118817a3f1482445c296ba404a99c39da.tar.gz |
Use HOME_OLD set by the init script for update mode instead. More robust
-rw-r--r-- | multihome.c | 17 |
1 files 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); |