1 --- beep-1.3.orig/beep.c
3 @@ -109,6 +109,7 @@ void do_beep(int freq) {
7 + memset(&e, 0, sizeof(e));
11 @@ -121,10 +122,6 @@ void do_beep(int freq) {
12 /* If we get interrupted, it would be nice to not leave the speaker beeping in
14 void handle_signal(int signum) {
17 - free(console_device);
22 @@ -254,7 +251,7 @@ void parse_command_line(int argc, char *
25 case 'e' : /* also --device */
26 - console_device = strdup(optarg);
27 + console_device = optarg;
29 case 'h' : /* notice that this is also --help */
31 @@ -273,26 +270,6 @@ void play_beep(beep_parms_t parms) {
32 "%d delay after) @ %.2f Hz\n",
33 parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq);
35 - /* try to snag the console */
37 - console_fd = open(console_device, O_WRONLY);
39 - if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
40 - console_fd = open("/dev/vc/0", O_WRONLY);
42 - if(console_fd == -1) {
43 - fprintf(stderr, "Could not open %s for writing\n",
44 - console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
45 - printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
50 - if (ioctl(console_fd, EVIOCGSND(0)) != -1)
51 - console_type = BEEP_TYPE_EVDEV;
53 - console_type = BEEP_TYPE_CONSOLE;
56 for (i = 0; i < parms.reps; i++) { /* start beep */
58 @@ -302,8 +279,6 @@ void play_beep(beep_parms_t parms) {
59 if(parms.end_delay || (i+1 < parms.reps))
60 usleep(1000*parms.delay); /* wait... */
67 @@ -325,6 +300,26 @@ int main(int argc, char **argv) {
68 signal(SIGTERM, handle_signal);
69 parse_command_line(argc, argv, parms);
71 + /* try to snag the console */
73 + console_fd = open(console_device, O_WRONLY);
75 + if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
76 + console_fd = open("/dev/vc/0", O_WRONLY);
78 + if(console_fd == -1) {
79 + fprintf(stderr, "Could not open %s for writing\n",
80 + console_device != NULL ? console_device : "/dev/tty0 or /dev/vc/0");
81 + printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
86 + if (ioctl(console_fd, EVIOCGSND(0)) != -1)
87 + console_type = BEEP_TYPE_EVDEV;
89 + console_type = BEEP_TYPE_CONSOLE;
91 /* this outermost while loop handles the possibility that -n/--new has been
92 used, i.e. that we have multiple beeps specified. Each iteration will
93 play, then free() one parms instance. */
94 @@ -362,8 +357,8 @@ int main(int argc, char **argv) {
99 - free(console_device);