2021-11-22 15:43:57 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2021-11-27 15:23:16 +01:00
|
|
|
* Copyright (c) 2021, Kenneth Myhra <kennethmyhra@gmail.com>
|
2021-12-25 12:52:19 +00:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2021-11-22 15:43:57 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Error.h>
|
2022-01-14 10:20:29 +01:00
|
|
|
#include <AK/StringView.h>
|
2021-12-25 12:52:19 +00:00
|
|
|
#include <fcntl.h>
|
2021-12-06 21:24:18 +01:00
|
|
|
#include <grp.h>
|
2021-11-29 22:03:19 +01:00
|
|
|
#include <pwd.h>
|
2021-11-22 16:11:03 +01:00
|
|
|
#include <signal.h>
|
2021-12-13 18:38:48 +01:00
|
|
|
#include <spawn.h>
|
2021-12-25 12:52:19 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
2021-11-23 11:10:19 +01:00
|
|
|
#include <sys/stat.h>
|
2022-01-16 17:25:26 -07:00
|
|
|
#include <sys/time.h>
|
2022-01-03 19:56:28 -07:00
|
|
|
#include <sys/utsname.h>
|
2021-12-13 18:43:39 +01:00
|
|
|
#include <sys/wait.h>
|
2021-11-29 23:28:10 +01:00
|
|
|
#include <termios.h>
|
2021-11-27 22:01:40 +01:00
|
|
|
#include <time.h>
|
2021-12-21 01:27:51 +01:00
|
|
|
#include <utime.h>
|
2021-11-22 15:43:57 +01:00
|
|
|
|
2022-01-01 18:26:17 +01:00
|
|
|
#ifndef AK_OS_BSD_GENERIC
|
|
|
|
# include <shadow.h>
|
|
|
|
#endif
|
|
|
|
|
2021-11-23 10:59:50 +01:00
|
|
|
namespace Core::System {
|
2021-11-22 15:43:57 +01:00
|
|
|
|
2021-11-23 10:59:50 +01:00
|
|
|
#ifdef __serenity__
|
2022-01-09 06:14:43 +01:00
|
|
|
ErrorOr<void> beep();
|
2021-11-27 14:23:58 -08:00
|
|
|
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
|
2021-11-22 15:43:57 +01:00
|
|
|
ErrorOr<void> unveil(StringView path, StringView permissions);
|
2021-11-28 09:12:29 +01:00
|
|
|
ErrorOr<void> sendfd(int sockfd, int fd);
|
|
|
|
ErrorOr<int> recvfd(int sockfd, int options);
|
2021-11-25 23:04:52 +01:00
|
|
|
ErrorOr<void> ptrace_peekbuf(pid_t tid, void const* tracee_addr, Bytes destination_buf);
|
2021-12-16 19:31:50 +01:00
|
|
|
ErrorOr<void> setgroups(Span<gid_t const>);
|
2021-12-16 20:23:21 +01:00
|
|
|
ErrorOr<void> mount(int source_fd, StringView target, StringView fs_type, int flags);
|
2022-01-21 23:10:59 +01:00
|
|
|
ErrorOr<void> umount(StringView mount_point);
|
2021-12-25 11:04:40 +01:00
|
|
|
ErrorOr<long> ptrace(int request, pid_t tid, void* address, void* data);
|
2021-12-29 16:22:22 +01:00
|
|
|
ErrorOr<void> disown(pid_t pid);
|
2022-02-13 00:07:51 +02:00
|
|
|
ErrorOr<void> profiling_enable(pid_t, u64 event_mask);
|
2022-02-13 00:08:16 +02:00
|
|
|
ErrorOr<void> profiling_disable(pid_t);
|
2022-02-13 00:08:37 +02:00
|
|
|
ErrorOr<void> profiling_free_buffer(pid_t);
|
2021-11-23 10:59:50 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-01 18:26:17 +01:00
|
|
|
#ifndef AK_OS_BSD_GENERIC
|
|
|
|
ErrorOr<Optional<struct spwd>> getspent();
|
|
|
|
ErrorOr<Optional<struct spwd>> getspnam(StringView name);
|
|
|
|
#endif
|
|
|
|
|
2021-12-25 12:52:19 +00:00
|
|
|
#ifndef AK_OS_MACOS
|
|
|
|
ErrorOr<int> accept4(int sockfd, struct sockaddr*, socklen_t*, int flags);
|
|
|
|
#endif
|
|
|
|
|
2021-11-22 16:11:03 +01:00
|
|
|
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
|
2022-02-14 14:48:23 +01:00
|
|
|
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
|
2021-11-23 21:03:53 +01:00
|
|
|
ErrorOr<sig_t> signal(int signal, sig_t handler);
|
|
|
|
#else
|
|
|
|
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler);
|
|
|
|
#endif
|
2021-11-23 11:10:19 +01:00
|
|
|
ErrorOr<struct stat> fstat(int fd);
|
|
|
|
ErrorOr<int> fcntl(int fd, int command, ...);
|
2021-11-23 11:47:32 +01:00
|
|
|
ErrorOr<void*> mmap(void* address, size_t, int protection, int flags, int fd, off_t, size_t alignment = 0, StringView name = {});
|
2021-11-23 11:51:11 +01:00
|
|
|
ErrorOr<void> munmap(void* address, size_t);
|
2022-01-23 23:03:09 +01:00
|
|
|
ErrorOr<int> anon_create(size_t size, int options);
|
2021-11-23 11:59:16 +01:00
|
|
|
ErrorOr<int> open(StringView path, int options, ...);
|
2021-11-23 12:05:56 +01:00
|
|
|
ErrorOr<void> close(int fd);
|
2021-11-23 12:16:07 +01:00
|
|
|
ErrorOr<void> ftruncate(int fd, off_t length);
|
2021-11-23 12:22:21 +01:00
|
|
|
ErrorOr<struct stat> stat(StringView path);
|
2021-12-02 22:41:40 +01:00
|
|
|
ErrorOr<struct stat> lstat(StringView path);
|
2021-11-27 13:02:33 -08:00
|
|
|
ErrorOr<ssize_t> read(int fd, Bytes buffer);
|
|
|
|
ErrorOr<ssize_t> write(int fd, ReadonlyBytes buffer);
|
2021-11-23 16:06:56 +01:00
|
|
|
ErrorOr<void> kill(pid_t, int signal);
|
2022-03-01 20:04:41 +01:00
|
|
|
ErrorOr<void> killpg(int pgrp, int signal);
|
2021-11-28 12:08:28 +01:00
|
|
|
ErrorOr<int> dup(int source_fd);
|
2021-11-24 22:36:28 +01:00
|
|
|
ErrorOr<int> dup2(int source_fd, int destination_fd);
|
2021-11-24 23:24:53 +01:00
|
|
|
ErrorOr<String> ptsname(int fd);
|
2021-11-27 10:13:33 +01:00
|
|
|
ErrorOr<String> gethostname();
|
2022-01-14 10:20:29 +01:00
|
|
|
ErrorOr<void> sethostname(StringView);
|
2021-12-24 08:20:29 -08:00
|
|
|
ErrorOr<String> getcwd();
|
2021-11-29 23:07:33 +01:00
|
|
|
ErrorOr<void> ioctl(int fd, unsigned request, ...);
|
2021-11-29 23:28:10 +01:00
|
|
|
ErrorOr<struct termios> tcgetattr(int fd);
|
|
|
|
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
|
2022-03-01 20:05:14 +01:00
|
|
|
ErrorOr<int> tcsetpgrp(int fd, pid_t pgrp);
|
2021-11-27 15:46:11 +01:00
|
|
|
ErrorOr<void> chmod(StringView pathname, mode_t mode);
|
2021-12-31 19:20:17 +01:00
|
|
|
ErrorOr<void> lchown(StringView pathname, uid_t uid, gid_t gid);
|
2021-11-27 15:23:16 +01:00
|
|
|
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
|
2021-12-23 09:41:00 +01:00
|
|
|
ErrorOr<Optional<struct passwd>> getpwnam(StringView name);
|
|
|
|
ErrorOr<Optional<struct group>> getgrnam(StringView name);
|
2022-01-01 17:53:57 +01:00
|
|
|
ErrorOr<Optional<struct passwd>> getpwuid(uid_t);
|
|
|
|
ErrorOr<Optional<struct group>> getgrgid(gid_t);
|
2021-11-27 22:01:40 +01:00
|
|
|
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
|
2021-12-13 18:38:48 +01:00
|
|
|
ErrorOr<pid_t> posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
|
2022-01-18 14:42:45 +00:00
|
|
|
ErrorOr<off_t> lseek(int fd, off_t, int whence);
|
2022-01-10 14:34:09 +01:00
|
|
|
|
|
|
|
struct WaitPidResult {
|
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
ErrorOr<WaitPidResult> waitpid(pid_t waitee, int options = 0);
|
2021-12-16 19:17:44 +01:00
|
|
|
ErrorOr<void> setuid(uid_t);
|
|
|
|
ErrorOr<void> seteuid(uid_t);
|
|
|
|
ErrorOr<void> setgid(gid_t);
|
|
|
|
ErrorOr<void> setegid(gid_t);
|
2021-12-21 06:17:50 +03:30
|
|
|
ErrorOr<void> setpgid(pid_t pid, pid_t pgid);
|
2022-01-03 01:58:58 +01:00
|
|
|
ErrorOr<pid_t> setsid();
|
2021-12-16 19:24:58 +01:00
|
|
|
ErrorOr<bool> isatty(int fd);
|
2021-12-16 20:23:21 +01:00
|
|
|
ErrorOr<void> symlink(StringView target, StringView link_path);
|
2021-12-16 20:27:25 +01:00
|
|
|
ErrorOr<void> mkdir(StringView path, mode_t);
|
2022-01-03 02:07:26 -07:00
|
|
|
ErrorOr<void> chdir(StringView path);
|
2022-02-12 18:35:38 -07:00
|
|
|
ErrorOr<void> rmdir(StringView path);
|
2021-12-16 20:28:54 +01:00
|
|
|
ErrorOr<pid_t> fork();
|
2021-12-16 21:10:59 +01:00
|
|
|
ErrorOr<int> mkstemp(Span<char> pattern);
|
2021-12-16 21:12:23 +01:00
|
|
|
ErrorOr<void> fchmod(int fd, mode_t mode);
|
2022-02-06 17:54:15 +00:00
|
|
|
ErrorOr<void> fchown(int fd, uid_t, gid_t);
|
2021-12-16 21:40:42 +01:00
|
|
|
ErrorOr<void> rename(StringView old_path, StringView new_path);
|
2021-12-29 21:47:38 +01:00
|
|
|
ErrorOr<void> unlink(StringView path);
|
2021-12-20 19:48:30 +01:00
|
|
|
ErrorOr<void> utime(StringView path, Optional<struct utimbuf>);
|
2022-01-03 19:56:28 -07:00
|
|
|
ErrorOr<struct utsname> uname();
|
2021-12-21 06:16:46 +03:30
|
|
|
ErrorOr<Array<int, 2>> pipe2(int flags);
|
2022-01-16 17:25:26 -07:00
|
|
|
ErrorOr<void> adjtime(const struct timeval* delta, struct timeval* old_delta);
|
2021-11-22 15:43:57 +01:00
|
|
|
|
2021-12-25 12:52:19 +00:00
|
|
|
ErrorOr<int> socket(int domain, int type, int protocol);
|
|
|
|
ErrorOr<void> bind(int sockfd, struct sockaddr const*, socklen_t);
|
|
|
|
ErrorOr<void> listen(int sockfd, int backlog);
|
|
|
|
ErrorOr<int> accept(int sockfd, struct sockaddr*, socklen_t*);
|
|
|
|
ErrorOr<void> connect(int sockfd, struct sockaddr const*, socklen_t);
|
|
|
|
ErrorOr<void> shutdown(int sockfd, int how);
|
|
|
|
ErrorOr<ssize_t> send(int sockfd, void const*, size_t, int flags);
|
|
|
|
ErrorOr<ssize_t> sendmsg(int sockfd, const struct msghdr*, int flags);
|
|
|
|
ErrorOr<ssize_t> sendto(int sockfd, void const*, size_t, int flags, struct sockaddr const*, socklen_t);
|
|
|
|
ErrorOr<ssize_t> recv(int sockfd, void*, size_t, int flags);
|
|
|
|
ErrorOr<ssize_t> recvmsg(int sockfd, struct msghdr*, int flags);
|
|
|
|
ErrorOr<ssize_t> recvfrom(int sockfd, void*, size_t, int flags, struct sockaddr*, socklen_t*);
|
|
|
|
ErrorOr<void> getsockopt(int sockfd, int level, int option, void* value, socklen_t* value_size);
|
|
|
|
ErrorOr<void> setsockopt(int sockfd, int level, int option, void const* value, socklen_t value_size);
|
|
|
|
ErrorOr<void> getsockname(int sockfd, struct sockaddr*, socklen_t*);
|
|
|
|
ErrorOr<void> getpeername(int sockfd, struct sockaddr*, socklen_t*);
|
|
|
|
ErrorOr<void> socketpair(int domain, int type, int protocol, int sv[2]);
|
2022-01-01 16:19:51 +01:00
|
|
|
ErrorOr<Vector<gid_t>> getgroups();
|
2022-01-14 17:08:46 +01:00
|
|
|
ErrorOr<void> mknod(StringView pathname, mode_t mode, dev_t dev);
|
2022-01-17 10:04:00 +01:00
|
|
|
ErrorOr<void> mkfifo(StringView pathname, mode_t mode);
|
2021-11-22 15:43:57 +01:00
|
|
|
}
|