Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions libc/include/unistd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions libc/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ add_entrypoint_object(
libc.src.errno.errno
)

add_entrypoint_object(
setsid
SRCS
setsid.cpp
HDRS
../setsid.h
DEPENDS
libc.hdr.types.pid_t
libc.hdr.fcntl_macros
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
)

add_entrypoint_object(
symlink
SRCS
Expand Down
23 changes: 23 additions & 0 deletions libc/src/unistd/linux/setsid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- 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 "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

#include <sys/syscall.h> // For syscall numbers.

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(pid_t, setsid, ()) {
return LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_setsid);
}

} // namespace LIBC_NAMESPACE_DECL
22 changes: 22 additions & 0 deletions libc/src/unistd/setsid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- 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 "hdr/unistd_macros.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
10 changes: 10 additions & 0 deletions libc/test/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions libc/test/src/unistd/setsid_test.cpp
Original file line number Diff line number Diff line change
@@ -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();
}