summaryrefslogtreecommitdiffstats
path: root/term-utils/setterm.c
diff options
context:
space:
mode:
authorSami Kerola2014-05-18 12:32:04 +0200
committerSami Kerola2014-05-19 23:45:38 +0200
commit609d48534a1602ea568f218c6740ca171ec71efb (patch)
tree777cecf4fa7c10594367e6fd72a51d1fa2df81bf /term-utils/setterm.c
parentsetterm: clean up screendump() (diff)
downloadkernel-qcow2-util-linux-609d48534a1602ea568f218c6740ca171ec71efb.tar.gz
kernel-qcow2-util-linux-609d48534a1602ea568f218c6740ca171ec71efb.tar.xz
kernel-qcow2-util-linux-609d48534a1602ea568f218c6740ca171ec71efb.zip
setterm: remove devfs and /dev/vcsa0 support
The devfs files /dev/vcc/a* does not need to be supported, and vcsa0 has not existed in years if ever. Reference: http://lwn.net/Articles/65197/ Reference: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devices.txt?id=14186fea0cb06bc43181ce239efe0df6f1af260a#n260 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/setterm.c')
-rw-r--r--term-utils/setterm.c37
1 files changed, 10 insertions, 27 deletions
diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 76c43675c..0858a7612 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -713,35 +713,17 @@ static void show_tabs(void)
}
}
-static void __attribute__((__noreturn__)) read_error(struct setterm_control *ctl)
-{
- if (ctl->opt_sn_num != 0)
- errx(EXIT_DUMPFILE, _("Couldn't read %s"), ctl->in_device);
- else
- errx(EXIT_DUMPFILE, _("Couldn't read neither /dev/vcsa0 nor /dev/vcsa"));
-}
-
static int open_snapshot_device(struct setterm_control *ctl)
{
- char infile[MAXPATHLEN];
int fd;
- sprintf(infile, "/dev/vcsa%d", ctl->opt_sn_num);
- fd = open(infile, O_RDONLY);
- if (fd < 0 && ctl->opt_sn_num == 0) {
- /* vcsa0 is often called vcsa */
- sprintf(infile, "/dev/vcsa");
- fd = open(infile, O_RDONLY);
- }
- if (fd < 0) {
- /* try devfs name - for zero ctl->opt_sn_num just /dev/vcc/a */
- /* some gcc's warn for %.u - add 0 */
- sprintf(infile, "/dev/vcc/a%.0u", ctl->opt_sn_num);
- fd = open(infile, O_RDONLY);
- }
- ctl->in_device = infile;
+ if (ctl->opt_sn_num)
+ xasprintf(&ctl->in_device, "/dev/vcsa%d", ctl->opt_sn_num);
+ else
+ xasprintf(&ctl->in_device, "/dev/vcsa");
+ fd = open(ctl->in_device, O_RDONLY);
if (fd < 0)
- read_error(ctl);
+ err(EXIT_DUMPFILE, _("Couldn't read %s"), ctl->in_device);
return fd;
}
@@ -765,18 +747,18 @@ static void screendump(struct setterm_control *ctl)
err(EXIT_DUMPFILE, _("can not open dump file %s for output"), ctl->opt_sn_name);
/* determine snapshot size */
if (read(fd, header, 4) != 4)
- read_error(ctl);
+ err(EXIT_DUMPFILE, _("Couldn't read %s"), ctl->in_device);
rows = header[0];
cols = header[1];
if (rows * cols == 0)
- read_error(ctl);
+ err(EXIT_DUMPFILE, _("Couldn't read %s"), ctl->in_device);
/* allocate buffers */
inbuf = xmalloc(rows * cols * 2);
outbuf = xmalloc(rows * (cols + 1));
/* read input */
rc = read(fd, inbuf, rows * cols * 2);
if (rc < 0 || (size_t)rc != rows * cols * 2)
- read_error(ctl);
+ err(EXIT_DUMPFILE, _("Couldn't read %s"), ctl->in_device);
p = inbuf;
q = outbuf;
/* copy inbuf to outbuf */
@@ -794,6 +776,7 @@ static void screendump(struct setterm_control *ctl)
close(fd);
free(inbuf);
free(outbuf);
+ free(ctl->in_device);
if (close_stream(out) != 0)
errx(EXIT_FAILURE, _("write error"));
return;