Commit 21fc74ec authored by Alexey Gladkov's avatar Alexey Gladkov

Check the return code of getfd

Signed-off-by: default avatarAlexey Gladkov <gladkov.alexey@gmail.com>
parent eadc5ff5
...@@ -33,7 +33,9 @@ main(int argc, char *argv[]) { ...@@ -33,7 +33,9 @@ main(int argc, char *argv[]) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
num = atoi(argv[1]); num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) { if (ioctl(fd,VT_ACTIVATE,num)) {
......
...@@ -26,7 +26,8 @@ main(int argc, char *argv[]) { ...@@ -26,7 +26,8 @@ main(int argc, char *argv[]) {
if (argc >= 3 && !strcmp(argv[1], "-C")) if (argc >= 3 && !strcmp(argv[1], "-C"))
console = argv[2]; console = argv[2];
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
return loadunimap (fd, NULL, NULL); return loadunimap (fd, NULL, NULL);
} }
...@@ -39,7 +39,8 @@ main(int argc, char *argv[]) { ...@@ -39,7 +39,8 @@ main(int argc, char *argv[]) {
} }
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (argc == 1) { if (argc == 1) {
/* deallocate all unused consoles */ /* deallocate all unused consoles */
...@@ -57,5 +58,5 @@ main(int argc, char *argv[]) { ...@@ -57,5 +58,5 @@ main(int argc, char *argv[]) {
"ioctl VT_DISALLOCATE"), num); "ioctl VT_DISALLOCATE"), num);
} }
} }
exit(0); exit(EXIT_SUCCESS);
} }
...@@ -152,7 +152,8 @@ main (int argc, char *argv[]) { ...@@ -152,7 +152,8 @@ main (int argc, char *argv[]) {
if (optind < argc) if (optind < argc)
usage(); usage();
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
/* check whether the keyboard is in Unicode mode */ /* check whether the keyboard is in Unicode mode */
if (ioctl(fd, KDGKBMODE, &kbd_mode)) { if (ioctl(fd, KDGKBMODE, &kbd_mode)) {
......
...@@ -64,7 +64,9 @@ main(int argc, char **argv){ ...@@ -64,7 +64,9 @@ main(int argc, char **argv){
} }
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (show_vt) { if (show_vt) {
if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) { if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
kbd_error(2, errno, _("Couldn't read VTNO: ")); kbd_error(2, errno, _("Couldn't read VTNO: "));
......
...@@ -39,7 +39,9 @@ main(int argc, char **argv) { ...@@ -39,7 +39,9 @@ main(int argc, char **argv) {
if (argc != 1) if (argc != 1)
usage(); usage();
fd = getfd(NULL);
if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
/* Old kernels don't support changing scancodes below SC_LIM. */ /* Old kernels don't support changing scancodes below SC_LIM. */
a.scancode = 0; a.scancode = 0;
......
...@@ -67,7 +67,9 @@ main(int argc, char **argv){ ...@@ -67,7 +67,9 @@ main(int argc, char **argv){
if (optind < argc) if (optind < argc)
usage(); usage();
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (getunimap(fd, &ud)) if (getunimap(fd, &ud))
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -74,7 +74,8 @@ main(int argc, char *argv[]){ ...@@ -74,7 +74,8 @@ main(int argc, char *argv[]){
} }
} }
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (n == 0) { if (n == 0) {
/* report mode */ /* report mode */
......
...@@ -75,7 +75,8 @@ main(int argc, char **argv) { ...@@ -75,7 +75,8 @@ main(int argc, char **argv) {
if (optind < argc) if (optind < argc)
value = argv[optind++]; value = argv[optind++];
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (!strcasecmp("GETMODE", action)) { if (!strcasecmp("GETMODE", action)) {
if (ioctl(fd, KDGETMODE, &mode) == -1) if (ioctl(fd, KDGETMODE, &mode) == -1)
......
...@@ -175,7 +175,8 @@ main(int argc, char *argv[]) ...@@ -175,7 +175,8 @@ main(int argc, char *argv[])
if (!(options & OPT_M) && !(options & OPT_B)) { if (!(options & OPT_M) && !(options & OPT_B)) {
/* get console */ /* get console */
fd = getfd(console); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
/* check whether the keyboard is in Unicode mode */ /* check whether the keyboard is in Unicode mode */
if (ioctl(fd, KDGKBMODE, &kbd_mode) || if (ioctl(fd, KDGKBMODE, &kbd_mode) ||
......
...@@ -78,7 +78,8 @@ main(int argc, char *argv[]) { ...@@ -78,7 +78,8 @@ main(int argc, char *argv[]) {
if (argc > optind+1 || (argc == optind && !outfnam)) if (argc > optind+1 || (argc == optind && !outfnam))
usage(); usage();
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (outfnam) { if (outfnam) {
saveunicodemap(fd, outfnam); saveunicodemap(fd, outfnam);
......
...@@ -55,23 +55,24 @@ main(int argc, char *argv[]) { ...@@ -55,23 +55,24 @@ main(int argc, char *argv[]) {
argv++; argv++;
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (argc >= 3 && !strcmp(argv[1], "-o")) { if (argc >= 3 && !strcmp(argv[1], "-o")) {
saveoldmap(fd, argv[2]); saveoldmap(fd, argv[2]);
argc -= 2; argc -= 2;
argv += 2; argv += 2;
if (argc == 1) if (argc == 1)
exit(0); exit(EXIT_SUCCESS);
} }
if (argc != 2) { if (argc != 2) {
fprintf(stderr, _("usage: %s [-V] [-v] [-o map.orig] map-file\n"), fprintf(stderr, _("usage: %s [-V] [-v] [-o map.orig] map-file\n"),
progname); progname);
exit(1); exit(EXIT_FAILURE);
} }
loadnewmap(fd, argv[1]); loadnewmap(fd, argv[1]);
exit(0); exit(EXIT_SUCCESS);
} }
#endif #endif
......
...@@ -151,7 +151,8 @@ main(int argc, char **argv) { ...@@ -151,7 +151,8 @@ main(int argc, char **argv) {
lk_fpclose(&fp); lk_fpclose(&fp);
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if(ioctl(fd, TIOCGWINSZ, &winsize)) { if(ioctl(fd, TIOCGWINSZ, &winsize)) {
kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ"); kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ");
......
...@@ -188,7 +188,8 @@ main(int argc, char *argv[]) { ...@@ -188,7 +188,8 @@ main(int argc, char *argv[]) {
exit(EX_USAGE); exit(EX_USAGE);
} }
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
int kd_mode = -1; int kd_mode = -1;
if (!ioctl(fd, KDGETMODE, &kd_mode) && (kd_mode == KD_GRAPHICS)) if (!ioctl(fd, KDGETMODE, &kd_mode) && (kd_mode == KD_GRAPHICS))
......
...@@ -45,7 +45,9 @@ main(int argc, char **argv) { ...@@ -45,7 +45,9 @@ main(int argc, char **argv) {
if (argc % 2 != 1) if (argc % 2 != 1)
usage(_("even number of arguments expected")); usage(_("even number of arguments expected"));
fd = getfd(NULL);
if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
while (argc > 2) { while (argc > 2) {
a.keycode = atoi(argv[2]); a.keycode = atoi(argv[2]);
......
...@@ -31,7 +31,9 @@ main(int argc, char **argv){ ...@@ -31,7 +31,9 @@ main(int argc, char **argv){
else else
cons = 0; /* current console */ cons = 0; /* current console */
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
arg.fn = 11; /* redirect kernel messages */ arg.fn = 11; /* redirect kernel messages */
arg.subarg = cons; /* to specified console */ arg.subarg = cons; /* to specified console */
if (ioctl(fd, TIOCLINUX, &arg)) { if (ioctl(fd, TIOCLINUX, &arg)) {
......
...@@ -32,7 +32,8 @@ main(int argc, char **argv){ ...@@ -32,7 +32,8 @@ main(int argc, char **argv){
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (ioctl(fd, GIO_CMAP, cmap)) if (ioctl(fd, GIO_CMAP, cmap))
kbd_error(EXIT_FAILURE, errno, "ioctl GIO_CMAP"); kbd_error(EXIT_FAILURE, errno, "ioctl GIO_CMAP");
......
...@@ -27,7 +27,8 @@ main(int argc, char *argv[]) { ...@@ -27,7 +27,8 @@ main(int argc, char *argv[]) {
fprintf(stderr, _("usage: %s\n"), "setvesablank ON|on|off"); fprintf(stderr, _("usage: %s\n"), "setvesablank ON|on|off");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
arg.ten = 10; arg.ten = 10;
arg.onoff = 0; arg.onoff = 0;
if (!strcmp(argv[1], "on")) if (!strcmp(argv[1], "on"))
......
...@@ -136,7 +136,8 @@ main(int argc, char **argv) { ...@@ -136,7 +136,8 @@ main(int argc, char **argv) {
fclose(f); fclose(f);
} }
fd = getfd(NULL); if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
/* Apply the color map to the tty via ioctl */ /* Apply the color map to the tty via ioctl */
if (ioctl(fd, PIO_CMAP, colormap) == -1) if (ioctl(fd, PIO_CMAP, colormap) == -1)
......
...@@ -143,7 +143,8 @@ main (int argc, char **argv) { ...@@ -143,7 +143,8 @@ main (int argc, char **argv) {
if (optind != argc) if (optind != argc)
usage(); usage();
fd = getfd(console); if ((fd = getfd(console)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
if (ioctl(fd, KDGKBMODE, &mode)) { if (ioctl(fd, KDGKBMODE, &mode)) {
kbd_warning(errno, "ioctl KDGKBMODE"); kbd_warning(errno, "ioctl KDGKBMODE");
......
...@@ -175,8 +175,8 @@ main (int argc, char *argv[]) { ...@@ -175,8 +175,8 @@ main (int argc, char *argv[]) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if ((fd = getfd(NULL)) < 0)
fd = getfd(NULL); kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
/* the program terminates when there is no input for 10 secs */ /* the program terminates when there is no input for 10 secs */
signal(SIGALRM, watch_dog); signal(SIGALRM, watch_dog);
......
...@@ -32,7 +32,10 @@ main(int argc, char *argv[]) { ...@@ -32,7 +32,10 @@ main(int argc, char *argv[]) {
if (argc != 2) { if (argc != 2) {
kbd_error(EXIT_FAILURE, 0, _("usage: totextmode\n")); kbd_error(EXIT_FAILURE, 0, _("usage: totextmode\n"));
} }
fd = getfd(NULL);
if ((fd = getfd(NULL)) < 0)
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
num = atoi(argv[1]); num = atoi(argv[1]);
if (ioctl(fd,KDSETMODE,KD_TEXT)) { if (ioctl(fd,KDSETMODE,KD_TEXT)) {
kbd_error(EXIT_FAILURE, errno, "totextmode: KDSETMODE"); kbd_error(EXIT_FAILURE, errno, "totextmode: KDSETMODE");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment