[Midnightbsd-cvs] src [10310] trunk/usr.sbin/tzsetup: update tzsetup
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 3 14:57:29 EDT 2018
Revision: 10310
http://svnweb.midnightbsd.org/src/?rev=10310
Author: laffer1
Date: 2018-06-03 14:57:28 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
update tzsetup
Modified Paths:
--------------
trunk/usr.sbin/tzsetup/Makefile
trunk/usr.sbin/tzsetup/tzsetup.8
trunk/usr.sbin/tzsetup/tzsetup.c
Modified: trunk/usr.sbin/tzsetup/Makefile
===================================================================
--- trunk/usr.sbin/tzsetup/Makefile 2018-06-03 18:56:55 UTC (rev 10309)
+++ trunk/usr.sbin/tzsetup/Makefile 2018-06-03 18:57:28 UTC (rev 10310)
@@ -1,13 +1,25 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/tzsetup/Makefile 322098 2017-08-05 14:49:40Z marius $
+.include <bsd.own.mk>
+
PROG= tzsetup
MAN= tzsetup.8
-CFLAGS+= -I${.CURDIR}/../../contrib/dialog -I.
+CFLAGS+= -I.
+.if ${MK_DIALOG} != no
WARNS?= 3
+CFLAGS+= -I${.CURDIR}/../../contrib/dialog -DHAVE_DIALOG
+DPADD= ${LIBDIALOG} ${LIBM}
+LDADD= -ldialog -lm
+.if ${MK_NCURSESW} == "no"
+DPADD+= ${LIBNCURSES}
+LDADD+= -lncurses
+.else
+DPADD+= ${LIBNCURSESW}
+LDADD+= -lncursesw
+.endif
+.endif
-DPADD= ${LIBDIALOG} ${LIBNCURSESW} ${LIBM}
-LDADD= -ldialog -lncursesw -lm
-
.include <bsd.prog.mk>
Modified: trunk/usr.sbin/tzsetup/tzsetup.8
===================================================================
--- trunk/usr.sbin/tzsetup/tzsetup.8 2018-06-03 18:56:55 UTC (rev 10309)
+++ trunk/usr.sbin/tzsetup/tzsetup.8 2018-06-03 18:57:28 UTC (rev 10310)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" Copyright (c) 1996 Wolfram Schneider <wosch at FreeBSD.org>. Berlin.
.\" All rights reserved.
.\"
@@ -22,9 +23,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/tzsetup/tzsetup.8 232297 2012-02-29 14:44:42Z emaste $
.\"
-.Dd September 13, 2014
+.Dd October 21, 2009
.Dt TZSETUP 8
.Os
.Sh NAME
Modified: trunk/usr.sbin/tzsetup/tzsetup.c
===================================================================
--- trunk/usr.sbin/tzsetup/tzsetup.c 2018-06-03 18:56:55 UTC (rev 10309)
+++ trunk/usr.sbin/tzsetup/tzsetup.c 2018-06-03 18:57:28 UTC (rev 10310)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright 1996 Massachusetts Institute of Technology
*
@@ -33,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/tzsetup/tzsetup.c 322376 2017-08-10 21:39:22Z marius $");
#include <err.h>
#include <errno.h>
@@ -47,8 +48,11 @@
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
+#ifdef HAVE_DIALOG
#include <dialog.h>
+#endif
#define _PATH_ZONETAB "/usr/share/zoneinfo/zone.tab"
#define _PATH_ISO3166 "/usr/share/misc/iso3166"
@@ -71,6 +75,19 @@
#define DITEM_LEAVE_MENU (1 << 16)
#define DITEM_RECREATE (1 << 18)
+static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
+ path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
+ path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
+
+static int reallydoit = 1;
+static int reinstall = 0;
+static char *chrootenv = NULL;
+
+static void usage(void);
+static int install_zoneinfo(const char *zoneinfo);
+static int install_zoneinfo_file(const char *zoneinfo_file);
+
+#ifdef HAVE_DIALOG
/* for use in describing more exotic behaviors */
typedef struct dialogMenuItem {
char *prompt;
@@ -91,7 +108,7 @@
rows++;
}
- return rows ? rows : 1;
+ return (rows ? rows : 1);
}
static int
@@ -108,7 +125,7 @@
len = strlen(p);
max_len = MAX(max_len, len);
- return max_len;
+ return (max_len);
}
static int
@@ -148,7 +165,8 @@
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);
@@ -183,22 +201,13 @@
free(listitems);
dlg_restore_vars(&save_vars);
- return result;
+ return (result);
}
-static char path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
- path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN],
- path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
-
-static int reallydoit = 1;
-static int reinstall = 0;
static int usedialog = 1;
-static char *chrootenv = NULL;
-static void usage(void);
static int confirm_zone(const char *filename);
static int continent_country_menu(dialogMenuItem *);
-static int install_zoneinfo_file(const char *zoneinfo_file);
static int set_zone_multi(dialogMenuItem *);
static int set_zone_whole_country(dialogMenuItem *);
static int set_zone_menu(dialogMenuItem *);
@@ -262,7 +271,7 @@
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)
@@ -343,7 +352,7 @@
err(1, "%s", path_iso3166);
lineno = 0;
- while ((s = fgetln(fp, &len)) != 0) {
+ while ((s = fgetln(fp, &len)) != NULL) {
lineno++;
if (s[len - 1] != '\n')
errx(1, "%s:%d: invalid format", path_iso3166, lineno);
@@ -353,7 +362,7 @@
/* Isolate the two-letter code. */
t = strsep(&s, "\t");
- if (t == 0 || strlen(t) != 2)
+ if (t == NULL || strlen(t) != 2)
errx(1, "%s:%d: invalid format", path_iso3166, lineno);
if (t[0] < 'A' || t[0] > 'Z' || t[1] < 'A' || t[1] > 'Z')
errx(1, "%s:%d: invalid code `%s'", path_iso3166,
@@ -361,10 +370,10 @@
/* Now skip past the three-letter and numeric codes. */
name = strsep(&s, "\t"); /* 3-let */
- if (name == 0 || strlen(name) != 3)
+ if (name == NULL || strlen(name) != 3)
errx(1, "%s:%d: invalid format", path_iso3166, lineno);
name = strsep(&s, "\t"); /* numeric */
- if (name == 0 || strlen(name) != 3)
+ if (name == NULL || strlen(name) != 3)
errx(1, "%s:%d: invalid format", path_iso3166, lineno);
name = s;
@@ -406,7 +415,7 @@
path_zonetab, lineno);
zp = malloc(sizeof(*zp));
- if (zp == 0)
+ if (zp == NULL)
errx(1, "malloc(%zu)", sizeof(*zp));
if (cp->nzones == 0)
@@ -474,7 +483,7 @@
FILE *fp;
struct continent *cont;
size_t len;
- char *line, *tlc, *coord, *file, *descr, *p;
+ char *line, *tlc, *file, *descr, *p;
int lineno;
fp = fopen(path_zonetab, "r");
@@ -482,7 +491,7 @@
err(1, "%s", path_zonetab);
lineno = 0;
- while ((line = fgetln(fp, &len)) != 0) {
+ while ((line = fgetln(fp, &len)) != NULL) {
lineno++;
if (line[len - 1] != '\n')
errx(1, "%s:%d: invalid format", path_zonetab, lineno);
@@ -494,10 +503,10 @@
if (strlen(tlc) != 2)
errx(1, "%s:%d: invalid country code `%s'",
path_zonetab, lineno, tlc);
- coord = strsep(&line, "\t"); /* Unused */
+ /* coord = */ strsep(&line, "\t"); /* Unused */
file = strsep(&line, "\t");
p = strchr(file, '/');
- if (p == 0)
+ if (p == NULL)
errx(1, "%s:%d: invalid zone name `%s'", path_zonetab,
lineno, file);
contbuf[0] = '\0';
@@ -557,7 +566,7 @@
continent_names[i].continent->menu =
malloc(sizeof(dialogMenuItem) *
continent_names[i].continent->nitems);
- if (continent_names[i].continent->menu == 0)
+ if (continent_names[i].continent->menu == NULL)
errx(1, "malloc for continent menu");
continent_names[i].continent->nitems = 0;
continents[i].prompt = continent_items[i].prompt;
@@ -632,16 +641,63 @@
return (DITEM_LEAVE_MENU);
}
-int
+static int
set_zone_utc(void)
{
- if (!confirm_zone(NULL))
+ if (!confirm_zone("UTC"))
return (DITEM_FAILURE | DITEM_RECREATE);
- return (install_zoneinfo_file(NULL));
+ return (install_zoneinfo("UTC"));
}
static int
+confirm_zone(const char *filename)
+{
+ char title[64], prompt[64];
+ time_t t = time(0);
+ struct tm *tm;
+ int rv;
+
+ setenv("TZ", filename, 1);
+ tzset();
+ tm = localtime(&t);
+
+ snprintf(title, sizeof(title), "Confirmation");
+ snprintf(prompt, sizeof(prompt),
+ "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
+ rv = !dialog_yesno(title, prompt, 5, 72);
+ return (rv);
+}
+
+static int
+set_zone_multi(dialogMenuItem *dmi)
+{
+ struct zone *zp = dmi->data;
+ int rv;
+
+ if (!confirm_zone(zp->filename))
+ return (DITEM_FAILURE | DITEM_RECREATE);
+
+ rv = install_zoneinfo(zp->filename);
+ return (rv);
+}
+
+static int
+set_zone_whole_country(dialogMenuItem *dmi)
+{
+ struct country *cp = dmi->data;
+ int rv;
+
+ if (!confirm_zone(cp->filename))
+ return (DITEM_FAILURE | DITEM_RECREATE);
+
+ rv = install_zoneinfo(cp->filename);
+ return (rv);
+}
+
+#endif
+
+static int
install_zoneinfo_file(const char *zoneinfo_file)
{
char buf[1024];
@@ -660,60 +716,22 @@
#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),
"Creating symbolic link %s to %s",
path_localtime, zoneinfo_file);
+#ifdef HAVE_DIALOG
if (usedialog)
dialog_msgbox(title, prompt, 8, 72, 1);
else
+#endif
fprintf(stderr, "%s\n", prompt);
#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));
- if (usedialog)
- dialog_msgbox(title, prompt, 8, 72, 1);
- else
- 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));
- if (usedialog)
- dialog_msgbox(title, prompt, 8, 72, 1);
- else
- 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);
- if (usedialog)
- dialog_msgbox(title, prompt, 8, 72, 1);
- else
- fprintf(stderr, "%s\n", prompt);
-#endif
- return (DITEM_LEAVE_MENU);
- }
-
if (copymode) {
fd1 = open(zoneinfo_file, O_RDONLY, 0);
if (fd1 < 0) {
@@ -721,9 +739,11 @@
snprintf(prompt, sizeof(prompt),
"Could not open %s: %s", zoneinfo_file,
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);
}
@@ -730,12 +750,14 @@
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) {
snprintf(title, sizeof(title), "Error");
dialog_msgbox(title, prompt, 8, 72, 1);
} else
+#endif
fprintf(stderr, "%s\n", prompt);
return (DITEM_FAILURE | DITEM_RECREATE);
}
@@ -747,9 +769,11 @@
snprintf(prompt, sizeof(prompt),
"Could not open %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);
}
@@ -763,9 +787,11 @@
snprintf(prompt, sizeof(prompt),
"Error copying %s to %s %s", zoneinfo_file,
path_localtime, strerror(errno));
+#ifdef HAVE_DIALOG
if (usedialog)
dialog_msgbox(title, prompt, 8, 72, 1);
else
+#endif
fprintf(stderr, "%s\n", prompt);
/* Better to leave none than a corrupt one. */
unlink(path_localtime);
@@ -779,20 +805,24 @@
snprintf(prompt, sizeof(prompt),
"Cannot access %s: %s", zoneinfo_file,
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_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) {
snprintf(title, sizeof(title), "Error");
dialog_msgbox(title, prompt, 8, 72, 1);
} else
+#endif
fprintf(stderr, "%s\n", prompt);
return (DITEM_FAILURE | DITEM_RECREATE);
}
@@ -802,9 +832,11 @@
"Cannot create symbolic link %s to %s: %s",
path_localtime, zoneinfo_file,
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);
}
@@ -820,9 +852,11 @@
snprintf(prompt, sizeof(prompt),
"Created symbolic link from %s to %s",
zoneinfo_file, path_localtime);
+#ifdef HAVE_DIALOG
if (usedialog)
dialog_msgbox(title, prompt, 8, 72, 1);
else
+#endif
fprintf(stderr, "%s\n", prompt);
#endif
} /* reallydoit */
@@ -837,7 +871,9 @@
FILE *f;
char path_zoneinfo_file[MAXPATHLEN];
- sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo);
+ 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);
rv = install_zoneinfo_file(path_zoneinfo_file);
/* Save knowledge for later */
@@ -851,51 +887,6 @@
return (rv);
}
-static int
-confirm_zone(const char *filename)
-{
- char title[64], prompt[64];
- time_t t = time(0);
- struct tm *tm;
- int rv;
-
- setenv("TZ", filename == NULL ? "" : filename, 1);
- tzset();
- tm = localtime(&t);
-
- snprintf(title, sizeof(title), "Confirmation");
- snprintf(prompt, sizeof(prompt),
- "Does the abbreviation `%s' look reasonable?", tm->tm_zone);
- rv = !dialog_yesno(title, prompt, 5, 72);
- return (rv);
-}
-
-static int
-set_zone_multi(dialogMenuItem *dmi)
-{
- struct zone *zp = dmi->data;
- int rv;
-
- if (!confirm_zone(zp->filename))
- return (DITEM_FAILURE | DITEM_RECREATE);
-
- rv = install_zoneinfo(zp->filename);
- return (rv);
-}
-
-static int
-set_zone_whole_country(dialogMenuItem *dmi)
-{
- struct country *cp = dmi->data;
- int rv;
-
- if (!confirm_zone(cp->filename))
- return (DITEM_FAILURE | DITEM_RECREATE);
-
- rv = install_zoneinfo(cp->filename);
- return (rv);
-}
-
static void
usage(void)
{
@@ -908,10 +899,21 @@
int
main(int argc, char **argv)
{
+#ifdef HAVE_DIALOG
char title[64], prompt[128];
- int c, fd, rv, skiputc;
+ int fd;
+#endif
+ int c, rv, skiputc;
+ char vm_guest[16] = "";
+ size_t len = sizeof(vm_guest);
skiputc = 0;
+
+ /* Default skiputc to 1 for VM guests */
+ if (sysctlbyname("kern.vm_guest", vm_guest, &len, NULL, 0) == 0 &&
+ strcmp(vm_guest, "none") != 0)
+ skiputc = 1;
+
while ((c = getopt(argc, argv, "C:nrs")) != -1) {
switch(c) {
case 'C':
@@ -922,7 +924,9 @@
break;
case 'r':
reinstall = 1;
+#ifdef HAVE_DIALOG
usedialog = 0;
+#endif
break;
case 's':
skiputc = 1;
@@ -952,7 +956,6 @@
_PATH_WALL_CMOS_CLOCK);
}
-
/* Override the user-supplied umask. */
(void)umask(S_IWGRP | S_IWOTH);
@@ -986,12 +989,15 @@
struct stat sb;
if (stat(argv[optind], &sb) != 0) {
+#ifdef HAVE_DIALOG
usedialog = 0;
+#endif
rv = install_zoneinfo(argv[optind]);
exit(rv & ~DITEM_LEAVE_MENU);
}
/* FALLTHROUGH */
}
+#ifdef HAVE_DIALOG
read_iso3166_table();
read_zones();
@@ -1052,5 +1058,8 @@
dlg_clear();
end_dialog();
+#else
+ usage();
+#endif
return (0);
}
More information about the Midnightbsd-cvs
mailing list