From c78cc02b89f6f5e562e5cf93d54faaa1bd79dfef Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Mon, 1 Apr 1996 08:17:49 +0000 Subject: [PATCH] Copy /etc/localtime, unless it's already a symlink. --- usr.sbin/tzsetup/main.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/usr.sbin/tzsetup/main.c b/usr.sbin/tzsetup/main.c index e42006eebfb..c0074dfc9e3 100644 --- a/usr.sbin/tzsetup/main.c +++ b/usr.sbin/tzsetup/main.c @@ -28,7 +28,7 @@ */ static const char rcsid[] = - "$Id: main.c,v 1.5 1996/03/22 22:22:38 joerg Exp $"; + "$Id: main.c,v 1.6 1996/03/31 09:55:00 joerg Exp $"; #include #include @@ -242,12 +242,25 @@ setzone(const char *zone) if (rv) return 1; - snprintf(msg, sizeof msg, PATH_ZONEINFO "/%s", zone); - (void)unlink(PATH_LOCALTIME); - if (symlink(msg, PATH_LOCALTIME) == -1) { - dialog_notify("Could not create a symbolic link for " - PATH_LOCALTIME); - return 1; + if (lstat(PATH_LOCALTIME, &sb) == 0 && S_ISLNK(sb.st_mode)) { + /* The destination is already a symlink, symlink it. */ + (void)unlink(PATH_LOCALTIME); + snprintf(msg, sizeof msg, PATH_ZONEINFO "/%s", zone); + if (symlink(msg, PATH_LOCALTIME) == -1) { + dialog_notify("Could not create a symbolic link for " + PATH_LOCALTIME); + return 1; + } + } else { + /* Copy it. */ + snprintf(msg, sizeof msg, + "install -C -o bin -g bin -m 0444 " + PATH_ZONEINFO "/%s " PATH_LOCALTIME, zone); + if (system(msg) != 0) { + dialog_notify("Could not copy zone information into " + PATH_LOCALTIME); + return 1; + } } snprintf(msg, sizeof msg, "Installed timezone file %s", zone);