devd.cc (243930) | devd.cc (243931) |
---|---|
1/*- 2 * Copyright (c) 2002-2010 M. Warner Losh. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 49 unchanged lines hidden (view full) --- 58 */ 59 60// TODO list: 61// o devd.conf and devd man pages need a lot of help: 62// - devd needs to document the unix domain socket 63// - devd.conf needs more details on the supported statements. 64 65#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002-2010 M. Warner Losh. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 49 unchanged lines hidden (view full) --- 58 */ 59 60// TODO list: 61// o devd.conf and devd man pages need a lot of help: 62// - devd needs to document the unix domain socket 63// - devd.conf needs more details on the supported statements. 64 65#include <sys/cdefs.h> |
66__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 243930 2012-12-06 01:25:14Z eadler $"); | 66__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 243931 2012-12-06 01:25:17Z eadler $"); |
67 68#include <sys/param.h> 69#include <sys/socket.h> 70#include <sys/stat.h> 71#include <sys/sysctl.h> 72#include <sys/types.h> 73#include <sys/wait.h> 74#include <sys/un.h> --- 47 unchanged lines hidden (view full) --- 122static void event_loop(void); 123static void usage(void); 124 125template <class T> void 126delete_and_clear(vector<T *> &v) 127{ 128 typename vector<T *>::const_iterator i; 129 | 67 68#include <sys/param.h> 69#include <sys/socket.h> 70#include <sys/stat.h> 71#include <sys/sysctl.h> 72#include <sys/types.h> 73#include <sys/wait.h> 74#include <sys/un.h> --- 47 unchanged lines hidden (view full) --- 122static void event_loop(void); 123static void usage(void); 124 125template <class T> void 126delete_and_clear(vector<T *> &v) 127{ 128 typename vector<T *>::const_iterator i; 129 |
130 for (i = v.begin(); i != v.end(); i++) | 130 for (i = v.begin(); i != v.end(); ++i) |
131 delete *i; 132 v.clear(); 133} 134 135config cfg; 136 137event_proc::event_proc() : _prio(-1) 138{ --- 11 unchanged lines hidden (view full) --- 150 _epsvec.push_back(eps); 151} 152 153bool 154event_proc::matches(config &c) const 155{ 156 vector<eps *>::const_iterator i; 157 | 131 delete *i; 132 v.clear(); 133} 134 135config cfg; 136 137event_proc::event_proc() : _prio(-1) 138{ --- 11 unchanged lines hidden (view full) --- 150 _epsvec.push_back(eps); 151} 152 153bool 154event_proc::matches(config &c) const 155{ 156 vector<eps *>::const_iterator i; 157 |
158 for (i = _epsvec.begin(); i != _epsvec.end(); i++) | 158 for (i = _epsvec.begin(); i != _epsvec.end(); ++i) |
159 if (!(*i)->do_match(c)) 160 return (false); 161 return (true); 162} 163 164bool 165event_proc::run(config &c) const 166{ 167 vector<eps *>::const_iterator i; 168 | 159 if (!(*i)->do_match(c)) 160 return (false); 161 return (true); 162} 163 164bool 165event_proc::run(config &c) const 166{ 167 vector<eps *>::const_iterator i; 168 |
169 for (i = _epsvec.begin(); i != _epsvec.end(); i++) | 169 for (i = _epsvec.begin(); i != _epsvec.end(); ++i) |
170 if (!(*i)->do_action(c)) 171 return (false); 172 return (true); 173} 174 175action::action(const char *cmd) 176 : _cmd(cmd) 177{ --- 118 unchanged lines hidden (view full) --- 296 { IFM_ETHER, "Ethernet" }, 297 { IFM_TOKEN, "Tokenring" }, 298 { IFM_FDDI, "FDDI" }, 299 { IFM_IEEE80211, "802.11" }, 300 { IFM_ATM, "ATM" }, 301 { -1, "unknown" }, 302 { 0, NULL }, 303 }; | 170 if (!(*i)->do_action(c)) 171 return (false); 172 return (true); 173} 174 175action::action(const char *cmd) 176 : _cmd(cmd) 177{ --- 118 unchanged lines hidden (view full) --- 296 { IFM_ETHER, "Ethernet" }, 297 { IFM_TOKEN, "Tokenring" }, 298 { IFM_FDDI, "FDDI" }, 299 { IFM_IEEE80211, "802.11" }, 300 { IFM_ATM, "ATM" }, 301 { -1, "unknown" }, 302 { 0, NULL }, 303 }; |
304 for (int i = 0; media_types[i].ifmt_string != NULL; i++) | 304 for (int i = 0; media_types[i].ifmt_string != NULL; ++i) |
305 if (strcasecmp(type, media_types[i].ifmt_string) == 0) { 306 _type = media_types[i].ifmt_word; 307 break; 308 } 309} 310 311media::~media() 312{ --- 136 unchanged lines hidden (view full) --- 449} 450 451void 452config::parse(void) 453{ 454 vector<string>::const_iterator i; 455 456 parse_one_file(configfile); | 305 if (strcasecmp(type, media_types[i].ifmt_string) == 0) { 306 _type = media_types[i].ifmt_word; 307 break; 308 } 309} 310 311media::~media() 312{ --- 136 unchanged lines hidden (view full) --- 449} 450 451void 452config::parse(void) 453{ 454 vector<string>::const_iterator i; 455 456 parse_one_file(configfile); |
457 for (i = _dir_list.begin(); i != _dir_list.end(); i++) | 457 for (i = _dir_list.begin(); i != _dir_list.end(); ++i) |
458 parse_files_in_dir((*i).c_str()); 459 sort_vector(_attach_list); 460 sort_vector(_detach_list); 461 sort_vector(_nomatch_list); 462 sort_vector(_notify_list); 463} 464 465void --- 98 unchanged lines hidden (view full) --- 564 _var_list_table.back()->set_variable(var, val); 565} 566 567const string & 568config::get_variable(const string &var) 569{ 570 vector<var_list *>::reverse_iterator i; 571 | 458 parse_files_in_dir((*i).c_str()); 459 sort_vector(_attach_list); 460 sort_vector(_detach_list); 461 sort_vector(_nomatch_list); 462 sort_vector(_notify_list); 463} 464 465void --- 98 unchanged lines hidden (view full) --- 564 _var_list_table.back()->set_variable(var, val); 565} 566 567const string & 568config::get_variable(const string &var) 569{ 570 vector<var_list *>::reverse_iterator i; 571 |
572 for (i = _var_list_table.rbegin(); i != _var_list_table.rend(); i++) { | 572 for (i = _var_list_table.rbegin(); i != _var_list_table.rend(); ++i) { |
573 if ((*i)->is_set(var)) 574 return ((*i)->get_variable(var)); 575 } 576 return (var_list::nothing); 577} 578 579bool 580config::is_id_char(char ch) const --- 140 unchanged lines hidden (view full) --- 721 break; 722 case detach: 723 l = &_detach_list; 724 s = "detach"; 725 break; 726 } 727 if (Dflag) 728 fprintf(stderr, "Processing %s event\n", s); | 573 if ((*i)->is_set(var)) 574 return ((*i)->get_variable(var)); 575 } 576 return (var_list::nothing); 577} 578 579bool 580config::is_id_char(char ch) const --- 140 unchanged lines hidden (view full) --- 721 break; 722 case detach: 723 l = &_detach_list; 724 s = "detach"; 725 break; 726 } 727 if (Dflag) 728 fprintf(stderr, "Processing %s event\n", s); |
729 for (i = l->begin(); i != l->end(); i++) { | 729 for (i = l->begin(); i != l->end(); ++i) { |
730 if ((*i)->matches(*this)) { 731 (*i)->run(*this); 732 break; 733 } 734 } 735 736} 737 --- 80 unchanged lines hidden (view full) --- 818list<int> clients; 819 820void 821notify_clients(const char *data, int len) 822{ 823 list<int> bad; 824 list<int>::const_iterator i; 825 | 730 if ((*i)->matches(*this)) { 731 (*i)->run(*this); 732 break; 733 } 734 } 735 736} 737 --- 80 unchanged lines hidden (view full) --- 818list<int> clients; 819 820void 821notify_clients(const char *data, int len) 822{ 823 list<int> bad; 824 list<int>::const_iterator i; 825 |
826 for (i = clients.begin(); i != clients.end(); i++) { | 826 for (i = clients.begin(); i != clients.end(); ++i) { |
827 if (write(*i, data, len) <= 0) { 828 bad.push_back(*i); 829 close(*i); 830 } 831 } 832 | 827 if (write(*i, data, len) <= 0) { 828 bad.push_back(*i); 829 close(*i); 830 } 831 } 832 |
833 for (i = bad.begin(); i != bad.end(); i++) | 833 for (i = bad.begin(); i != bad.end(); ++i) |
834 clients.erase(find(clients.begin(), clients.end(), *i)); 835} 836 837void 838new_client(int fd) 839{ 840 int s; 841 --- 230 unchanged lines hidden --- | 834 clients.erase(find(clients.begin(), clients.end(), *i)); 835} 836 837void 838new_client(int fd) 839{ 840 int s; 841 --- 230 unchanged lines hidden --- |