]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/monitor.h
github: Update for main branch
[mirror_lxc.git] / src / lxc / monitor.h
CommitLineData
cc73685d
CB
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
f1a4a029
ÇO
3#ifndef __LXC_MONITOR_H
4#define __LXC_MONITOR_H
0ad19a3f 5
1160ce89
CB
6#include "config.h"
7
f9870943 8#include <limits.h>
d38dd64a 9#include <poll.h>
80f41298 10#include <sys/param.h>
e51d4895
DE
11#include <sys/un.h>
12
85b035a1
CB
13#include "compiler.h"
14
eae6543d 15typedef enum {
16 lxc_msg_state,
17 lxc_msg_priority,
1787abca 18 lxc_msg_exit_code,
eae6543d 19} lxc_msg_type_t;
20
21struct lxc_msg {
22 lxc_msg_type_t type;
85b035a1 23 char name[NAME_MAX + 1];
eae6543d 24 int value;
25};
26
85b035a1
CB
27__hidden extern int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr);
28__hidden extern int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path_sz,
29 int do_mkdirp);
30__hidden extern void lxc_monitor_send_state(const char *name, lxc_state_t state, const char *lxcpath);
31__hidden extern void lxc_monitor_send_exit_code(const char *name, int exit_code, const char *lxcpath);
32__hidden extern int lxc_monitord_spawn(const char *lxcpath);
0ad19a3f 33
2366b8a7
SH
34/*
35 * Open the monitoring mechanism for a specific container
36 * The function will return an fd corresponding to the events
37 * Returns a file descriptor on success, < 0 otherwise
38 */
85b035a1 39__hidden extern int lxc_monitor_open(const char *lxcpath);
2366b8a7
SH
40
41/*
42 * Blocking read for the next container state change
43 * @fd : the file descriptor provided by lxc_monitor_open
44 * @msg : the variable which will be filled with the state
45 * Returns 0 if the monitored container has exited, > 0 if
46 * data was read, < 0 otherwise
47 */
85b035a1 48__hidden extern int lxc_monitor_read(int fd, struct lxc_msg *msg);
2366b8a7
SH
49
50/*
51 * Blocking read for the next container state change with timeout
52 * @fd : the file descriptor provided by lxc_monitor_open
53 * @msg : the variable which will be filled with the state
54 * @timeout : the timeout in seconds to wait for a state change
55 * Returns 0 if the monitored container has exited, > 0 if
56 * data was read, < 0 otherwise
57 */
85b035a1 58__hidden extern int lxc_monitor_read_timeout(int fd, struct lxc_msg *msg, int timeout);
2366b8a7
SH
59
60/*
61 * Blocking read from multiple monitors for the next container state
62 * change with timeout
13dff219 63 * @fds : struct pollfd describing the fds to use
2366b8a7
SH
64 * @nfds : the number of entries in fds
65 * @msg : the variable which will be filled with the state
66 * @timeout : the timeout in seconds to wait for a state change
67 * Returns 0 if the monitored container has exited, > 0 if
68 * data was read, < 0 otherwise
69 */
85b035a1
CB
70__hidden extern int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg,
71 int timeout);
2366b8a7 72
85b035a1 73#endif /* __LXC_MONITOR_H */