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

jimjag pushed a commit to branch AOO50X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit fb856822bb3ed7d2b9c47013cb7b6df49fb56560
Author: Jim Jagielski <[email protected]>
AuthorDate: Thu Oct 22 08:09:49 2026 -0400

    unopkg: treat end of input at the license prompt as a "no"
    
    With stdin at EOF it re-prompted forever at full CPU.
    
    (cherry picked from commit f8a0ffbbd0d7df0e0952e0568544022aac776eee)
---
 main/desktop/source/deployment/inc/dp_misc.h        |  3 ++-
 main/desktop/source/deployment/misc/dp_misc.cxx     | 13 ++++++++-----
 main/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx |  9 ++++++++-
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/main/desktop/source/deployment/inc/dp_misc.h 
b/main/desktop/source/deployment/inc/dp_misc.h
index 1627363183..e50425be5a 100644
--- a/main/desktop/source/deployment/inc/dp_misc.h
+++ b/main/desktop/source/deployment/inc/dp_misc.h
@@ -150,9 +150,10 @@ void writeConsoleError(::rtl::OString const & sText);
     On Linux/Unix/etc. it uses fgets to read char values and converts them to 
OUString
     using osl_getThreadTextEncoding as target encoding. The returned string 
has a maximum
     size of 1024 and does NOT include leading and trailing white space(applied 
OUString::trim())
+    Returns false at end of input or on a read error.
 */
 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
-::rtl::OUString readConsole();
+bool readConsole( ::rtl::OUString & rLine );
 
 /** print the text to the console in a debug build.
     The argument is forwarded to writeConsole. The function does not add new 
line.
diff --git a/main/desktop/source/deployment/misc/dp_misc.cxx 
b/main/desktop/source/deployment/misc/dp_misc.cxx
index a03c692323..921a46c34c 100644
--- a/main/desktop/source/deployment/misc/dp_misc.cxx
+++ b/main/desktop/source/deployment/misc/dp_misc.cxx
@@ -542,17 +542,18 @@ void writeConsoleError(::rtl::OString const & sText)
 
 
 
-OUString readConsole()
+bool readConsole( OUString & rLine )
 {
 #ifdef WNT
     sal_Unicode aBuffer[1024];
        DWORD   dwRead = 0;
     //unopkg.com feeds unopkg.exe with wchar_t|s
-    if (ReadFile( GetStdHandle(STD_INPUT_HANDLE), &aBuffer, sizeof(aBuffer), 
&dwRead, NULL ) )
+    if (ReadFile( GetStdHandle(STD_INPUT_HANDLE), &aBuffer, sizeof(aBuffer), 
&dwRead, NULL ) && dwRead > 0)
        {
         OSL_ASSERT((dwRead % 2) == 0);
         OUString value( aBuffer, dwRead / 2);
-        return value.trim();
+        rLine = value.trim();
+        return true;
        }
 #else
        char buf[1024];
@@ -561,10 +562,12 @@ OUString readConsole()
        if (fgets(buf, 1024, stdin) != NULL)
     {
         OUString value = ::rtl::OStringToOUString(::rtl::OString(buf), 
osl_getThreadTextEncoding());
-        return value.trim();
+        rLine = value.trim();
+        return true;
     }
 #endif
-    return OUString();
+    rLine = OUString();
+    return false;
 }
 
 void TRACE(::rtl::OUString const & sText)
diff --git a/main/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx 
b/main/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
index d6b91fb6d5..552ecf2d5a 100644
--- a/main/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
+++ b/main/desktop/source/pkgchk/unopkg/unopkg_cmdenv.cxx
@@ -183,7 +183,14 @@ void CommandEnvironmentImpl::printLicense(
 
        do
        {
-        OUString sAnswer = dp_misc::readConsole();
+        OUString sAnswer;
+        if (! dp_misc::readConsole( sAnswer ))
+        {
+            // end of input: answer "no" rather than asking forever
+            dp_misc::writeConsole(sNewLine);
+            decline = true;
+            break;
+        }
                if (xCollator->compareString(sAnswer, sYES) == 0
                        || xCollator->compareString(sAnswer, sY) == 0)
                {

Reply via email to