From nobody@FreeBSD.org  Thu Jan 12 05:26:46 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5B1CB106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 05:26:46 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 2B1B58FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 05:26:46 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0C5QjuA030983
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 05:26:45 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0C5QjB3030982;
	Thu, 12 Jan 2012 05:26:45 GMT
	(envelope-from nobody)
Message-Id: <201201120526.q0C5QjB3030982@red.freebsd.org>
Date: Thu, 12 Jan 2012 05:26:45 GMT
From: Devin Teske <dteske@vicor.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] tzsetup(8): Remove unnecessary code duplication and clean-up reinstall option
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164041
>Category:       bin
>Synopsis:       [PATCH] tzsetup(8): Remove unnecessary code duplication and clean-up reinstall option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dteske
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 12 05:30:11 UTC 2012
>Closed-Date:    Mon Mar 04 11:19:56 UTC 2013
>Last-Modified:  Mon Mar 04 11:19:56 UTC 2013
>Originator:     Devin Teske
>Release:        FreeBSD 9.0-RELEASE amd64
>Organization:
FIS Global, Inc.
>Environment:
FreeBSD scribe.vicor.com 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2010
root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
This makes some code-cleanups to the "reinstall" option added in SVN r198267.

Most notably, it moves the reinstall logic to be before the initialization of the menus (as the menus are not needed in reinstalling a zonefile).

Additionally, remove unnecessary re-initialization of path_db.

Further, since SVN r198350, the logic would be clearer if "zoneinfo" is used instead of "zonefile" as the contents no longer contain a path to a file but the name of a zone relative to /usr/share/zoneinfo.
>How-To-Repeat:

>Fix:
See attached patch.txt

Patch attached with submission follows:

--- usr.sbin/tzsetup/tzsetup.c.orig	Fri Dec  2 11:19:10 2011
+++ usr.sbin/tzsetup/tzsetup.c	Wed Jan 11 20:07:00 2012
@@ -914,32 +914,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);
@@ -947,7 +931,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);
 	}
@@ -966,6 +950,11 @@ main(int argc, char **argv)
 		}
 		/* FALLTHROUGH */
 	}
+
+	read_iso3166_table();
+	read_zones();
+	sort_countries();
+	make_menus();
 
 	init_dialog(stdin, stdout);
 	if (skiputc == 0) {


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: emaste 
State-Changed-When: Wed Jan 25 02:15:56 UTC 2012 
State-Changed-Why:  
Committed as r230520. 


Responsible-Changed-From-To: freebsd-bugs->emaste 
Responsible-Changed-By: emaste 
Responsible-Changed-When: Wed Jan 25 02:15:56 UTC 2012 
Responsible-Changed-Why:  
Grab. 
aNATS: Lines beginning with "GNATS:" will be deleted. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164041 
Responsible-Changed-From-To: emaste->dteske 
Responsible-Changed-By: emaste 
Responsible-Changed-When: Mon Apr 9 13:21:53 UTC 2012 
Responsible-Changed-Why:  
Submitter is becoming a committer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164041 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/164041: commit references a PR
Date: Sun,  3 Mar 2013 19:31:56 +0000 (UTC)

 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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: dteske 
State-Changed-When: Mon Mar 4 11:18:49 UTC 2013 
State-Changed-Why:  
MFC'd to stable/9 with r247729 and stable/8 with r247749 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164041 
>Unformatted:
