You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "extinguish (via GitHub)" <gi...@apache.org> on 2023/07/12 03:50:24 UTC

[GitHub] [nuttx] extinguish opened a new pull request, #9789: libs/libc/getpgid: add getpgid implementation

extinguish opened a new pull request, #9789:
URL: https://github.com/apache/nuttx/pull/9789

   ## Summary
   1. the getpgid function can help to pass the ltp/open_posix_testsuite/killpg related testcases
   2. NuttX do not support process group, so we use the process id as process group id
   3. the implementation are referred to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgid.html
   
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9789: libs/libc/getpgid: add getpgid implementation

Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #9789:
URL: https://github.com/apache/nuttx/pull/9789#discussion_r1260849235


##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;
+    }
+
+  if (pid == 0)
+    {
+      return getpid();
+    }
+
+  if (kill(pid, 0) != 0)
+    {
+      set_errno(ESRCH);
+      return (pid_t)ERROR;

Review Comment:
   ```suggestion
         return INVALID_PROCESS_ID;
   ```



##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;
+    }
+
+  if (pid == 0)
+    {
+      return getpid();

Review Comment:
   ```suggestion
         return getpgrp();
   ```



##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;

Review Comment:
   ```suggestion
         return INVALID_PROCESS_ID;
   ```



##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+

Review Comment:
   ```suggestion
   #include <nuttx/sched.h>
   #include <nuttx/signal.h>
   
   ```



##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;
+    }
+
+  if (pid == 0)
+    {
+      return getpid();
+    }
+
+  if (kill(pid, 0) != 0)

Review Comment:
   ```suggestion
     else if (_SIG_KILL(pid, 0) != 0)
   ```



##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;
+    }
+
+  if (pid == 0)
+    {
+      return getpid();
+    }
+
+  if (kill(pid, 0) != 0)
+    {
+      set_errno(ESRCH);

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #9789: libs/libc/getpgid: add getpgid implementation

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #9789:
URL: https://github.com/apache/nuttx/pull/9789


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #9789: libs/libc/getpgid: add getpgid implementation

Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #9789:
URL: https://github.com/apache/nuttx/pull/9789#discussion_r1260850634


##########
libs/libc/unistd/lib_getpgid.c:
##########
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_getpgid.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: getpgid
+ *
+ * Description:
+ *   Get the Process Group ID of the required process id. But since NuttX do
+ *   not support process group, so the process group id are same as process
+ *   id, so this method will return the pid that transferred in directly,
+ *   which is same as getpgrp() method
+ *
+ * Input parameters:
+ *   pid - the process id that required to fetch the process group id
+ *
+ * Returned Value:
+ *   getpgid() shall return a process group ID. Otherwise, it shall return
+ *   (pid_t)-1 and set errno to indicate the error. If the given process id
+ *   are invalid, set errno as EINVAL, if the given process id do not exist,
+ *   set errno as ESRCH
+ *
+ ****************************************************************************/
+
+pid_t getpgid(pid_t pid)
+{
+  if (pid < 0)
+    {
+      set_errno(EINVAL);
+      return (pid_t)ERROR;
+    }
+
+  if (pid == 0)
+    {
+      return getpid();
+    }
+
+  if (kill(pid, 0) != 0)

Review Comment:
   ```suggestion
     else if (_SIG_KILL(pid, 0) < 0)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org