svn commit: r322097 - head/usr.sbin/tzsetup

Marius Strobl marius at FreeBSD.org
Sat Aug 5 12:59:04 UTC 2017


Author: marius
Date: Sat Aug  5 12:59:03 2017
New Revision: 322097
URL: https://svnweb.freebsd.org/changeset/base/322097

Log:
  - Move creation and unlinking of /etc/wall_cmos_clock from the handling
    of the initial UTC dialog to install_zoneinfo() so that file gets the
    necessary treatment also when that dialog is skipped via "-s", when
    selecting UTC from the time zone menu or on the command-line instead
    etc.
  - Make the initial UTC dialog actually work by giving the relevant files
    the necessary treatment and then exit when choosing "Yes" there instead
    of moving on to the time zone menu regardless.
  - Since r301131, /etc/localtime is also installed when selecting UTC in
    interactive configurations (which previously meant only via the time
    zone menu, though). Thus, the code added in r230298 which treats a
    NULL zone file name as UTC and removes /etc/localtime in that case can
    go again.
  - Consistently refer to "could not delete" (as chosen by the oldest such
    code in here) when unlink(2) fails instead of a to mixture of "delete"
    and "unlink" in error messages.

Modified:
  head/usr.sbin/tzsetup/tzsetup.c

Modified: head/usr.sbin/tzsetup/tzsetup.c
==============================================================================
--- head/usr.sbin/tzsetup/tzsetup.c	Sat Aug  5 12:54:07 2017	(r322096)
+++ head/usr.sbin/tzsetup/tzsetup.c	Sat Aug  5 12:59:03 2017	(r322097)
@@ -107,7 +107,7 @@ xdialog_count_rows(const char *p)
 		rows++;
 	}
 
-	return rows ? rows : 1;
+	return (rows ? rows : 1);
 }
 
 static int
@@ -124,7 +124,7 @@ xdialog_count_columns(const char *p)
 
 	len = strlen(p);
 	max_len = MAX(max_len, len);
-	return max_len;
+	return (max_len);
 }
 
 static int
@@ -164,7 +164,8 @@ xdialog_menu(const char *title, const char *cprompt, i
 				tag_x = MAX(tag_x, l + k + 2);
 			}
 		}
-		width = MAX(xdialog_count_columns(cprompt), title != NULL ? xdialog_count_columns(title) : 0);
+		width = MAX(xdialog_count_columns(cprompt), title != NULL ?
+		    xdialog_count_columns(title) : 0);
 		width = MAX(width, tag_x + 4) + 4;
 	}
 	width = MAX(width, 24);
@@ -199,7 +200,7 @@ again:
 
 	free(listitems);
 	dlg_restore_vars(&save_vars);
-	return result;
+	return (result);
 }
 
 static int usedialog = 1;
@@ -269,7 +270,7 @@ continent_country_menu(dialogMenuItem *continent)
 	int		rv;
 
 	if (strcmp(continent->title, "UTC") == 0)
-	        return set_zone_utc();
+		return (set_zone_utc());
 
 	/* Short cut -- if there's only one country, don't post a menu. */
 	if (contp->nitems == 1)
@@ -642,7 +643,7 @@ set_zone_menu(dialogMenuItem *dmi)
 static int
 set_zone_utc(void)
 {
-	if (!confirm_zone(NULL))
+	if (!confirm_zone("UTC"))
 		return (DITEM_FAILURE | DITEM_RECREATE);
 
 	return (install_zoneinfo("UTC"));
@@ -656,7 +657,7 @@ confirm_zone(const char *filename)
 	struct tm	*tm;
 	int		rv;
 
-	setenv("TZ", filename == NULL ? "" : filename, 1);
+	setenv("TZ", filename, 1);
 	tzset();
 	tm = localtime(&t);
 
@@ -714,11 +715,8 @@ install_zoneinfo_file(const char *zoneinfo_file)
 
 #ifdef VERBOSE
 	snprintf(title, sizeof(title), "Info");
-	if (zoneinfo_file == NULL)
+	if (copymode)
 		snprintf(prompt, sizeof(prompt),
-		    "Removing %s", path_localtime);
-	else if (copymode)
-		snprintf(prompt, sizeof(prompt),
 		    "Copying %s to %s", zoneinfo_file, path_localtime);
 	else
 		snprintf(prompt, sizeof(prompt),
@@ -733,49 +731,6 @@ install_zoneinfo_file(const char *zoneinfo_file)
 #endif
 
 	if (reallydoit) {
-		if (zoneinfo_file == NULL) {
-			if (unlink(path_localtime) < 0 && errno != ENOENT) {
-				snprintf(title, sizeof(title), "Error");
-				snprintf(prompt, sizeof(prompt),
-				     "Could not delete %s: %s", path_localtime,
-				     strerror(errno));
-#ifdef HAVE_DIALOG
-				if (usedialog)
-					dialog_msgbox(title, prompt, 8, 72, 1);
-				else
-#endif
-					fprintf(stderr, "%s\n", prompt);
-
-				return (DITEM_FAILURE | DITEM_RECREATE);
-			}
-			if (unlink(path_db) < 0 && errno != ENOENT) {
-				snprintf(title, sizeof(title), "Error");
-				snprintf(prompt, sizeof(prompt),
-				     "Could not delete %s: %s", path_db,
-				     strerror(errno));
-#ifdef HAVE_DIALOG
-				if (usedialog)
-					dialog_msgbox(title, prompt, 8, 72, 1);
-				else
-#endif
-					fprintf(stderr, "%s\n", prompt);
-
-				return (DITEM_FAILURE | DITEM_RECREATE);
-			}
-#ifdef VERBOSE
-			snprintf(title, sizeof(title), "Done");
-			snprintf(prompt, sizeof(prompt),
-			    "Removed %s", path_localtime);
-#ifdef HAVE_DIALOG
-			if (usedialog)
-				dialog_msgbox(title, prompt, 8, 72, 1);
-			else
-#endif
-				fprintf(stderr, "%s\n", prompt);
-#endif
-			return (DITEM_LEAVE_MENU);
-		}
-
 		if (copymode) {
 			fd1 = open(zoneinfo_file, O_RDONLY, 0);
 			if (fd1 < 0) {
@@ -794,7 +749,7 @@ install_zoneinfo_file(const char *zoneinfo_file)
 
 			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 				snprintf(prompt, sizeof(prompt),
-				    "Could not unlink %s: %s",
+				    "Could not delete %s: %s",
 				    path_localtime, strerror(errno));
 #ifdef HAVE_DIALOG
 				if (usedialog) {
@@ -859,7 +814,7 @@ install_zoneinfo_file(const char *zoneinfo_file)
 			}
 			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 				snprintf(prompt, sizeof(prompt),
-				    "Could not unlink %s: %s",
+				    "Could not delete %s: %s",
 				    path_localtime, strerror(errno));
 #ifdef HAVE_DIALOG
 				if (usedialog) {
@@ -911,10 +866,48 @@ install_zoneinfo_file(const char *zoneinfo_file)
 static int
 install_zoneinfo(const char *zoneinfo)
 {
-	int		rv;
+	int		fd, rv;
 	FILE		*f;
 	char		path_zoneinfo_file[MAXPATHLEN];
+	char		prompt[SILLY_BUFFER_SIZE], title[64];
 
+	if (reallydoit) {
+		if (strcmp(zoneinfo, "UTC") == 0) {
+			if (unlink(path_wall_cmos_clock) < 0 &&
+			    errno != ENOENT) {
+				snprintf(title, sizeof(title), "Error");
+				snprintf(prompt, sizeof(prompt),
+				    "Could not delete %s: %s",
+				    path_wall_cmos_clock, strerror(errno));
+#ifdef HAVE_DIALOG
+				if (usedialog)
+					dialog_msgbox(title, prompt, 8, 72, 1);
+				else
+#endif
+					fprintf(stderr, "%s\n", prompt);
+
+				return (DITEM_FAILURE | DITEM_RECREATE);
+			}
+		} else {
+			fd = open(path_wall_cmos_clock, O_WRONLY | O_CREAT |
+			    O_TRUNC, S_IRUSR | S_IRGRP | S_IROTH);
+			if (fd < 0) {
+				snprintf(title, sizeof(title), "Error");
+				snprintf(prompt, sizeof(prompt),
+				    "Could not create %s: %s",
+				    path_wall_cmos_clock, strerror(errno));
+#ifdef HAVE_DIALOG
+				if (usedialog)
+					dialog_msgbox(title, prompt, 8, 72, 1);
+				else
+#endif
+					fprintf(stderr, "%s\n", prompt);
+				return (DITEM_FAILURE | DITEM_RECREATE);
+			}
+			close(fd);
+		}
+	}
+
 	if ((size_t)snprintf(path_zoneinfo_file, sizeof(path_zoneinfo_file),
 	    "%s/%s", path_zoneinfo, zoneinfo) >= sizeof(path_zoneinfo_file))
 		errx(1, "%s/%s name too long", path_zoneinfo, zoneinfo);
@@ -945,7 +938,6 @@ main(int argc, char **argv)
 {
 #ifdef HAVE_DIALOG
 	char		title[64], prompt[128];
-	int		fd;
 #endif
 	int		c, rv, skiputc;
 	char		vm_guest[16] = "";
@@ -1067,19 +1059,11 @@ main(int argc, char **argv)
 		yesno = dialog_yesno(title, prompt, 7, 73);
 		dlg_restore_vars(&save_vars);
 		if (!yesno) {
-			if (reallydoit)
-				unlink(path_wall_cmos_clock);
-		} else {
 			if (reallydoit) {
-				fd = open(path_wall_cmos_clock,
-				    O_WRONLY | O_CREAT | O_TRUNC,
-				    S_IRUSR | S_IRGRP | S_IROTH);
-				if (fd < 0) {
-					end_dialog();
-					err(1, "create %s",
-					    path_wall_cmos_clock);
-				}
-				close(fd);
+				rv = install_zoneinfo("UTC");
+				dlg_clear();
+				end_dialog();
+				exit(rv & ~DITEM_LEAVE_MENU);
 			}
 		}
 		dlg_clear();


More information about the svn-src-all mailing list