Deleted Added
full compact
devd.cc (302408) devd.cc (314427)
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: stable/11/sbin/devd/devd.cc 297529 2016-04-03 20:29:21Z imp $");
66__FBSDID("$FreeBSD: stable/11/sbin/devd/devd.cc 314427 2017-02-28 22:49:41Z asomers $");
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>

--- 15 unchanged lines hidden (view full) ---

90#include <regex.h>
91#include <syslog.h>
92#include <unistd.h>
93
94#include <algorithm>
95#include <map>
96#include <string>
97#include <list>
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>

--- 15 unchanged lines hidden (view full) ---

90#include <regex.h>
91#include <syslog.h>
92#include <unistd.h>
93
94#include <algorithm>
95#include <map>
96#include <string>
97#include <list>
98#include <stdexcept>
98#include <vector>
99
100#include "devd.h" /* C compatible definitions */
101#include "devd.hh" /* C++ class definitions */
102
103#define STREAMPIPE "/var/run/devd.pipe"
104#define SEQPACKETPIPE "/var/run/devd.seqpacket.pipe"
105#define CF "/etc/devd.conf"

--- 261 unchanged lines hidden (view full) ---

367 devdlog(LOG_DEBUG, "Testing media type of %s against 0x%x\n",
368 value.c_str(), _type);
369
370 retval = false;
371
372 s = socket(PF_INET, SOCK_DGRAM, 0);
373 if (s >= 0) {
374 memset(&ifmr, 0, sizeof(ifmr));
99#include <vector>
100
101#include "devd.h" /* C compatible definitions */
102#include "devd.hh" /* C++ class definitions */
103
104#define STREAMPIPE "/var/run/devd.pipe"
105#define SEQPACKETPIPE "/var/run/devd.seqpacket.pipe"
106#define CF "/etc/devd.conf"

--- 261 unchanged lines hidden (view full) ---

368 devdlog(LOG_DEBUG, "Testing media type of %s against 0x%x\n",
369 value.c_str(), _type);
370
371 retval = false;
372
373 s = socket(PF_INET, SOCK_DGRAM, 0);
374 if (s >= 0) {
375 memset(&ifmr, 0, sizeof(ifmr));
375 strncpy(ifmr.ifm_name, value.c_str(), sizeof(ifmr.ifm_name));
376 strlcpy(ifmr.ifm_name, value.c_str(), sizeof(ifmr.ifm_name));
376
377 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0 &&
378 ifmr.ifm_status & IFM_AVALID) {
379 devdlog(LOG_DEBUG, "%s has media type 0x%x\n",
380 value.c_str(), IFM_TYPE(ifmr.ifm_active));
381 retval = (IFM_TYPE(ifmr.ifm_active) == _type);
382 } else if (_type == -1) {
383 devdlog(LOG_DEBUG, "%s has unknown media type\n",

--- 482 unchanged lines hidden (view full) ---

866 strlcpy(sun.sun_path, name, sizeof(sun.sun_path));
867 slen = SUN_LEN(&sun);
868 unlink(name);
869 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
870 err(1, "fcntl");
871 if (::bind(fd, (struct sockaddr *) & sun, slen) < 0)
872 err(1, "bind");
873 listen(fd, 4);
377
378 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0 &&
379 ifmr.ifm_status & IFM_AVALID) {
380 devdlog(LOG_DEBUG, "%s has media type 0x%x\n",
381 value.c_str(), IFM_TYPE(ifmr.ifm_active));
382 retval = (IFM_TYPE(ifmr.ifm_active) == _type);
383 } else if (_type == -1) {
384 devdlog(LOG_DEBUG, "%s has unknown media type\n",

--- 482 unchanged lines hidden (view full) ---

867 strlcpy(sun.sun_path, name, sizeof(sun.sun_path));
868 slen = SUN_LEN(&sun);
869 unlink(name);
870 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
871 err(1, "fcntl");
872 if (::bind(fd, (struct sockaddr *) & sun, slen) < 0)
873 err(1, "bind");
874 listen(fd, 4);
874 chown(name, 0, 0); /* XXX - root.wheel */
875 chmod(name, 0666);
875 if (chown(name, 0, 0)) /* XXX - root.wheel */
876 err(1, "chown");
877 if (chmod(name, 0666))
878 err(1, "chmod");
876 return (fd);
877}
878
879unsigned int max_clients = 10; /* Default, can be overridden on cmdline. */
880unsigned int num_clients;
881
882list<client_t> clients;
883

--- 169 unchanged lines hidden (view full) ---

1053 devdlog(LOG_WARNING, "Warning: "
1054 "available event data exceeded "
1055 "buffer space\n");
1056 }
1057 notify_clients(buffer, rv);
1058 buffer[rv] = '\0';
1059 while (buffer[--rv] == '\n')
1060 buffer[rv] = '\0';
879 return (fd);
880}
881
882unsigned int max_clients = 10; /* Default, can be overridden on cmdline. */
883unsigned int num_clients;
884
885list<client_t> clients;
886

--- 169 unchanged lines hidden (view full) ---

1056 devdlog(LOG_WARNING, "Warning: "
1057 "available event data exceeded "
1058 "buffer space\n");
1059 }
1060 notify_clients(buffer, rv);
1061 buffer[rv] = '\0';
1062 while (buffer[--rv] == '\n')
1063 buffer[rv] = '\0';
1061 process_event(buffer);
1064 try {
1065 process_event(buffer);
1066 }
1067 catch (std::length_error e) {
1068 devdlog(LOG_ERR, "Dropping event %s "
1069 "due to low memory", buffer);
1070 }
1062 } else if (rv < 0) {
1063 if (errno != EINTR)
1064 break;
1065 } else {
1066 /* EOF */
1067 break;
1068 }
1069 }
1070 if (FD_ISSET(stream_fd, &fds))
1071 new_client(stream_fd, SOCK_STREAM);
1072 /*
1073 * Aside from the socket type, both sockets use the same
1074 * protocol, so we can process clients the same way.
1075 */
1076 if (FD_ISSET(seqpacket_fd, &fds))
1077 new_client(seqpacket_fd, SOCK_SEQPACKET);
1078 }
1071 } else if (rv < 0) {
1072 if (errno != EINTR)
1073 break;
1074 } else {
1075 /* EOF */
1076 break;
1077 }
1078 }
1079 if (FD_ISSET(stream_fd, &fds))
1080 new_client(stream_fd, SOCK_STREAM);
1081 /*
1082 * Aside from the socket type, both sockets use the same
1083 * protocol, so we can process clients the same way.
1084 */
1085 if (FD_ISSET(seqpacket_fd, &fds))
1086 new_client(seqpacket_fd, SOCK_SEQPACKET);
1087 }
1088 close(seqpacket_fd);
1089 close(stream_fd);
1079 close(fd);
1080}
1081
1082/*
1083 * functions that the parser uses.
1084 */
1085void
1086add_attach(int prio, event_proc *p)

--- 126 unchanged lines hidden (view full) ---

1213 size_t len;
1214
1215 len = sizeof(val);
1216 if (sysctlbyname(SYSCTL, &val, &len, NULL, 0) != 0)
1217 errx(1, "devctl sysctl missing from kernel!");
1218 if (val == 0) {
1219 warnx("Setting " SYSCTL " to 1000");
1220 val = 1000;
1090 close(fd);
1091}
1092
1093/*
1094 * functions that the parser uses.
1095 */
1096void
1097add_attach(int prio, event_proc *p)

--- 126 unchanged lines hidden (view full) ---

1224 size_t len;
1225
1226 len = sizeof(val);
1227 if (sysctlbyname(SYSCTL, &val, &len, NULL, 0) != 0)
1228 errx(1, "devctl sysctl missing from kernel!");
1229 if (val == 0) {
1230 warnx("Setting " SYSCTL " to 1000");
1231 val = 1000;
1221 sysctlbyname(SYSCTL, NULL, NULL, &val, sizeof(val));
1232 if (sysctlbyname(SYSCTL, NULL, NULL, &val, sizeof(val)))
1233 err(1, "sysctlbyname");
1222 }
1223}
1224
1225/*
1226 * main
1227 */
1228int
1229main(int argc, char **argv)

--- 40 unchanged lines hidden ---
1234 }
1235}
1236
1237/*
1238 * main
1239 */
1240int
1241main(int argc, char **argv)

--- 40 unchanged lines hidden ---