All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test
@ 2016-06-21 23:00 Timur Tabi
  2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Timur Tabi @ 2016-06-21 23:00 UTC (permalink / raw)
  To: Wim Van Sebroeck, linux-watchdog

The watchdog-test utility outputs all messages to stderr, even those
that are not error messages.  Output to stdout instead.

Instead of flushing the output after every write, just disabled
the output buffer.

Also display a dot for every ping of the watchdog, so that the user
knows that it's working.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
---
 Documentation/watchdog/src/watchdog-test.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index fcdde8f..b3cc7aa 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -23,6 +23,7 @@ static void keep_alive(void)
 {
     int dummy;
 
+    printf(".");
     ioctl(fd, WDIOC_KEEPALIVE, &dummy);
 }
 
@@ -34,7 +35,7 @@ static void keep_alive(void)
 static void term(int sig)
 {
     close(fd);
-    fprintf(stderr, "Stopping watchdog ticks...\n");
+    printf("\nStopping watchdog ticks...\n");
     exit(0);
 }
 
@@ -43,11 +44,12 @@ int main(int argc, char *argv[])
     int flags;
     unsigned int ping_rate = 1;
 
+    setbuf(stdout, NULL);
+
     fd = open("/dev/watchdog", O_WRONLY);
 
     if (fd == -1) {
-	fprintf(stderr, "Watchdog device not enabled.\n");
-	fflush(stderr);
+	printf("Watchdog device not enabled.\n");
 	exit(-1);
     }
 
@@ -55,36 +57,30 @@ int main(int argc, char *argv[])
 	if (!strncasecmp(argv[1], "-d", 2)) {
 	    flags = WDIOS_DISABLECARD;
 	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
-	    fprintf(stderr, "Watchdog card disabled.\n");
-	    fflush(stderr);
+	    printf("Watchdog card disabled.\n");
 	    goto end;
 	} else if (!strncasecmp(argv[1], "-e", 2)) {
 	    flags = WDIOS_ENABLECARD;
 	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
-	    fprintf(stderr, "Watchdog card enabled.\n");
-	    fflush(stderr);
+	    printf("Watchdog card enabled.\n");
 	    goto end;
 	} else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
 	    flags = atoi(argv[2]);
 	    ioctl(fd, WDIOC_SETTIMEOUT, &flags);
-	    fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags);
-	    fflush(stderr);
+	    printf("Watchdog timeout set to %u seconds.\n", flags);
 	    goto end;
 	} else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
 	    ping_rate = strtoul(argv[2], NULL, 0);
-	    fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate);
-	    fflush(stderr);
+	    printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
 	} else {
-	    fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \
+	    printf("-d to disable, -e to enable, -t <n> to set " \
 		"the timeout,\n-p <n> to set the ping rate, and \n");
-	    fprintf(stderr, "run by itself to tick the card.\n");
-	    fflush(stderr);
+	    printf("run by itself to tick the card.\n");
 	    goto end;
 	}
     }
 
-    fprintf(stderr, "Watchdog Ticking Away!\n");
-    fflush(stderr);
+    printf("Watchdog Ticking Away!\n");
 
     signal(SIGINT, term);
 
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test
  2016-06-21 23:00 [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Timur Tabi
@ 2016-06-21 23:00 ` Timur Tabi
  2016-06-23 13:45   ` Guenter Roeck
  2016-07-17 20:17   ` Wim Van Sebroeck
  2016-06-23 13:44 ` [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Guenter Roeck
  2016-07-17 20:17 ` Wim Van Sebroeck
  2 siblings, 2 replies; 6+ messages in thread
From: Timur Tabi @ 2016-06-21 23:00 UTC (permalink / raw)
  To: Wim Van Sebroeck, linux-watchdog

Some drivers have the WDIOF_MAGICCLOSE set, which means that applications
need to write 'V' to the watchdog device before closing, otherwise the
driver won't stop the watchdog timer.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
---
 Documentation/watchdog/src/watchdog-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index b3cc7aa..c691539 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -13,6 +13,7 @@
 #include <linux/watchdog.h>
 
 int fd;
+const char v = 'V';
 
 /*
  * This function simply sends an IOCTL to the driver, which in turn ticks
@@ -34,6 +35,7 @@ static void keep_alive(void)
 
 static void term(int sig)
 {
+    write(fd, &v, 1);
     close(fd);
     printf("\nStopping watchdog ticks...\n");
     exit(0);
@@ -89,6 +91,7 @@ int main(int argc, char *argv[])
 	sleep(ping_rate);
     }
 end:
+    write(fd, &v, 1);
     close(fd);
     return 0;
 }
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test
  2016-06-21 23:00 [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Timur Tabi
  2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
@ 2016-06-23 13:44 ` Guenter Roeck
  2016-07-17 20:17 ` Wim Van Sebroeck
  2 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2016-06-23 13:44 UTC (permalink / raw)
  To: Timur Tabi, Wim Van Sebroeck, linux-watchdog

On 06/21/2016 04:00 PM, Timur Tabi wrote:
> The watchdog-test utility outputs all messages to stderr, even those
> that are not error messages.  Output to stdout instead.
>
> Instead of flushing the output after every write, just disabled
> the output buffer.
>
> Also display a dot for every ping of the watchdog, so that the user
> knows that it's working.
>
> Signed-off-by: Timur Tabi <timur@codeaurora.org>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   Documentation/watchdog/src/watchdog-test.c | 28 ++++++++++++----------------
>   1 file changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index fcdde8f..b3cc7aa 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -23,6 +23,7 @@ static void keep_alive(void)
>   {
>       int dummy;
>
> +    printf(".");
>       ioctl(fd, WDIOC_KEEPALIVE, &dummy);
>   }
>
> @@ -34,7 +35,7 @@ static void keep_alive(void)
>   static void term(int sig)
>   {
>       close(fd);
> -    fprintf(stderr, "Stopping watchdog ticks...\n");
> +    printf("\nStopping watchdog ticks...\n");
>       exit(0);
>   }
>
> @@ -43,11 +44,12 @@ int main(int argc, char *argv[])
>       int flags;
>       unsigned int ping_rate = 1;
>
> +    setbuf(stdout, NULL);
> +
>       fd = open("/dev/watchdog", O_WRONLY);
>
>       if (fd == -1) {
> -	fprintf(stderr, "Watchdog device not enabled.\n");
> -	fflush(stderr);
> +	printf("Watchdog device not enabled.\n");
>   	exit(-1);
>       }
>
> @@ -55,36 +57,30 @@ int main(int argc, char *argv[])
>   	if (!strncasecmp(argv[1], "-d", 2)) {
>   	    flags = WDIOS_DISABLECARD;
>   	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
> -	    fprintf(stderr, "Watchdog card disabled.\n");
> -	    fflush(stderr);
> +	    printf("Watchdog card disabled.\n");
>   	    goto end;
>   	} else if (!strncasecmp(argv[1], "-e", 2)) {
>   	    flags = WDIOS_ENABLECARD;
>   	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
> -	    fprintf(stderr, "Watchdog card enabled.\n");
> -	    fflush(stderr);
> +	    printf("Watchdog card enabled.\n");
>   	    goto end;
>   	} else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
>   	    flags = atoi(argv[2]);
>   	    ioctl(fd, WDIOC_SETTIMEOUT, &flags);
> -	    fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags);
> -	    fflush(stderr);
> +	    printf("Watchdog timeout set to %u seconds.\n", flags);
>   	    goto end;
>   	} else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
>   	    ping_rate = strtoul(argv[2], NULL, 0);
> -	    fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate);
> -	    fflush(stderr);
> +	    printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
>   	} else {
> -	    fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \
> +	    printf("-d to disable, -e to enable, -t <n> to set " \
>   		"the timeout,\n-p <n> to set the ping rate, and \n");
> -	    fprintf(stderr, "run by itself to tick the card.\n");
> -	    fflush(stderr);
> +	    printf("run by itself to tick the card.\n");
>   	    goto end;
>   	}
>       }
>
> -    fprintf(stderr, "Watchdog Ticking Away!\n");
> -    fflush(stderr);
> +    printf("Watchdog Ticking Away!\n");
>
>       signal(SIGINT, term);
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test
  2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
@ 2016-06-23 13:45   ` Guenter Roeck
  2016-07-17 20:17   ` Wim Van Sebroeck
  1 sibling, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2016-06-23 13:45 UTC (permalink / raw)
  To: Timur Tabi, Wim Van Sebroeck, linux-watchdog

On 06/21/2016 04:00 PM, Timur Tabi wrote:
> Some drivers have the WDIOF_MAGICCLOSE set, which means that applications
> need to write 'V' to the watchdog device before closing, otherwise the
> driver won't stop the watchdog timer.
>
> Signed-off-by: Timur Tabi <timur@codeaurora.org>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   Documentation/watchdog/src/watchdog-test.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index b3cc7aa..c691539 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -13,6 +13,7 @@
>   #include <linux/watchdog.h>
>
>   int fd;
> +const char v = 'V';
>
>   /*
>    * This function simply sends an IOCTL to the driver, which in turn ticks
> @@ -34,6 +35,7 @@ static void keep_alive(void)
>
>   static void term(int sig)
>   {
> +    write(fd, &v, 1);
>       close(fd);
>       printf("\nStopping watchdog ticks...\n");
>       exit(0);
> @@ -89,6 +91,7 @@ int main(int argc, char *argv[])
>   	sleep(ping_rate);
>       }
>   end:
> +    write(fd, &v, 1);
>       close(fd);
>       return 0;
>   }
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test
  2016-06-21 23:00 [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Timur Tabi
  2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
  2016-06-23 13:44 ` [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Guenter Roeck
@ 2016-07-17 20:17 ` Wim Van Sebroeck
  2 siblings, 0 replies; 6+ messages in thread
From: Wim Van Sebroeck @ 2016-07-17 20:17 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linux-watchdog

Hi Timur,

> The watchdog-test utility outputs all messages to stderr, even those
> that are not error messages.  Output to stdout instead.
> 
> Instead of flushing the output after every write, just disabled
> the output buffer.
> 
> Also display a dot for every ping of the watchdog, so that the user
> knows that it's working.
> 
> Signed-off-by: Timur Tabi <timur@codeaurora.org>
> ---
>  Documentation/watchdog/src/watchdog-test.c | 28 ++++++++++++----------------
>  1 file changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index fcdde8f..b3cc7aa 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -23,6 +23,7 @@ static void keep_alive(void)
>  {
>      int dummy;
>  
> +    printf(".");
>      ioctl(fd, WDIOC_KEEPALIVE, &dummy);
>  }
>  
> @@ -34,7 +35,7 @@ static void keep_alive(void)
>  static void term(int sig)
>  {
>      close(fd);
> -    fprintf(stderr, "Stopping watchdog ticks...\n");
> +    printf("\nStopping watchdog ticks...\n");
>      exit(0);
>  }
>  
> @@ -43,11 +44,12 @@ int main(int argc, char *argv[])
>      int flags;
>      unsigned int ping_rate = 1;
>  
> +    setbuf(stdout, NULL);
> +
>      fd = open("/dev/watchdog", O_WRONLY);
>  
>      if (fd == -1) {
> -	fprintf(stderr, "Watchdog device not enabled.\n");
> -	fflush(stderr);
> +	printf("Watchdog device not enabled.\n");
>  	exit(-1);
>      }
>  
> @@ -55,36 +57,30 @@ int main(int argc, char *argv[])
>  	if (!strncasecmp(argv[1], "-d", 2)) {
>  	    flags = WDIOS_DISABLECARD;
>  	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
> -	    fprintf(stderr, "Watchdog card disabled.\n");
> -	    fflush(stderr);
> +	    printf("Watchdog card disabled.\n");
>  	    goto end;
>  	} else if (!strncasecmp(argv[1], "-e", 2)) {
>  	    flags = WDIOS_ENABLECARD;
>  	    ioctl(fd, WDIOC_SETOPTIONS, &flags);
> -	    fprintf(stderr, "Watchdog card enabled.\n");
> -	    fflush(stderr);
> +	    printf("Watchdog card enabled.\n");
>  	    goto end;
>  	} else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
>  	    flags = atoi(argv[2]);
>  	    ioctl(fd, WDIOC_SETTIMEOUT, &flags);
> -	    fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags);
> -	    fflush(stderr);
> +	    printf("Watchdog timeout set to %u seconds.\n", flags);
>  	    goto end;
>  	} else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
>  	    ping_rate = strtoul(argv[2], NULL, 0);
> -	    fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate);
> -	    fflush(stderr);
> +	    printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
>  	} else {
> -	    fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \
> +	    printf("-d to disable, -e to enable, -t <n> to set " \
>  		"the timeout,\n-p <n> to set the ping rate, and \n");
> -	    fprintf(stderr, "run by itself to tick the card.\n");
> -	    fflush(stderr);
> +	    printf("run by itself to tick the card.\n");
>  	    goto end;
>  	}
>      }
>  
> -    fprintf(stderr, "Watchdog Ticking Away!\n");
> -    fflush(stderr);
> +    printf("Watchdog Ticking Away!\n");
>  
>      signal(SIGINT, term);
>  
> -- 
> Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project.
> 

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test
  2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
  2016-06-23 13:45   ` Guenter Roeck
@ 2016-07-17 20:17   ` Wim Van Sebroeck
  1 sibling, 0 replies; 6+ messages in thread
From: Wim Van Sebroeck @ 2016-07-17 20:17 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linux-watchdog

Hi Timur,

> Some drivers have the WDIOF_MAGICCLOSE set, which means that applications
> need to write 'V' to the watchdog device before closing, otherwise the
> driver won't stop the watchdog timer.
> 
> Signed-off-by: Timur Tabi <timur@codeaurora.org>
> ---
>  Documentation/watchdog/src/watchdog-test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index b3cc7aa..c691539 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -13,6 +13,7 @@
>  #include <linux/watchdog.h>
>  
>  int fd;
> +const char v = 'V';
>  
>  /*
>   * This function simply sends an IOCTL to the driver, which in turn ticks
> @@ -34,6 +35,7 @@ static void keep_alive(void)
>  
>  static void term(int sig)
>  {
> +    write(fd, &v, 1);
>      close(fd);
>      printf("\nStopping watchdog ticks...\n");
>      exit(0);
> @@ -89,6 +91,7 @@ int main(int argc, char *argv[])
>  	sleep(ping_rate);
>      }
>  end:
> +    write(fd, &v, 1);
>      close(fd);
>      return 0;
>  }
> -- 
> Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project.
> 

Patch has been added to linux-watchdog-next.

Kind regards,
Wim.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-07-17 20:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-21 23:00 [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Timur Tabi
2016-06-21 23:00 ` [PATCH 2/2] Documentation/watchdog: add support for magic close to watchdog-test Timur Tabi
2016-06-23 13:45   ` Guenter Roeck
2016-07-17 20:17   ` Wim Van Sebroeck
2016-06-23 13:44 ` [PATCH 1/2] Documentation/watchdog: use stdout instead of stderr in watchdog-test Guenter Roeck
2016-07-17 20:17 ` Wim Van Sebroeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.