diff options
author | David Cantrell <dcantrell@redhat.com> | 2009-09-04 15:18:55 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2009-09-17 13:40:46 -1000 |
commit | a1f43eb57e2bbc789ce84e4f2b8f68a8085fdc52 (patch) | |
tree | f42ef4f5e9ffc2b86251092c7886cbf62f36b98a | |
parent | ac36231c529ab291f9bdddda05d3438a5a81f870 (diff) | |
download | anaconda-a1f43eb57e2bbc789ce84e4f2b8f68a8085fdc52.tar.gz anaconda-a1f43eb57e2bbc789ce84e4f2b8f68a8085fdc52.tar.xz anaconda-a1f43eb57e2bbc789ce84e4f2b8f68a8085fdc52.zip |
Catch failures from write(2) in utils/snarffont.c
Remove the die() function and replace with calls to fprintf() and return
EXIT_FAILURE. Catch write(2) failures as well instead of just ignoring
them.
-rw-r--r-- | utils/snarffont.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/utils/snarffont.c b/utils/snarffont.c index 1d8bce7c3..49bad6e51 100644 --- a/utils/snarffont.c +++ b/utils/snarffont.c @@ -25,12 +25,7 @@ #include <stdlib.h> #include <unistd.h> -void die(char * mess) { - perror(mess); - exit(1); -} - -#define MAXFONTSIZE 65536 +#define MAXFONTSIZE 65536 int main(void) { unsigned char buf[MAXFONTSIZE]; @@ -38,10 +33,12 @@ int main(void) { unsigned short map[E_TABSZ]; struct unipair descs[2048]; struct unimapdesc d; - int fd, i; + int fd; - if ((fd = open("/dev/tty0", O_RDONLY)) < 0) - die("open"); + if ((fd = open("/dev/tty0", O_RDONLY)) < 0) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } cfo.op = KD_FONT_OP_GET; cfo.flags = 0; @@ -49,21 +46,52 @@ int main(void) { cfo.height = 16; cfo.charcount = 512; cfo.data = buf; - if (ioctl(fd, KDFONTOP, &cfo)) - die("KDFONTOP KD_FONT_OP_GET"); + if (ioctl(fd, KDFONTOP, &cfo)) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } - if (ioctl(fd, GIO_UNISCRNMAP, map)) - die("GIO_UNISCRNMAP"); + if (ioctl(fd, GIO_UNISCRNMAP, map)) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } d.entry_ct = 2048; d.entries = descs; - if (ioctl(fd, GIO_UNIMAP, &d)) - die("GIO_UNIMAP"); + if (ioctl(fd, GIO_UNIMAP, &d)) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, &cfo, sizeof(cfo)) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, &cfo, sizeof(cfo)) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, buf, sizeof(buf)) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, map, sizeof(map)) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, &d.entry_ct, sizeof(d.entry_ct)) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } + + if (write(1, descs, d.entry_ct * sizeof(descs[0])) == -1) { + fprintf(stderr, "%s: %m", __func__); + return EXIT_FAILURE; + } - i = write(1, &cfo, sizeof(cfo)); - i = write(1, buf, sizeof(buf)); - i = write(1, map, sizeof(map)); - i = write(1, &d.entry_ct, sizeof(d.entry_ct)); - i = write(1, descs, d.entry_ct * sizeof(descs[0])); return 0; } |