summaryrefslogtreecommitdiff
path: root/debian/patches/04_up_down_beep_options.dpatch
blob: 8ddcf882170597892b411c274edea3c2fe09b91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /bin/sh /usr/share/dpatch/dpatch-run
## 04_up_down_beep_options.dpatch by Y Giridhar Appaji Nag <giridhar@appaji.net>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Implement --no-beep-up and --no-beep-down options

@DPATCH@
diff -urNad ifplugd-0.28~/man/ifplugd.8 ifplugd-0.28/man/ifplugd.8
--- ifplugd-0.28~/man/ifplugd.8	2008-04-04 16:30:15.000000000 +0530
+++ ifplugd-0.28/man/ifplugd.8	2008-04-04 16:30:53.000000000 +0530
@@ -22,7 +22,13 @@
 Do not use syslog, use stdout instead (for debugging) (default: off). 
 .TP
 \fB\-b | \-\-no-beep\f1
-Do not beep (off) 
+Do not beep (off), overrides \fB\-\-no-beep-up\f1 and \fB\-\-no-beep-down\f1.
+.TP
+\fB\-U | \-\-no-beep-up\f1
+Do not beep on interface up (off)
+.TP
+\fB\-D | \-\-no-beep-down\f1
+Do not beep on interface down (off)
 .TP
 \fB\-f | \-\-ignore-fail\f1
 Ignore detection failure, retry instead. Failure is treated as "no link". (default: off) 
diff -urNad ifplugd-0.28~/man/ifplugd.8.xml.in ifplugd-0.28/man/ifplugd.8.xml.in
--- ifplugd-0.28~/man/ifplugd.8.xml.in	2008-04-04 16:30:15.000000000 +0530
+++ ifplugd-0.28/man/ifplugd.8.xml.in	2008-04-04 16:30:15.000000000 +0530
@@ -73,7 +73,21 @@
 	  <option>
 		<p><opt>-b | --no-beep</opt></p>
 		<optdesc><p>
-			Do not beep (off)
+			Do not beep (off), overrides <opt>--no-beep-up</opt> and <opt>--no-beep-down</opt>.
+		  </p></optdesc>
+	  </option>
+	  
+	  <option>
+		<p><opt>-U | --no-beep-up</opt></p>
+		<optdesc><p>
+			Do not beep on interface up (off)
+		  </p></optdesc>
+	  </option>
+	  
+	  <option>
+		<p><opt>-D | --no-beep-down</opt></p>
+		<optdesc><p>
+			Do not beep on interface down (off)
 		  </p></optdesc>
 	  </option>
 	  
diff -urNad ifplugd-0.28~/src/ifplugd.c ifplugd-0.28/src/ifplugd.c
--- ifplugd-0.28~/src/ifplugd.c	2008-04-04 16:28:48.000000000 +0530
+++ ifplugd-0.28/src/ifplugd.c	2008-04-04 16:30:15.000000000 +0530
@@ -73,6 +73,8 @@
 
 int daemonize = 1,
     use_beep = 1,
+    beep_on_up = 1,
+    beep_on_down = 1,
     no_startup_script = 0,
     no_shutdown_script = 0,
     wait_on_fork = 0,
@@ -126,6 +128,18 @@
     return;
 }
 
+static void beep_up(int b) {
+	if(!beep_on_up)
+		return;
+	beep(b);
+}
+
+static void beep_down(int b) {
+	if(!beep_on_down)
+		return;
+	beep(b);
+}
+
 const char *pid_file_proc() {
     static char fn[PATH_MAX];
     snprintf(fn, sizeof(fn), "%s/ifplugd.%s.pid", VARRUN, interface);
@@ -237,13 +251,13 @@
 
     if (!WIFEXITED(r) || WEXITSTATUS(r) != 0) {
         if (status == IFSTATUS_UP)
-            beep(2);
+            beep_up(2);
         daemon_log(LOG_ERR, "Program execution failed, return value is %i.", WEXITSTATUS(r));
 
         return ignore_retval ? 0 : -1;
     } else {
         if (status == IFSTATUS_UP)
-            beep(0);
+            beep_up(0);
 
         daemon_log(LOG_INFO, "Program executed successfully.");
         return 0;
@@ -440,7 +454,10 @@
         goto finish;
     
     daemon_log(LOG_INFO, "Initialization complete, link beat %sdetected%s.", status == IFSTATUS_UP ? "" : "not ", use_ifmonitor ? (disabled ? ", interface disabled" : ", interface enabled") : "");
-    beep(status == IFSTATUS_UP ? 0 : 1);
+    if(status == IFSTATUS_UP)
+        beep_up(0);
+    else
+        beep_down(1);
 
     if ((!no_startup_script && status == IFSTATUS_UP) || initial_down)
         if (action(status) < 0)
@@ -513,7 +530,10 @@
 
         if (status != s) {
             daemon_log(LOG_INFO, "Link beat %s.", status == IFSTATUS_DOWN ? "lost" : "detected");
-            beep(status == IFSTATUS_UP ? 0 : 1);
+            if(status == IFSTATUS_UP)
+                beep_up(0);
+            else
+                beep_down(1);
             
             if (t)
                 t = 0;
@@ -586,7 +606,7 @@
         setenv(IFPLUGD_ENV_PREVIOUS, strstatus(status), 1);
         setenv(IFPLUGD_ENV_CURRENT, strstatus(-1), 1);
         action(IFSTATUS_DOWN);
-        beep(1);
+        beep_down(1);
     }
     
 finish:
@@ -628,6 +648,8 @@
            "   -n --no-daemon            Do not daemonize (for debugging) (%s)\n"
            "   -s --no-syslog            Do not use syslog, use stderr instead (for debugging) (%s)\n"
            "   -b --no-beep              Do not beep (%s)\n"
+           "   -U --no-beep-up           Do not beep on interface up (%s)\n"
+           "   -D --no-beep-down         Do not beep on interface down (%s)\n"
            "   -f --ignore-fail          Ignore detection failure, retry instead (failure is treated as DOWN) (%s)\n"
            "   -F --ignore-fail-positive Ignore detection failure, retry instead (failure is treated as UP) (%s)\n"
            "   -i --iface=IFACE          Specify ethernet interface (%s)\n"
@@ -656,6 +678,8 @@
            !daemonize ? "on" : "off",
            !use_syslog ? "on" : "off",
            !use_beep ? "on" : "off",
+           !beep_on_up ? "on" : "off",
+           !beep_on_down ? "on" : "off",
            failure_status == IFSTATUS_DOWN ? "on" : "off",
            failure_status == IFSTATUS_UP ? "on" : "off",
            interface,
@@ -679,6 +703,8 @@
         {"no-daemon",            no_argument, 0, 'n'},
         {"no-syslog",            no_argument, 0, 's'},
         {"no-beep",              no_argument, 0, 'b'},
+        {"no-beep-up",           no_argument, 0, 'U'},
+        {"no-beep-down",         no_argument, 0, 'D'},
         {"ignore-fail",          no_argument, 0, 'f'},
         {"ignore-fail-positive", no_argument, 0, 'F'},
         {"ignore-retval",        no_argument, 0, 'I'},
@@ -710,7 +736,7 @@
     for (;;) {
         int c;
         
-        if ((c = getopt_long(argc, argv, "asni:r:t:u:d:hkbfFvm:pqwx:cISRzlMW", long_options, &option_index)) < 0)
+        if ((c = getopt_long(argc, argv, "asni:r:t:u:d:hkbUDfFvm:pqwx:cISRzlMW", long_options, &option_index)) < 0)
             break;
 
         switch (c) {
@@ -759,6 +785,12 @@
             case 'b':
                 use_beep = !use_beep;
                 break;
+            case 'U':
+                beep_on_up = !beep_on_up;
+                break;
+            case 'D':
+                beep_on_down = !beep_on_down;
+                break;
             case 'f':
                 failure_status = IFSTATUS_DOWN;
                 break;