|
root / stub / src / socket.reef
socket.reef Reef 38 lines 1.3 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// socket.reef — Unix domain socket server for zygctl communication
//
// Listens on /var/run/zyginit.sock for commands from zygctl.
// Protocol: newline-delimited text commands, JSON responses.
//
// Commands:
//   status              → list all services and their states
//   status <name>       → status of a single service
//   start <name>        → start a service (transient, not persisted)
//   stop <name>         → stop a service
//   restart <name>      → stop then start
//   enable <name>       → create symlink in enabled.d/ (persisted)
//   disable <name>      → remove symlink from enabled.d/
//   list                → list all known service definitions

const SOCKET_PATH: &str = "/var/run/zyginit.sock";

// Create and bind the Unix domain socket
fn create_socket() -> Result<i32, String> {
    // TODO: implement
    // 1. socket(AF_UNIX, SOCK_STREAM, 0)
    // 2. bind() to SOCKET_PATH
    // 3. listen()
    // 4. Return fd for poll()
    Err("not yet implemented")
}

// Handle a client connection — read command, dispatch, respond
fn handle_client(client_fd: i32) -> Result<(), String> {
    // TODO: implement
    // 1. Read command line from client
    // 2. Parse command + args
    // 3. Dispatch to appropriate handler
    // 4. Send response (JSON)
    // 5. Close client fd
    Err("not yet implemented")
}