Commit Graph

86 Commits

Author SHA1 Message Date
Brooks Davis
eec02418d8 Remove support for FDDI and token ring media types in userland utilities.
Reviewed by:	kib
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D15077
2018-04-16 18:07:51 +00:00
Eitan Adler
dacbef689d devd: don't pass &fds in useless parameters to select(2)
select(2) should be declared as restrict. In addition the only fd in
the fdset is open O_RDONLY, and it's not a socket that can provide OOB
notifications,

Reviewed by:	ian, imp, vangyzen
2018-02-15 03:22:53 +00:00
Eitan Adler
510a8c88f0 devd: minor nits
- mark usage as noreturn
- config does not need a virtual destructor
2018-01-26 04:40:41 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Alan Somers
91cfa6b8f9 devd(8): Remove pidfile on shutdown
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-06-20 19:32:39 +00:00
Warner Losh
416823b103 Use a more stream-lined version of fix_value.
Submitted by: ian@
2017-03-24 13:46:26 +00:00
Warner Losh
192af3b7c3 Implement quote escaping. String values may now contain " if you
it is preceded by \.

foo="I \"like\" C++"

gives the value 'I "like" C++' to the variable 'foo'. If a character
other than " follows the \, both the \ and that character are passed
through.

Differential Revision: https://reviews.freebsd.org/D6286
Sponsored by: Netflix
2017-03-23 02:36:51 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Alan Somers
3e9662dcb4 Fix build of devd with GCC 4.2
Reported by:	olivier
Pointy-hat-to:	asomers
MFC after:	27 days
X-MFC-with:	312395
Sponsored by:	Spectra Logic Corp
2017-01-19 16:59:55 +00:00
Alan Somers
daa0d9dd7e Fix several Coverity CIDs in devd
CID 1362055, 1362054: File descriptor leaks during shutdown
CID 1362013: Potential null-termination fail with long network device names
CID 1362097: Uncaught exception during memory pressure
CID 1362017, 1362016: Unchecked errors, possibly resulting in weird behavior
	if two devd instances start at the same time.
CID 1362015:	Unchecked error that will probably never fail

Reported by:	Coverity
CID:	1362055 1362054 1362013 1362097 1362017 1362016 1362015
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
2017-01-18 20:24:37 +00:00
Warner Losh
4d00d13c3e Simplify test. 2016-12-01 04:35:38 +00:00
Warner Losh
3b336ac34f Add a timestamp variable to the environment. This is when the event
was read from the kernel by devd.
2016-04-03 20:29:21 +00:00
Warner Losh
535595db8d Make $_ match the docs. 2016-04-03 20:29:14 +00:00
Warner Losh
b3d322926d Sometimes, it's useful to export the entire line to an external
program without listening to the devd socket for all events. Define
two new pseudo variables $*, the entire event from devctl and $_,
the entire event without the type character, since it might be easier
to use in some circumstances.
2016-03-28 04:22:22 +00:00
Alan Somers
d9ca81dabe Increase devd's client socket buffer size to 256KB. This is not as large as
it looks, because we'll hit the sockbuf's mbuf limit long before hitting its
data limit. A 256KB data limit allows creating a ZFS pool on about 450
drives without overflowing the client socket buffers.

MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D4476
2015-12-09 18:55:25 +00:00
Eitan Adler
463a577b27 Fix a ton of speelling errors
arc lint is helpful

Reviewed By: allanjude, wblock, #manpages, chris@bsdjunk.com
Differential Revision: https://reviews.freebsd.org/D3337
2015-10-21 05:37:09 +00:00
Alan Somers
9102691e9c sbin/devd/devd.8
sbin/devd/devd.cc
	Create a new socket, of type SOCK_SEQPACKET, for communicating with
	clients.  SOCK_SEQPACKET sockets preserve record boundaries,
	simplying code in the client.  The old SOCK_STREAM socket is
	retained for backwards-compatibility with existing clients.

Sponsored by:	Spectra Logic
2014-05-21 23:04:47 +00:00
Mateusz Guzik
ee38f2e004 Update userspace users of hw.bus.devctl_disable.
This fixes breakage resulting from r263754.

Reported by:	AN <andy@neu.net>
Reviewed by:	imp
Pointy hat to:	me
2014-03-26 02:25:40 +00:00
Alan Somers
6a2ae0eb16 sbin/devd/devd.8
sbin/devd/devd.cc
	Add a -q flag to devd that will suppress syslog logging at
	LOG_NOTICE or below.

Requested by:	ian@ and imp@
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corporation
2014-03-07 23:30:48 +00:00
Alan Somers
f0038a8e98 sbin/devd/devd.cc
Promoting the SIGINFO handler's log message from LOG_INFO to
	LOG_NOTICE, and promoting the "Processing event ..." message from
	LOG_DEBUG to LOG_INFO.  Setting the logfile to LOG_NOTICE with this
	change will have the same result as setting it to LOG_INFO without
	this change.  Setting it to LOG_INFO with this change will include
	the useful "Processing event ..." messages that were previously at
	LOG_DEBUG, without including useless messages like "Pushing table".

	The intent of this change is that one can log "Processing event ..."
	without logging "Pushing table" and related messages that are sent
	for every event.  The number of lines actually logged is reduced by
	about 75% by making this change and setting syslog to LOG_INFO vs
	setting syslog to LOG_DEBUG.

etc/syslog.conf
	Changing the recommended loglevel to notice instead of info.

Sponsored by:	Spectra Logic Corp
MFC after:	4 weeks
2013-12-13 22:58:57 +00:00
Alan Somers
b026eddfea sbin/devd/devd.cc
Increase the size of devd's client socket's send buffer from the
	default (8k) to 128k.  This prevents clients from getting
	POLLHUPped during event storms.  For example, during zpool creation,
	the kernel emits a resource.fs.zfs.statechange event for every vdev
	in the pool.  A 128k buffer is large enough to hold the statechange
	events for a pool with nearly 800 drives.

Reviewed by:	ian, imp
Approved by:	ken (mentor)
Sponsored by:	Spectra Logic Corp
MFC after:	4 weeks
2013-12-13 21:49:41 +00:00
Andriy Gapon
1bb0777e41 devd: lower priority of action execution logging to info
Reviewed by:	asomers
2013-11-07 16:24:31 +00:00
Andriy Gapon
2e024bc22f devd: fix a typo in a comment
Reviewed by:	asomers
2013-11-07 16:22:04 +00:00
Alan Somers
3449b15aa2 Correct the printf format specifier for total_events.
Add __printflike argument checking for devdlog().

Reported by: pjd
Approved by: gibbs (co-mentor)
2013-07-08 21:10:30 +00:00
Alan Somers
967ecf4aed Explicitly include <cstdarg> to fix compilation with libc++. It is implicitly
included by libstdc++.

Reported By: Oliver Hartmann
Approved by: gibbs (co-mentor, implicit)
2013-07-02 14:48:39 +00:00
Alan Somers
0285e9b1cf style(9) fixes, including the removal of page break characters. No functional
changes.

Approved by:	gibbs (co-mentor)
2013-07-01 21:49:17 +00:00
Alan Somers
be685e0128 Add a SIGINFO handler to devd. It will send useful statistics to syslog or
stderr as appropriate.  Currently, the only statistic printed is the number of
events received.

Reviewed by:	eadler
Approved by:	gibbs (co-mentor)
2013-07-01 21:33:05 +00:00
Alan Somers
6d1014a32b Add syslog(3) support to devd(8).
sbin/devd/devd.cc
        All output will now go to syslog(3) if devd is daemonized, or stderr
        if it's running in the foreground.

sbin/devd/devd.8
        Remove the "-D" flag.  Filtering messages by priority now
	happens in the usual syslog way.  For performance reasons, a few
	extra-verbose debugging statements are now conditional on the "-d" (do
	not daemonize) flag.

etc/syslog.conf
etc/newsyslog.conf
        Direct messages from devd(8) to /var/log/devd.log, but leave it
        disabled by default

Reviewed by:	eadler
Approved by:	gibbs (co-mentor)
MFC after:	never (removed a command-line option from devd)
2013-07-01 21:20:17 +00:00
Eitan Adler
d005340fe9 Prefer using the C++ version of the standard headers. These place the
names within the std namespace (and possibly within the global
namespace).

The main advantage is that the C++ versions can provide optimized
versions or simplified interfaces.
2013-05-02 17:02:50 +00:00
Eitan Adler
4cb9d1beca devd: Correct typo in comment.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:31 +00:00
Eitan Adler
7d9e9c60a0 devd: Use simpler dst += *x instead of str.append(x, 1).
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:29 +00:00
Eitan Adler
a6393aa163 devd: Use string::empty() instea of string::length() == 0.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:26 +00:00
Eitan Adler
5a3b1a3d7c devd: Avoid unnecessary temporary objects (and simplify the code) when handling std::string.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:19 +00:00
Eitan Adler
67ae3bf165 devd: Simplify while (1) { if (x) break; } to while (!x) {}.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:15 +00:00
Eitan Adler
4efceb186c devd: Remove call to _exit() from signal handler, which also sets a stop flag.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:12 +00:00
Eitan Adler
fcdcaa8807 devd: Use volatile sig_atomic_t for the flag set by a signal handler.
Submitted by:	Christoph Mallon <christoph.mallon@gmx.de>
Approved by:	cperciva (mentor)
2013-03-04 02:21:08 +00:00
Eitan Adler
11fd1366bc Constify where possible.
Approved by:	cperciva (mentor)
2013-03-04 02:19:55 +00:00
Ian Lepore
5dfc0f6c53 Improve devd startup time, by tweaking some string handling routines that are
heavily used when parsing config files.  Mostly these changes avoid making
temporary copies of the strings, and avoid doing byte at a time append
operations, on the most-used code path.

On a 1.2 GHz ARM processor this reduces the time to parse the config files
from 13 to 6 seconds.

Reviewed by:	imp
Approved by:	cognet (mentor)
2013-01-30 23:37:35 +00:00
Ian Lepore
e1334f935f Fix a descriptor leak in devd. Clients reading /var/run/devd.pipe can close
their socket connection any time, and devd only notices that when it gets an
error trying to write an event to the client.  On a system with no device
change activity, clients could connect and disappear repeatedly without devd
noticing, leading to an ever-growing list of open socket descriptors in devd.

Now devd uses poll(2) looking for POLLHUP on all existing clients every time
a new client connection is established, and also periodically (once a minute)
to proactively find zombie clients and reap the socket descriptors.  It also
now has a connection limit, configurable with a new -l <num> command line arg.
When the maximum number of connections is reached it stops accepting new
connections until some current clients drop off.

Reviewed by:	imp
Approved by:	cognet (mentor)
2013-01-30 15:21:18 +00:00
Eitan Adler
c3fa0037ba Prefer the use of initalizer lists to ctor assignment.
Approved by:	cperciva
MFC after:	2 weeks
2012-12-06 01:25:21 +00:00
Eitan Adler
edee691dcf Avoid the creation of a temporary object by using the prefix operator
for non-primitive types.

Approved by:	cperciva
MFC after:	2 weeks
2012-12-06 01:25:17 +00:00
Eitan Adler
ef370346d6 Constify where possible
Approved by:	cperciva
MFC after:	2 weeks
2012-12-06 01:25:14 +00:00
Dimitry Andric
0c04d1850f Fix an old bug in devd, where it uses std::sort() to sort the various
lists it reads from its configuration files on the priority field.

Because some items in the lists have the same priority, and std::sort()
is not stable, the exact order in which the items are enumerated does
not have to correspond to the order they appear in the configuration
files.

Apparently this was never noticed with libstdc++, but with libc++ it
could cause the "uhid" entry from /etc/devd/usb.conf to be used instead
of the "ums" entry (which is earlier in the file).  This caused the
problem described in the PR: the USB mouse module was never loaded, and
the other actions (such as starting moused) were not executed.

To fix the problem, make devd use std:stable_sort() instead.

Reported by:	Jan Beich <jbeich@tormail.org>
PR:		bin/172958
MFC after:	2 weeks
2012-12-05 20:50:40 +00:00
Pawel Jakub Dawidek
901610f4b8 Use O_CLOEXEC for open instead of separate fcntl(2) call. 2012-09-22 12:42:51 +00:00
Dimitry Andric
5d586d29dd Make devd build with libc++.
MFC after:	3 days
2012-06-01 06:56:35 +00:00
Gleb Smirnoff
48df024e0f Fix build. 2012-01-06 15:01:05 +00:00
Hiroki Sato
0321b694c7 - Add support for a "!" character in regex matching in devd(8). It inverts
the logic (true/false) of the matching.

- Add "!usbus[0-9]+" to IFNET ATTACH notification handler in the default
  devd.conf to prevent rc.d/netif from running when usbus[0-9]+ is attached.

Reviewed by:	imp
2011-10-26 02:11:28 +00:00
Kevin Lo
5983e89162 Fix missing closedir()
Reviewed by:	imp
2010-11-21 04:02:37 +00:00
Warner Losh
9b6cb52091 Allow the kernel to generate more spacy things and still have devd
cope.  Skip multiple spaces in a few contexts.

PR:		96854
Submitted by:	Shin'ya Kumabuchi
MFC after:	1 week
2010-10-09 07:29:13 +00:00
Ulf Lilleengen
5bf0842244 - Avoid calling the copy constructor when it is not necessary. 2010-07-29 16:06:40 +00:00