diff --git a/cereal/messaging/tests/test_services.py b/cereal/messaging/tests/test_services.py index 01e859a5a3..8bfd2ea978 100644 --- a/cereal/messaging/tests/test_services.py +++ b/cereal/messaging/tests/test_services.py @@ -17,5 +17,5 @@ class TestServices: def test_generated_header(self): with tempfile.NamedTemporaryFile(suffix=".h") as f: - ret = os.system(f"python3 {services.__file__} > {f.name} && clang++ {f.name}") + ret = os.system(f"python3 {services.__file__} > {f.name} && clang++ {f.name} -std=c++11") assert ret == 0, "generated services header is not valid C" diff --git a/common/prefix.h b/common/prefix.h index 11d0bc1066..2612c05d4f 100644 --- a/common/prefix.h +++ b/common/prefix.h @@ -13,7 +13,7 @@ public: if (prefix.empty()) { prefix = util::random_string(15); } - msgq_path = "/dev/shm/" + prefix; + msgq_path = Path::shm_path() + "/" + prefix; bool ret = util::create_directories(msgq_path, 0777); assert(ret); setenv("OPENPILOT_PREFIX", prefix.c_str(), 1); diff --git a/common/prefix.py b/common/prefix.py index 3292acae86..762ae70fb4 100644 --- a/common/prefix.py +++ b/common/prefix.py @@ -11,7 +11,7 @@ from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT class OpenpilotPrefix: def __init__(self, prefix: str = None, clean_dirs_on_exit: bool = True, shared_download_cache: bool = False): self.prefix = prefix if prefix else str(uuid.uuid4().hex[0:15]) - self.msgq_path = os.path.join('/dev/shm', self.prefix) + self.msgq_path = os.path.join(Paths.shm_path(), self.prefix) self.clean_dirs_on_exit = clean_dirs_on_exit self.shared_download_cache = shared_download_cache diff --git a/common/watchdog.cc b/common/watchdog.cc index 3483ad21c2..44e8c83e6d 100644 --- a/common/watchdog.cc +++ b/common/watchdog.cc @@ -2,8 +2,9 @@ #include "common/watchdog.h" #include "common/util.h" +#include "system/hardware/hw.h" -const std::string watchdog_fn_prefix = "/dev/shm/wd_"; // + +const std::string watchdog_fn_prefix = Path::shm_path() + "/wd_"; // + bool watchdog_kick(uint64_t ts) { static std::string fn = watchdog_fn_prefix + std::to_string(getpid()); diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 448dc6896d..45210f1648 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -5,13 +5,13 @@ import copy import json import heapq import signal -import platform from collections import Counter, OrderedDict from dataclasses import dataclass, field from typing import Any from collections.abc import Callable, Iterable from tqdm import tqdm import capnp +from openpilot.system.hardware.hw import Paths import cereal.messaging as messaging from cereal import car @@ -780,8 +780,7 @@ def generate_params_config(lr=None, CP=None, fingerprint=None, custom_params=Non def generate_environ_config(CP=None, fingerprint=None, log_dir=None) -> dict[str, Any]: environ_dict = {} - if platform.system() != "Darwin": - environ_dict["PARAMS_ROOT"] = "/dev/shm/params" + environ_dict["PARAMS_ROOT"] = f"{Paths.shm_path()}/params" if log_dir is not None: environ_dict["LOG_ROOT"] = log_dir diff --git a/system/hardware/hw.h b/system/hardware/hw.h index 394807ccb5..d2083a5985 100644 --- a/system/hardware/hw.h +++ b/system/hardware/hw.h @@ -47,4 +47,12 @@ namespace Path { } return "/tmp/comma_download_cache" + Path::openpilot_prefix() + "/"; } + + inline std::string shm_path() { + #ifdef __APPLE__ + return"/tmp"; + #else + return "/dev/shm"; + #endif + } } // namespace Path diff --git a/system/hardware/hw.py b/system/hardware/hw.py index 694299d72e..dc36dc0474 100644 --- a/system/hardware/hw.py +++ b/system/hardware/hw.py @@ -1,4 +1,5 @@ import os +import platform from pathlib import Path from openpilot.system.hardware import PC @@ -56,3 +57,9 @@ class Paths: return Paths.comma_home() else: return "/tmp/.comma" + + @staticmethod + def shm_path() -> str: + if PC and platform.system() == "Darwin": + return "/tmp" # This is not really shared memory on macOS, but it's the closest we can get + return "/dev/shm" diff --git a/system/manager/manager.py b/system/manager/manager.py index 9ebbdf422d..4a5da353e9 100755 --- a/system/manager/manager.py +++ b/system/manager/manager.py @@ -17,7 +17,7 @@ from openpilot.system.manager.process_config import managed_processes from openpilot.system.athena.registration import register, UNREGISTERED_DONGLE_ID from openpilot.common.swaglog import cloudlog, add_file_handler from openpilot.system.version import get_build_metadata, terms_version, training_version - +from openpilot.system.hardware.hw import Paths def manager_init() -> None: @@ -52,11 +52,11 @@ def manager_init() -> None: # Create folders needed for msgq try: - os.mkdir("/dev/shm") + os.mkdir(Paths.shm_path()) except FileExistsError: pass except PermissionError: - print("WARNING: failed to make /dev/shm") + print(f"WARNING: failed to make {Paths.shm_path()}") # set version params params.put("Version", build_metadata.openpilot.version) diff --git a/system/manager/process.py b/system/manager/process.py index 10c8f74f9d..0e9c9b9804 100644 --- a/system/manager/process.py +++ b/system/manager/process.py @@ -16,8 +16,9 @@ import openpilot.system.sentry as sentry from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params from openpilot.common.swaglog import cloudlog +from openpilot.system.hardware.hw import Paths -WATCHDOG_FN = "/dev/shm/wd_" +WATCHDOG_FN = f"{Paths.shm_path()}/wd_" ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None