Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Mar 2013 19:31:44 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r247729 - stable/9/usr.sbin/tzsetup
Message-ID:  <201303031931.r23JViKf058027@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Sun Mar  3 19:31:44 2013
New Revision: 247729
URL: http://svnweb.freebsd.org/changeset/base/247729

Log:
  MFC r230520:
  
  Clean up reinstall option and remove duplicate code
  
  - Move the reinstall logic to be before menus are initialised
    (menus are not needed when reinstalling a zonefile).
  
  - Remove unnecessary re-initialization of path_db.
  
  - Update variable name and error message because we now use the
    zone name relative to /usr/share/zoneinfo, not the full path.
  
  PR:		bin/164041
  Submitted by:	dteske

Modified:
  stable/9/usr.sbin/tzsetup/tzsetup.c

Modified: stable/9/usr.sbin/tzsetup/tzsetup.c
==============================================================================
--- stable/9/usr.sbin/tzsetup/tzsetup.c	Sun Mar  3 19:26:05 2013	(r247728)
+++ stable/9/usr.sbin/tzsetup/tzsetup.c	Sun Mar  3 19:31:44 2013	(r247729)
@@ -951,32 +951,16 @@ main(int argc, char **argv)
 	/* Override the user-supplied umask. */
 	(void)umask(S_IWGRP | S_IWOTH);
 
-	read_iso3166_table();
-	read_zones();
-	sort_countries();
-	make_menus();
-
 	if (reinstall == 1) {
 		FILE *f;
-		char zonefile[MAXPATHLEN];
-		char path_db[MAXPATHLEN];
-
-		zonefile[0] = '\0';
-		path_db[0] = '\0';
-		if (chrootenv != NULL) {
-			sprintf(zonefile, "%s/", chrootenv);
-			sprintf(path_db, "%s/", chrootenv);
-		}
-		strcat(zonefile, _PATH_ZONEINFO);
-		strcat(zonefile, "/");
-		strcat(path_db, _PATH_DB);
+		char zoneinfo[MAXPATHLEN];
 
 		if ((f = fopen(path_db, "r")) != NULL) {
-			if (fgets(zonefile, sizeof(zonefile), f) != NULL) {
-				zonefile[sizeof(zonefile) - 1] = 0;
-				if (strlen(zonefile) > 0) {
-					zonefile[strlen(zonefile) - 1] = 0;
-					rv = install_zoneinfo(zonefile);
+			if (fgets(zoneinfo, sizeof(zoneinfo), f) != NULL) {
+				zoneinfo[sizeof(zoneinfo) - 1] = 0;
+				if (strlen(zoneinfo) > 0) {
+					zoneinfo[strlen(zoneinfo) - 1] = 0;
+					rv = install_zoneinfo(zoneinfo);
 					exit(rv & ~DITEM_LEAVE_MENU);
 				}
 				errx(1, "Error reading %s.\n", path_db);
@@ -984,7 +968,7 @@ main(int argc, char **argv)
 			fclose(f);
 			errx(1,
 			    "Unable to determine earlier installed zoneinfo "
-			    "file. Check %s", path_db);
+			    "name. Check %s", path_db);
 		}
 		errx(1, "Cannot open %s for reading. Does it exist?", path_db);
 	}
@@ -1004,6 +988,11 @@ main(int argc, char **argv)
 		/* FALLTHROUGH */
 	}
 
+	read_iso3166_table();
+	read_zones();
+	sort_countries();
+	make_menus();
+
 	init_dialog(stdin, stdout);
 	if (skiputc == 0) {
 		DIALOG_VARS save_vars;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303031931.r23JViKf058027>