|
@@ -1,5 +1,6 @@
|
|
|
/*
|
|
|
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
|
|
+ * Copyright (c) 2021, Spencer Dixon <spencercdixon@gmail.com>
|
|
|
*
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
*/
|
|
@@ -103,4 +104,24 @@ Vector<String> AppFile::launcher_protocols() const
|
|
|
return protocols;
|
|
|
}
|
|
|
|
|
|
+bool AppFile::spawn() const
|
|
|
+{
|
|
|
+ if (!is_valid())
|
|
|
+ return false;
|
|
|
+
|
|
|
+ pid_t child_pid;
|
|
|
+ const char* argv[] = { executable().characters(), nullptr };
|
|
|
+ if ((errno = posix_spawn(&child_pid, executable().characters(), nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
|
|
+ perror("posix_spawn");
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ if (disown(child_pid) < 0) {
|
|
|
+ perror("disown");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
}
|