@@ -1,106 +0,0 @@
1−diff --git a/beep.c b/beep.c
2−index 7da2e70..4323d31 100644
3−--- a/beep.c
4−+++ b/beep.c
5−@@ -109,6 +109,7 @@ void do_beep(int freq) {
6− /* BEEP_TYPE_EVDEV */
7− struct input_event e;
8−
9−+ memset(&e, 0, sizeof(e));
10− e.type = EV_SND;
11− e.code = SND_TONE;
12− e.value = freq;
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
15− perpetuity. */
16− void handle_signal(int signum) {
17−-
18−- if(console_device)
19−- free(console_device);
20−-
21− switch(signum) {
22− case SIGINT:
23− case SIGTERM:
24−@@ -257,7 +254,7 @@ void parse_command_line(int argc, char **argv, beep_parms_t *result) {
25− result->verbose = 1;
26− break;
27− case 'e' : /* also --device */
28−- console_device = strdup(optarg);
29−+ console_device = optarg;
30− break;
31− case 'h' : /* notice that this is also --help */
32− default :
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);
36−
37−- /* try to snag the console */
38−- if(console_device)
39−- console_fd = open(console_device, O_WRONLY);
40−- else
41−- if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
42−- console_fd = open("/dev/vc/0", O_WRONLY);
43−-
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 */
48−- perror("open");
49−- exit(1);
50−- }
51−-
52−- if (ioctl(console_fd, EVIOCGSND(0)) != -1)
53−- console_type = BEEP_TYPE_EVDEV;
54−- else
55−- console_type = BEEP_TYPE_CONSOLE;
56−-
57− /* Beep */
58− for (i = 0; i < parms.reps; i++) { /* start beep */
59− do_beep(parms.freq);
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... */
63− } /* repeat. */
64−-
65−- close(console_fd);
66− }
67−
68−
69−@@ -328,6 +303,26 @@ int main(int argc, char **argv) {
70− signal(SIGTERM, handle_signal);
71− parse_command_line(argc, argv, parms);
72−
73−+ /* try to snag the console */
74−+ if(console_device)
75−+ console_fd = open(console_device, O_WRONLY);
76−+ else
77−+ if((console_fd = open("/dev/tty0", O_WRONLY)) == -1)
78−+ console_fd = open("/dev/vc/0", O_WRONLY);
79−+
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 */
84−+ perror("open");
85−+ exit(1);
86−+ }
87−+
88−+ if (ioctl(console_fd, EVIOCGSND(0)) != -1)
89−+ console_type = BEEP_TYPE_EVDEV;
90−+ else
91−+ console_type = BEEP_TYPE_CONSOLE;
92−+
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) {
97− parms = next;
98− }
99−
100−- if(console_device)
101−- free(console_device);
102−+ close(console_fd);
103−+ console_fd = -1;
104−
105− return EXIT_SUCCESS;
106− }