1 diff --git a/beep.c b/beep.c
2 index 7da2e70..4323d31 100644
5 @@ -109,6 +109,7 @@ void do_beep(int freq) {
9 + memset(&e, 0, sizeof(e));
13 @@ -124,10 +125,6 @@ void do_beep(int freq) {
14 /* If we get interrupted, it would be nice to not leave the speaker beeping in
16 void handle_signal(int signum) {
19 - free(console_device);
24 @@ -257,7 +254,7 @@ void parse_command_line(int argc, char **argv, beep_parms_t *result) {
27 case 'e' : /* also --device */
28 - console_device = strdup(optarg);
29 + console_device = optarg;
31 case 'h' : /* notice that this is also --help */
33 @@ -276,26 +273,6 @@ void play_beep(beep_parms_t parms) {
34 "%d delay after) @ %.2f Hz\n",
35 parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq);
37 - /* try to snag the console */
39 - console_fd = open(console_device, O_WRONLY);
41 - if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
42 - console_fd = open("/dev/vc/0", O_WRONLY);
44 - if(console_fd == -1) {
45 - fprintf(stderr, "Could not open %s for writing\n",
46 - console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
47 - printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
52 - if (ioctl(console_fd, EVIOCGSND(0)) != -1)
53 - console_type = BEEP_TYPE_EVDEV;
55 - console_type = BEEP_TYPE_CONSOLE;
58 for (i = 0; i < parms.reps; i++) { /* start beep */
60 @@ -305,8 +282,6 @@ void play_beep(beep_parms_t parms) {
61 if(parms.end_delay || (i+1 < parms.reps))
62 usleep(1000*parms.delay); /* wait... */
69 @@ -328,6 +303,26 @@ int main(int argc, char **argv) {
70 signal(SIGTERM, handle_signal);
71 parse_command_line(argc, argv, parms);
73 + /* try to snag the console */
75 + console_fd = open(console_device, O_WRONLY);
77 + if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
78 + console_fd = open("/dev/vc/0", O_WRONLY);
80 + if(console_fd == -1) {
81 + fprintf(stderr, "Could not open %s for writing\n",
82 + console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
83 + printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
88 + if (ioctl(console_fd, EVIOCGSND(0)) != -1)
89 + console_type = BEEP_TYPE_EVDEV;
91 + console_type = BEEP_TYPE_CONSOLE;
93 /* this outermost while loop handles the possibility that -n/--new has been
94 used, i.e. that we have multiple beeps specified. Each iteration will
95 play, then free() one parms instance. */
96 @@ -365,8 +360,8 @@ int main(int argc, char **argv) {
101 - free(console_device);