This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 27b5021e0 nshlib/cmd_dd: Retry if read() was interrupted
27b5021e0 is described below

commit 27b5021e0dc4138b0de35cc4a9426b47201417e4
Author: wangjianyu3 <[email protected]>
AuthorDate: Sun Nov 10 23:18:00 2024 +0800

    nshlib/cmd_dd: Retry if read() was interrupted
    
    Without this patch
    
      nsh> ls /etc/group | dd | dd
      sh [13:100]
      sh [14:100]
      nsh: dd: read failed: 4
      nsh>
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 nshlib/nsh_ddcmd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/nshlib/nsh_ddcmd.c b/nshlib/nsh_ddcmd.c
index db1aff68c..4f43a1a45 100644
--- a/nshlib/nsh_ddcmd.c
+++ b/nshlib/nsh_ddcmd.c
@@ -126,6 +126,11 @@ static int dd_read(FAR struct dd_s *dd)
       nbytes = read(dd->infd, buffer, dd->sectsize - dd->nbytes);
       if (nbytes < 0)
         {
+          if (errno == EINTR)
+            {
+              continue;
+            }
+
           FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
           nsh_error(vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO);
           return ERROR;
@@ -134,7 +139,7 @@ static int dd_read(FAR struct dd_s *dd)
       dd->nbytes += nbytes;
       buffer     += nbytes;
     }
-  while (dd->nbytes < dd->sectsize && nbytes > 0);
+  while (dd->nbytes < dd->sectsize && nbytes != 0);
 
   dd->eof |= (dd->nbytes == 0);
   return OK;

Reply via email to