ports/www/chromium/patches/patch-base_process_process_posix_cc

96 lines
2.4 KiB
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
Index: base/process/process_posix.cc
--- base/process/process_posix.cc.orig
+++ base/process/process_posix.cc
@@ -23,10 +23,15 @@
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
#include <sys/event.h>
#endif
2023-09-14 00:49:35 +00:00
+#if BUILDFLAG(IS_BSD)
2023-08-16 22:26:55 +00:00
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#if BUILDFLAG(CLANG_PROFILING)
#include "base/test/clang_profiling.h"
#endif
@@ -93,7 +98,7 @@ bool WaitpidWithTimeout(base::ProcessHandle handle,
return ret_pid > 0;
}
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
// Using kqueue on Mac so that we can wait on non-child processes.
// We can't use kqueues on child processes because we need to reap
// our own children using wait.
@@ -198,7 +203,7 @@ bool WaitForExitWithTimeoutImpl(base::ProcessHandle ha
const bool exited = (parent_pid < 0);
if (!exited && parent_pid != our_pid) {
-#if BUILDFLAG(IS_MAC)
+#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_BSD)
// On Mac we can wait on non child processes.
return WaitForSingleNonChildProcess(handle, timeout);
#else
2023-09-14 00:49:35 +00:00
@@ -387,7 +392,56 @@ void Process::Exited(int exit_code) const {
2023-08-16 22:26:55 +00:00
2023-09-14 00:49:35 +00:00
int Process::GetOSPriority() const {
2023-08-16 22:26:55 +00:00
DCHECK(IsValid());
+// avoid pledge(2) violation
2023-09-14 00:49:35 +00:00
+#if BUILDFLAG(IS_BSD)
2023-08-16 22:26:55 +00:00
+ return 0;
+#else
return getpriority(PRIO_PROCESS, static_cast<id_t>(process_));
+#endif
2023-09-14 00:49:35 +00:00
}
2023-08-16 22:26:55 +00:00
+
+Time Process::CreationTime() const {
+// avoid ps pledge in the network process
2023-09-14 00:49:35 +00:00
+#if !BUILDFLAG(IS_BSD)
2023-08-16 22:26:55 +00:00
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid(),
+ sizeof(struct kinfo_proc), 0 };
+ struct kinfo_proc *info = nullptr;
+ size_t info_size;
+#endif
+ Time ct = Time();
+
2023-09-14 00:49:35 +00:00
+#if !BUILDFLAG(IS_BSD)
2023-08-16 22:26:55 +00:00
+ if (sysctl(mib, std::size(mib), NULL, &info_size, NULL, 0) < 0)
+ goto out;
+
+ mib[5] = (info_size / sizeof(struct kinfo_proc));
+ if ((info = reinterpret_cast<kinfo_proc*>(malloc(info_size))) == NULL)
+ goto out;
+
+ if (sysctl(mib, std::size(mib), info, &info_size, NULL, 0) < 0)
+ goto out;
+
+ ct = Time::FromTimeT(info->p_ustart_sec);
+
+out:
+ if (info)
+ free(info);
+#endif
+ return ct;
+}
+
2023-09-14 00:49:35 +00:00
+#if BUILDFLAG(IS_BSD)
+Process::Priority Process::GetPriority() const {
+ return Priority::kUserBlocking;
2023-08-16 22:26:55 +00:00
+}
2023-09-14 00:49:35 +00:00
+
+bool Process::SetPriority(Priority priority) {
2023-08-16 22:26:55 +00:00
+ return false;
+}
2023-09-14 00:49:35 +00:00
+
+bool Process::CanSetPriority() {
2023-08-16 22:26:55 +00:00
+ return false;
2023-09-14 00:49:35 +00:00
+}
+#endif
2023-08-16 22:26:55 +00:00
} // namespace base