--- beep.c.orig 2008-12-19 16:16:20.000000000 -0800 +++ beep.c.orig 2008-12-19 16:15:51.000000000 -0800 @@ -220,25 +220,28 @@ /* try to snag the console */ if((console_fd = open("/dev/console", O_WRONLY)) == -1) { fprintf(stderr, "Could not open /dev/console for writing.\n"); - printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */ perror("open"); - exit(1); } /* Beep */ for (i = 0; i < parms.reps; i++) { /* start beep */ - if(ioctl(console_fd, KIOCSOUND, (int)(CLOCK_TICK_RATE/parms.freq)) < 0) { - printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */ - perror("ioctl"); - } + if (console_fd >= 0) + if(ioctl(console_fd, KIOCSOUND, (int)(CLOCK_TICK_RATE/parms.freq)) < 0) { + fprintf(stderr, "\a"); /* Output the only beep we can, in an effort to fall back on usefulness */ + perror("ioctl"); + } + else + fprintf(stderr, "\a"); /* Output the only beep we can, in an effort to fall back on usefulness */ /* Look ma, I'm not ansi C compatible! */ usleep(1000*parms.length); /* wait... */ - ioctl(console_fd, KIOCSOUND, 0); /* stop beep */ + if (console_fd >= 0) + ioctl(console_fd, KIOCSOUND, 0); /* stop beep */ if(parms.end_delay || (i+1 < parms.reps)) usleep(1000*parms.delay); /* wait... */ } /* repeat. */ - close(console_fd); + if (console_fd >= 0) + close(console_fd); }