Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
sys
System.hpp
Go to the documentation of this file.
1
// The Reactive C++ Toolbox.
2
// Copyright (C) 2013-2019 Swirly Cloud Limited
3
// Copyright (C) 2021 Reactive Markets Limited
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#ifndef TOOLBOX_SYS_SYSTEM_HPP
18
#define TOOLBOX_SYS_SYSTEM_HPP
19
20
#include <
toolbox/sys/Error.hpp
>
21
22
#include <unistd.h>
23
24
namespace
toolbox
{
25
namespace
os {
26
28
inline
void
chdir
(
const
char
* path, std::error_code&
ec
)
noexcept
29
{
30
const
auto
ret
=
::chdir
(path);
31
if
(
ret
< 0) {
32
ec
=
make_error
(
errno
);
33
}
34
}
35
37
inline
void
chdir
(
const
char
* path)
38
{
39
const
auto
ret
=
::chdir
(path);
40
if
(
ret
< 0) {
41
throw
std::system_error{
make_error
(
errno
),
"chdir"
};
42
}
43
}
44
46
inline
pid_t
fork
(std::error_code&
ec
)
noexcept
47
{
48
const
auto
pid
=
::fork
();
49
if
(
pid
< 0) {
50
ec
=
make_error
(
errno
);
51
}
52
return
pid
;
53
}
54
56
inline
pid_t
fork
()
57
{
58
const
auto
pid
=
::fork
();
59
if
(
pid
< 0) {
60
throw
std::system_error{
make_error
(
errno
),
"fork"
};
61
}
62
return
pid
;
63
}
64
66
inline
pid_t
setsid
(std::error_code&
ec
)
noexcept
67
{
68
const
auto
sid =
::setsid
();
69
if
(sid < 0) {
70
ec
=
make_error
(
errno
);
71
}
72
return
sid;
73
}
74
76
inline
pid_t
setsid
()
77
{
78
const
auto
sid =
::setsid
();
79
if
(sid < 0) {
80
throw
std::system_error{
make_error
(
errno
),
"setsid"
};
81
}
82
return
sid;
83
}
84
85
}
// namespace os
86
}
// namespace toolbox
87
88
#endif
// TOOLBOX_SYS_SYSTEM_HPP
toolbox::os::chdir
void chdir(const char *path, std::error_code &ec) noexcept
Change working directory.
Definition
System.hpp:28
toolbox::os::fork
pid_t fork()
Create a child process.
Definition
System.hpp:56
toolbox::os::setsid
pid_t setsid()
Creates a session and sets the process group ID.
Definition
System.hpp:76
toolbox::sys::make_error
std::error_code make_error(int err) noexcept
Definition
Error.hpp:25
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
Error.hpp
Generated by
1.9.8