Skip to content

Commit 6f750cf

Browse files
authored
1 parent 41d5d2b commit 6f750cf

File tree

10 files changed

+98
-0
lines changed

10 files changed

+98
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ set(TARGET_LIBC_ENTRYPOINTS
341341
libc.src.unistd.readlink
342342
libc.src.unistd.readlinkat
343343
libc.src.unistd.rmdir
344+
libc.src.unistd.setsid
344345
libc.src.unistd.symlink
345346
libc.src.unistd.symlinkat
346347
libc.src.unistd.sysconf

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ set(TARGET_LIBC_ENTRYPOINTS
337337
libc.src.unistd.readlink
338338
libc.src.unistd.readlinkat
339339
libc.src.unistd.rmdir
340+
libc.src.unistd.setsid
340341
libc.src.unistd.symlink
341342
libc.src.unistd.symlinkat
342343
libc.src.unistd.sysconf

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ set(TARGET_LIBC_ENTRYPOINTS
340340
libc.src.unistd.readlink
341341
libc.src.unistd.readlinkat
342342
libc.src.unistd.rmdir
343+
libc.src.unistd.setsid
343344
libc.src.unistd.symlink
344345
libc.src.unistd.symlinkat
345346
libc.src.unistd.sysconf

libc/include/unistd.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ functions:
275275
- type: const void *__restrict
276276
- type: void *
277277
- type: ssize_t
278+
- name: setsid
279+
standards:
280+
- POSIX
281+
return_type: pid_t
282+
arguments:
283+
- type: void
278284
- name: symlink
279285
standards:
280286
- POSIX

libc/src/unistd/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ add_entrypoint_object(
231231
.${LIBC_TARGET_OS}.rmdir
232232
)
233233

234+
add_entrypoint_object(
235+
setsid
236+
ALIAS
237+
DEPENDS
238+
.${LIBC_TARGET_OS}.setsid
239+
)
240+
234241
add_entrypoint_object(
235242
symlink
236243
ALIAS

libc/src/unistd/linux/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,18 @@ add_entrypoint_object(
459459
libc.src.errno.errno
460460
)
461461

462+
add_entrypoint_object(
463+
setsid
464+
SRCS
465+
setsid.cpp
466+
HDRS
467+
../setsid.h
468+
DEPENDS
469+
libc.hdr.types.pid_t
470+
libc.include.sys_syscall
471+
libc.src.__support.OSUtil.osutil
472+
)
473+
462474
add_entrypoint_object(
463475
symlink
464476
SRCS

libc/src/unistd/linux/setsid.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Linux implementation of setsid-------------------------------------===//
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/setsid.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+
16+
#include <sys/syscall.h> // For syscall numbers.
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
20+
LLVM_LIBC_FUNCTION(pid_t, setsid, ()) {
21+
return LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_setsid);
22+
}
23+
24+
} // namespace LIBC_NAMESPACE_DECL

libc/src/unistd/setsid.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for setsid ------------------------*- 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_GETPID_H
10+
#define LLVM_LIBC_SRC_UNISTD_GETPID_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 setsid();
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_UNISTD_GETPID_H

libc/test/src/unistd/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ add_libc_unittest(
287287
libc.src.__support.CPP.string_view
288288
)
289289

290+
add_libc_unittest(
291+
setsid_test
292+
SUITE
293+
libc_unistd_unittests
294+
SRCS
295+
setsid_test.cpp
296+
DEPENDS
297+
libc.src.unistd.setsid
298+
)
299+
290300
add_libc_unittest(
291301
symlink_test
292302
SUITE

libc/test/src/unistd/setsid_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- Unittests for setsid ----------------------------------------------===//
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/setsid.h"
10+
#include "test/UnitTest/Test.h"
11+
12+
TEST(LlvmLibcGetPidTest, SmokeTest) {
13+
// setsid always succeeds. So, we just call it as a smoke test.
14+
LIBC_NAMESPACE::setsid();
15+
}

0 commit comments

Comments
 (0)