summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2015-11-26 06:59:13 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2015-11-26 06:59:13 +0000
commita52d6a761b9afede5aea89b653e09803ab276862 (patch)
tree004ff56066876afa00ccf1dfb58967c8fe29883a
parent4b81d7002cc5258a1d5f1c08ab04f9b0908c512c (diff)
Instead, hoist TIOCGWINSZ up to the top, then "tty" pledge is not needed.
-rw-r--r--sbin/newfs_ext2fs/mke2fs.c12
-rw-r--r--sbin/newfs_ext2fs/newfs_ext2fs.c10
2 files changed, 13 insertions, 9 deletions
diff --git a/sbin/newfs_ext2fs/mke2fs.c b/sbin/newfs_ext2fs/mke2fs.c
index fb49bed59af..1a83472f4f8 100644
--- a/sbin/newfs_ext2fs/mke2fs.c
+++ b/sbin/newfs_ext2fs/mke2fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mke2fs.c,v 1.13 2015/01/16 06:40:00 deraadt Exp $ */
+/* $OpenBSD: mke2fs.c,v 1.14 2015/11/26 06:59:12 deraadt Exp $ */
/* $NetBSD: mke2fs.c,v 1.13 2009/10/19 18:41:08 bouyer Exp $ */
/*-
@@ -176,6 +176,8 @@ static uint8_t buf[MAXBSIZE]; /* for initcg() and makedir() ops */
static int fsi, fso;
+extern int max_cols;
+
void
mke2fs(const char *fsys, int fi, int fo)
{
@@ -185,8 +187,7 @@ mke2fs(const char *fsys, int fi, int fo)
uint blocks_gd, blocks_per_cg, inodes_per_cg, iblocks_per_cg;
uint minblocks_per_cg, blocks_lastcg;
uint ncg, cylno, sboff;
- int i, len, col, delta, fld_width, max_cols;
- struct winsize winsize;
+ int i, len, col, delta, fld_width;
gettimeofday(&tv, NULL);
fsi = fi;
@@ -577,11 +578,6 @@ mke2fs(const char *fsys, int fi, int fo)
/* If we are printing more than one line of numbers, line up columns */
fld_width = verbosity < 4 ? 1 : snprintf(NULL, 0, "%" PRIu64,
(uint64_t)cgbase(&sblock, ncg - 1));
- /* Get terminal width */
- if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) == 0)
- max_cols = winsize.ws_col;
- else
- max_cols = 80;
if (Nflag && verbosity == 3)
/* Leave space to add " ..." after one row of numbers */
max_cols -= 4;
diff --git a/sbin/newfs_ext2fs/newfs_ext2fs.c b/sbin/newfs_ext2fs/newfs_ext2fs.c
index 1dd26233d3c..cfd5c673fd4 100644
--- a/sbin/newfs_ext2fs/newfs_ext2fs.c
+++ b/sbin/newfs_ext2fs/newfs_ext2fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs_ext2fs.c,v 1.19 2015/11/26 06:45:08 deraadt Exp $ */
+/* $OpenBSD: newfs_ext2fs.c,v 1.20 2015/11/26 06:59:12 deraadt Exp $ */
/* $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */
/*
@@ -101,6 +101,7 @@ uint bsize = 0; /* block size */
uint minfree = MINFREE; /* free space threshold */
uint density; /* number of bytes per inode */
uint num_inodes; /* number of inodes (overrides density) */
+int max_cols;
char *volname = NULL; /* volume name */
static char *disktype = NULL;
@@ -121,6 +122,13 @@ main(int argc, char *argv[])
uint blocks; /* number of blocks */
struct partition *pp = NULL;
struct disklabel *lp;
+ struct winsize winsize;
+
+ /* Get terminal width */
+ if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) == 0)
+ max_cols = winsize.ws_col;
+ else
+ max_cols = 80;
if (pledge("stdio rpath wpath tty disklabel", NULL) == -1)
err(1, "pledge");