svn commit: r247721 - stable/9/usr.sbin/tzsetup

Devin Teske dteske at FreeBSD.org
Sun Mar 3 17:39:30 UTC 2013


Author: dteske
Date: Sun Mar  3 17:39:29 2013
New Revision: 247721
URL: http://svnweb.freebsd.org/changeset/base/247721

Log:
  MFC r230005:
  
  Use a reasonable-sized buffer when formatting error messages about
  installing zoneinfo.  While we're in the vicinity, add some missing
  error checking to eliminate an unhelpful error message when unlink()
  fails.
  
  /me is embarrassed by the quality of his 16-year-old code.
  The whole thing is awful and could stand a complete rewrite.
  
  PR:		164038
  Submitted by:	Devin Teske (but implemented differently)

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 17:33:59 2013	(r247720)
+++ stable/9/usr.sbin/tzsetup/tzsetup.c	Sun Mar  3 17:39:29 2013	(r247721)
@@ -56,6 +56,13 @@ __FBSDID("$FreeBSD$");
 #define	_PATH_DB		"/var/db/zoneinfo"
 #define	_PATH_WALL_CMOS_CLOCK	"/etc/wall_cmos_clock"
 
+#ifdef PATH_MAX
+#define	SILLY_BUFFER_SIZE	2*PATH_MAX
+#else
+#warning "Somebody needs to fix this to dynamically size this buffer."
+#define	SILLY_BUFFER_SIZE	2048
+#endif
+
 static char	path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
 		path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN], 
 		path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
@@ -523,7 +530,7 @@ static int
 install_zoneinfo_file(const char *zoneinfo_file)
 {
 	char		buf[1024];
-	char		title[64], prompt[64];
+	char		title[64], prompt[SILLY_BUFFER_SIZE];
 	struct stat	sb;
 	ssize_t		len;
 	int		fd1, fd2, copymode;
@@ -594,7 +601,18 @@ install_zoneinfo_file(const char *zonein
 				return (DITEM_FAILURE | DITEM_RECREATE);
 			}
 
-			unlink(path_localtime);
+			if (unlink(path_localtime) < 0 && errno != ENOENT) {
+				snprintf(prompt, sizeof(prompt),
+				    "Could not unlink %s: %s",
+				    path_localtime, strerror(errno));
+				if (usedialog) {
+					snprintf(title, sizeof(title), "Error");
+					dialog_msgbox(title, prompt, 8, 72, 1);
+				} else
+					fprintf(stderr, "%s\n", prompt);
+				return (DITEM_FAILURE | DITEM_RECREATE);
+			}
+
 			fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
 			    S_IRUSR | S_IRGRP | S_IROTH);
 			if (fd2 < 0) {
@@ -640,7 +658,17 @@ install_zoneinfo_file(const char *zonein
 					fprintf(stderr, "%s\n", prompt);
 				return (DITEM_FAILURE | DITEM_RECREATE);
 			}
-			unlink(path_localtime);
+			if (unlink(path_localtime) < 0 && errno != ENOENT) {
+				snprintf(prompt, sizeof(prompt),
+				    "Could not unlink %s: %s",
+				    path_localtime, strerror(errno));
+				if (usedialog) {
+					snprintf(title, sizeof(title), "Error");
+					dialog_msgbox(title, prompt, 8, 72, 1);
+				} else
+					fprintf(stderr, "%s\n", prompt);
+				return (DITEM_FAILURE | DITEM_RECREATE);
+			}
 			if (symlink(zoneinfo_file, path_localtime) < 0) {
 				snprintf(title, sizeof(title), "Error");
 				snprintf(prompt, sizeof(prompt),


More information about the svn-src-stable-9 mailing list