Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1446282 > unrolled thread

[PATCH] Documentation/watchdog: check return value for magic close

Started byArnd Bergmann <arnd@arndb.de>
First post2016-07-19 11:30 +0200
Last post2016-07-19 17:00 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Documentation/watchdog: check return value for magic close Arnd Bergmann <arnd@arndb.de> - 2016-07-19 11:30 +0200
    Re: [PATCH] Documentation/watchdog: check return value for magic  close Guenter Roeck <linux@roeck-us.net> - 2016-07-19 15:30 +0200
    Re: [PATCH] Documentation/watchdog: check return value for magic  close Randy Dunlap <rdunlap@infradead.org> - 2016-07-19 17:00 +0200

#1446282 — [PATCH] Documentation/watchdog: check return value for magic close

FromArnd Bergmann <arnd@arndb.de>
Date2016-07-19 11:30 +0200
Subject[PATCH] Documentation/watchdog: check return value for magic close
Message-ID<rWzvH-2e4-17@gated-at.bofh.it>
A recent commit added a write to the watchdog test code for doing the "magic
close", but that caused a compile-time warning:

Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]

This changes the code to print a runtime warning if the write fails.

Fixes: 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 Documentation/watchdog/src/watchdog-test.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index c69153913722..52eea54649ab 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -2,6 +2,7 @@
  * Watchdog Driver Test Program
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -35,9 +36,13 @@ static void keep_alive(void)
 
 static void term(int sig)
 {
-    write(fd, &v, 1);
+    int ret = write(fd, &v, 1);
+
     close(fd);
-    printf("\nStopping watchdog ticks...\n");
+    if (ret < 0)
+	printf("\nStopping watchdog ticks failed (%d)...\n", errno);
+    else
+	printf("\nStopping watchdog ticks...\n");
     exit(0);
 }
 
@@ -45,6 +50,7 @@ int main(int argc, char *argv[])
 {
     int flags;
     unsigned int ping_rate = 1;
+    int ret;
 
     setbuf(stdout, NULL);
 
@@ -91,7 +97,9 @@ int main(int argc, char *argv[])
 	sleep(ping_rate);
     }
 end:
-    write(fd, &v, 1);
+    ret = write(fd, &v, 1);
+    if (ret < 0)
+	printf("Sopping watchdog ticks failed (%d)...\n", errno);
     close(fd);
     return 0;
 }
-- 
2.9.0

[toc] | [next] | [standalone]


#1446465 — Re: [PATCH] Documentation/watchdog: check return value for magic close

FromGuenter Roeck <linux@roeck-us.net>
Date2016-07-19 15:30 +0200
SubjectRe: [PATCH] Documentation/watchdog: check return value for magic close
Message-ID<rWDfY-4xj-9@gated-at.bofh.it>
In reply to#1446282
On 07/19/2016 02:24 AM, Arnd Bergmann wrote:
> A recent commit added a write to the watchdog test code for doing the "magic
> close", but that caused a compile-time warning:
>
> Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
> Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
>
> This changes the code to print a runtime warning if the write fails.
>
> Fixes: 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   Documentation/watchdog/src/watchdog-test.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index c69153913722..52eea54649ab 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -2,6 +2,7 @@
>    * Watchdog Driver Test Program
>    */
>
> +#include <errno.h>
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <string.h>
> @@ -35,9 +36,13 @@ static void keep_alive(void)
>
>   static void term(int sig)
>   {
> -    write(fd, &v, 1);
> +    int ret = write(fd, &v, 1);
> +
>       close(fd);
> -    printf("\nStopping watchdog ticks...\n");
> +    if (ret < 0)
> +	printf("\nStopping watchdog ticks failed (%d)...\n", errno);
> +    else
> +	printf("\nStopping watchdog ticks...\n");
>       exit(0);
>   }
>
> @@ -45,6 +50,7 @@ int main(int argc, char *argv[])
>   {
>       int flags;
>       unsigned int ping_rate = 1;
> +    int ret;
>
>       setbuf(stdout, NULL);
>
> @@ -91,7 +97,9 @@ int main(int argc, char *argv[])
>   	sleep(ping_rate);
>       }
>   end:
> -    write(fd, &v, 1);
> +    ret = write(fd, &v, 1);
> +    if (ret < 0)
> +	printf("Sopping watchdog ticks failed (%d)...\n", errno);

Stopping

>       close(fd);
>       return 0;
>   }
>

[toc] | [prev] | [next] | [standalone]


#1446534 — Re: [PATCH] Documentation/watchdog: check return value for magic close

FromRandy Dunlap <rdunlap@infradead.org>
Date2016-07-19 17:00 +0200
SubjectRe: [PATCH] Documentation/watchdog: check return value for magic close
Message-ID<rWEF4-5jj-11@gated-at.bofh.it>
In reply to#1446282
On 07/19/16 02:24, Arnd Bergmann wrote:
> A recent commit added a write to the watchdog test code for doing the "magic
> close", but that caused a compile-time warning:
> 
> Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
> Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
> 
> This changes the code to print a runtime warning if the write fails.
> 
> Fixes: 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  Documentation/watchdog/src/watchdog-test.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
> index c69153913722..52eea54649ab 100644
> --- a/Documentation/watchdog/src/watchdog-test.c
> +++ b/Documentation/watchdog/src/watchdog-test.c
> @@ -2,6 +2,7 @@
>   * Watchdog Driver Test Program
>   */
>  
> +#include <errno.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -35,9 +36,13 @@ static void keep_alive(void)
>  
>  static void term(int sig)
>  {
> -    write(fd, &v, 1);
> +    int ret = write(fd, &v, 1);
> +
>      close(fd);
> -    printf("\nStopping watchdog ticks...\n");
> +    if (ret < 0)
> +	printf("\nStopping watchdog ticks failed (%d)...\n", errno);
> +    else
> +	printf("\nStopping watchdog ticks...\n");
>      exit(0);
>  }
>  
> @@ -45,6 +50,7 @@ int main(int argc, char *argv[])
>  {
>      int flags;
>      unsigned int ping_rate = 1;
> +    int ret;
>  
>      setbuf(stdout, NULL);
>  
> @@ -91,7 +97,9 @@ int main(int argc, char *argv[])
>  	sleep(ping_rate);
>      }
>  end:
> -    write(fd, &v, 1);
> +    ret = write(fd, &v, 1);
> +    if (ret < 0)
> +	printf("Sopping watchdog ticks failed (%d)...\n", errno);

Stopping

>      close(fd);
>      return 0;
>  }
> 


-- 
~Randy

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web