X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/821d856a610b21f2946e3283db7f79443227776e..da6f998486f1070e205f2e0a54f22a1b67cb32a4:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index d757498cc3..98548a2e3f 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -2,7 +2,6 @@ // Name: src/unix/utilsunx.cpp // Purpose: generic Unix implementation of many wx functions (for wxBase) // Author: Vadim Zeitlin -// Id: $Id$ // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin // (c) 2013 Rob Bresalier, Vadim Zeitlin // Licence: wxWindows licence @@ -48,6 +47,7 @@ #include "wx/private/selectdispatcher.h" #include "wx/private/fdiodispatcher.h" #include "wx/unix/execute.h" +#include "wx/unix/pipe.h" #include "wx/unix/private.h" #include "wx/evtloop.h" @@ -499,6 +499,8 @@ int BlockUntilChildExit(wxExecuteData& execData) wxCHECK_MSG( wxTheApp, -1, wxS("Can't block until child exit without wxTheApp") ); +#if wxUSE_SELECT_DISPATCHER + // Even if we don't want to dispatch events, we still need to handle // child IO notifications and process termination concurrently, i.e. // we can't simply block waiting for the child to terminate as we would @@ -553,6 +555,11 @@ int BlockUntilChildExit(wxExecuteData& execData) } return execData.exitcode; +#else // !wxUSE_SELECT_DISPATCHER + wxFAIL_MSG( wxS("Can't block until child exit without wxSelectDispatcher") ); + + return -1; +#endif // wxUSE_SELECT_DISPATCHER/!wxUSE_SELECT_DISPATCHER } } // anonymous namespace @@ -907,9 +914,14 @@ wxString wxGetUserHome( const wxString &user ) // network and user id routines // ---------------------------------------------------------------------------- -// private utility function which returns output of the given command, removing -// the trailing newline -static wxString wxGetCommandOutput(const wxString &cmd) +// Private utility function which returns output of the given command, removing +// the trailing newline. +// +// Note that by default use Latin-1 just to ensure that we never fail, but if +// the encoding is known (e.g. UTF-8 for lsb_release), it should be explicitly +// used instead. +static wxString +wxGetCommandOutput(const wxString &cmd, wxMBConv& conv = wxConvISO8859_1) { // Suppress stderr from the shell to avoid outputting errors if the command // doesn't exist. @@ -930,7 +942,7 @@ static wxString wxGetCommandOutput(const wxString &cmd) if ( !fgets(buf, sizeof(buf), f) ) break; - s += wxString::FromAscii(buf); + s += wxString(buf, conv); } pclose(f); @@ -1071,23 +1083,38 @@ bool wxIsPlatform64Bit() } #ifdef __LINUX__ -wxLinuxDistributionInfo wxGetLinuxDistributionInfo() + +static bool +wxGetValueFromLSBRelease(wxString arg, const wxString& lhs, wxString* rhs) { - const wxString id = wxGetCommandOutput(wxT("lsb_release --id")); - const wxString desc = wxGetCommandOutput(wxT("lsb_release --description")); - const wxString rel = wxGetCommandOutput(wxT("lsb_release --release")); - const wxString codename = wxGetCommandOutput(wxT("lsb_release --codename")); + // lsb_release seems to just read a global file which is always in UTF-8 + // and hence its output is always in UTF-8 as well, regardless of the + // locale currently configured by our environment. + return wxGetCommandOutput(wxS("lsb_release ") + arg, wxConvUTF8) + .StartsWith(lhs, rhs); +} +wxLinuxDistributionInfo wxGetLinuxDistributionInfo() +{ wxLinuxDistributionInfo ret; - id.StartsWith("Distributor ID:\t", &ret.Id); - desc.StartsWith("Description:\t", &ret.Description); - rel.StartsWith("Release:\t", &ret.Release); - codename.StartsWith("Codename:\t", &ret.CodeName); + if ( !wxGetValueFromLSBRelease(wxS("--id"), wxS("Distributor ID:\t"), + &ret.Id) ) + { + // Don't bother to continue, lsb_release is probably not available. + return ret; + } + + wxGetValueFromLSBRelease(wxS("--description"), wxS("Description:\t"), + &ret.Description); + wxGetValueFromLSBRelease(wxS("--release"), wxS("Release:\t"), + &ret.Release); + wxGetValueFromLSBRelease(wxS("--codename"), wxS("Codename:\t"), + &ret.CodeName); return ret; } -#endif +#endif // __LINUX__ // these functions are in src/osx/utilsexc_base.cpp for wxMac #ifndef __DARWIN__ @@ -1407,8 +1434,14 @@ bool wxHandleFatalExceptions(bool doit) int wxAppTraits::WaitForChild(wxExecuteData& execData) { +#if wxUSE_CONSOLE_EVENTLOOP wxConsoleEventLoop loop; return RunLoopUntilChildExit(execData, loop); +#else // !wxUSE_CONSOLE_EVENTLOOP + wxFAIL_MSG( wxS("Can't wait for child process without wxConsoleEventLoop") ); + + return -1; +#endif // wxUSE_CONSOLE_EVENTLOOP/!wxUSE_CONSOLE_EVENTLOOP } // This function is common code for both console and GUI applications and used