* [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
@ 2012-05-17 9:36 Devendra Naga
2012-05-17 14:13 ` Rob Landley
0 siblings, 1 reply; 4+ messages in thread
From: Devendra Naga @ 2012-05-17 9:36 UTC (permalink / raw)
To: Rob Landley, Devendra Naga, linux-watchdog, linux-doc
we start a infinite loop when user gives ./watchdog-test, and when user
ctrl + c's the program, we just exit immeadiately with out closing the
filedescriptor of the watchdog device. a signal handler is used to
do the job of closing the filedescriptor and exiting the program.
Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
---
Documentation/watchdog/src/watchdog-test.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index 23084f2..73ff5cc 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <signal.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
@@ -29,6 +30,14 @@ static void keep_alive(void)
* The main program. Run the program with "-d" to disable the card,
* or "-e" to enable the card.
*/
+
+void term(int sig)
+{
+ close(fd);
+ fprintf(stderr, "Stopping watchdog ticks...\n");
+ exit(0);
+}
+
int main(int argc, char *argv[])
{
int flags;
@@ -65,6 +74,8 @@ int main(int argc, char *argv[])
fflush(stderr);
}
+ signal(SIGINT, term);
+
while(1) {
keep_alive();
sleep(1);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
@ 2012-05-17 9:37 Devendra Naga
0 siblings, 0 replies; 4+ messages in thread
From: Devendra Naga @ 2012-05-17 9:37 UTC (permalink / raw)
To: Wim Van Sebroeck, Rob Landley, Devendra Naga, linux-watchdog,
linux-doc
we start a infinite loop when user gives ./watchdog-test, and when user
ctrl + c's the program, we just exit immeadiately with out closing the
filedescriptor of the watchdog device. a signal handler is used to
do the job of closing the filedescriptor and exiting the program.
Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
---
Documentation/watchdog/src/watchdog-test.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index 23084f2..73ff5cc 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <signal.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
@@ -29,6 +30,14 @@ static void keep_alive(void)
* The main program. Run the program with "-d" to disable the card,
* or "-e" to enable the card.
*/
+
+void term(int sig)
+{
+ close(fd);
+ fprintf(stderr, "Stopping watchdog ticks...\n");
+ exit(0);
+}
+
int main(int argc, char *argv[])
{
int flags;
@@ -65,6 +74,8 @@ int main(int argc, char *argv[])
fflush(stderr);
}
+ signal(SIGINT, term);
+
while(1) {
keep_alive();
sleep(1);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
2012-05-17 9:36 Devendra Naga
@ 2012-05-17 14:13 ` Rob Landley
2012-05-17 14:33 ` devendra.aaru
0 siblings, 1 reply; 4+ messages in thread
From: Rob Landley @ 2012-05-17 14:13 UTC (permalink / raw)
To: Devendra Naga; +Cc: linux-watchdog, linux-doc
On 05/17/2012 04:36 AM, Devendra Naga wrote:
> we start a infinite loop when user gives ./watchdog-test, and when user
> ctrl + c's the program, we just exit immeadiately with out closing the
> filedescriptor of the watchdog device. a signal handler is used to
> do the job of closing the filedescriptor and exiting the program.
Doesn't exiting a process close all its filehandles already?
Rob
--
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation. Pick one.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
2012-05-17 14:13 ` Rob Landley
@ 2012-05-17 14:33 ` devendra.aaru
0 siblings, 0 replies; 4+ messages in thread
From: devendra.aaru @ 2012-05-17 14:33 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-watchdog, linux-doc
On Thu, May 17, 2012 at 7:43 PM, Rob Landley <rob@landley.net> wrote:
> On 05/17/2012 04:36 AM, Devendra Naga wrote:
>> we start a infinite loop when user gives ./watchdog-test, and when user
>> ctrl + c's the program, we just exit immeadiately with out closing the
>> filedescriptor of the watchdog device. a signal handler is used to
>> do the job of closing the filedescriptor and exiting the program.
>
> Doesn't exiting a process close all its filehandles already?
I think kernel will take care of releasing process resources. i am not
so sure of it.
but running valgrind --track-fds=yes ./a.out as root shows a descriptor leak.
BTW, there is another miss, if the user is non-root we still leak a
file descriptor.
>
> Rob
> --
> GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
> Either it's "mere aggregation", or a license violation. Pick one.
Thanks,
Devendra.
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-05-17 14:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-17 9:37 [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given Devendra Naga
-- strict thread matches above, loose matches on Subject: below --
2012-05-17 9:36 Devendra Naga
2012-05-17 14:13 ` Rob Landley
2012-05-17 14:33 ` devendra.aaru
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).