From ff0432665a0dc30bec1aa09d92ecfe2ac4d25f4d Mon Sep 17 00:00:00 2001 From: imp Date: Fri, 24 Oct 2003 22:02:29 +0000 Subject: Parse the ! lines that will soon be coming from the kernel. These are a generalized notification mechanism for subsystems wishing to report events. Revieded by: njl # The kernel side seems like it might be causing panics for me, but should # be forthcoming shortly. --- sbin/devd/devd.cc | 45 ++++++++++++++++++++++++++++++++++++--------- sbin/devd/devd.h | 1 + sbin/devd/devd.hh | 2 ++ sbin/devd/parse.y | 9 ++++++++- sbin/devd/token.l | 1 + 5 files changed, 48 insertions(+), 10 deletions(-) (limited to 'sbin/devd') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index bc2e8f6..71a0f29 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -67,6 +67,7 @@ using namespace std; extern FILE *yyin; extern int lineno; +static const char notify = '!'; static const char nomatch = '?'; static const char attach = '+'; static const char detach = '-'; @@ -219,6 +220,7 @@ config::reset(void) delete_and_clear(_attach_list); delete_and_clear(_detach_list); delete_and_clear(_nomatch_list); + delete_and_clear(_notify_list); } void @@ -282,6 +284,7 @@ config::parse(void) sort_vector(_attach_list); sort_vector(_detach_list); sort_vector(_nomatch_list); + sort_vector(_notify_list); } void @@ -326,6 +329,13 @@ config::add_nomatch(int prio, event_proc *p) } void +config::add_notify(int prio, event_proc *p) +{ + p->set_priority(prio); + _notify_list.push_back(p); +} + +void config::set_pidfile(const char *fn) { _pidfile = string(fn); @@ -501,6 +511,10 @@ config::find_and_execute(char type) switch (type) { default: return; + case notify: + l = &_notify_list; + s = "notify"; + break; case nomatch: l = &_nomatch_list; s = "nomatch"; @@ -539,25 +553,32 @@ process_event(char *buffer) cfg.push_var_table(); // No match doesn't have a device, and the format is a little // different, so handle it separately. - if (type != nomatch) { - sp = strchr(sp, ' '); - if (sp == NULL) - return; /* Can't happen? */ - *sp++ = '\0'; - cfg.set_variable("device-name", buffer); + switch (type) { + case notify: + sp = cfg.set_vars(sp); + break; + case nomatch: + //?vars at location on bus + sp = cfg.set_vars(sp); if (strncmp(sp, "at ", 3) == 0) sp += 3; sp = cfg.set_vars(sp); if (strncmp(sp, "on ", 3) == 0) cfg.set_variable("bus", sp + 3); - } else { - //?vars at location on bus - sp = cfg.set_vars(sp); + break; + case attach: /*FALLTHROUGH*/ + case detach: + sp = strchr(sp, ' '); + if (sp == NULL) + return; /* Can't happen? */ + *sp++ = '\0'; + cfg.set_variable("device-name", buffer); if (strncmp(sp, "at ", 3) == 0) sp += 3; sp = cfg.set_vars(sp); if (strncmp(sp, "on ", 3) == 0) cfg.set_variable("bus", sp + 3); + break; } cfg.find_and_execute(type); @@ -643,6 +664,12 @@ add_nomatch(int prio, event_proc *p) cfg.add_nomatch(prio, p); } +void +add_notify(int prio, event_proc *p) +{ + cfg.add_notify(prio, p); +} + event_proc * add_to_event_proc(event_proc *ep, eps *eps) { diff --git a/sbin/devd/devd.h b/sbin/devd/devd.h index c2f54a6..8a032e4 100644 --- a/sbin/devd/devd.h +++ b/sbin/devd/devd.h @@ -40,6 +40,7 @@ void add_attach(int, struct event_proc *); void add_detach(int, struct event_proc *); void add_directory(const char *); void add_nomatch(int, struct event_proc *); +void add_notify(int, struct event_proc *); struct event_proc *add_to_event_proc(struct event_proc *, struct eps *); struct eps *new_match(const char *, const char *); struct eps *new_action(const char *); diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh index 15dba5d..4730267 100644 --- a/sbin/devd/devd.hh +++ b/sbin/devd/devd.hh @@ -133,6 +133,7 @@ public: void add_detach(int, event_proc *); void add_directory(const char *); void add_nomatch(int, event_proc *); + void add_notify(int, event_proc *); void set_pidfile(const char *); void reset(); void parse(); @@ -158,6 +159,7 @@ private: std::vector _attach_list; std::vector _detach_list; std::vector _nomatch_list; + std::vector _notify_list; }; #endif /* DEVD_HH */ diff --git a/sbin/devd/parse.y b/sbin/devd/parse.y index cfc9313..9269ef2 100644 --- a/sbin/devd/parse.y +++ b/sbin/devd/parse.y @@ -47,7 +47,7 @@ %token STRING %token ID %token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH -%token ATTACH DETACH NOMATCH +%token ATTACH DETACH NOMATCH NOTIFY %type match_or_action_list %type match_or_action match action @@ -69,6 +69,7 @@ config | attach_block | detach_block | nomatch_block + | notify_block ; option_block @@ -115,6 +116,12 @@ nomatch_block | NOMATCH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON ; +notify_block + : NOTIFY NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON + { add_notify($2, $4); } + | NOTIFY NUMBER BEGINBLOCK ENDBLOCK SEMICOLON + ; + match_or_action_list : match_or_action { $$ = add_to_event_proc( NULL, $1); } | match_or_action_list match_or_action diff --git a/sbin/devd/token.l b/sbin/devd/token.l index 03a5a72..0aa8cb6 100644 --- a/sbin/devd/token.l +++ b/sbin/devd/token.l @@ -93,6 +93,7 @@ device-name { return DEVICE_NAME; } action { return ACTION; } match { return MATCH; } nomatch { return NOMATCH; } +notify { return NOTIFY; } [A-Za-z][A-Za-z0-9_-]* { yylval.str = strdup(yytext); return ID; -- cgit v1.1