Documentation ¶
Index ¶
- func RawSockStopper(fd int) (readableOrStop func() (bool, error), stop func(), err error)
- type Env
- type KObjAction
- type Matcher
- type Mode
- type NetlinkConn
- type RuleDefinition
- type RuleDefinitions
- func (rs *RuleDefinitions) AddRule(r RuleDefinition)
- func (rs *RuleDefinitions) Compile() error
- func (rs RuleDefinitions) Evaluate(e UEvent) bool
- func (rs RuleDefinitions) EvaluateAction(a KObjAction) (match bool)
- func (rs RuleDefinitions) EvaluateEnv(e map[string]string) bool
- func (rs RuleDefinitions) String() string
- type UEvent
- type UEventConn
- func (c *UEventConn) Close() error
- func (c *UEventConn) Connect(mode Mode) (err error)
- func (c *UEventConn) Monitor(queue chan UEvent, errors chan error, matcher Matcher) (stop func(stopTimeout time.Duration) (ok bool))
- func (c *UEventConn) ReadMsg() (msg []byte, err error)
- func (c *UEventConn) ReadUEvent() (*UEvent, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RawSockStopper ¶
RawSockStopper returns a pair of functions to manage stopping code reading from a raw socket, readableOrStop blocks until fd is readable or stop was called. To work properly it sets fd to non-blocking mode. TODO: with go 1.11+ it should be possible to just switch to setting fd to non-blocking and then wrapping the socket via os.NewFile and use Close to force a read to stop. c.f. https://github.com/golang/go/commit/ea5825b0b64e1a017a76eac0ad734e11ff557c8e
Types ¶
type KObjAction ¶
type KObjAction string
const ( ADD KObjAction = "add" REMOVE KObjAction = "remove" CHANGE KObjAction = "change" MOVE KObjAction = "move" ONLINE KObjAction = "online" OFFLINE KObjAction = "offline" BIND KObjAction = "bind" UNBIND KObjAction = "unbind" )
func ParseKObjAction ¶
func ParseKObjAction(raw string) (a KObjAction, err error)
func (KObjAction) String ¶
func (a KObjAction) String() string
type NetlinkConn ¶
type NetlinkConn struct { Fd int Addr syscall.SockaddrNetlink }
Generic connection
type RuleDefinition ¶
type RuleDefinition struct { Action *string `json:"action,omitempty"` Env map[string]string `json:"env,omitempty"` // contains filtered or unexported fields }
func (*RuleDefinition) Compile ¶
func (r *RuleDefinition) Compile() error
Compile prepare rule definition to be able to Evaluate() an UEvent
func (RuleDefinition) Evaluate ¶
func (r RuleDefinition) Evaluate(e UEvent) bool
Evaluate return true if all condition match uevent and envs in rule exists in uevent
func (RuleDefinition) EvaluateAction ¶
func (r RuleDefinition) EvaluateAction(a KObjAction) (match bool)
EvaluateAction return true if the action match
func (RuleDefinition) EvaluateEnv ¶
func (r RuleDefinition) EvaluateEnv(e map[string]string) bool
EvaluateEnv return true if all env match and exists
func (RuleDefinition) String ¶
func (r RuleDefinition) String() string
type RuleDefinitions ¶
type RuleDefinitions struct {
Rules []RuleDefinition
}
RuleDefinitions is like chained rule with OR operator
func (*RuleDefinitions) AddRule ¶
func (rs *RuleDefinitions) AddRule(r RuleDefinition)
func (*RuleDefinitions) Compile ¶
func (rs *RuleDefinitions) Compile() error
func (RuleDefinitions) Evaluate ¶
func (rs RuleDefinitions) Evaluate(e UEvent) bool
func (RuleDefinitions) EvaluateAction ¶
func (rs RuleDefinitions) EvaluateAction(a KObjAction) (match bool)
EvaluateAction return true if the action match
func (RuleDefinitions) EvaluateEnv ¶
func (rs RuleDefinitions) EvaluateEnv(e map[string]string) bool
EvaluateEnv return true if almost one env match all regexp
func (RuleDefinitions) String ¶
func (rs RuleDefinitions) String() string
type UEvent ¶
type UEvent struct { Action KObjAction KObj string Env map[string]string }
func ParseUEvent ¶
type UEventConn ¶
type UEventConn struct {
NetlinkConn
}
func (*UEventConn) Close ¶
func (c *UEventConn) Close() error
Close allow to close file descriptor and socket bound
func (*UEventConn) Connect ¶
func (c *UEventConn) Connect(mode Mode) (err error)
Connect allow to connect to system socket AF_NETLINK with family NETLINK_KOBJECT_UEVENT to catch events about block/char device see: - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/netlink.h#L23 - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/socket.h#L11
func (*UEventConn) Monitor ¶
func (c *UEventConn) Monitor(queue chan UEvent, errors chan error, matcher Matcher) (stop func(stopTimeout time.Duration) (ok bool))
Monitor run in background a worker to read netlink msg in loop and notify when msg receive inside a queue using channel. To be notified with only relevant message, use Matcher.
func (*UEventConn) ReadMsg ¶
func (c *UEventConn) ReadMsg() (msg []byte, err error)
ReadMsg allow to read an entire uevent msg
func (*UEventConn) ReadUEvent ¶
func (c *UEventConn) ReadUEvent() (*UEvent, error)
ReadMsg allow to read an entire uevent msg