blob: efdf3909e71051c6d530def78c8bb9f18ece9c4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <LibCore/Process.h>
#include <errno.h>
#include <spawn.h>
#ifdef __serenity__
# include <serenity.h>
#endif
extern char** environ;
namespace Core {
pid_t Process::spawn(StringView path)
{
String path_string = path;
pid_t pid;
char const* argv[] = { path_string.characters(), nullptr };
if ((errno = posix_spawn(&pid, path_string.characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("Process::spawn posix_spawn");
} else {
#ifdef __serenity__
if (disown(pid) < 0)
perror("Process::spawn disown");
#endif
}
return pid;
}
}
|