|
1 | 1 | __author__ = "desultory" |
2 | | -__version__ = "7.1.0" |
| 2 | +__version__ = "7.2.0" |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from shutil import which |
@@ -36,12 +36,26 @@ def _process_loglevel(self, loglevel: int) -> None: |
36 | 36 | @contains("autodetect_init", log_level=30) |
37 | 37 | @unset("init_target", "init_target is already set, skipping autodetection.", log_level=30) |
38 | 38 | def autodetect_init(self) -> None: |
39 | | - """Autodetects the init_target.""" |
| 39 | + """Autodetects the init_target. |
| 40 | + Attempts to find the "init" binary using which, |
| 41 | + if this fails, read /proc/1/exe to find the init binary. |
| 42 | + """ |
40 | 43 | if init := which("init"): |
41 | 44 | self.logger.info("Detected init at: %s", c_(init, "cyan", bright=True)) |
42 | 45 | self["init_target"] = init |
43 | | - else: |
44 | | - raise AutodetectError("init_target is not specified and could not be detected.") |
| 46 | + return |
| 47 | + |
| 48 | + self.logger.info(f"No init found in PATH, checking {c_('/proc/1/exe', 'green')}") |
| 49 | + try: |
| 50 | + init = Path("/proc/1/exe").readlink() |
| 51 | + init = init.resolve() # Resolve the symlink to get the actual path |
| 52 | + self.logger.info("Detected from process 1: %s", c_(init, "cyan", bright=True)) |
| 53 | + self["init_target"] = init |
| 54 | + return |
| 55 | + except PermissionError: |
| 56 | + self.logger.eror("Unable to read /proc/1/exe, permission denied.") |
| 57 | + |
| 58 | + raise AutodetectError("init_target is not specified and could not be detected.") |
45 | 59 |
|
46 | 60 |
|
47 | 61 | @unset("shebang", "shebang is already set.", log_level=10) |
|
0 commit comments