This is the mail archive of the cygwin-patches 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]

[PATCH 1/1] Cygwin: don't allow getpgrp() to fail


According to POSIX, "The getpgrp() function shall always be successful
and no return value is reserved to indicate an error."  Cygwin's
getpgrp() is defined in terms of getpgid(), which is allowed to fail.
Change getpgrp() so that it doesn't fail even if getpgid() fails.
---
 winsup/cygwin/syscalls.cc | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index a914ae8a9..3fd62c286 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3339,7 +3339,19 @@ setpgrp (void)
 extern "C" pid_t
 getpgrp (void)
 {
-  return getpgid (0);
+  pid_t pid = getpgid (0);
+  if (pid != -1)
+    return pid;
+  else
+    {
+      /* According to POSIX, "The getpgrp() function shall always be
+	 successful and no return value is reserved to indicate an
+	 error."  We return 0 instead of -1 for the sake of
+	 applications that mistakenly check whether the return value
+	 is -1. */
+      set_errno (0);
+      return 0;
+    }
 }
 
 extern "C" char *
-- 
2.21.0


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