Message ID | 1310758694-6360-4-git-send-email-weil@mail.berlios.de |
---|---|
State | Accepted |
Headers | show |
Am 15.07.2011 um 21:38 schrieb Stefan Weil: > Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 > introduced FMT_pid which is wrong for w32 and w64 getpid(): > those getpid() implementations always return an int value. Where is __int64 FMT_pid used then if not for the returned pid? Andreas > > Signed-off-by: Stefan Weil <weil@mail.berlios.de> > --- > os-win32.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/os-win32.c b/os-win32.c > index b6652af..e153058 100644 > --- a/os-win32.c > +++ b/os-win32.c > @@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename) > if (file == INVALID_HANDLE_VALUE) { > return -1; > } > - len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid()); > + len = snprintf(buffer, sizeof(buffer), "%d\n", getpid()); > ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, > &overlap, NULL); > if (ret == 0) { > -- > 1.7.2.5 > >
On Fri, Jul 15, 2011 at 11:42 PM, Andreas Färber <andreas.faerber@web.de> wrote: > Am 15.07.2011 um 21:38 schrieb Stefan Weil: > >> Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 >> introduced FMT_pid which is wrong for w32 and w64 getpid(): >> those getpid() implementations always return an int value. This is not in line with Posix: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243 > Where is __int64 FMT_pid used then if not for the returned pid? For shutdown_pid which is pid_t: src/qemu/vl.c:1200: fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); > Andreas > >> >> Signed-off-by: Stefan Weil <weil@mail.berlios.de> >> --- >> os-win32.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/os-win32.c b/os-win32.c >> index b6652af..e153058 100644 >> --- a/os-win32.c >> +++ b/os-win32.c >> @@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename) >> if (file == INVALID_HANDLE_VALUE) { >> return -1; >> } >> - len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid()); >> + len = snprintf(buffer, sizeof(buffer), "%d\n", getpid()); Another way would be to cast the result of getpid to pid_t. Then if the buggy getpid() implementations are fixed one day, there will be no truncation. >> ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, >> &overlap, NULL); >> if (ret == 0) { >> -- >> 1.7.2.5 >> >> > >
Am 17.07.2011 11:03, schrieb Blue Swirl: > On Fri, Jul 15, 2011 at 11:42 PM, Andreas Färber > <andreas.faerber@web.de> wrote: >> Am 15.07.2011 um 21:38 schrieb Stefan Weil: >>> Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 >>> introduced FMT_pid which is wrong for w32 and w64 getpid(): >>> those getpid() implementations always return an int value. > > This is not in line with Posix: > http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243 Maybe I should have added that getpid() is a function in a vendor specific API. Microsoft does not claim that getpid() is in line with Posix (they say it is a deprecated POSIX function, see http://msdn.microsoft.com/en-us/library/ms235372%28v=vs.80%29.aspx). Visual Studio uses this declaration: _CRT_NONSTDC_DEPRECATE(_getpid) _CRTIMP int __cdecl getpid(void); Mingw32 tries to be more POSIX like and uses (with pid_t = int) this declaration: _CRTIMP pid_t __cdecl __MINGW_NOTHROW getpid (void); Mingw-w64 is closer to the VS declaration: int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; The replacement for getpid() is _getpid(). It also has a wrong declaration in mingw32. A patch which simply replaces getpid by _getpid is on my todo list, but not urgent, because the current code works when my patch was applied. Regards, Stefan
On Sun, Jul 17, 2011 at 9:34 PM, Stefan Weil <weil@mail.berlios.de> wrote: > Am 17.07.2011 11:03, schrieb Blue Swirl: >> >> On Fri, Jul 15, 2011 at 11:42 PM, Andreas Färber <andreas.faerber@web.de> >> wrote: >>> >>> Am 15.07.2011 um 21:38 schrieb Stefan Weil: >>>> >>>> Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 >>>> introduced FMT_pid which is wrong for w32 and w64 getpid(): >>>> those getpid() implementations always return an int value. >> >> This is not in line with Posix: >> >> http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243 > > Maybe I should have added that getpid() is a function in a vendor specific > API. > Microsoft does not claim that getpid() is in line with Posix > (they say it is a deprecated POSIX function, see > http://msdn.microsoft.com/en-us/library/ms235372%28v=vs.80%29.aspx). > > Visual Studio uses this declaration: > _CRT_NONSTDC_DEPRECATE(_getpid) _CRTIMP int __cdecl getpid(void); > > Mingw32 tries to be more POSIX like and uses (with pid_t = int) this > declaration: > _CRTIMP pid_t __cdecl __MINGW_NOTHROW getpid (void); > > Mingw-w64 is closer to the VS declaration: > int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; > > The replacement for getpid() is _getpid(). It also has a wrong > declaration in mingw32. A patch which simply replaces getpid by > _getpid is on my todo list, but not urgent, because the current > code works when my patch was applied. Since for example GetProcessById uses int, it looks like pid_t is instead wrong.
diff --git a/os-win32.c b/os-win32.c index b6652af..e153058 100644 --- a/os-win32.c +++ b/os-win32.c @@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename) if (file == INVALID_HANDLE_VALUE) { return -1; } - len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid()); + len = snprintf(buffer, sizeof(buffer), "%d\n", getpid()); ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, &overlap, NULL); if (ret == 0) {
Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid(): those getpid() implementations always return an int value. Signed-off-by: Stefan Weil <weil@mail.berlios.de> --- os-win32.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)