devd.cc (146306) | devd.cc (147874) |
---|---|
1/*- 2 * Copyright (c) 2002-2003 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 --- 20 unchanged lines hidden (view full) --- 29 */ 30 31// TODO list: 32// o devd.conf and devd man pages need a lot of help: 33// - devd needs to document the unix domain socket 34// - devd.conf needs more details on the supported statements. 35 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002-2003 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 --- 20 unchanged lines hidden (view full) --- 29 */ 30 31// TODO list: 32// o devd.conf and devd man pages need a lot of help: 33// - devd needs to document the unix domain socket 34// - devd.conf needs more details on the supported statements. 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 146306 2005-05-16 20:51:46Z imp $"); | 37__FBSDID("$FreeBSD: head/sbin/devd/devd.cc 147874 2005-07-10 03:37:15Z imp $"); |
38 39#include <sys/param.h> 40#include <sys/socket.h> 41#include <sys/stat.h> 42#include <sys/sysctl.h> 43#include <sys/types.h> 44#include <sys/un.h> 45 --- 139 unchanged lines hidden (view full) --- 185 if (Dflag) 186 fprintf(stderr, "Testing %s=%s against %s\n", _var.c_str(), 187 value.c_str(), _re.c_str()); 188 189 retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0); 190 return retval; 191} 192 | 38 39#include <sys/param.h> 40#include <sys/socket.h> 41#include <sys/stat.h> 42#include <sys/sysctl.h> 43#include <sys/types.h> 44#include <sys/un.h> 45 --- 139 unchanged lines hidden (view full) --- 185 if (Dflag) 186 fprintf(stderr, "Testing %s=%s against %s\n", _var.c_str(), 187 value.c_str(), _re.c_str()); 188 189 retval = (regexec(&_regex, value.c_str(), 0, NULL, 0) == 0); 190 return retval; 191} 192 |
193#include <sys/sockio.h> 194#include <net/if.h> 195#include <net/if_media.h> 196 197media::media(config &c, const char *var, const char *type) 198 : _var(var), _type(-1) 199{ 200 static struct ifmedia_description media_types[] = { 201 { IFM_ETHER, "Ethernet" }, 202 { IFM_TOKEN, "Tokenring" }, 203 { IFM_FDDI, "FDDI" }, 204 { IFM_IEEE80211, "802.11" }, 205 { IFM_ATM, "ATM" }, 206 { IFM_CARP, "CARP" }, 207 { -1, "unknown" }, 208 { 0, NULL }, 209 }; 210 for (int i = 0; media_types[i].ifmt_string != NULL; i++) 211 if (strcasecmp(type, media_types[i].ifmt_string) == 0) { 212 _type = media_types[i].ifmt_word; 213 break; 214 } 215} 216 217media::~media() 218{ 219} 220 221bool 222media::do_match(config &c) 223{ 224 string value = c.get_variable("device-name"); 225 struct ifmediareq ifmr; 226 bool retval; 227 int s; 228 229 if (Dflag) 230 fprintf(stderr, "Testing media type of %s against 0x%x\n", 231 value.c_str(), _type); 232 233 retval = false; 234 235 s = socket(PF_INET, SOCK_DGRAM, 0); 236 if (s >= 0) { 237 memset(&ifmr, 0, sizeof(ifmr)); 238 strncpy(ifmr.ifm_name, value.c_str(), sizeof(ifmr.ifm_name)); 239 240 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0 && 241 ifmr.ifm_status & IFM_AVALID) { 242 if (Dflag) 243 fprintf(stderr, "%s has media type 0x%x\n", 244 value.c_str(), IFM_TYPE(ifmr.ifm_active)); 245 retval = (IFM_TYPE(ifmr.ifm_active) == _type); 246 } else if (_type == -1) { 247 if (Dflag) 248 fprintf(stderr, "%s has unknown media type\n", 249 value.c_str()); 250 retval = true; 251 } 252 close(s); 253 } 254 255 return retval; 256} 257 |
|
193const string var_list::bogus = "_$_$_$_$_B_O_G_U_S_$_$_$_$_"; 194const string var_list::nothing = ""; 195 196const string & 197var_list::get_variable(const string &var) const 198{ 199 map<string, string>::const_iterator i; 200 --- 566 unchanged lines hidden (view full) --- 767new_match(const char *var, const char *re) 768{ 769 eps *e = new match(cfg, var, re); 770 free(const_cast<char *>(var)); 771 free(const_cast<char *>(re)); 772 return (e); 773} 774 | 258const string var_list::bogus = "_$_$_$_$_B_O_G_U_S_$_$_$_$_"; 259const string var_list::nothing = ""; 260 261const string & 262var_list::get_variable(const string &var) const 263{ 264 map<string, string>::const_iterator i; 265 --- 566 unchanged lines hidden (view full) --- 832new_match(const char *var, const char *re) 833{ 834 eps *e = new match(cfg, var, re); 835 free(const_cast<char *>(var)); 836 free(const_cast<char *>(re)); 837 return (e); 838} 839 |
840eps * 841new_media(const char *var, const char *re) 842{ 843 eps *e = new media(cfg, var, re); 844 free(const_cast<char *>(var)); 845 free(const_cast<char *>(re)); 846 return (e); 847} 848 |
|
775void 776set_pidfile(const char *name) 777{ 778 cfg.set_pidfile(name); 779 free(const_cast<char *>(name)); 780} 781 782void --- 76 unchanged lines hidden --- | 849void 850set_pidfile(const char *name) 851{ 852 cfg.set_pidfile(name); 853 free(const_cast<char *>(name)); 854} 855 856void --- 76 unchanged lines hidden --- |