#macos #sockets #activation #launchd

raunch

launchd 的安全包装器:launch_activate_socket

2 个稳定版本

1.0.1 2024 年 4 月 15 日
1.0.0 2020 年 5 月 7 日

macOS 和 iOS APIs 中排名 33

Download history 151/week @ 2024-04-22 80/week @ 2024-04-29 140/week @ 2024-05-06 84/week @ 2024-05-13 48/week @ 2024-05-20 30/week @ 2024-05-27 79/week @ 2024-06-03 70/week @ 2024-06-10 13/week @ 2024-06-17 29/week @ 2024-06-24 165/week @ 2024-07-08 12/week @ 2024-07-15 9/week @ 2024-07-22 82/week @ 2024-07-29 10/week @ 2024-08-05

每月下载量 114
3 个 crate 中使用(通过 service-binding

MIT/Apache 协议

5KB
63 行代码(不含注释)

Raunch

launchd 的安全包装器:launch_activate_socket。

#[cfg(target_os = "macos")]
let descriptors = raunch::activate_socket("socket-name").expect("activation to work");

套接字名称(此处为 socket-name)需要与 plist 文件中的套接字名称匹配

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.example.agent</string>
	<key>OnDemand</key>
	<true/>
	<key>ProgramArguments</key>
	<array>
		<string>example-agent</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>Sockets</key>
	<dict>
		<key>socket-name</key>
		<dict>
			<key>SockPathName</key>
			<string>/Users/test/.openpgp-card-ssh-agent</string>
			<key>SockFamily</key>
			<string>Unix</string>
		</dict>
	</dict>
</dict>
</plist>

该文件可以放置在 ~/Library/LaunchAgents 中,并通过 launchctl load ~/Library/LaunchAgents/com.example.agent.plist 加载。

依赖项

~43KB