File tree Expand file tree Collapse file tree 10 files changed +110
-0
lines changed Expand file tree Collapse file tree 10 files changed +110
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,7 @@ set(TARGET_LIBC_ENTRYPOINTS
329329 libc.src.unistd.geteuid
330330 libc.src.unistd.getpid
331331 libc.src.unistd.getppid
332+ libc.src.unistd.getsid
332333 libc.src.unistd.gettid
333334 libc.src.unistd.getuid
334335 libc.src.unistd.isatty
Original file line number Diff line number Diff line change @@ -326,6 +326,7 @@ set(TARGET_LIBC_ENTRYPOINTS
326326 libc.src.unistd.geteuid
327327 libc.src.unistd.getpid
328328 libc.src.unistd.getppid
329+ libc.src.unistd.getsid
329330 libc.src.unistd.gettid
330331 libc.src.unistd.getuid
331332 libc.src.unistd.isatty
Original file line number Diff line number Diff line change @@ -328,6 +328,7 @@ set(TARGET_LIBC_ENTRYPOINTS
328328 libc.src.unistd.geteuid
329329 libc.src.unistd.getpid
330330 libc.src.unistd.getppid
331+ libc.src.unistd.getsid
331332 libc.src.unistd.gettid
332333 libc.src.unistd.getuid
333334 libc.src.unistd.isatty
Original file line number Diff line number Diff line change @@ -161,6 +161,12 @@ functions:
161161 return_type : int
162162 arguments :
163163 - type : void
164+ - name : getsid
165+ standards :
166+ - POSIX
167+ return_type : pid_t
168+ arguments :
169+ - type : pid_t
164170 - name : gettid
165171 standards :
166172 - Linux
Original file line number Diff line number Diff line change @@ -125,6 +125,13 @@ add_entrypoint_object(
125125 .${LIBC_TARGET_OS} .getppid
126126)
127127
128+ add_entrypoint_object(
129+ getsid
130+ ALIAS
131+ DEPENDS
132+ .${LIBC_TARGET_OS} .getsid
133+ )
134+
128135add_entrypoint_object(
129136 geteuid
130137 ALIAS
Original file line number Diff line number Diff line change 1+ // ===-- Implementation header for getsid ------------------------*- C++ -*-===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ #ifndef LLVM_LIBC_SRC_UNISTD_GETSID_H
10+ #define LLVM_LIBC_SRC_UNISTD_GETSID_H
11+
12+ #include " hdr/types/pid_t.h"
13+ #include " src/__support/macros/config.h"
14+
15+ namespace LIBC_NAMESPACE_DECL {
16+
17+ pid_t getsid (pid_t );
18+
19+ } // namespace LIBC_NAMESPACE_DECL
20+
21+ #endif // LLVM_LIBC_SRC_UNISTD_GETSID_H
Original file line number Diff line number Diff line change @@ -235,6 +235,19 @@ add_entrypoint_object(
235235 libc.src.__support.OSUtil.osutil
236236)
237237
238+ add_entrypoint_object(
239+ getsid
240+ SRCS
241+ getsid.cpp
242+ HDRS
243+ ../getsid.h
244+ DEPENDS
245+ libc.hdr.types.pid_t
246+ libc.include .sys_syscall
247+ libc.src.__support.OSUtil.osutil
248+ libc.src.errno.errno
249+ )
250+
238251add_entrypoint_object(
239252 getuid
240253 SRCS
Original file line number Diff line number Diff line change 1+ // ===-- Linux implementation of getsid-------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ #include " src/unistd/getsid.h"
10+
11+ #include " hdr/types/pid_t.h"
12+ #include " src/__support/OSUtil/syscall.h" // For internal syscall function.
13+ #include " src/__support/common.h"
14+ #include " src/__support/macros/config.h"
15+ #include " src/errno/libc_errno.h"
16+ #include < sys/syscall.h> // For syscall numbers.
17+
18+ namespace LIBC_NAMESPACE_DECL {
19+
20+ LLVM_LIBC_FUNCTION (pid_t , getsid, (pid_t pid)) {
21+ pid_t ret = LIBC_NAMESPACE::syscall_impl<pid_t >(SYS_getsid, pid);
22+ if (ret < 0 ) {
23+ libc_errno = static_cast <int >(-ret);
24+ return -1 ;
25+ }
26+ return ret;
27+ }
28+
29+ } // namespace LIBC_NAMESPACE_DECL
Original file line number Diff line number Diff line change @@ -394,6 +394,16 @@ add_libc_unittest(
394394 libc.src.unistd.getppid
395395)
396396
397+ add_libc_unittest(
398+ getsid_test
399+ SUITE
400+ libc_unistd_unittests
401+ SRCS
402+ getsid_test.cpp
403+ DEPENDS
404+ libc.src.unistd.getsid
405+ )
406+
397407add_libc_unittest(
398408 getuid_test
399409 SUITE
Original file line number Diff line number Diff line change 1+ // ===-- Unittests for getsid ----------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ #include " src/errno/libc_errno.h"
10+ #include " src/unistd/getsid.h"
11+ #include " test/UnitTest/Test.h"
12+
13+ TEST (LlvmLibcGetPidTest, GetCurrSID) {
14+ pid_t sid = LIBC_NAMESPACE::getsid (0 );
15+ ASSERT_NE (sid, -1 );
16+ ASSERT_ERRNO_SUCCESS ();
17+
18+ pid_t nonexist_sid = LIBC_NAMESPACE::getsid (-1 );
19+ ASSERT_EQ (nonexist_sid, -1 );
20+ ASSERT_ERRNO_FAILURE ();
21+ }
You can’t perform that action at this time.
0 commit comments