Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: use /tmp instead of /dev/shm #34097

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cereal/messaging/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_services(self, s):

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"
2 changes: 1 addition & 1 deletion common/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OpenpilotPrefix {
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);
Expand Down
2 changes: 1 addition & 1 deletion common/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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

Expand Down
3 changes: 2 additions & 1 deletion common/watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_"; // + <pid>
const std::string watchdog_fn_prefix = Path::shm_path() + "/wd_"; // + <pid>

bool watchdog_kick(uint64_t ts) {
static std::string fn = watchdog_fn_prefix + std::to_string(getpid());
Expand Down
5 changes: 2 additions & 3 deletions selfdrive/test/process_replay/process_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions system/hardware/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions system/hardware/hw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
from pathlib import Path

from openpilot.system.hardware import PC
Expand Down Expand Up @@ -56,3 +57,9 @@ def config_root() -> str:
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"
6 changes: 3 additions & 3 deletions system/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion system/manager/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
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


Expand Down