This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: vfork always fail problem


On Tue, May 18, 2010 at 02:47:57PM +0900, Kazuhiro Fujieda wrote:
>>>> On Fri, 14 May 2010 21:22:02 +0200
>>>> Corinna Vinschen said:
>
>> That sounds a bit weird.  The joke of using the ...W functions is that
>> the string parameters are always given in UTF-16.  GBK is a multibyte
>> charset and can only be used in conjunction with the ...A functions.
>> However, I'm on vacation so I can't test this scenario right now.
>
>GetModuleFileName used in pinfo_basic::pinfo_basic disturbs the
>order. This function uses ANSI codepage. 'fork' for a file whose
>name contains multibyte characters doesn't work well in UTF-8 locales.
>
>This call should be GetModuleFileNameW and the type of progname
>in _pinfo should be wide characters. I attached the patch.
>
>2010-05-18  Kazuhiro Fujida  <fujieda@acm.org>
>
>	* environ.cc (regopt): Change the first argument to wide char string.
>	(environ_init): Accommodate change to the first argument of regopt.
>	* exception.cc (open_stackdumpfile): Accommodate change to the type
>	of progname in _pinfo.
>	* external.cc (fillout_pinfo): Ditto.
>	* fhandler_process.cc (format_process_winexename): Ditto.
>	(format_process_stat): Ditto.
>	* fork.cc (fork::parent): Ditto.
>	* pinfo.cc (pinfo_basic::pinfo_basic): Call GetModuleFileNameW
>	instead of GetModuleFileName.
>	(pinfo::thisproc): Accommodate change to the type of progname in
>	_pinfo.
>	(pinfo_init): Ditto.
>	* pinfo.h (_pinfo): Change the type of progname to a wide char array.
>	* registry.h (reg_key::get_int): Change the first argument from
>	constant point to pointer to constant.
>	(reg_key::get_string): Ditto. Change the last argument likewise.
>	* registry.cc (reg_key::get_int): Accommodate change to the
>	declaration.
>	(reg_key::get_string): Ditto.
>	* strace.cc (strace::hello): Accommodate change to the type of
>	progname in _pinfo.
>	(strace::vsprntf): Ditto.
>
>Index: environ.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/cygwin/environ.cc,v
>retrieving revision 1.182
>diff -u -r1.182 environ.cc
>--- environ.cc	16 Nov 2009 20:05:49 -0000	1.182
>+++ environ.cc	18 May 2010 05:31:45 -0000
>@@ -29,6 +29,7 @@
> #include "registry.h"
> #include "environ.h"
> #include "child_info.h"
>+#include "ntdll.h"
> 
> extern bool dos_file_warning;
> extern bool ignore_case_with_glob;
>@@ -698,18 +699,24 @@
> 
> /* Set options from the registry. */
> static bool __stdcall
>-regopt (const char *name, char *buf)
>+regopt (const WCHAR *name, char *buf)
> {
>   bool parsed_something = false;
>-  char lname[strlen (name) + 1];
>-  strlwr (strcpy (lname, name));
>+  UNICODE_STRING lname;
>+  size_t len = (wcslen(name) + 1) * sizeof (WCHAR);
>+  RtlInitEmptyUnicodeString(&lname, (PWCHAR) alloca (len), len);
>+  wcscpy(lname.Buffer, name);
>+  RtlDowncaseUnicodeString(&lname, &lname, FALSE);
> 
>   for (int i = 0; i < 2; i++)
>     {
>       reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
> 
>-      if (r.get_string (lname, buf, NT_MAX_PATH, "") == ERROR_SUCCESS)
>+      if (r.get_string (lname.Buffer, (PWCHAR) buf, NT_MAX_PATH, L"") == ERROR_SUCCESS)
> 	{
>+	  char *newp;
>+	  sys_wcstombs_alloc(&newp, HEAP_NOTHEAP, (PWCHAR) buf);
>+	  strcpy(buf, newp);
> 	  parse_options (buf);
> 	  parsed_something = true;
> 	  break;
>@@ -747,7 +754,7 @@
>       }
> 
>   char *tmpbuf = tp.t_get ();
>-  got_something_from_registry = regopt ("default", tmpbuf);
>+  got_something_from_registry = regopt (L"default", tmpbuf);
>   if (myself->progname[0])
>     got_something_from_registry = regopt (myself->progname, tmpbuf)
> 				  || got_something_from_registry;
>Index: exceptions.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/cygwin/exceptions.cc,v
>retrieving revision 1.343
>diff -u -r1.343 exceptions.cc
>--- exceptions.cc	20 Apr 2010 10:44:52 -0000	1.343
>+++ exceptions.cc	18 May 2010 05:31:45 -0000
>@@ -130,24 +130,21 @@
> {
>   if (myself->progname[0])
>     {
>-      const char *p;
>+      const WCHAR *p;
>       /* write to progname.stackdump if possible */
>       if (!myself->progname[0])
>-	p = "unknown";
>-      else if ((p = strrchr (myself->progname, '\\')))
>+	p = L"unknown";
>+      else if ((p = wcsrchr (myself->progname, L'\\')))
> 	p++;
>       else
> 	p = myself->progname;
> 
>-      WCHAR corefile[strlen (p) + sizeof (".stackdump")];
>+      WCHAR corefile[wcslen (p) + sizeof (L".stackdump")];
                                    ^^^^^^^^^^^^^^^^^^^^^^
No L" is needed here, AFAICT.

I've checked this in, removing the L.

Thanks for the patch.

Appreciated.

Next time maybe you could send this to cygwin-patches?

cgf

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]