From owner-freebsd-bugs@FreeBSD.ORG Thu Jan 12 05:30:12 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D96B71065676 for ; Thu, 12 Jan 2012 05:30:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A88458FC16 for ; Thu, 12 Jan 2012 05:30:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q0C5UBUu000922 for ; Thu, 12 Jan 2012 05:30:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q0C5UBLu000921; Thu, 12 Jan 2012 05:30:11 GMT (envelope-from gnats) Resent-Date: Thu, 12 Jan 2012 05:30:11 GMT Resent-Message-Id: <201201120530.q0C5UBLu000921@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Devin Teske Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B1CB106566C for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/164041: [PATCH] tzsetup(8): Remove unnecessary code duplication and clean-up reinstall option X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jan 2012 05:30:12 -0000 >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: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jan 12 05:30:11 UTC 2012 >Closed-Date: >Last-Modified: >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: >Unformatted: