diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 09eb51a3f8fc6..49e3c04b0ca16 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -341,6 +341,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.readlink libc.src.unistd.readlinkat libc.src.unistd.rmdir + libc.src.unistd.setsid libc.src.unistd.symlink libc.src.unistd.symlinkat libc.src.unistd.sysconf diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 14a05a2f3fbf2..4d1d87170208d 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -337,6 +337,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.readlink libc.src.unistd.readlinkat libc.src.unistd.rmdir + libc.src.unistd.setsid libc.src.unistd.symlink libc.src.unistd.symlinkat libc.src.unistd.sysconf diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 366e4d34294d1..c8e0adaeee282 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -340,6 +340,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.unistd.readlink libc.src.unistd.readlinkat libc.src.unistd.rmdir + libc.src.unistd.setsid libc.src.unistd.symlink libc.src.unistd.symlinkat libc.src.unistd.sysconf diff --git a/libc/include/unistd.yaml b/libc/include/unistd.yaml index c1901be446fe5..d04d46bd5c002 100644 --- a/libc/include/unistd.yaml +++ b/libc/include/unistd.yaml @@ -275,6 +275,12 @@ functions: - type: const void *__restrict - type: void * - type: ssize_t + - name: setsid + standards: + - POSIX + return_type: pid_t + arguments: + - type: void - name: symlink standards: - POSIX diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt index 6bdea0c7693bd..fb563ec4ecfd9 100644 --- a/libc/src/unistd/CMakeLists.txt +++ b/libc/src/unistd/CMakeLists.txt @@ -231,6 +231,13 @@ add_entrypoint_object( .${LIBC_TARGET_OS}.rmdir ) +add_entrypoint_object( + setsid + ALIAS + DEPENDS + .${LIBC_TARGET_OS}.setsid +) + add_entrypoint_object( symlink ALIAS diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 2bb17f56f7b32..afdc595d0b26f 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -459,6 +459,18 @@ add_entrypoint_object( libc.src.errno.errno ) +add_entrypoint_object( + setsid + SRCS + setsid.cpp + HDRS + ../setsid.h + DEPENDS + libc.hdr.types.pid_t + libc.include.sys_syscall + libc.src.__support.OSUtil.osutil +) + add_entrypoint_object( symlink SRCS diff --git a/libc/src/unistd/linux/setsid.cpp b/libc/src/unistd/linux/setsid.cpp new file mode 100644 index 0000000000000..df4629bb326cc --- /dev/null +++ b/libc/src/unistd/linux/setsid.cpp @@ -0,0 +1,24 @@ +//===-- Linux implementation of setsid-------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/unistd/setsid.h" + +#include "hdr/types/pid_t.h" +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +#include // For syscall numbers. + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(pid_t, setsid, ()) { + return LIBC_NAMESPACE::syscall_impl(SYS_setsid); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/unistd/setsid.h b/libc/src/unistd/setsid.h new file mode 100644 index 0000000000000..44dd7dd2ce816 --- /dev/null +++ b/libc/src/unistd/setsid.h @@ -0,0 +1,21 @@ +//===-- Implementation header for setsid ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_UNISTD_GETPID_H +#define LLVM_LIBC_SRC_UNISTD_GETPID_H + +#include "hdr/types/pid_t.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +pid_t setsid(); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_UNISTD_GETPID_H diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt index b01cce931a1eb..665cb367ba4fd 100644 --- a/libc/test/src/unistd/CMakeLists.txt +++ b/libc/test/src/unistd/CMakeLists.txt @@ -287,6 +287,16 @@ add_libc_unittest( libc.src.__support.CPP.string_view ) +add_libc_unittest( + setsid_test + SUITE + libc_unistd_unittests + SRCS + setsid_test.cpp + DEPENDS + libc.src.unistd.setsid +) + add_libc_unittest( symlink_test SUITE diff --git a/libc/test/src/unistd/setsid_test.cpp b/libc/test/src/unistd/setsid_test.cpp new file mode 100644 index 0000000000000..466faa16ea1eb --- /dev/null +++ b/libc/test/src/unistd/setsid_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for setsid ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/unistd/setsid.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcGetPidTest, SmokeTest) { + // setsid always succeeds. So, we just call it as a smoke test. + LIBC_NAMESPACE::setsid(); +}