From 5ec50be2abafa55b62e4d5f66fafd719cfedcdfc Mon Sep 17 00:00:00 2001 From: wblock Date: Sun, 4 Nov 2012 03:19:07 +0000 Subject: Add an example showing the use of gnop(8) to skip over header data. PR: kern/145999 Reviewed by: mjg MFC after: 1 week --- sbin/mdconfig/mdconfig.8 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 89f150e..c18027c 100644 --- a/sbin/mdconfig/mdconfig.8 +++ b/sbin/mdconfig/mdconfig.8 @@ -41,7 +41,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 27, 2012 +.Dd November 3, 2012 .Dt MDCONFIG 8 .Os .Sh NAME @@ -267,6 +267,18 @@ are implied device, and then mount the new memory disk: .Bd -literal -offset indent mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt +.Pp +.Ed +Create a file-backed device from a hard disk image that begins +with 512K of raw header information. +.Xr gnop 8 +is used to skip over the header information, positioning +.Pa md1.nop +to the start of the filesystem in the image. +.Bd -literal -offset indent +mdconfig -f diskimage.img -u 1 +gnop create -o 512K md1 +mount /dev/md1.nop /mnt .Ed .Sh SEE ALSO .Xr md 4 , -- cgit v1.1 From 712fa475acb802cc12bddf7fe3eafbf15203f1cc Mon Sep 17 00:00:00 2001 From: pjd Date: Mon, 5 Nov 2012 00:38:14 +0000 Subject: Revert r228695. We use __func__ here as a format to distinguish between abort and assert. It would be cleaner to use NULL or "" here, but gcc complains in both cases. --- sbin/hastd/pjdlog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/hastd/pjdlog.h b/sbin/hastd/pjdlog.h index bae431e..0f01f79 100644 --- a/sbin/hastd/pjdlog.h +++ b/sbin/hastd/pjdlog.h @@ -95,7 +95,7 @@ void pjdlog_abort(const char *func, const char *file, int line, #define PJDLOG_VERIFY(expr) do { \ if (!(expr)) { \ pjdlog_abort(__func__, __FILE__, __LINE__, #expr, \ - "%s", __func__); \ + __func__); \ } \ } while (0) #define PJDLOG_RVERIFY(expr, ...) do { \ -- cgit v1.1 From f42c814c08825fe4486caf2d62b2ce0d7351b941 Mon Sep 17 00:00:00 2001 From: wblock Date: Wed, 7 Nov 2012 15:59:24 +0000 Subject: Add devd.conf(5) and devd(8) to SEE ALSO xrefs. Give users a pointer to seemingly mysterious actions that are not done by ifconfig itself, but by devd triggering on events caused by ifconfig. PR: docs/173405 Submitted by: Mateusz Kwiatkowski MFC after: 1 week --- sbin/ifconfig/ifconfig.8 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index f22cc50..a34247c 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd July 9, 2012 +.Dd November 7, 2012 .Dt IFCONFIG 8 .Os .Sh NAME @@ -2714,7 +2714,9 @@ tried to alter an interface's configuration. .Xr pfsync 4 , .Xr polling 4 , .Xr vlan 4 , +.Xr devd.conf 5 , .\" .Xr eon 5 , +.Xr devd 8 , .Xr rc 8 , .Xr routed 8 , .Xr jail 8 , -- cgit v1.1 From 8a426194883066032fa15ca3929e128c04410af8 Mon Sep 17 00:00:00 2001 From: wblock Date: Wed, 7 Nov 2012 19:26:32 +0000 Subject: Remove fifteen-year-old notes on media selection (suggested by simon@). Add commas after "e.g." and "i.e.". Change "silent" to "silence" in wireless create section (reviewed by adri@). MFC after: 1 week --- sbin/ifconfig/ifconfig.8 | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'sbin') diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index a34247c..a2997ab 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -142,7 +142,7 @@ The link-level address is specified as a series of colon-separated hex digits. This can be used to -e.g.\& set a new MAC address on an ethernet interface, though the +e.g.,\& set a new MAC address on an ethernet interface, though the mechanism used is not ethernet-specific. If the interface is already up when this option is used, it will be briefly brought down and @@ -301,7 +301,7 @@ Specify interface FIB. A FIB .Ar fib_number is assigned to all frames or packets received on that interface. -The FIB is not inherited, e.g. vlans or other sub-interfaces will use +The FIB is not inherited, e.g., vlans or other sub-interfaces will use the default FIB (0) irrespective of the parent interface's FIB. The kernel needs to be tuned to support more than the default FIB using the @@ -1003,7 +1003,7 @@ For example, if a device is capable of operating on channel 6 with 802.11n and 802.11g then one can specify that g-only use should be used by specifying ``6:g''. Similarly the channel width can be specified by appending it -with ``/''; e.g. ``6/40'' specifies a 40MHz wide channel, +with ``/''; e.g., ``6/40'' specifies a 40MHz wide channel, These attributes can be combined as in: ``6:ht/40''. The full set of flags specified following a ``:'' are: .Cm a @@ -1036,7 +1036,7 @@ and In addition, a 40MHz HT channel specification may include the location of the extension channel by appending ``+'' or ``-'' for above and below, -respectively; e.g. ``2437:ht/40+'' specifies 40MHz wide HT operation +respectively; e.g., ``2437:ht/40+'' specifies 40MHz wide HT operation with the center channel at frequency 2437 and the extension channel above. .It Cm country Ar name Set the country code to use in calculating the regulatory constraints @@ -1046,7 +1046,7 @@ will operation on the channels, and the maximum transmit power that can be used on a channel are defined by this setting. Country/Region codes are specified as a 2-character abbreviation defined by ISO 3166 or using a longer, but possibly ambiguous, spelling; -e.g. "ES" and "Spain". +e.g., "ES" and "Spain". The set of country codes are taken from /etc/regdomain.xml and can also be viewed with the ``list countries'' request. Note that not all devices support changing the country code from a default @@ -1063,7 +1063,7 @@ DFS embodies several facilities including detection of overlapping radar signals, dynamic transmit power control, and channel selection according to a least-congested criteria. DFS support is mandatory for some 5GHz frequencies in certain -locales (e.g. ETSI). +locales (e.g., ETSI). By default DFS is enabled according to the regulatory definitions specified in /etc/regdomain.xml and the current country code, regdomain, and channel. @@ -1168,7 +1168,7 @@ Enable Dynamic WDS (DWDS) support. DWDS is a facility by which 4-address traffic can be carried between stations operating in infrastructure mode. A station first associates to an access point and authenticates using -normal procedures (e.g. WPA). +normal procedures (e.g., WPA). Then 4-address frames are passed to carry traffic for stations operating on either side of the wireless link. DWDS extends the normal WDS mechanism by leveraging existing security @@ -1186,7 +1186,7 @@ When DWDS is enabled on a station, traffic with a destination address different from the peer station are encapsulated in a 4-address frame and transmitted to the peer. All 4-address traffic uses the security information of the stations -(e.g. cryptographic keys). +(e.g., cryptographic keys). A station is associated using 802.11n facilities may transport 4-address traffic using these same mechanisms; this depends on available resources and capabilities of the device. @@ -1236,7 +1236,7 @@ Stations negotiate use of these facilities, termed HT20 and HT40, when they associate. To disable all use of 802.11n use .Fl ht . -To disable use of HT20 (e.g. to force only HT40 use) use +To disable use of HT20 (e.g., to force only HT40 use) use .Fl ht20 . To disable use of HT40 use .Fl ht40 . @@ -1250,7 +1250,7 @@ Auto Channel Selection is used to locate a channel to operate on, HT configuration controls whether legacy, HT20, or HT40 operation is setup on the selected channel. If a fixed channel is specified for a station then HT configuration can -be given as part of the channel specification; e.g. 6:ht/20 to setup +be given as part of the channel specification; e.g., 6:ht/20 to setup HT20 operation on channel 6. .It Cm htcompat Enable use of compatibility support for pre-802.11n devices (default). @@ -1506,13 +1506,13 @@ The default setting is 6 but drivers may override this with a value they choose. .It Cm mcastrate Ar rate Set the rate for transmitting multicast/broadcast frames. -Rates are specified as megabits/second in decimal; e.g.\& 5.5 for 5.5 Mb/s. +Rates are specified as megabits/second in decimal; e.g.,\& 5.5 for 5.5 Mb/s. This rate should be valid for the current operating conditions; if an invalid rate is specified drivers are free to chose an appropriate rate. .It Cm mgtrate Ar rate Set the rate for transmitting management and/or control frames. -Rates are specified as megabits/second in decimal; e.g.\& 5.5 for 5.5 Mb/s. +Rates are specified as megabits/second in decimal; e.g.,\& 5.5 for 5.5 Mb/s. .It Cm outdoor Set the location to use in calculating regulatory constraints. The location is also advertised in beacon and probe response frames @@ -1672,7 +1672,7 @@ request can be used to show recent scan results without initiating a new scan. .It Cm scanvalid Ar threshold Set the maximum time the scan cache contents are considered valid; -i.e. will be used without first triggering a scan operation to +i.e., will be used without first triggering a scan operation to refresh the data. The .Ar threshold @@ -1734,7 +1734,7 @@ When operating with TDMA, setup a BSS with slots. The slot count may be at most 8. The current implementation is only tested with two stations -(i.e. point to point applications). +(i.e., point to point applications). This setting is only meaningful when a station is configured as slot 0; other stations adopt this setting from the BSS they join. By default @@ -1758,7 +1758,7 @@ is set to 10 milliseconds. When operating with TDMA, setup a BSS such that beacons are transmitted every .Ar intval superframes to synchronize the TDMA slot timing. -A superframe is defined as the number of slots times the slot length; e.g. +A superframe is defined as the number of slots times the slot length; e.g., a BSS with two slots of 10 milliseconds has a 20 millisecond superframe. The beacon interval may not be zero. A lower setting of @@ -1784,7 +1784,7 @@ the driver will use the setting closest to the specified value. Not all adapters support changing the transmit power. .It Cm ucastrate Ar rate Set a fixed rate for transmitting unicast frames. -Rates are specified as megabits/second in decimal; e.g.\& 5.5 for 5.5 Mb/s. +Rates are specified as megabits/second in decimal; e.g.,\& 5.5 for 5.5 Mb/s. This rate should be valid for the current operating conditions; if an invalid rate is specified drivers are free to chose an appropriate rate. @@ -2519,7 +2519,7 @@ protocol on an interface: Set the virtual host ID. This is a required setting to initiate .Xr carp 4 . -If the virtual host ID doesn't exist yet, it is created and attached to the +If the virtual host ID does not exist yet, it is created and attached to the interface, otherwise configuration of an existing vhid is adjusted. If the .Cm vhid @@ -2628,9 +2628,6 @@ The flag disables this behavior. .Pp Only the super-user may modify the configuration of a network interface. -.Sh NOTES -The media selection system is relatively new and only some drivers support -it (or have need for it). .Sh EXAMPLES Assign the IPv4 address .Li 192.0.2.10 , -- cgit v1.1 From bbb1601ed6732dace0e76d185b7a8ab6b7ea7047 Mon Sep 17 00:00:00 2001 From: wblock Date: Wed, 7 Nov 2012 19:32:21 +0000 Subject: Actually change "silent" to "silence" this time (reviewed by adri@). MFC after: 1 week --- sbin/ifconfig/ifconfig.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index a2997ab..f4c6daa 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -1115,7 +1115,7 @@ specifies the number of beacon intervals between DTIM and must be in the range 1 to 15. By default DTIM is 1 (i.e., DTIM occurs at each beacon). .It Cm quiet -Enable the use of quiet IE. Hostap will use this to silent other +Enable the use of quiet IE. Hostap will use this to silence other stations to reduce interference for radar detection when operating on 5GHz frequency and doth support is enabled. Use -- cgit v1.1 From 36a92a29f76cbe9b485bd6151d9ca55620d25a7f Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 14 Nov 2012 06:31:47 +0000 Subject: - blk_equals() is too strict. If the journal entry defines more frags than we're claiming it should still be considered an exact match. This would previously leak frags that had been extended. - If there is a sequence number problem in the journal print the sequence numbers we've seen so far for debugging. - Clean up the block mask related debuging printfs. Some are redundant. MFC after: 1 week --- sbin/fsck_ffs/suj.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'sbin') diff --git a/sbin/fsck_ffs/suj.c b/sbin/fsck_ffs/suj.c index 0800a5c..ae47487 100644 --- a/sbin/fsck_ffs/suj.c +++ b/sbin/fsck_ffs/suj.c @@ -504,7 +504,7 @@ blk_equals(struct jblkrec *brec, ino_t ino, ufs_lbn_t lbn, ufs2_daddr_t start, return (0); if (brec->jb_blkno + brec->jb_oldfrags != start) return (0); - if (brec->jb_frags != frags) + if (brec->jb_frags < frags) return (0); return (1); } @@ -551,7 +551,6 @@ blk_freemask(ufs2_daddr_t blk, ino_t ino, ufs_lbn_t lbn, int frags) brec = (struct jblkrec *)srec->sr_rec; /* * If the block overlaps but does not match - * exactly it's a new allocation. If it matches * exactly this record refers to the current * location. */ @@ -648,7 +647,8 @@ blk_free(ufs2_daddr_t bno, int mask, int frags) uint8_t *blksfree; if (debug) - printf("Freeing %d frags at blk %jd\n", frags, bno); + printf("Freeing %d frags at blk %jd mask 0x%x\n", + frags, bno, mask); cg = dtog(fs, bno); sc = cg_lookup(cg); cgp = sc->sc_cgp; @@ -1143,12 +1143,8 @@ ino_adjblks(struct suj_ino *sino) static void blk_free_visit(ino_t ino, ufs_lbn_t lbn, ufs2_daddr_t blk, int frags) { - int mask; - mask = blk_freemask(blk, ino, lbn, frags); - if (debug) - printf("blk %jd freemask 0x%X\n", blk, mask); - blk_free(blk, mask, frags); + blk_free(blk, blk_freemask(blk, ino, lbn, frags), frags); } /* @@ -1163,8 +1159,6 @@ blk_free_lbn(ufs2_daddr_t blk, ino_t ino, ufs_lbn_t lbn, int frags, int follow) int mask; mask = blk_freemask(blk, ino, lbn, frags); - if (debug) - printf("blk %jd freemask 0x%X\n", blk, mask); resid = 0; if (lbn <= -NDADDR && follow && mask == 0) indir_visit(ino, lbn, blk, &resid, blk_free_visit, VISIT_INDIR); @@ -2334,6 +2328,10 @@ suj_prune(void) } if (newseq != oldseq) { + TAILQ_FOREACH(seg, &allsegs, ss_next) { + printf("%jd, ", seg->ss_rec.jsr_seq); + } + printf("\n"); err_suj("Journal file sequence mismatch %jd != %jd\n", newseq, oldseq); } -- cgit v1.1 From b210c68711637745afda58b4b52726ddb91bfbf5 Mon Sep 17 00:00:00 2001 From: glebius Date: Wed, 14 Nov 2012 08:05:21 +0000 Subject: Remove remnants of classful addressing. These magic transformations of supplied arguments is not what a modern sysadmin expect. --- sbin/route/route.c | 49 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 717a09a..f81d7a8 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -422,7 +422,7 @@ routename(struct sockaddr *sa) /* * Return the name of the network whose address is given. - * The address is assumed to be that of a net or subnet, not a host. + * The address is assumed to be that of a net, not a host. */ const char * netname(struct sockaddr *sa) @@ -430,9 +430,8 @@ netname(struct sockaddr *sa) const char *cp = NULL; static char line[MAXHOSTNAMELEN + 1]; struct netent *np = NULL; - u_long net, mask; u_long i; - int n, subnetshift; + int n; switch (sa->sa_family) { @@ -444,28 +443,7 @@ netname(struct sockaddr *sa) if (in.s_addr == 0) cp = "default"; else if (!nflag) { - if (IN_CLASSA(i)) { - mask = IN_CLASSA_NET; - subnetshift = 8; - } else if (IN_CLASSB(i)) { - mask = IN_CLASSB_NET; - subnetshift = 8; - } else { - mask = IN_CLASSC_NET; - subnetshift = 4; - } - /* - * If there are more bits than the standard mask - * would suggest, subnets must be in use. - * Guess at the subnet mask, assuming reasonable - * width subnet fields. - */ - while (in.s_addr & ~mask) - mask |= mask >> subnetshift; - net = in.s_addr & mask; - while ((mask & 1) == 0) - mask >>= 1, net >>= 1; - np = getnetbyaddr(net, AF_INET); + np = getnetbyaddr(i, AF_INET); if (np != NULL) cp = np->n_name; } @@ -810,30 +788,19 @@ newroute(int argc, char **argv) static void inet_makenetandmask(u_long net, struct sockaddr_in *sin, u_long bits) { - u_long addr, mask = 0; + u_long mask = 0; char *cp; rtm_addrs |= RTA_NETMASK; - /* - * XXX: This approach unable to handle 0.0.0.1/32 correctly - * as inet_network() converts 0.0.0.1 and 1 equally. - */ - if (net <= 0xff) - addr = net << IN_CLASSA_NSHIFT; - else if (net <= 0xffff) - addr = net << IN_CLASSB_NSHIFT; - else if (net <= 0xffffff) - addr = net << IN_CLASSC_NSHIFT; - else - addr = net; + /* * If no /xx was specified we must calculate the * CIDR address. */ - if ((bits == 0) && (addr != 0)) { + if ((bits == 0) && (net != 0)) { u_long i, j; for(i=0,j=0xff; i<4; i++) { - if (addr & j) { + if (net & j) { break; } j <<= 8; @@ -844,7 +811,7 @@ inet_makenetandmask(u_long net, struct sockaddr_in *sin, u_long bits) if (bits != 0) mask = 0xffffffff << (32 - bits); - sin->sin_addr.s_addr = htonl(addr); + sin->sin_addr.s_addr = htonl(net); sin = &so_mask.sin; sin->sin_addr.s_addr = htonl(mask); sin->sin_len = 0; -- cgit v1.1 From a3bf527f51a280bda9086aa025f54348fd4a619a Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 15 Nov 2012 15:06:21 +0000 Subject: Fix memory leak in umount.c PR: bin/172553 Submitted by: Erik Cederstrand Approved by: cperciva MFC after: 3 days --- sbin/umount/umount.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index f179a4c..f2e02f2 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -359,8 +359,10 @@ umountfs(struct statfs *sfs) do_rpc = 1; } - if (!namematch(ai)) + if (!namematch(ai)) { + free(orignfsdirname); return (1); + } /* First try to unmount using the file system ID. */ snprintf(fsidbuf, sizeof(fsidbuf), "FSID:%d:%d", sfs->f_fsid.val[0], sfs->f_fsid.val[1]); @@ -369,13 +371,16 @@ umountfs(struct statfs *sfs) if (errno != ENOENT || sfs->f_fsid.val[0] != 0 || sfs->f_fsid.val[1] != 0) warn("unmount of %s failed", sfs->f_mntonname); - if (errno != ENOENT) + if (errno != ENOENT) { + free(orignfsdirname); return (1); + } /* Compatibility for old kernels. */ if (sfs->f_fsid.val[0] != 0 || sfs->f_fsid.val[1] != 0) warnx("retrying using path instead of file system ID"); if (unmount(sfs->f_mntonname, fflag) != 0) { warn("unmount of %s failed", sfs->f_mntonname); + free(orignfsdirname); return (1); } } @@ -393,6 +398,7 @@ umountfs(struct statfs *sfs) if (clp == NULL) { warnx("%s: %s", hostp, clnt_spcreateerror("MOUNTPROG")); + free(orignfsdirname); return (1); } clp->cl_auth = authsys_create_default(); @@ -403,6 +409,7 @@ umountfs(struct statfs *sfs) if (clnt_stat != RPC_SUCCESS) { warnx("%s: %s", hostp, clnt_sperror(clp, "RPCMNT_UMOUNT")); + free(orignfsdirname); return (1); } /* @@ -415,10 +422,10 @@ umountfs(struct statfs *sfs) hostp, nfsdirname); free_mtab(); } - free(orignfsdirname); auth_destroy(clp->cl_auth); clnt_destroy(clp); } + free(orignfsdirname); return (0); } -- cgit v1.1 From beace53e29166cd087c9e1f48d43899f7c742d2b Mon Sep 17 00:00:00 2001 From: hrs Date: Sat, 17 Nov 2012 19:54:23 +0000 Subject: Add -fib modifier to specify FIB number. The FIB number can be in a comma-separated list and/or range specification: # route add -inet 192.0.2.0/24 198.51.100.1 -fib 1,3-5,6 Although all of the subcommands supports the modifier, "monitor" does not support the list or range specification at this moment. Reviewed by: bz --- sbin/route/keywords | 1 + sbin/route/route.8 | 53 +++++- sbin/route/route.c | 500 +++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 440 insertions(+), 114 deletions(-) (limited to 'sbin') diff --git a/sbin/route/keywords b/sbin/route/keywords index 8817f30..adfba7c 100644 --- a/sbin/route/keywords +++ b/sbin/route/keywords @@ -10,6 +10,7 @@ del delete dst expire +fib flush gateway genmask diff --git a/sbin/route/route.8 b/sbin/route/route.8 index 6bf65b4..b786106 100644 --- a/sbin/route/route.8 +++ b/sbin/route/route.8 @@ -28,7 +28,7 @@ .\" @(#)route.8 8.3 (Berkeley) 3/19/94 .\" $FreeBSD$ .\" -.Dd March 24, 2012 +.Dd November 17, 2012 .Dt ROUTE 8 .Os .Sh NAME @@ -118,16 +118,14 @@ The monitor command has the syntax: .Bd -ragged -offset indent -compact .Nm .Op Fl n -.Cm monitor +.Cm monitor Op Fl fib Ar number .Ed .Pp The flush command has the syntax: .Pp .Bd -ragged -offset indent -compact .Nm -.Op Fl n -.Cm flush -.Op Ar family +.Oo Fl n Cm flush Oc Oo Ar family Oc Op Fl fib Ar number .Ed .Pp If the @@ -144,6 +142,11 @@ or .Fl inet modifiers, only routes having destinations with addresses in the delineated family will be deleted. +When a +.Fl fib +option is specified, the operation will be applied to +the specified FIB +.Pq routing table . .Pp The other commands have the following syntax: .Pp @@ -154,6 +157,7 @@ The other commands have the following syntax: .Op Fl net No \&| Fl host .Ar destination gateway .Op Ar netmask +.Op Fl fib Ar number .Ed .Pp where @@ -210,9 +214,15 @@ A .Ar destination of .Ar default -is a synonym for -.Fl net Li 0.0.0.0 , -which is the default route. +is a synonym for the default route. +For +.Li IPv4 +it is +.Fl net Fl inet Li 0.0.0.0 , +and for +.Li IPv6 +it is +.Fl net Fl inet6 Li :: . .Pp If the destination is directly reachable via an interface requiring @@ -314,6 +324,33 @@ specify that all ensuing metrics may be locked by the .Fl lockrest meta-modifier. .Pp +The optional modifier +.Fl fib Ar number +specifies that the command will be applied to a non-default FIB. +The +.Ar number +must be smaller than the +.Va net.fibs +.Xr sysctl 8 +MIB. +When this modifier is not specified, +or a negative number is specified, +the default FIB shown in the +.Va net.my_fibnum +.Xr sysctl 8 +MIB will be used. +.Pp +The +.Ar number +allows multiple FIBs by a comma-separeted list and/or range +specification. +The +.Qq Fl fib Li 2,4,6 +means the FIB number 2, 4, and 6. +The +.Qq Fl fib Li 1,3-5,6 +means the 1, 3, 4, 5, and 6. +.Pp In a .Cm change or diff --git a/sbin/route/route.c b/sbin/route/route.c index f81d7a8..135d378 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -77,7 +78,6 @@ struct keytab { {0, 0} }; -struct ortentry route; union sockunion { struct sockaddr sa; struct sockaddr_in sin; @@ -99,11 +99,14 @@ int locking, lockrest, debugonly; struct rt_metrics rt_metrics; u_long rtm_inits; uid_t uid; +static int defaultfib; +static int numfibs; static int atalk_aton(const char *, struct at_addr *); static char *atalk_ntoa(struct at_addr); static void bprintf(FILE *, int, u_char *); static void flushroutes(int argc, char *argv[]); +static int flushroutes_fib(int); static int getaddr(int, char *, struct hostent **); static int keyword(const char *); static void inet_makenetandmask(u_long, struct sockaddr_in *, u_long); @@ -112,21 +115,36 @@ static int inet6_makenetandmask(struct sockaddr_in6 *, const char *); #endif static void interfaces(void); static void mask_addr(void); -static void monitor(void); +static void monitor(int, char*[]); static const char *netname(struct sockaddr *); static void newroute(int, char **); +static int newroute_fib(int, char *, int); static void pmsg_addrs(char *, int, size_t); static void pmsg_common(struct rt_msghdr *, size_t); static int prefixlen(const char *); -static void print_getmsg(struct rt_msghdr *, int); +static void print_getmsg(struct rt_msghdr *, int, int); static void print_rtmsg(struct rt_msghdr *, size_t); static const char *routename(struct sockaddr *); -static int rtmsg(int, int); +static int rtmsg(int, int, int); static void set_metric(char *, int); +static int set_sofib(int); +static int set_procfib(int); static void sockaddr(char *, struct sockaddr *); static void sodump(sup, const char *); extern char *iso_ntoa(void); +struct fibl { + TAILQ_ENTRY(fibl) fl_next; + + int fl_num; + int fl_error; + int fl_errno; +}; +TAILQ_HEAD(fibl_head_t, fibl) fibl_head; + +static int fiboptlist_csv(const char *, struct fibl_head_t *); +static int fiboptlist_range(const char *, struct fibl_head_t *); + static void usage(const char *) __dead2; void @@ -144,6 +162,7 @@ int main(int argc, char **argv) { int ch; + size_t len; if (argc < 2) usage(NULL); @@ -180,6 +199,17 @@ main(int argc, char **argv) s = socket(PF_ROUTE, SOCK_RAW, 0); if (s < 0) err(EX_OSERR, "socket"); + + len = sizeof(numfibs); + if (sysctlbyname("net.fibs", (void *)&numfibs, &len, NULL, 0) == -1) + numfibs = -1; + + len = sizeof(defaultfib); + if (numfibs != -1 && + sysctlbyname("net.my_fibnum", (void *)&defaultfib, &len, NULL, + 0) == -1) + defaultfib = -1; + if (*argv != NULL) switch (keyword(*argv)) { case K_GET: @@ -195,7 +225,7 @@ main(int argc, char **argv) /* NOTREACHED */ case K_MONITOR: - monitor(); + monitor(argc, argv); /* NOTREACHED */ case K_FLUSH: @@ -207,6 +237,124 @@ main(int argc, char **argv) /* NOTREACHED */ } +static int +set_sofib(int fib) +{ + + if (fib < 0) + return (0); + return (setsockopt(s, SOL_SOCKET, SO_SETFIB, (void *)&fib, + sizeof(fib))); +} + +static int +set_procfib(int fib) +{ + + if (fib < 0) + return (0); + return (setfib(fib)); +} + +static int +fiboptlist_range(const char *arg, struct fibl_head_t *flh) +{ + struct fibl *fl; + char *str, *token, *endptr; + int fib[2], i, error; + + str = strdup(arg); + error = 0; + i = 0; + while ((token = strsep(&str, "-")) != NULL) { + switch (i) { + case 0: + case 1: + fib[i] = strtol(token, &endptr, 0); + if (*endptr != '\0' || (fib[i] == 0 && + (errno == EINVAL || errno == ERANGE))) + error = 1; + break; + default: + error = 1; + } + if (error) + goto fiboptlist_range_ret; + i++; + } + if (fib[0] >= fib[1]) { + error = 1; + goto fiboptlist_range_ret; + } + for (i = fib[0]; i <= fib[1]; i++) { + fl = calloc(1, sizeof(*fl)); + if (fl == NULL) { + error = 1; + goto fiboptlist_range_ret; + } + fl->fl_num = i; + TAILQ_INSERT_TAIL(flh, fl, fl_next); + } +fiboptlist_range_ret: + free(str); + return (error); +} + +#define ALLSTRLEN 64 +static int +fiboptlist_csv(const char *arg, struct fibl_head_t *flh) +{ + struct fibl *fl; + char *str, *token, *endptr; + int fib, error; + + if (strcmp("all", arg) == 0) { + str = calloc(1, ALLSTRLEN); + if (str == NULL) { + error = 1; + goto fiboptlist_csv_ret; + } + if (numfibs > 1) + snprintf(str, ALLSTRLEN - 1, "%d-%d", 0, numfibs - 1); + else + snprintf(str, ALLSTRLEN - 1, "%d", 0); + } else if (strcmp("default", arg) == 0) { + str = calloc(1, ALLSTRLEN); + if (str == NULL) { + error = 1; + goto fiboptlist_csv_ret; + } + snprintf(str, ALLSTRLEN - 1, "%d", defaultfib); + } else + str = strdup(arg); + + error = 0; + while ((token = strsep(&str, ",")) != NULL) { + if (*token != '-' && strchr(token, '-') != NULL) { + error = fiboptlist_range(token, flh); + if (error) + goto fiboptlist_csv_ret; + } else { + fib = strtol(token, &endptr, 0); + if (*endptr != '\0' || (fib == 0 && + (errno == EINVAL || errno == ERANGE))) { + error = 1; + goto fiboptlist_csv_ret; + } + fl = calloc(1, sizeof(*fl)); + if (fl == NULL) { + error = 1; + goto fiboptlist_csv_ret; + } + fl->fl_num = fib; + TAILQ_INSERT_TAIL(flh, fl, fl_next); + } + } +fiboptlist_csv_ret: + free(str); + return (error); +} + /* * Purge all entries in the routing tables not * associated with network interfaces. @@ -214,38 +362,71 @@ main(int argc, char **argv) static void flushroutes(int argc, char *argv[]) { - size_t needed; - int mib[6], rlen, seqno, count = 0; - char *buf, *next, *lim; - struct rt_msghdr *rtm; + struct fibl *fl; + int error; if (uid != 0 && !debugonly) { errx(EX_NOPERM, "must be root to alter routing table"); } shutdown(s, SHUT_RD); /* Don't want to read back our messages */ - if (argc > 1) { + + TAILQ_INIT(&fibl_head); + while (argc > 1) { + argc--; argv++; - if (argc == 2 && **argv == '-') - switch (keyword(*argv + 1)) { - case K_INET: - af = AF_INET; - break; + if (**argv != '-') + usage(*argv); + switch (keyword(*argv + 1)) { + case K_INET: + af = AF_INET; + break; #ifdef INET6 - case K_INET6: - af = AF_INET6; - break; + case K_INET6: + af = AF_INET6; + break; #endif - case K_ATALK: - af = AF_APPLETALK; - break; - case K_LINK: - af = AF_LINK; - break; - default: - goto bad; - } else -bad: usage(*argv); + case K_ATALK: + af = AF_APPLETALK; + break; + case K_LINK: + af = AF_LINK; + break; + case K_FIB: + if (!--argc) + usage(*argv); + error = fiboptlist_csv(*++argv, &fibl_head); + if (error) + usage(*argv); + break; + default: + usage(*argv); + } } + if (TAILQ_EMPTY(&fibl_head)) { + error = fiboptlist_csv("default", &fibl_head); + if (error) + errx(EX_OSERR, "fiboptlist_csv failed."); + } + TAILQ_FOREACH(fl, &fibl_head, fl_next) + flushroutes_fib(fl->fl_num); +} + +static int +flushroutes_fib(int fib) +{ + struct rt_msghdr *rtm; + size_t needed; + char *buf, *next, *lim; + int mib[6], rlen, seqno, count = 0; + int error; + + error = set_sofib(fib); + error += set_procfib(fib); + if (error) { + warn("fib number %d is ignored", fib); + return (error); + } + retry: mib[0] = CTL_NET; mib[1] = PF_ROUTE; @@ -303,13 +484,17 @@ retry: print_rtmsg(rtm, rlen); else { struct sockaddr *sa = (struct sockaddr *)(rtm + 1); - (void) printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ? + + printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ? routename(sa) : netname(sa)); sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa); - (void) printf("%-20.20s ", routename(sa)); - (void) printf("done\n"); + printf("%-20.20s ", routename(sa)); + if (fib >= 0) + printf("-fib %-3d ", fib); + printf("done\n"); } } + return (error); } const char * @@ -551,18 +736,32 @@ set_metric(char *value, int key) *valp = atoi(value); } +#define F_ISHOST 0x01 +#define F_FORCENET 0x02 +#define F_FORCEHOST 0x04 +#define F_PROXY 0x08 +#define F_INTERFACE 0x10 + static void newroute(int argc, char **argv) { + struct hostent *hp; + struct fibl *fl; char *cmd; - const char *dest = "", *gateway = "", *errmsg; - int ishost = 0, proxy = 0, ret, attempts, oerrno, flags = RTF_STATIC; - int key; - struct hostent *hp = 0; + const char *dest, *gateway, *errmsg; + int key, error, flags, nrflags, fibnum; if (uid != 0) { errx(EX_NOPERM, "must be root to alter routing table"); } + + dest = NULL; + gateway = NULL; + flags = RTF_STATIC; + nrflags = 0; + hp = NULL; + TAILQ_INIT(&fibl_head); + cmd = argv[0]; if (*cmd != 'g' && *cmd != 's') shutdown(s, SHUT_RD); /* Don't want to read back our messages */ @@ -594,7 +793,7 @@ newroute(int argc, char **argv) break; case K_IFACE: case K_INTERFACE: - iflag++; + nrflags |= F_INTERFACE; break; case K_NOSTATIC: flags &= ~RTF_STATIC; @@ -606,7 +805,7 @@ newroute(int argc, char **argv) lockrest = 1; break; case K_HOST: - forcehost++; + nrflags |= F_FORCEHOST; break; case K_REJECT: flags |= RTF_REJECT; @@ -621,7 +820,7 @@ newroute(int argc, char **argv) flags |= RTF_PROTO2; break; case K_PROXY: - proxy = 1; + nrflags |= F_PROXY; break; case K_XRESOLVE: flags |= RTF_XRESOLVE; @@ -635,6 +834,13 @@ newroute(int argc, char **argv) case K_NOSTICK: flags &= ~RTF_STICKY; break; + case K_FIB: + if (!--argc) + usage(NULL); + error = fiboptlist_csv(*++argv, &fibl_head); + if (error) + usage(NULL); + break; case K_IFA: if (!--argc) usage(NULL); @@ -658,7 +864,8 @@ newroute(int argc, char **argv) case K_DST: if (!--argc) usage(NULL); - ishost = getaddr(RTA_DST, *++argv, &hp); + if (getaddr(RTA_DST, *++argv, &hp)) + nrflags |= F_ISHOST; dest = *argv; break; case K_NETMASK: @@ -667,17 +874,17 @@ newroute(int argc, char **argv) (void) getaddr(RTA_NETMASK, *++argv, 0); /* FALLTHROUGH */ case K_NET: - forcenet++; + nrflags |= F_FORCENET; break; case K_PREFIXLEN: if (!--argc) usage(NULL); if (prefixlen(*++argv) == -1) { - forcenet = 0; - ishost = 1; + nrflags &= ~F_FORCENET; + nrflags |= F_ISHOST; } else { - forcenet = 1; - ishost = 0; + nrflags |= F_FORCENET; + nrflags &= ~F_ISHOST; } break; case K_MTU: @@ -699,18 +906,20 @@ newroute(int argc, char **argv) } else { if ((rtm_addrs & RTA_DST) == 0) { dest = *argv; - ishost = getaddr(RTA_DST, *argv, &hp); + if (getaddr(RTA_DST, *argv, &hp)) + nrflags |= F_ISHOST; } else if ((rtm_addrs & RTA_GATEWAY) == 0) { gateway = *argv; (void) getaddr(RTA_GATEWAY, *argv, &hp); } else { (void) getaddr(RTA_NETMASK, *argv, 0); - forcenet = 1; + nrflags |= F_FORCENET; } } } - if (forcehost) { - ishost = 1; + + if (nrflags & F_FORCEHOST) { + nrflags |= F_ISHOST; #ifdef INET6 if (af == AF_INET6) { rtm_addrs &= ~RTA_NETMASK; @@ -718,71 +927,125 @@ newroute(int argc, char **argv) } #endif } - if (forcenet) - ishost = 0; + if (nrflags & F_FORCENET) + nrflags &= ~F_ISHOST; flags |= RTF_UP; - if (ishost) + if (nrflags & F_ISHOST) flags |= RTF_HOST; - if (iflag == 0) + if ((nrflags & F_INTERFACE) == 0) flags |= RTF_GATEWAY; - if (proxy) { + if (nrflags & F_PROXY) { so_dst.sinarp.sin_other = SIN_PROXY; flags |= RTF_ANNOUNCE; } - for (attempts = 1; ; attempts++) { - errno = 0; - if ((ret = rtmsg(*cmd, flags)) == 0) - break; - if (errno != ENETUNREACH && errno != ESRCH) - break; - if (af == AF_INET && *gateway != '\0' && - hp != NULL && hp->h_addr_list[1] != NULL) { - hp->h_addr_list++; - memmove(&so_gate.sin.sin_addr, hp->h_addr_list[0], - MIN((size_t)hp->h_length, - sizeof(so_gate.sin.sin_addr))); - } else - break; + if (dest == NULL) + dest = ""; + if (gateway == NULL) + gateway = ""; + + if (TAILQ_EMPTY(&fibl_head)) { + error = fiboptlist_csv("default", &fibl_head); + if (error) + errx(EX_OSERR, "fiboptlist_csv failed."); + } + error = 0; + TAILQ_FOREACH(fl, &fibl_head, fl_next) { + fl->fl_error = newroute_fib(fl->fl_num, cmd, flags); + if (fl->fl_error) + fl->fl_errno = errno; + error += fl->fl_error; } if (*cmd == 'g' || *cmd == 's') - exit(ret != 0); + exit(error); + + error = 0; if (!qflag) { - oerrno = errno; - (void) printf("%s %s %s", cmd, ishost? "host" : "net", dest); - if (*gateway) { - (void) printf(": gateway %s", gateway); - if (attempts > 1 && ret == 0 && af == AF_INET) - (void) printf(" (%s)", - inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr)); + fibnum = 0; + TAILQ_FOREACH(fl, &fibl_head, fl_next) { + if (fl->fl_error == 0) + fibnum++; } - if (ret == 0) { - (void) printf("\n"); - } else { - switch (oerrno) { - case ESRCH: - errmsg = "not in table"; - break; - case EBUSY: - errmsg = "entry in use"; - break; - case ENOBUFS: - errmsg = "not enough memory"; - break; - case EADDRINUSE: - /* handle recursion avoidance in rt_setgate() */ - errmsg = "gateway uses the same route"; - break; - case EEXIST: - errmsg = "route already in table"; - break; - default: - errmsg = strerror(oerrno); - break; + if (fibnum > 0) { + int firstfib = 1; + + printf("%s %s %s", cmd, + (nrflags & F_ISHOST) ? "host" : "net", dest); + if (*gateway) + printf(": gateway %s", gateway); + + if (numfibs > 1) { + TAILQ_FOREACH(fl, &fibl_head, fl_next) { + if (fl->fl_error == 0 + && fl->fl_num >= 0) { + if (firstfib) { + printf(" fib "); + firstfib = 0; + } + printf("%d", fl->fl_num); + if (fibnum-- > 1) + printf(","); + } + } } - (void) printf(": %s\n", errmsg); + printf("\n"); } + + fibnum = 0; + TAILQ_FOREACH(fl, &fibl_head, fl_next) { + if (fl->fl_error != 0) { + printf("%s %s %s", cmd, (nrflags & F_ISHOST) + ? "host" : "net", dest); + if (*gateway) + printf(": gateway %s", gateway); + + if (fl->fl_num >= 0) + printf(" fib %d", fl->fl_num); + + switch (fl->fl_errno) { + case ESRCH: + errmsg = "not in table"; + break; + case EBUSY: + errmsg = "entry in use"; + break; + case ENOBUFS: + errmsg = "not enough memory"; + break; + case EADDRINUSE: + /* + * handle recursion avoidance + * in rt_setgate() + */ + errmsg = "gateway uses the same route"; + break; + case EEXIST: + errmsg = "route already in table"; + break; + default: + errmsg = strerror(fl->fl_errno); + break; + } + printf(": %s\n", errmsg); + error = 1; + } + } + } + exit(error); +} + +static int +newroute_fib(int fib, char *cmd, int flags) +{ + int error; + + error = set_sofib(fib); + if (error) { + warn("fib number %d is ignored", fib); + return (error); } - exit(ret != 0); + + error = rtmsg(*cmd, flags, fib); + return (error); } static void @@ -1132,10 +1395,33 @@ retry2: } static void -monitor(void) +monitor(int argc, char *argv[]) { - int n; - char msg[2048]; + int n, fib, error; + char msg[2048], *endptr; + + fib = defaultfib; + while (argc > 1) { + argc--; + argv++; + if (**argv != '-') + usage(*argv); + switch (keyword(*argv + 1)) { + case K_FIB: + if (!--argc) + usage(*argv); + fib = strtol(*++argv, &endptr, 0); + if (*endptr != '\0' || (fib == 0 && + (errno == EINVAL || errno == ERANGE))) + usage(*argv); + break; + default: + usage(*argv); + } + } + error = set_sofib(fib); + if (error) + errx(EX_USAGE, "invalid fib number: %d", fib); verbose = 1; if (debugonly) { @@ -1157,7 +1443,7 @@ struct { } m_rtmsg; static int -rtmsg(int cmd, int flags) +rtmsg(int cmd, int flags, int fib) { static int seq; int rlen; @@ -1220,7 +1506,7 @@ rtmsg(int cmd, int flags) if (l < 0) warn("read from routing socket"); else - print_getmsg(&rtm, l); + print_getmsg(&rtm, l, fib); } #undef rtm return (0); @@ -1397,7 +1683,7 @@ badlen: } static void -print_getmsg(struct rt_msghdr *rtm, int msglen) +print_getmsg(struct rt_msghdr *rtm, int msglen, int fib) { struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL; struct sockaddr_dl *ifp = NULL; @@ -1457,6 +1743,8 @@ print_getmsg(struct rt_msghdr *rtm, int msglen) } if (gate && rtm->rtm_flags & RTF_GATEWAY) (void)printf(" gateway: %s\n", routename(gate)); + if (fib >= 0) + (void)printf(" fib: %u\n", (unsigned int)fib); if (ifp) (void)printf(" interface: %.*s\n", ifp->sdl_nlen, ifp->sdl_data); -- cgit v1.1 From 456b7a93418939408dbedc100658b7b995c87a8b Mon Sep 17 00:00:00 2001 From: hrs Date: Sat, 17 Nov 2012 20:19:00 +0000 Subject: Fill sin6_scope_id in sockaddr_in6 before passing it from the kernel to userland via routing socket or sysctl. This eliminates the following KAME-specific sin6_scope_id handling routine from each userland utility: sin6.sin6_scope_id = ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); This behavior can be controlled by net.inet6.ip6.deembed_scopeid. This is set to 1 by default (sin6_scope_id will be filled in the kernel). Reviewed by: bz --- sbin/ifconfig/af_inet6.c | 43 ++----------------------------------------- sbin/route/route.c | 34 ---------------------------------- 2 files changed, 2 insertions(+), 75 deletions(-) (limited to 'sbin') diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index d74b0d2..a9ad867 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -62,7 +62,6 @@ static struct in6_aliasreq in6_addreq = .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; static int ip6lifetime; -static void in6_fillscopeid(struct sockaddr_in6 *sin6); static int prefix(void *, int); static char *sec2str(time_t); static int explicit_prefix = 0; @@ -166,18 +165,6 @@ setip6eui64(const char *cmd, int dummy __unused, int s, } static void -in6_fillscopeid(struct sockaddr_in6 *sin6) -{ -#if defined(__KAME__) && defined(KAME_SCOPEID) - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { - sin6->sin6_scope_id = - ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); - sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0; - } -#endif -} - -static void in6_status(int s __unused, const struct ifaddrs *ifa) { struct sockaddr_in6 *sin, null_sin; @@ -187,7 +174,6 @@ in6_status(int s __unused, const struct ifaddrs *ifa) struct in6_addrlifetime lifetime; time_t t = time(NULL); int error; - u_int32_t scopeid; memset(&null_sin, 0, sizeof(null_sin)); @@ -217,18 +203,6 @@ in6_status(int s __unused, const struct ifaddrs *ifa) lifetime = ifr6.ifr_ifru.ifru_lifetime; close(s6); - /* XXX: embedded link local addr check */ - if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && - *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { - u_short index; - - index = *(u_short *)&sin->sin6_addr.s6_addr[2]; - *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; - if (sin->sin6_scope_id == 0) - sin->sin6_scope_id = ntohs(index); - } - scopeid = sin->sin6_scope_id; - error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); if (error != 0) @@ -245,17 +219,6 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if (sin != NULL && sin->sin6_family == AF_INET6) { int error; - /* XXX: embedded link local addr check */ - if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && - *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { - u_short index; - - index = *(u_short *)&sin->sin6_addr.s6_addr[2]; - *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; - if (sin->sin6_scope_id == 0) - sin->sin6_scope_id = ntohs(index); - } - error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf, sizeof(addr_buf), NULL, 0, @@ -288,8 +251,8 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if ((flags6 & IN6_IFF_TEMPORARY) != 0) printf("temporary "); - if (scopeid) - printf("scopeid 0x%x ", scopeid); + if (sin->sin6_scope_id) + printf("scopeid 0x%x ", sin->sin6_scope_id); if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); @@ -458,7 +421,6 @@ in6_status_tunnel(int s) return; if (sa->sa_family != AF_INET6) return; - in6_fillscopeid(&in6_ifr.ifr_addr); if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0, NI_NUMERICHOST) != 0) src[0] = '\0'; @@ -467,7 +429,6 @@ in6_status_tunnel(int s) return; if (sa->sa_family != AF_INET6) return; - in6_fillscopeid(&in6_ifr.ifr_addr); if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, NI_NUMERICHOST) != 0) dst[0] = '\0'; diff --git a/sbin/route/route.c b/sbin/route/route.c index 135d378..58a92e1 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -557,18 +557,6 @@ routename(struct sockaddr *sa) memcpy(&sin6, sa, sa->sa_len); sin6.sin6_len = sizeof(struct sockaddr_in6); sin6.sin6_family = AF_INET6; -#ifdef __KAME__ - if (sa->sa_len == sizeof(struct sockaddr_in6) && - (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr) || - IN6_IS_ADDR_MC_NODELOCAL(&sin6.sin6_addr)) && - sin6.sin6_scope_id == 0) { - sin6.sin6_scope_id = - ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); - sin6.sin6_addr.s6_addr[2] = 0; - sin6.sin6_addr.s6_addr[3] = 0; - } -#endif if (nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, @@ -661,18 +649,6 @@ netname(struct sockaddr *sa) memcpy(&sin6, sa, sa->sa_len); sin6.sin6_len = sizeof(struct sockaddr_in6); sin6.sin6_family = AF_INET6; -#ifdef __KAME__ - if (sa->sa_len == sizeof(struct sockaddr_in6) && - (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr) || - IN6_IS_ADDR_MC_NODELOCAL(&sin6.sin6_addr)) && - sin6.sin6_scope_id == 0) { - sin6.sin6_scope_id = - ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); - sin6.sin6_addr.s6_addr[2] = 0; - sin6.sin6_addr.s6_addr[3] = 0; - } -#endif if (nflag) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, @@ -1232,16 +1208,6 @@ getaddr(int which, char *str, struct hostent **hpp) exit(1); } memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6)); -#ifdef __KAME__ - if ((IN6_IS_ADDR_LINKLOCAL(&su->sin6.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&su->sin6.sin6_addr) || - IN6_IS_ADDR_MC_NODELOCAL(&su->sin6.sin6_addr)) && - su->sin6.sin6_scope_id) { - *(u_int16_t *)&su->sin6.sin6_addr.s6_addr[2] = - htons(su->sin6.sin6_scope_id); - su->sin6.sin6_scope_id = 0; - } -#endif freeaddrinfo(res); if (q != NULL) *q++ = '/'; -- cgit v1.1 From 9376662aac53d43f14e729f78bc36cddffaf65e2 Mon Sep 17 00:00:00 2001 From: trasz Date: Sun, 18 Nov 2012 19:01:00 +0000 Subject: Make it possible to resize filesystems mounted read-write, using newly introduced UFS write suspension mechanism. Reviewed by: kib, mckusick Sponsored by: FreeBSD Foundation --- sbin/growfs/growfs.8 | 6 ++++++ sbin/growfs/growfs.c | 30 +++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'sbin') diff --git a/sbin/growfs/growfs.8 b/sbin/growfs/growfs.8 index 92508da..682cf44 100644 --- a/sbin/growfs/growfs.8 +++ b/sbin/growfs/growfs.8 @@ -115,11 +115,17 @@ The .Nm utility first appeared in .Fx 4.4 . +The ability to resize mounted filesystems was added in +.Fx 10.0 . .Sh AUTHORS .An Christoph Herrmann Aq chm@FreeBSD.org .An Thomas-Henning von Kamptz Aq tomsoft@FreeBSD.org .An The GROWFS team Aq growfs@Tomsoft.COM .An Edward Tomasz Napierala Aq trasz@FreeBSD.org +.Sh CAVEATS +.Pp +When expanding a file system mounted read-write, any writes to that file system +will be temporarily suspended until the expansion is finished. .Sh BUGS Normally .Nm diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index ad837a8..042aada 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1525,8 +1526,9 @@ main(int argc, char **argv) if (yflag == 0 && Nflag == 0) { if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) - errx(1, "%s is mounted read-write on %s", - statfsp->f_mntfromname, statfsp->f_mntonname); + printf("Device is mounted read-write; resizing will " + "result in temporary write suspension for %s.\n", + statfsp->f_mntonname); printf("It's strongly recommended to make a backup " "before growing the file system.\n" "OK to grow filesystem on %s", device); @@ -1555,9 +1557,18 @@ main(int argc, char **argv) if (Nflag) { fso = -1; } else { - fso = open(device, O_WRONLY); - if (fso < 0) - err(1, "%s", device); + if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) { + fso = open(_PATH_UFSSUSPEND, O_RDWR); + if (fso == -1) + err(1, "unable to open %s", _PATH_UFSSUSPEND); + error = ioctl(fso, UFSSUSPEND, &statfsp->f_fsid); + if (error != 0) + err(1, "UFSSUSPEND"); + } else { + fso = open(device, O_WRONLY); + if (fso < 0) + err(1, "%s", device); + } } /* @@ -1627,12 +1638,17 @@ main(int argc, char **argv) close(fsi); if (fso > -1) { + if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) { + error = ioctl(fso, UFSRESUME); + if (error != 0) + err(1, "UFSRESUME"); + } error = close(fso); if (error != 0) err(1, "close"); + if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) != 0) + mount_reload(statfsp); } - if (statfsp != NULL) - mount_reload(statfsp); DBG_CLOSE; -- cgit v1.1 From 70911364a7bdfbdd417e4cf7a5b1b85321204c76 Mon Sep 17 00:00:00 2001 From: joel Date: Sun, 18 Nov 2012 19:39:42 +0000 Subject: Remove superfluous paragraph macro. --- sbin/growfs/growfs.8 | 1 - 1 file changed, 1 deletion(-) (limited to 'sbin') diff --git a/sbin/growfs/growfs.8 b/sbin/growfs/growfs.8 index 682cf44..664e723 100644 --- a/sbin/growfs/growfs.8 +++ b/sbin/growfs/growfs.8 @@ -123,7 +123,6 @@ The ability to resize mounted filesystems was added in .An The GROWFS team Aq growfs@Tomsoft.COM .An Edward Tomasz Napierala Aq trasz@FreeBSD.org .Sh CAVEATS -.Pp When expanding a file system mounted read-write, any writes to that file system will be temporarily suspended until the expansion is finished. .Sh BUGS -- cgit v1.1 From e82a3d82c2e6323735987f75e75353ea73e49142 Mon Sep 17 00:00:00 2001 From: jh Date: Wed, 21 Nov 2012 16:56:47 +0000 Subject: Disallow attaching preloaded memory disks via ioctl. - The feature is dangerous because the kernel code didn't check validity of the memory address provided from user space. - It seems that mdconfig(8) never really supported attaching preloaded memory disks. - Preloaded memory disks are automatically attached during md(4) initialization. Thus there shouldn't be much use for the feature. PR: kern/169683 Discussed on: freebsd-hackers --- sbin/mdconfig/mdconfig.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 55d1567..70cefe9 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -84,7 +84,7 @@ usage(void) " mdconfig -r -u unit -s size [-o [no]force]\n" " mdconfig -l [-v] [-n] [-u unit]\n" " mdconfig file\n"); - fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n"); + fprintf(stderr, "\t\ttype = {malloc, vnode, swap}\n"); fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n"); fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%db (B),\n"); fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB) or\n"); @@ -148,8 +148,6 @@ main(int argc, char **argv) if (!strcmp(optarg, "malloc")) { mdio.md_type = MD_MALLOC; mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; - } else if (!strcmp(optarg, "preload")) { - mdio.md_type = MD_PRELOAD; } else if (!strcmp(optarg, "vnode")) { mdio.md_type = MD_VNODE; mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; -- cgit v1.1 From 0e3887790cdaafe42670f8bb2eb6002edd508df2 Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 29 Nov 2012 05:16:50 +0000 Subject: Mark non-returning function as such PR: bin/172978 Approved by: cperciva MFC after: 3 days --- sbin/dump/dump.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index 2a65865..4a8af10 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -121,7 +121,7 @@ void trewind(void); void writerec(char *dp, int isspcl); void Exit(int status) __dead2; -void dumpabort(int signo); +void dumpabort(int signo) __dead2; void dump_getfstab(void); char *rawname(char *cp); -- cgit v1.1 From b5d427feeaa43560621a4bd651ee2a30caeb4c74 Mon Sep 17 00:00:00 2001 From: glebius Date: Tue, 4 Dec 2012 10:24:50 +0000 Subject: No need to be root when running with -t or -d. --- sbin/route/route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 58a92e1..2d470e1 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -365,7 +365,7 @@ flushroutes(int argc, char *argv[]) struct fibl *fl; int error; - if (uid != 0 && !debugonly) { + if (uid != 0 && !debugonly && !tflag) { errx(EX_NOPERM, "must be root to alter routing table"); } shutdown(s, SHUT_RD); /* Don't want to read back our messages */ @@ -727,7 +727,7 @@ newroute(int argc, char **argv) const char *dest, *gateway, *errmsg; int key, error, flags, nrflags, fibnum; - if (uid != 0) { + if (uid != 0 && !debugonly && !tflag) { errx(EX_NOPERM, "must be root to alter routing table"); } -- cgit v1.1 From ca0235c9502df6e25f0f8b61929dea4ddd8ce279 Mon Sep 17 00:00:00 2001 From: glebius Date: Tue, 4 Dec 2012 11:10:01 +0000 Subject: Flush stdout after RTM_IFANNOUNCE message. PR: bin/151600 Submitted by: Eric van Gyzen --- sbin/route/route.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 2d470e1..107c66f 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1632,6 +1632,7 @@ print_rtmsg(struct rt_msghdr *rtm, size_t msglen) break; } printf("\n"); + fflush(stdout); break; default: -- cgit v1.1 From db5359d69a9ec06842730b8af2a30072a38b5aa1 Mon Sep 17 00:00:00 2001 From: hrs Date: Tue, 4 Dec 2012 17:12:23 +0000 Subject: - Fix LOR in sa6_recoverscope() in rt_msg2()[1]. - Check V_deembed_scopeid before checking if sa_family == AF_INET6. - Fix scope id handing in route(8)[2] and ifconfig(8). Reported by: rpaulo[1], Mateusz Guzik[1], peter[2] --- sbin/ifconfig/af_inet6.c | 5 +++-- sbin/route/route.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index a9ad867..5911a94 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -251,8 +251,9 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if ((flags6 & IN6_IFF_TEMPORARY) != 0) printf("temporary "); - if (sin->sin6_scope_id) - printf("scopeid 0x%x ", sin->sin6_scope_id); + if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) + printf("scopeid 0x%x ", + ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); diff --git a/sbin/route/route.c b/sbin/route/route.c index 107c66f..b63ce63 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1208,6 +1208,16 @@ getaddr(int which, char *str, struct hostent **hpp) exit(1); } memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6)); +#ifdef __KAME__ + if ((IN6_IS_ADDR_LINKLOCAL(&su->sin6.sin6_addr) || + IN6_IS_ADDR_MC_LINKLOCAL(&su->sin6.sin6_addr) || + IN6_IS_ADDR_MC_NODELOCAL(&su->sin6.sin6_addr)) && + su->sin6.sin6_scope_id) { + *(u_int16_t *)&su->sin6.sin6_addr.s6_addr[2] = + htons(su->sin6.sin6_scope_id); + su->sin6.sin6_scope_id = 0; + } +#endif freeaddrinfo(res); if (q != NULL) *q++ = '/'; -- cgit v1.1 From e3194b87ca5c4f35638ebd27dfe4f3c8a2344e58 Mon Sep 17 00:00:00 2001 From: glebius Date: Tue, 4 Dec 2012 20:05:01 +0000 Subject: Fix fallout from r243019, which broke parsing of shortened network prefixes. Reported and tested by: delphij --- sbin/route/route.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index b63ce63..809dc9f 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1033,6 +1033,13 @@ inet_makenetandmask(u_long net, struct sockaddr_in *sin, u_long bits) rtm_addrs |= RTA_NETMASK; /* + * MSB of net should be meaningful. 0/0 is exception. + */ + if (net > 0) + while ((net & 0xff000000) == 0) + net <<= 8; + + /* * If no /xx was specified we must calculate the * CIDR address. */ -- cgit v1.1 From 377b89c55f75aba70c2c66bfc96fb4c4af7311ae Mon Sep 17 00:00:00 2001 From: hrs Date: Wed, 5 Dec 2012 19:45:24 +0000 Subject: - Move definition of V_deembed_scopeid to scope6_var.h. - Deembed scope id in L3 address in in6_lltable_dump(). - Simplify scope id recovery in rtsock routines. - Remove embedded scope id handling in ndp(8) and route(8) completely. --- sbin/route/route.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 809dc9f..be85184 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1215,16 +1215,6 @@ getaddr(int which, char *str, struct hostent **hpp) exit(1); } memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6)); -#ifdef __KAME__ - if ((IN6_IS_ADDR_LINKLOCAL(&su->sin6.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&su->sin6.sin6_addr) || - IN6_IS_ADDR_MC_NODELOCAL(&su->sin6.sin6_addr)) && - su->sin6.sin6_scope_id) { - *(u_int16_t *)&su->sin6.sin6_addr.s6_addr[2] = - htons(su->sin6.sin6_scope_id); - su->sin6.sin6_scope_id = 0; - } -#endif freeaddrinfo(res); if (q != NULL) *q++ = '/'; -- cgit v1.1 From ab2b1f57e9cea68bf7483479d6e2e84fe7886d5f Mon Sep 17 00:00:00 2001 From: dim Date: Wed, 5 Dec 2012 20:50:40 +0000 Subject: 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 PR: bin/172958 MFC after: 2 weeks --- sbin/devd/devd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index 7724719..fa75c3f 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -445,7 +445,7 @@ public: void config::sort_vector(vector &v) { - sort(v.begin(), v.end(), epv_greater()); + stable_sort(v.begin(), v.end(), epv_greater()); } void -- cgit v1.1 From be40a13e591d429128dff12fe9d55a513ed76e4e Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 6 Dec 2012 01:25:14 +0000 Subject: Constify where possible Approved by: cperciva MFC after: 2 weeks --- sbin/devd/devd.cc | 8 ++++---- sbin/devd/devd.hh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'sbin') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index fa75c3f..b734d7e 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -151,7 +151,7 @@ event_proc::add(eps *eps) } bool -event_proc::matches(config &c) +event_proc::matches(config &c) const { vector::const_iterator i; @@ -162,7 +162,7 @@ event_proc::matches(config &c) } bool -event_proc::run(config &c) +event_proc::run(config &c) const { vector::const_iterator i; @@ -436,7 +436,7 @@ config::parse_files_in_dir(const char *dirname) class epv_greater { public: - int operator()(event_proc *const&l1, event_proc *const&l2) + int operator()(event_proc *const&l1, event_proc *const&l2) const { return (l1->get_priority() > l2->get_priority()); } @@ -577,7 +577,7 @@ config::get_variable(const string &var) } bool -config::is_id_char(char ch) +config::is_id_char(char ch) const { return (ch != '\0' && (isalpha(ch) || isdigit(ch) || ch == '_' || ch == '-')); diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh index 1830dad..f50e502 100644 --- a/sbin/devd/devd.hh +++ b/sbin/devd/devd.hh @@ -134,8 +134,8 @@ public: int get_priority() const { return (_prio); } void set_priority(int prio) { _prio = prio; } void add(eps *); - bool matches(config &); - bool run(config &); + bool matches(config &) const; + bool run(config &) const; private: int _prio; std::vector _epsvec; @@ -170,7 +170,7 @@ protected: void parse_one_file(const char *fn); void parse_files_in_dir(const char *dirname); void expand_one(const char *&src, std::string &dst); - bool is_id_char(char); + bool is_id_char(char) const; bool chop_var(char *&buffer, char *&lhs, char *&rhs); private: std::vector _dir_list; -- cgit v1.1 From 76f827328bff797fb7cf44ba938fedf5f11ab20f Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 6 Dec 2012 01:25:17 +0000 Subject: Avoid the creation of a temporary object by using the prefix operator for non-primitive types. Approved by: cperciva MFC after: 2 weeks --- sbin/devd/devd.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'sbin') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index b734d7e..332b6cb 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -127,7 +127,7 @@ delete_and_clear(vector &v) { typename vector::const_iterator i; - for (i = v.begin(); i != v.end(); i++) + for (i = v.begin(); i != v.end(); ++i) delete *i; v.clear(); } @@ -155,7 +155,7 @@ event_proc::matches(config &c) const { vector::const_iterator i; - for (i = _epsvec.begin(); i != _epsvec.end(); i++) + for (i = _epsvec.begin(); i != _epsvec.end(); ++i) if (!(*i)->do_match(c)) return (false); return (true); @@ -166,7 +166,7 @@ event_proc::run(config &c) const { vector::const_iterator i; - for (i = _epsvec.begin(); i != _epsvec.end(); i++) + for (i = _epsvec.begin(); i != _epsvec.end(); ++i) if (!(*i)->do_action(c)) return (false); return (true); @@ -301,7 +301,7 @@ media::media(config &, const char *var, const char *type) { -1, "unknown" }, { 0, NULL }, }; - for (int i = 0; media_types[i].ifmt_string != NULL; i++) + for (int i = 0; media_types[i].ifmt_string != NULL; ++i) if (strcasecmp(type, media_types[i].ifmt_string) == 0) { _type = media_types[i].ifmt_word; break; @@ -454,7 +454,7 @@ config::parse(void) vector::const_iterator i; parse_one_file(configfile); - for (i = _dir_list.begin(); i != _dir_list.end(); i++) + for (i = _dir_list.begin(); i != _dir_list.end(); ++i) parse_files_in_dir((*i).c_str()); sort_vector(_attach_list); sort_vector(_detach_list); @@ -569,7 +569,7 @@ config::get_variable(const string &var) { vector::reverse_iterator i; - for (i = _var_list_table.rbegin(); i != _var_list_table.rend(); i++) { + for (i = _var_list_table.rbegin(); i != _var_list_table.rend(); ++i) { if ((*i)->is_set(var)) return ((*i)->get_variable(var)); } @@ -726,7 +726,7 @@ config::find_and_execute(char type) } if (Dflag) fprintf(stderr, "Processing %s event\n", s); - for (i = l->begin(); i != l->end(); i++) { + for (i = l->begin(); i != l->end(); ++i) { if ((*i)->matches(*this)) { (*i)->run(*this); break; @@ -823,14 +823,14 @@ notify_clients(const char *data, int len) list bad; list::const_iterator i; - for (i = clients.begin(); i != clients.end(); i++) { + for (i = clients.begin(); i != clients.end(); ++i) { if (write(*i, data, len) <= 0) { bad.push_back(*i); close(*i); } } - for (i = bad.begin(); i != bad.end(); i++) + for (i = bad.begin(); i != bad.end(); ++i) clients.erase(find(clients.begin(), clients.end(), *i)); } -- cgit v1.1 From d63ec4c24b02575838256ea35e13bf20df348995 Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 6 Dec 2012 01:25:21 +0000 Subject: Prefer the use of initalizer lists to ctor assignment. Approved by: cperciva MFC after: 2 weeks --- sbin/devd/devd.cc | 3 +-- sbin/devd/devd.hh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index 332b6cb..576dcf6 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -248,9 +248,8 @@ action::do_action(config &c) } match::match(config &c, const char *var, const char *re) - : _var(var) + : _var(var), _re("^") { - _re = "^"; if (!c.expand_string(string(re)).empty() && c.expand_string(string(re)).at(0) == '!') { _re.append(c.expand_string(string(re)).substr(1)); diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh index f50e502..3613216 100644 --- a/sbin/devd/devd.hh +++ b/sbin/devd/devd.hh @@ -144,7 +144,7 @@ private: class config { public: - config() { _pidfile = ""; push_var_table(); } + config() : _pidfile("") { push_var_table(); } virtual ~config() { reset(); } void add_attach(int, event_proc *); void add_detach(int, event_proc *); -- cgit v1.1 From 98601953890f2c4381eda07f2914bfc1f8b114ec Mon Sep 17 00:00:00 2001 From: eadler Date: Sat, 8 Dec 2012 22:16:36 +0000 Subject: A number of places in the source tree still reference cuad.* after sio(4) was deprecated by uart(4). s/cuad/cuau/g/ PR: docs/171533 Reviewed by: imp Approved by: cperciva (implicit) MFC after: 3 weeks --- sbin/comcontrol/comcontrol.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/comcontrol/comcontrol.8 b/sbin/comcontrol/comcontrol.8 index 87a7630..ec12dee 100644 --- a/sbin/comcontrol/comcontrol.8 +++ b/sbin/comcontrol/comcontrol.8 @@ -49,7 +49,7 @@ startup script. .Bl -tag -width /dev/ttyd? -compact .It Pa /dev/ttyd? dialin devices, hardwired terminals -.It Pa /dev/cuad? +.It Pa /dev/cuau? dialout devices .El .Sh SEE ALSO -- cgit v1.1 From 93c63cbc5ffea154731bbf88f4cdb1f6b2e48293 Mon Sep 17 00:00:00 2001 From: rmacklem Date: Sun, 9 Dec 2012 21:26:47 +0000 Subject: Document the new NFS mount options added by r244042. This is a content change. --- sbin/mount_nfs/mount_nfs.8 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/mount_nfs/mount_nfs.8 b/sbin/mount_nfs/mount_nfs.8 index b1b5c6e..26ed091 100644 --- a/sbin/mount_nfs/mount_nfs.8 +++ b/sbin/mount_nfs/mount_nfs.8 @@ -28,7 +28,7 @@ .\" @(#)mount_nfs.8 8.3 (Berkeley) 3/29/95 .\" $FreeBSD$ .\" -.Dd May 3, 2011 +.Dd December 9, 2012 .Dt MOUNT_NFS 8 .Os .Sh NAME @@ -175,6 +175,18 @@ Use the NFS Version 3 protocol. Use the NFS Version 4 protocol. This option will force the mount to use TCP transport. +.It Cm minorversion Ns = Ns Aq Ar value +Override the default of 0 for the minor version of the NFS Version 4 protocol. +The only minor version currently supported is 1. +This option is only meaningful when used with the +.Cm nfsv4 +option. +.It Cm pnfs +Enable support for parallel NFS (pNFS) for minor version 1 of the +NFS Version 4 protocol. +This option is only meaningful when used with the +.Cm minorversion +option. .It Cm noconn For UDP mount points, do not do a .Xr connect 2 . -- cgit v1.1 From c136207370d0cc68d4f9f23f8781e719f1e71b6e Mon Sep 17 00:00:00 2001 From: delphij Date: Tue, 11 Dec 2012 01:12:29 +0000 Subject: In parse(): - Only operate on copy, don't operate on source. - Eliminate home-rolled strsep(). - Constify the parameter. MFC after: 2 weeks --- sbin/sysctl/sysctl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sbin') diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 7379155..83e1337 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -62,7 +62,7 @@ static int aflag, bflag, dflag, eflag, hflag, iflag; static int Nflag, nflag, oflag, qflag, xflag, warncount; static int oidfmt(int *, int, char *, u_int *); -static void parse(char *); +static void parse(const char *); static int show_var(int *, int); static int sysctl_all(int *oid, int len); static int name2oid(char *, int *); @@ -161,7 +161,7 @@ main(int argc, char **argv) * Set a new value if requested. */ static void -parse(char *string) +parse(const char *string) { int len, i, j; void *newval = 0; @@ -176,12 +176,11 @@ parse(char *string) char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ]; u_int kind; - bufp = buf; + cp = buf; if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) errx(1, "oid too long: '%s'", string); - if ((cp = strchr(string, '=')) != NULL) { - *strchr(buf, '=') = '\0'; - *cp++ = '\0'; + bufp = strsep(&cp, "="); + if (cp != NULL) { while (isspace(*cp)) cp++; newval = cp; -- cgit v1.1 From 2a065c7bf07356bbc84ff330f04ecf38d851febf Mon Sep 17 00:00:00 2001 From: alfred Date: Tue, 11 Dec 2012 01:28:06 +0000 Subject: Allow sysctl to filter boot and runtime tunables. Add the following flags to sysctl: -W - show only writable sysctls -T - show only tuneable sysctls This can be used to create a /var/run/sysctl.boot to compare set tunables versus booted tunables. Sponsored by: iXsystems --- sbin/sysctl/sysctl.8 | 9 +++++++-- sbin/sysctl/sysctl.c | 27 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'sbin') diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8 index be43e68..514acd1 100644 --- a/sbin/sysctl/sysctl.8 +++ b/sbin/sysctl/sysctl.8 @@ -36,11 +36,11 @@ .Nd get or set kernel state .Sh SYNOPSIS .Nm -.Op Fl bdehiNnoqx +.Op Fl bdehiNnoRTqx .Ar name Ns Op = Ns Ar value .Ar ... .Nm -.Op Fl bdehNnoqx +.Op Fl bdehNnoRTqx .Fl a .Sh DESCRIPTION The @@ -121,6 +121,11 @@ sixteen bytes of the value. Suppress some warnings generated by .Nm to standard error. +.It Fl T +Display only variables that are setable via loader (CTLFLAG_TUN). +.It Fl W +Display only wriable variables that are not statistical. +Useful for determining the set of runtime tunable sysctls. .It Fl X Equivalent to .Fl x a diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 83e1337..a1acf88 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -59,7 +59,7 @@ static const char rcsid[] = #include static int aflag, bflag, dflag, eflag, hflag, iflag; -static int Nflag, nflag, oflag, qflag, xflag, warncount; +static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag, warncount; static int oidfmt(int *, int, char *, u_int *); static void parse(const char *); @@ -74,8 +74,8 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bdehiNnoqx] name[=value] ...", - " sysctl [-bdehNnoqx] -a"); + "usage: sysctl [-bdehiNnoqTWx] name[=value] ...", + " sysctl [-bdehNnoqTWx] -a"); exit(1); } @@ -88,7 +88,7 @@ main(int argc, char **argv) setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabdehiNnoqwxX")) != -1) { + while ((ch = getopt(argc, argv, "AabdehiNnoqTwWxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -124,10 +124,16 @@ main(int argc, char **argv) case 'q': qflag = 1; break; + case 'T': + Tflag = 1; + break; case 'w': /* compatibility */ /* ignored */ break; + case 'W': + Wflag = 1; + break; case 'X': /* compatibility */ aflag = xflag = 1; @@ -181,6 +187,11 @@ parse(const char *string) errx(1, "oid too long: '%s'", string); bufp = strsep(&cp, "="); if (cp != NULL) { + /* Tflag just lists tunables, do not allow assignment */ + if (Tflag || Wflag) { + warnx("Can't set variables when using -T or -W"); + usage(); + } while (isspace(*cp)) cp++; newval = cp; @@ -602,6 +613,14 @@ show_var(int *oid, int nlen) sign = ctl_sign[ctltype]; intlen = ctl_size[ctltype]; + /* if Wflag then only list sysctls that are writeable and not stats. */ + if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0)) + return 1; + + /* if Tflag then only list sysctls that are tuneables. */ + if (Tflag && (kind & CTLFLAG_TUN) == 0) + return 1; + switch (ctltype) { case CTLTYPE_STRING: if (!nflag) -- cgit v1.1 From f97c062bec223fe6716fac1497b773e0deac83a1 Mon Sep 17 00:00:00 2001 From: alfred Date: Wed, 12 Dec 2012 02:55:40 +0000 Subject: Make Tflag and Wflag filters work for more sysctl options. To do this move the Tflag and Wflag checks earlier in show_var() so we bail earlier for variables not matching our query. --- sbin/sysctl/sysctl.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'sbin') diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index a1acf88..a9c2b7a 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -539,7 +539,7 @@ static int show_var(int *oid, int nlen) { u_char buf[BUFSIZ], *val, *oval, *p; - char name[BUFSIZ], *fmt; + char name[BUFSIZ], fmt[BUFSIZ]; const char *sep, *sep1; int qoid[CTL_MAXNAME+2]; uintmax_t umv; @@ -554,6 +554,7 @@ show_var(int *oid, int nlen) umv = mv = intlen = 0; bzero(buf, BUFSIZ); + bzero(fmt, BUFSIZ); bzero(name, BUFSIZ); qoid[0] = 0; memcpy(qoid + 2, oid, nlen * sizeof(int)); @@ -564,6 +565,15 @@ show_var(int *oid, int nlen) if (i || !j) err(1, "sysctl name %d %zu %d", i, j, errno); + oidfmt(oid, nlen, fmt, &kind); + /* if Wflag then only list sysctls that are writeable and not stats. */ + if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0)) + return 1; + + /* if Tflag then only list sysctls that are tuneables. */ + if (Tflag && (kind & CTLFLAG_TUN) == 0) + return 1; + if (Nflag) { printf("%s", name); return (0); @@ -606,21 +616,11 @@ show_var(int *oid, int nlen) return (0); } val[len] = '\0'; - fmt = buf; - oidfmt(oid, nlen, fmt, &kind); p = val; ctltype = (kind & CTLTYPE); sign = ctl_sign[ctltype]; intlen = ctl_size[ctltype]; - /* if Wflag then only list sysctls that are writeable and not stats. */ - if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0)) - return 1; - - /* if Tflag then only list sysctls that are tuneables. */ - if (Tflag && (kind & CTLFLAG_TUN) == 0) - return 1; - switch (ctltype) { case CTLTYPE_STRING: if (!nflag) -- cgit v1.1 From 976943f3a93bdb52ea2fb077b56f27c14b99da8c Mon Sep 17 00:00:00 2001 From: delphij Date: Thu, 13 Dec 2012 23:32:47 +0000 Subject: Teach sysctl(8) about parsing a file (while I'm there also give it capability of parsing both = and : formats). Submitted by: hrs (initial version, bugs are mine) MFC after: 3 months --- sbin/sysctl/sysctl.8 | 8 +- sbin/sysctl/sysctl.c | 229 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 175 insertions(+), 62 deletions(-) (limited to 'sbin') diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8 index 514acd1..fe0a75a 100644 --- a/sbin/sysctl/sysctl.8 +++ b/sbin/sysctl/sysctl.8 @@ -28,7 +28,7 @@ .\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd January 17, 2011 +.Dd December 13, 2012 .Dt SYSCTL 8 .Os .Sh NAME @@ -37,6 +37,7 @@ .Sh SYNOPSIS .Nm .Op Fl bdehiNnoRTqx +.Op Fl f Ar filename .Ar name Ns Op = Ns Ar value .Ar ... .Nm @@ -80,6 +81,11 @@ This option is ignored if either or .Fl n is specified, or a variable is being set. +.It Fl f Ar filename +Specify a file which contains a pair of name and value in each line. +.Nm +reads and processes the specified file first and then processes the name +and value pairs in the command line argument. .It Fl h Format output for human, rather than machine, readability. .It Fl i diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index a9c2b7a..8fad089 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -56,13 +56,17 @@ static const char rcsid[] = #include #include #include +#include #include +static const char *conffile; + static int aflag, bflag, dflag, eflag, hflag, iflag; -static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag, warncount; +static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag; static int oidfmt(int *, int, char *, u_int *); -static void parse(const char *); +static int parsefile(const char *); +static int parse(const char *, int); static int show_var(int *, int); static int sysctl_all(int *oid, int len); static int name2oid(char *, int *); @@ -74,7 +78,7 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bdehiNnoqTWx] name[=value] ...", + "usage: sysctl [-bdehiNnoqTWx] [-f filename] name[=value] ...", " sysctl [-bdehNnoqTWx] -a"); exit(1); } @@ -83,12 +87,13 @@ int main(int argc, char **argv) { int ch; + int warncount = 0; setlocale(LC_NUMERIC, ""); setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabdehiNnoqTwWxX")) != -1) { + while ((ch = getopt(argc, argv, "Aabdef:hiNnoqTwWxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -106,6 +111,9 @@ main(int argc, char **argv) case 'e': eflag = 1; break; + case 'f': + conffile = optarg; + break; case 'h': hflag = 1; break; @@ -152,13 +160,17 @@ main(int argc, char **argv) usage(); if (aflag && argc == 0) exit(sysctl_all(0, 0)); - if (argc == 0) + if (argc == 0 && conffile == NULL) usage(); warncount = 0; + if (conffile != NULL) + warncount += parsefile(conffile); + while (argc-- > 0) - parse(*argv++); - exit(warncount); + warncount += parse(*argv++, 0); + + return (warncount); } /* @@ -166,8 +178,8 @@ main(int argc, char **argv) * Lookup and print out the MIB entry if it exists. * Set a new value if requested. */ -static void -parse(const char *string) +static int +parse(const char *string, int lineno) { int len, i, j; void *newval = 0; @@ -179,13 +191,20 @@ parse(const char *string) int64_t i64val; uint64_t u64val; int mib[CTL_MAXNAME]; - char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ]; + char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ], line[BUFSIZ]; u_int kind; + if (lineno) + snprintf(line, sizeof(line), " at line %d", lineno); + else + line[0] = '\0'; + cp = buf; - if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) - errx(1, "oid too long: '%s'", string); - bufp = strsep(&cp, "="); + if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) { + warn("oid too long: '%s'%s", string, line); + return (1); + } + bufp = strsep(&cp, "=:"); if (cp != NULL) { /* Tflag just lists tunables, do not allow assignment */ if (Tflag || Wflag) { @@ -194,6 +213,14 @@ parse(const char *string) } while (isspace(*cp)) cp++; + /* Strip a pair of " or ' if any. */ + switch (*cp) { + case '\"': + case '\'': + if (cp[strlen(cp) - 1] == *cp) + cp[strlen(cp) - 1] = '\0'; + cp++; + } newval = cp; newsize = strlen(cp); } @@ -201,15 +228,22 @@ parse(const char *string) if (len < 0) { if (iflag) - return; + return (0); if (qflag) - exit(1); - else - errx(1, "unknown oid '%s'", bufp); + return (1); + else { + warn("unknown oid '%s'%s", bufp, line); + return (1); + } } - if (oidfmt(mib, len, fmt, &kind)) - err(1, "couldn't find format of oid '%s'", bufp); + if (oidfmt(mib, len, fmt, &kind)) { + warn("couldn't find format of oid '%s'%s", bufp, line); + if (iflag) + return (1); + else + exit(1); + } if (newval == NULL || dflag) { if ((kind & CTLTYPE) == CTLTYPE_NODE) { @@ -225,16 +259,18 @@ parse(const char *string) putchar('\n'); } } else { - if ((kind & CTLTYPE) == CTLTYPE_NODE) - errx(1, "oid '%s' isn't a leaf node", bufp); + if ((kind & CTLTYPE) == CTLTYPE_NODE) { + warn("oid '%s' isn't a leaf node%s", bufp, line); + return (1); + } if (!(kind & CTLFLAG_WR)) { if (kind & CTLFLAG_TUN) { - warnx("oid '%s' is a read only tunable", bufp); - errx(1, "Tunable values are set in /boot/loader.conf"); - } else { - errx(1, "oid '%s' is read only", bufp); - } + warnx("oid '%s' is a read only tunable%p", bufp, line); + warnx("Tunable values are set in /boot/loader.conf"); + } else + warnx("oid '%s' is read only%s", bufp, line); + return (1); } if ((kind & CTLTYPE) == CTLTYPE_INT || @@ -243,47 +279,59 @@ parse(const char *string) (kind & CTLTYPE) == CTLTYPE_ULONG || (kind & CTLTYPE) == CTLTYPE_S64 || (kind & CTLTYPE) == CTLTYPE_U64) { - if (strlen(newval) == 0) - errx(1, "empty numeric value"); + if (strlen(newval) == 0) { + warnx("empty numeric value"); + return (1); + } } switch (kind & CTLTYPE) { case CTLTYPE_INT: if (strcmp(fmt, "IK") == 0) { - if (!set_IK(newval, &intval)) - errx(1, "invalid value '%s'", - (char *)newval); + if (!set_IK(newval, &intval)) { + warnx("invalid value '%s'%s", + (char *)newval, line); + return (1); + } } else { intval = (int)strtol(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid integer '%s'", - (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid integer '%s'%s", + (char *)newval, line); + return (1); + } } newval = &intval; newsize = sizeof(intval); break; case CTLTYPE_UINT: uintval = (int) strtoul(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid unsigned integer '%s'", - (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid unsigned integer '%s'%s", + (char *)newval, line); + return (1); + } newval = &uintval; newsize = sizeof(uintval); break; case CTLTYPE_LONG: longval = strtol(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid long integer '%s'", - (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid long integer '%s'%s", + (char *)newval, line); + return (1); + } newval = &longval; newsize = sizeof(longval); break; case CTLTYPE_ULONG: ulongval = strtoul(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid unsigned long integer" - " '%s'", (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid unsigned long integer" + " '%s'%s", (char *)newval, line); + return (1); + } newval = &ulongval; newsize = sizeof(ulongval); break; @@ -291,26 +339,31 @@ parse(const char *string) break; case CTLTYPE_S64: i64val = strtoimax(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid int64_t '%s'", - (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid int64_t '%s'%s", + (char *)newval, line); + return (1); + } newval = &i64val; newsize = sizeof(i64val); break; case CTLTYPE_U64: u64val = strtoumax(newval, &endptr, 0); - if (endptr == newval || *endptr != '\0') - errx(1, "invalid uint64_t '%s'", - (char *)newval); + if (endptr == newval || *endptr != '\0') { + warnx("invalid uint64_t '%s'%s", + (char *)newval, line); + return (1); + } newval = &u64val; newsize = sizeof(u64val); break; case CTLTYPE_OPAQUE: /* FALLTHROUGH */ default: - errx(1, "oid '%s' is type %d," - " cannot set that", bufp, - kind & CTLTYPE); + warnx("oid '%s' is type %d," + " cannot set that%s", bufp, + kind & CTLTYPE, line); + return (1); } i = show_var(mib, len); @@ -319,18 +372,20 @@ parse(const char *string) putchar('\n'); switch (errno) { case EOPNOTSUPP: - errx(1, "%s: value is not available", - string); + warnx("%s: value is not available%s", + string, line); + return (1); case ENOTDIR: - errx(1, "%s: specification is incomplete", - string); + warnx("%s: specification is incomplete%s", + string, line); + return (1); case ENOMEM: - errx(1, "%s: type is unknown to this program", - string); + warnx("%s: type is unknown to this program%s", + string, line); + return (1); default: - warn("%s", string); - warncount++; - return; + warn("%s%s", string, line); + return (1); } } if (!bflag) @@ -342,6 +397,58 @@ parse(const char *string) putchar('\n'); nflag = i; } + + return (0); +} + +static int +parsefile(const char *filename) +{ + FILE *file; + char line[BUFSIZ], *p, *pq, *pdq; + int warncount = 0, lineno = 0; + + file = fopen(filename, "r"); + if (file == NULL) + err(EX_NOINPUT, "%s", filename); + while (fgets(line, sizeof(line), file) != NULL) { + lineno++; + p = line; + pq = strchr(line, '\''); + pdq = strchr(line, '\"'); + /* Replace the first # with \0. */ + while((p = strchr(p, '#')) != NULL) { + if (pq != NULL && p > pq) { + if ((p = strchr(pq+1, '\'')) != NULL) + *(++p) = '\0'; + break; + } else if (pdq != NULL && p > pdq) { + if ((p = strchr(pdq+1, '\"')) != NULL) + *(++p) = '\0'; + break; + } else if (p == line || *(p-1) != '\\') { + *p = '\0'; + break; + } + p++; + } + /* Trim spaces */ + p = line + strlen(line) - 1; + while (p >= line && isspace((int)*p)) { + *p = '\0'; + p--; + } + p = line; + while (isspace((int)*p)) + p++; + if (*p == '\0') + continue; + else + warncount += parse(p, lineno); + } + fclose(file); + + return (warncount); } /* These functions will dump out various interesting structures. */ -- cgit v1.1 From 389f3e3c15c55ab2fcda8488f853b194a3018c5d Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 14 Dec 2012 15:01:23 +0000 Subject: Whitespace cleanups. --- sbin/savecore/savecore.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index b3f2902..bbde36c 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -194,7 +194,7 @@ check_space(const char *savedir, off_t dumpsize) syslog(LOG_ERR, "%s: %m", savedir); exit(1); } - spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024; + spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024; totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024; (void)snprintf(path, sizeof(path), "%s/minfree", savedir); @@ -209,7 +209,7 @@ check_space(const char *savedir, off_t dumpsize) } needed = dumpsize / 1024 + 2; /* 2 for info file */ - if (((minfree > 0) ? spacefree : totfree) - needed < minfree) { + if (((minfree > 0) ? spacefree : totfree) - needed < minfree) { syslog(LOG_WARNING, "no dump, not enough free space on device (%lld available, need %lld)", (long long)(minfree > 0 ? spacefree : totfree), @@ -262,7 +262,7 @@ DoRegularFile(int fd, off_t dumpsize, char *buf, const char *device, if (he >= hs + BLOCKSIZE) break; } - + /* back down to a block boundary */ he &= BLOCKMASK; @@ -433,7 +433,7 @@ DoFile(const char *savedir, const char *device) syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); - + status = STATUS_BAD; if (force == 0) goto closefd; @@ -444,7 +444,7 @@ DoFile(const char *savedir, const char *device) syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); - + status = STATUS_BAD; if (force == 0) goto closefd; @@ -472,7 +472,7 @@ DoFile(const char *savedir, const char *device) syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); - + status = STATUS_BAD; if (force == 0) goto closefd; -- cgit v1.1 From a555e4822220799d8567f55fdb4d62de343e5d4e Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 14 Dec 2012 15:03:12 +0000 Subject: If we are not going to clear the dump (we are either just checking if the dump exists or we want to keep it), open device read-only. Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index bbde36c..2b9b6d8 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -394,7 +394,7 @@ DoFile(const char *savedir, const char *device) if (verbose) printf("checking for kernel dump on device %s\n", device); - fd = open(device, O_RDWR); + fd = open(device, (checkfor || keep) ? O_RDONLY : O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", device); return; @@ -612,7 +612,7 @@ DoFile(const char *savedir, const char *device) printf("dump saved\n"); nuke: - if (clear || !keep) { + if (!keep) { if (verbose) printf("clearing dump header\n"); memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic); -- cgit v1.1 From ab75315eecbefcf8a215a0a13500f0923fc962f9 Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 14 Dec 2012 15:04:39 +0000 Subject: The clear option (-c) is not compatible with keep (-k) and compress (-z) options. Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 2b9b6d8..c11c15e 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -681,6 +681,8 @@ main(int argc, char **argv) } if (checkfor && (clear || force || keep)) usage(); + if (clear && (compress || keep)) + usage(); argc -= optind; argv += optind; if (argc >= 1) { -- cgit v1.1 From 1d3ec906ca23ea5f5ff60e8ebe9b3bcc4f9033d2 Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 14 Dec 2012 15:12:08 +0000 Subject: - When checking if a dump exists on the given device there is no need to provide dump directory. Eliminate this redundant argument. This changes the usage, but the only risk here is that a warning will be printed about directory given as device. - Update usage of -C option. - When clearing dump header from the given device there is also no need to provide dump directory, although additional arguments for -c were not documented. - Document that -v can be used with -c and that list of devices can be given. Obtained from: WHEEL Systems --- sbin/savecore/savecore.8 | 6 ++++-- sbin/savecore/savecore.c | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.8 b/sbin/savecore/savecore.8 index 01be723..3e22f5a 100644 --- a/sbin/savecore/savecore.8 +++ b/sbin/savecore/savecore.8 @@ -28,7 +28,7 @@ .\" From: @(#)savecore.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd December 24, 2008 +.Dd December 14, 2012 .Dt SAVECORE 8 .Os .Sh NAME @@ -37,10 +37,12 @@ .Sh SYNOPSIS .Nm .Fl c +.Op Fl v +.Op Ar device ... .Nm .Fl C .Op Fl v -.Op Ar directory device +.Op Ar device ... .Nm .Op Fl fkvz .Op Ar directory Op Ar device ... diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index c11c15e..a1fe848 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -636,8 +636,8 @@ static void usage(void) { fprintf(stderr, "%s\n%s\n%s\n", - "usage: savecore -c", - " savecore -C [-v] [directory device]", + "usage: savecore -c [-v] [device ...]", + " savecore -C [-v] [device ...]", " savecore [-fkvz] [directory [device ...]]"); exit (1); } @@ -685,7 +685,7 @@ main(int argc, char **argv) usage(); argc -= optind; argv += optind; - if (argc >= 1) { + if (argc >= 1 && !checkfor && !clear) { error = chdir(argv[0]); if (error) { syslog(LOG_ERR, "chdir(%s): %m", argv[0]); -- cgit v1.1 From e2e5e9346150e2c5387945fa0637bbd1b60ab046 Mon Sep 17 00:00:00 2001 From: trasz Date: Sat, 15 Dec 2012 08:53:58 +0000 Subject: Fix extending filesystems of weird size by making sure the actual size is always multiple of fragment size. --- sbin/growfs/growfs.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sbin') diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 042aada..c93d111 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -1487,6 +1487,12 @@ main(int argc, char **argv) } } + /* + * Make sure the new size is a multiple of fs_fsize; /dev/ufssuspend + * only supports fragment-aligned IO requests. + */ + size -= size % osblock.fs_fsize; + if (size <= (uint64_t)(osblock.fs_size * osblock.fs_fsize)) { humanize_number(oldsizebuf, sizeof(oldsizebuf), osblock.fs_size * osblock.fs_fsize, -- cgit v1.1 From 1fdcf9e7be7549ebb4e865fadc73f5f6c4daf661 Mon Sep 17 00:00:00 2001 From: trasz Date: Sun, 16 Dec 2012 14:37:25 +0000 Subject: When growing a filesystem, don't leave unused space at the end if there is not enough room for a full cylinder group. Reviewed by: mckusick@ --- sbin/growfs/growfs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'sbin') diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index c93d111..745e9e9 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -1611,17 +1611,20 @@ main(int argc, char **argv) } sblock.fs_ncg = howmany(sblock.fs_size, sblock.fs_fpg); + /* + * Allocate last cylinder group only if there is enough room + * for at least one data block. + */ if (sblock.fs_size % sblock.fs_fpg != 0 && - sblock.fs_size % sblock.fs_fpg < cgdmin(&sblock, sblock.fs_ncg)) { - /* - * The space in the new last cylinder group is too small, - * so revert back. - */ + sblock.fs_size <= cgdmin(&sblock, sblock.fs_ncg - 1)) { + humanize_number(oldsizebuf, sizeof(oldsizebuf), + (sblock.fs_size % sblock.fs_fpg) * sblock.fs_fsize, + "B", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); + warnx("no room to allocate last cylinder group; " + "leaving %s unused", oldsizebuf); sblock.fs_ncg--; if (sblock.fs_magic == FS_UFS1_MAGIC) sblock.fs_old_ncyl = sblock.fs_ncg * sblock.fs_old_cpg; - printf("Warning: %jd sector(s) cannot be allocated.\n", - (intmax_t)fsbtodb(&sblock, sblock.fs_size % sblock.fs_fpg)); sblock.fs_size = sblock.fs_ncg * sblock.fs_fpg; } -- cgit v1.1 From e18befc88a006695eec98af0b3091ca54c2c7ab8 Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 16 Dec 2012 22:59:25 +0000 Subject: Prefer snprintf() over sprintf(). Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index a1fe848..26eae53 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -543,7 +543,7 @@ DoFile(const char *savedir, const char *device) writebounds(bounds + 1); - sprintf(buf, "info.%d", bounds); + snprintf(buf, sizeof(buf), "info.%d", bounds); /* * Create or overwrite any existing dump header files. @@ -556,12 +556,12 @@ DoFile(const char *savedir, const char *device) } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { - sprintf(filename, "%s.%d.gz", istextdump ? "textdump.tar" : - "vmcore", bounds); + snprintf(filename, sizeof(filename), "%s.%d.gz", + istextdump ? "textdump.tar" : "vmcore", bounds); fp = zopen(filename, "w"); } else { - sprintf(filename, "%s.%d", istextdump ? "textdump.tar" : - "vmcore", bounds); + snprintf(filename, sizeof(filename), "%s.%d", + istextdump ? "textdump.tar" : "vmcore", bounds); fp = fopen(filename, "w"); } if (fp == NULL) { -- cgit v1.1 From 1df9cc8b3f57738840eed7cdc84638812fbddc72 Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 16 Dec 2012 22:59:58 +0000 Subject: Sort flags properly. Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 26eae53..747377c 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -663,15 +663,15 @@ main(int argc, char **argv) case 'c': clear = 1; break; + case 'f': + force = 1; + break; case 'k': keep = 1; break; case 'v': verbose++; break; - case 'f': - force = 1; - break; case 'z': compress = 1; break; -- cgit v1.1 From ba44c5a926d6af2f2a4731e3bd7e59bd12dfd7f7 Mon Sep 17 00:00:00 2001 From: eadler Date: Sun, 16 Dec 2012 23:00:13 +0000 Subject: Minor wording improvments to some manual pages Approved by: bcr (mentor) Obtained from: DragonflyBSD (a5294ca835317c68c919ab43936da4f05ab6e926) MFC after: 3 days --- sbin/setkey/setkey.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/setkey/setkey.8 b/sbin/setkey/setkey.8 index 8f7bae13..19a9164 100644 --- a/sbin/setkey/setkey.8 +++ b/sbin/setkey/setkey.8 @@ -110,7 +110,7 @@ Loop forever and dump all the messages transmitted to .Dv PF_KEY socket. .Fl xx -makes each timestamps unformatted. +makes each timestamp unformatted. .El .Ss Configuration syntax With -- cgit v1.1 From f3f8bbc49800ecc3f3414633a1a66235d04e949d Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 16 Dec 2012 23:04:31 +0000 Subject: Make use of the fact that we changed working directory to the dump directory earlier. Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 747377c..3a2547a 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -188,17 +188,16 @@ check_space(const char *savedir, off_t dumpsize) FILE *fp; off_t minfree, spacefree, totfree, needed; struct statfs fsbuf; - char buf[100], path[MAXPATHLEN]; + char buf[100]; - if (statfs(savedir, &fsbuf) < 0) { + if (statfs(".", &fsbuf) < 0) { syslog(LOG_ERR, "%s: %m", savedir); exit(1); } spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024; totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024; - (void)snprintf(path, sizeof(path), "%s/minfree", savedir); - if ((fp = fopen(path, "r")) == NULL) + if ((fp = fopen("minfree", "r")) == NULL) minfree = 0; else { if (fgets(buf, sizeof(buf), fp) == NULL) -- cgit v1.1 From c5cbd42d14b9d344c2cfe474407c43ddfbc75995 Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 16 Dec 2012 23:06:12 +0000 Subject: Implement -m option to savecore(8) that allows to limit number of kernel dumps stored. Once the limit is reached it restarts from 0. Reviewed by: avg Obtained from: WHEEL Systems --- sbin/savecore/savecore.8 | 11 ++++- sbin/savecore/savecore.c | 106 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 96 insertions(+), 21 deletions(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.8 b/sbin/savecore/savecore.8 index 3e22f5a..c7d7e95 100644 --- a/sbin/savecore/savecore.8 +++ b/sbin/savecore/savecore.8 @@ -28,7 +28,7 @@ .\" From: @(#)savecore.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD$ .\" -.Dd December 14, 2012 +.Dd December 17, 2012 .Dt SAVECORE 8 .Os .Sh NAME @@ -45,6 +45,7 @@ .Op Ar device ... .Nm .Op Fl fkvz +.Op Fl m Ar maxdumps .Op Ar directory Op Ar device ... .Sh DESCRIPTION The @@ -59,7 +60,7 @@ and enters a reboot message and information about the core dump into the system log. .Pp The options are as follows: -.Bl -tag -width indent +.Bl -tag -width ".Fl m Ar maxdumps" .It Fl C Check to see if a dump exists, and display a brief message to indicate the status. @@ -77,6 +78,12 @@ Force a dump to be taken even if either the dump was cleared or if the dump header information is inconsistent. .It Fl k Do not clear the dump after saving it. +.It Fl m Ar maxdumps +Maximum number of dumps to store. +Once the number of stored dumps is equal to +.Ar maxdumps +the counter will restart from +.Dv 0 . .It Fl v Print out some additional debugging information. Specify twice for more information. diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 3a2547a..ca1cf13 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$"); static int checkfor, compress, clear, force, keep, verbose; /* flags */ static int nfound, nsaved, nerr; /* statistics */ +static int maxdumps; extern FILE *zopen(const char *, const char *); @@ -178,12 +179,62 @@ writebounds(int bounds) { fclose(fp); } +static off_t +file_size(const char *path) +{ + struct stat sb; + + /* Ignore all errors, those file may not exists. */ + if (stat(path, &sb) == -1) + return (0); + return (sb.st_size); +} + +static off_t +saved_dump_size(int bounds) +{ + static char path[PATH_MAX]; + off_t dumpsize; + + dumpsize = 0; + + (void)snprintf(path, sizeof(path), "info.%d", bounds); + dumpsize += file_size(path); + (void)snprintf(path, sizeof(path), "vmcore.%d", bounds); + dumpsize += file_size(path); + (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds); + dumpsize += file_size(path); + (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds); + dumpsize += file_size(path); + (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds); + dumpsize += file_size(path); + + return (dumpsize); +} + +static void +saved_dump_remove(int bounds) +{ + static char path[PATH_MAX]; + + (void)snprintf(path, sizeof(path), "info.%d", bounds); + (void)unlink(path); + (void)snprintf(path, sizeof(path), "vmcore.%d", bounds); + (void)unlink(path); + (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds); + (void)unlink(path); + (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds); + (void)unlink(path); + (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds); + (void)unlink(path); +} + /* * Check that sufficient space is available on the disk that holds the * save directory. */ static int -check_space(const char *savedir, off_t dumpsize) +check_space(const char *savedir, off_t dumpsize, int bounds) { FILE *fp; off_t minfree, spacefree, totfree, needed; @@ -208,7 +259,8 @@ check_space(const char *savedir, off_t dumpsize) } needed = dumpsize / 1024 + 2; /* 2 for info file */ - if (((minfree > 0) ? spacefree : totfree) - needed < minfree) { + needed -= saved_dump_size(bounds); + if ((minfree > 0 ? spacefree : totfree) - needed < minfree) { syslog(LOG_WARNING, "no dump, not enough free space on device (%lld available, need %lld)", (long long)(minfree > 0 ? spacefree : totfree), @@ -367,7 +419,7 @@ DoTextdumpFile(int fd, off_t dumpsize, off_t lasthd, char *buf, static void DoFile(const char *savedir, const char *device) { - static char filename[PATH_MAX]; + static char infoname[PATH_MAX], corename[PATH_MAX]; static char *buf = NULL; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd; @@ -382,6 +434,9 @@ DoFile(const char *savedir, const char *device) mediasize = 0; status = STATUS_UNKNOWN; + if (maxdumps > 0 && bounds == maxdumps) + bounds = 0; + if (buf == NULL) { buf = malloc(BUFFERSIZE); if (buf == NULL) { @@ -535,19 +590,22 @@ DoFile(const char *savedir, const char *device) if (verbose) printf("Checking for available free space\n"); - if (!check_space(savedir, dumpsize)) { + + if (!check_space(savedir, dumpsize, bounds)) { nerr++; goto closefd; } writebounds(bounds + 1); - snprintf(buf, sizeof(buf), "info.%d", bounds); + saved_dump_remove(bounds); + + snprintf(infoname, sizeof(infoname), "info.%d", bounds); /* * Create or overwrite any existing dump header files. */ - fdinfo = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600); + fdinfo = open(infoname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fdinfo < 0) { syslog(LOG_ERR, "%s: %m", buf); nerr++; @@ -555,16 +613,16 @@ DoFile(const char *savedir, const char *device) } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { - snprintf(filename, sizeof(filename), "%s.%d.gz", + snprintf(corename, sizeof(corename), "%s.%d.gz", istextdump ? "textdump.tar" : "vmcore", bounds); - fp = zopen(filename, "w"); + fp = zopen(corename, "w"); } else { - snprintf(filename, sizeof(filename), "%s.%d", + snprintf(corename, sizeof(corename), "%s.%d", istextdump ? "textdump.tar" : "vmcore", bounds); - fp = fopen(filename, "w"); + fp = fopen(corename, "w"); } if (fp == NULL) { - syslog(LOG_ERR, "%s: %m", filename); + syslog(LOG_ERR, "%s: %m", corename); close(fdinfo); nerr++; goto closefd; @@ -585,15 +643,15 @@ DoFile(const char *savedir, const char *device) printheader(info, &kdhl, device, bounds, status); fclose(info); - syslog(LOG_NOTICE, "writing %score to %s", - compress ? "compressed " : "", filename); + syslog(LOG_NOTICE, "writing %score to %s/%s", + compress ? "compressed " : "", savedir, corename); if (istextdump) { if (DoTextdumpFile(fd, dumpsize, lasthd, buf, device, - filename, fp) < 0) + corename, fp) < 0) goto closeall; } else { - if (DoRegularFile(fd, dumpsize, buf, device, filename, fp) + if (DoRegularFile(fd, dumpsize, buf, device, corename, fp) < 0) goto closeall; } @@ -601,10 +659,11 @@ DoFile(const char *savedir, const char *device) printf("\n"); if (fclose(fp) < 0) { - syslog(LOG_ERR, "error on %s: %m", filename); + syslog(LOG_ERR, "error on %s: %m", corename); nerr++; goto closeall; } + nsaved++; if (verbose) @@ -637,8 +696,8 @@ usage(void) fprintf(stderr, "%s\n%s\n%s\n", "usage: savecore -c [-v] [device ...]", " savecore -C [-v] [device ...]", - " savecore [-fkvz] [directory [device ...]]"); - exit (1); + " savecore [-fkvz] [-m maxdumps] [directory [device ...]]"); + exit(1); } int @@ -654,7 +713,7 @@ main(int argc, char **argv) openlog("savecore", LOG_PERROR, LOG_DAEMON); signal(SIGINFO, infohandler); - while ((ch = getopt(argc, argv, "Ccfkvz")) != -1) + while ((ch = getopt(argc, argv, "Ccfkm:vz")) != -1) switch(ch) { case 'C': checkfor = 1; @@ -668,6 +727,13 @@ main(int argc, char **argv) case 'k': keep = 1; break; + case 'm': + maxdumps = atoi(optarg); + if (maxdumps <= 0) { + syslog(LOG_ERR, "Invalid maxdump value"); + exit(1); + } + break; case 'v': verbose++; break; @@ -682,6 +748,8 @@ main(int argc, char **argv) usage(); if (clear && (compress || keep)) usage(); + if (maxdumps > 0 && (checkfor || clear)) + usage(); argc -= optind; argv += optind; if (argc >= 1 && !checkfor && !clear) { -- cgit v1.1 From 81a7aa503ccef5a267f9644672eb54b5256125de Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 16 Dec 2012 23:09:27 +0000 Subject: With rotating kernel dumps the higest dump number is not necessarily the last one. To make it easier to find the last one create symlinks with 'last' suffix that will point to the files of the last coredump, eg.: info.last -> info.5 textdump.tar.last.gz -> textdump.tar.5.gz Reviewed by: avg Obtained from: WHEEL Systems --- sbin/savecore/savecore.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index ca1cf13..bdbf7e3 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -229,6 +229,17 @@ saved_dump_remove(int bounds) (void)unlink(path); } +static void +symlinks_remove(void) +{ + + (void)unlink("info.last"); + (void)unlink("vmcore.last"); + (void)unlink("vmcore.last.gz"); + (void)unlink("textdump.tar.last"); + (void)unlink("textdump.tar.last.gz"); +} + /* * Check that sufficient space is available on the disk that holds the * save directory. @@ -419,7 +430,7 @@ DoTextdumpFile(int fd, off_t dumpsize, off_t lasthd, char *buf, static void DoFile(const char *savedir, const char *device) { - static char infoname[PATH_MAX], corename[PATH_MAX]; + static char infoname[PATH_MAX], corename[PATH_MAX], linkname[PATH_MAX]; static char *buf = NULL; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd; @@ -664,6 +675,23 @@ DoFile(const char *savedir, const char *device) goto closeall; } + symlinks_remove(); + if (symlink(infoname, "info.last") == -1) { + syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", + savedir, "info.last"); + } + if (compress) { + snprintf(linkname, sizeof(linkname), "%s.last.gz", + istextdump ? "textdump.tar" : "vmcore"); + } else { + snprintf(linkname, sizeof(linkname), "%s.last", + istextdump ? "textdump.tar" : "vmcore"); + } + if (symlink(corename, linkname) == -1) { + syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", + savedir, linkname); + } + nsaved++; if (verbose) -- cgit v1.1 From 2a6db409ab7daeaadc29117638217ffd0b02c64f Mon Sep 17 00:00:00 2001 From: hrs Date: Sun, 16 Dec 2012 23:46:59 +0000 Subject: - Fix strtol() error handling. - Add a range condition of given FIB number and the related error messages. - Fix free() problem. Spotted by: Artyom Mirgorodskiy Discussed with: glebius --- sbin/route/route.c | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index be85184..847f3ee 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -260,19 +260,25 @@ static int fiboptlist_range(const char *arg, struct fibl_head_t *flh) { struct fibl *fl; - char *str, *token, *endptr; + char *str0, *str, *token, *endptr; int fib[2], i, error; - str = strdup(arg); + str0 = str = strdup(arg); error = 0; i = 0; while ((token = strsep(&str, "-")) != NULL) { switch (i) { case 0: case 1: + errno = 0; fib[i] = strtol(token, &endptr, 0); - if (*endptr != '\0' || (fib[i] == 0 && - (errno == EINVAL || errno == ERANGE))) + if (errno == 0) { + if (*endptr != '\0' || + fib[i] < 0 || + (numfibs != -1 && fib[i] > numfibs - 1)) + errno = EINVAL; + } + if (errno) error = 1; break; default: @@ -296,7 +302,7 @@ fiboptlist_range(const char *arg, struct fibl_head_t *flh) TAILQ_INSERT_TAIL(flh, fl, fl_next); } fiboptlist_range_ret: - free(str); + free(str0); return (error); } @@ -305,7 +311,7 @@ static int fiboptlist_csv(const char *arg, struct fibl_head_t *flh) { struct fibl *fl; - char *str, *token, *endptr; + char *str0, *str, *token, *endptr; int fib, error; if (strcmp("all", arg) == 0) { @@ -319,14 +325,14 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) else snprintf(str, ALLSTRLEN - 1, "%d", 0); } else if (strcmp("default", arg) == 0) { - str = calloc(1, ALLSTRLEN); + str0 = str = calloc(1, ALLSTRLEN); if (str == NULL) { error = 1; goto fiboptlist_csv_ret; } snprintf(str, ALLSTRLEN - 1, "%d", defaultfib); } else - str = strdup(arg); + str0 = str = strdup(arg); error = 0; while ((token = strsep(&str, ",")) != NULL) { @@ -335,9 +341,15 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) if (error) goto fiboptlist_csv_ret; } else { + errno = 0; fib = strtol(token, &endptr, 0); - if (*endptr != '\0' || (fib == 0 && - (errno == EINVAL || errno == ERANGE))) { + if (errno == 0) { + if (*endptr != '\0' || + fib < 0 || + (numfibs != -1 && fib > numfibs - 1)) + errno = EINVAL; + } + if (errno) { error = 1; goto fiboptlist_csv_ret; } @@ -351,7 +363,7 @@ fiboptlist_csv(const char *arg, struct fibl_head_t *flh) } } fiboptlist_csv_ret: - free(str); + free(str0); return (error); } @@ -396,7 +408,7 @@ flushroutes(int argc, char *argv[]) usage(*argv); error = fiboptlist_csv(*++argv, &fibl_head); if (error) - usage(*argv); + errx(EX_USAGE, "invalid fib number: %s", *argv); break; default: usage(*argv); @@ -815,7 +827,8 @@ newroute(int argc, char **argv) usage(NULL); error = fiboptlist_csv(*++argv, &fibl_head); if (error) - usage(NULL); + errx(EX_USAGE, + "invalid fib number: %s", *argv); break; case K_IFA: if (!--argc) @@ -1383,10 +1396,16 @@ monitor(int argc, char *argv[]) case K_FIB: if (!--argc) usage(*argv); + errno = 0; fib = strtol(*++argv, &endptr, 0); - if (*endptr != '\0' || (fib == 0 && - (errno == EINVAL || errno == ERANGE))) - usage(*argv); + if (errno == 0) { + if (*endptr != '\0' || + fib < 0 || + (numfibs != -1 && fib > numfibs - 1)) + errno = EINVAL; + } + if (errno) + errx(EX_USAGE, "invalid fib number: %s", *argv); break; default: usage(*argv); -- cgit v1.1 From 804c67a4867afb8b7ef41a3ade748cab870b788c Mon Sep 17 00:00:00 2001 From: kevlo Date: Fri, 21 Dec 2012 15:54:13 +0000 Subject: Fix socket calls on error post-r243965. Submitted by: Garrett Cooper --- sbin/hastd/parse.y | 2 +- sbin/ifconfig/af_nd6.c | 2 +- sbin/ifconfig/ifconfig.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/hastd/parse.y b/sbin/hastd/parse.y index a20b61a..04ea7ab 100644 --- a/sbin/hastd/parse.y +++ b/sbin/hastd/parse.y @@ -769,7 +769,7 @@ family_supported(int family) int sock; sock = socket(family, SOCK_STREAM, 0); - if (sock == -1 && errno == EPROTONOSUPPORT) + if (sock == -1 && errno == EAFNOSUPPORT) return (false); if (sock >= 0) (void)close(sock); diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c index 654e2d9..80065f6 100644 --- a/sbin/ifconfig/af_nd6.c +++ b/sbin/ifconfig/af_nd6.c @@ -148,7 +148,7 @@ nd6_status(int s) memset(&nd, 0, sizeof(nd)); strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - if (errno != EPROTONOSUPPORT) + if (errno != EAFNOSUPPORT) warn("socket(AF_INET6, SOCK_DGRAM)"); return; } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 870acdd..983e21f 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -520,7 +520,7 @@ top: AF_LOCAL : afp->af_af; if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 && - (uafp != NULL || errno != EPROTONOSUPPORT || + (uafp != NULL || errno != EAFNOSUPPORT || (s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)) err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family); -- cgit v1.1 From 9e057f2c8223e05eabf1e5d37daa73d44ceb3c2d Mon Sep 17 00:00:00 2001 From: antoine Date: Tue, 1 Jan 2013 18:28:21 +0000 Subject: pflogd does not depend on libutil --- sbin/pflogd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/pflogd/Makefile b/sbin/pflogd/Makefile index ea37bd1..fcff8eb 100644 --- a/sbin/pflogd/Makefile +++ b/sbin/pflogd/Makefile @@ -9,7 +9,7 @@ MAN= pflogd.8 CFLAGS+=-include ${.CURDIR}/../../lib/libpcap/config.h LDADD= -lpcap -DPADD= ${LIBPCAP} ${LIBUTIL} +DPADD= ${LIBPCAP} WARNS?= 2 -- cgit v1.1 From a4c48922fc14fe124badb04c460263ca2db1c5c5 Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 3 Jan 2013 19:18:46 +0000 Subject: Allow to specify "cache" and "nocache" as an option for mount_nullfs(8). Tested by: pho MFC after: 2 weeks --- sbin/mount_nullfs/mount_nullfs.c | 49 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'sbin') diff --git a/sbin/mount_nullfs/mount_nullfs.c b/sbin/mount_nullfs/mount_nullfs.c index c88db3d..aaf66e5 100644 --- a/sbin/mount_nullfs/mount_nullfs.c +++ b/sbin/mount_nullfs/mount_nullfs.c @@ -57,27 +57,35 @@ static const char rcsid[] = #include "mntopts.h" -static struct mntopt mopts[] = { - MOPT_STDOPTS, - MOPT_END -}; - int subdir(const char *, const char *); static void usage(void) __dead2; int main(int argc, char *argv[]) { - struct iovec iov[6]; - int ch, mntflags; + struct iovec *iov; + char *p, *val; char source[MAXPATHLEN]; char target[MAXPATHLEN]; + char errmsg[255]; + int ch, mntflags, iovlen; + char nullfs[] = "nullfs"; + iov = NULL; + iovlen = 0; mntflags = 0; + errmsg[0] = '\0'; while ((ch = getopt(argc, argv, "o:")) != -1) switch(ch) { case 'o': - getmntopts(optarg, mopts, &mntflags, 0); + val = strdup(""); + p = strchr(optarg, '='); + if (p != NULL) { + free(val); + *p = '\0'; + val = p + 1; + } + build_iovec(&iov, &iovlen, optarg, val, (size_t)-1); break; case '?': default: @@ -99,21 +107,16 @@ main(int argc, char *argv[]) errx(EX_USAGE, "%s (%s) and %s are not distinct paths", argv[0], target, argv[1]); - iov[0].iov_base = strdup("fstype"); - iov[0].iov_len = sizeof("fstype"); - iov[1].iov_base = strdup("nullfs"); - iov[1].iov_len = strlen(iov[1].iov_base) + 1; - iov[2].iov_base = strdup("fspath"); - iov[2].iov_len = sizeof("fspath"); - iov[3].iov_base = source; - iov[3].iov_len = strlen(source) + 1; - iov[4].iov_base = strdup("target"); - iov[4].iov_len = sizeof("target"); - iov[5].iov_base = target; - iov[5].iov_len = strlen(target) + 1; - - if (nmount(iov, 6, mntflags)) - err(1, NULL); + build_iovec(&iov, &iovlen, "fstype", nullfs, (size_t)-1); + build_iovec(&iov, &iovlen, "fspath", source, (size_t)-1); + build_iovec(&iov, &iovlen, "target", target, (size_t)-1); + build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); + if (nmount(iov, iovlen, mntflags) < 0) { + if (errmsg[0] != 0) + err(1, "%s: %s", source, errmsg); + else + err(1, "%s", source); + } exit(0); } -- cgit v1.1 From 4f4f5f3fa0d54f0fdcae6392d8b27b25bff48ebe Mon Sep 17 00:00:00 2001 From: wblock Date: Thu, 3 Jan 2013 21:58:28 +0000 Subject: Document the output of the show command. Modified version of patch provided by Bas Smeelen . Use of 'gpart list' suggested by by Andrey V. Elsukov . PR: docs/174270 Submitted by: Ronald F.Guilmette Reviewed by: ae (block sizes) MFC after: 1 week --- sbin/geom/class/part/gpart.8 | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/part/gpart.8 b/sbin/geom/class/part/gpart.8 index 7a91d3d..61f8275 100644 --- a/sbin/geom/class/part/gpart.8 +++ b/sbin/geom/class/part/gpart.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 19, 2012 +.Dd January 3, 2013 .Dt GPART 8 .Os .Sh NAME @@ -453,8 +453,14 @@ about its use. .El .\" ==== SHOW ==== .It Cm show -Show the current partition information of the specified geoms -or all geoms if none are specified. +Show current partition information for the specified geoms, or all +geoms if none are specified. +The default output includes the logical starting block of each +partition, the partition size in blocks, the partition index number, +the partition type, and a human readable partition size. +Block sizes and locations are based on the device's Sectorsize +as shown by +.Cm gpart list . Additional options include: .Bl -tag -width 10n .It Fl l @@ -919,7 +925,7 @@ and .Cm list will report about corrupt tables. .Pp -If the size of the device has changed (e.g.\& volume expansion) the +If the size of the device has changed (e.g.,\& volume expansion) the secondary GPT header will no longer be located in the last sector. This is not a metadata corruption, but it is dangerous because any corruption of the primary GPT will lead to loss of the partition table. @@ -979,14 +985,14 @@ This may break a mirrored volume and lead to data damage. Exit status is 0 on success, and 1 if the command fails. .Sh EXAMPLES Create a GPT scheme on -.Pa ad0 : +.Pa ada0 : .Bd -literal -offset indent -/sbin/gpart create -s GPT ad0 +/sbin/gpart create -s GPT ada0 .Ed .Pp Embed GPT bootstrap code into a protective MBR: .Bd -literal -offset indent -/sbin/gpart bootcode -b /boot/pmbr ad0 +/sbin/gpart bootcode -b /boot/pmbr ada0 .Ed .Pp Create a dedicated @@ -1011,15 +1017,15 @@ aligned on a 64 kB boundary without the need to specify an explicit offset or alignment. The boot partition itself is aligned on a 4 kB boundary. .Bd -literal -offset indent -/sbin/gpart add -b 40 -s 88 -t freebsd-boot ad0 -/sbin/gpart bootcode -p /boot/gptboot -i 1 ad0 +/sbin/gpart add -b 40 -s 88 -t freebsd-boot ada0 +/sbin/gpart bootcode -p /boot/gptboot -i 1 ada0 .Ed .Pp Create a 512MB-sized .Cm freebsd-ufs partition to contain a UFS filesystem from which the system can boot. .Bd -literal -offset indent -/sbin/gpart add -s 512M -t freebsd-ufs ad0 +/sbin/gpart add -s 512M -t freebsd-ufs ada0 .Ed .Pp Create an MBR scheme on -- cgit v1.1 From a460c4d98bfbcfe6a8806ca36b0c1561326d108f Mon Sep 17 00:00:00 2001 From: kib Date: Sat, 5 Jan 2013 21:42:14 +0000 Subject: Do not round up the size of the UFS filesystem to the fragment size when comparing its size with the size of the media, to determine if the last disk block is unused. Submitted by: Andreas Longwitz Reviewed by: pjd MFC after: 2 weeks --- sbin/geom/class/journal/geom_journal_ufs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/journal/geom_journal_ufs.c b/sbin/geom/class/journal/geom_journal_ufs.c index c847a88..0497beb 100644 --- a/sbin/geom/class/journal/geom_journal_ufs.c +++ b/sbin/geom/class/journal/geom_journal_ufs.c @@ -70,9 +70,9 @@ g_journal_ufs_using_last_sector(const char *prov) fs = read_superblock(prov); if (fs == NULL) return (0); - /* Provider size in 512 bytes blocks. */ - psize = g_get_mediasize(prov) / DEV_BSIZE; - /* File system size in 512 bytes blocks. */ - fssize = fsbtodb(fs, dbtofsb(fs, psize)); - return (psize == fssize); + /* Provider size in 512 bytes blocks. */ + psize = g_get_mediasize(prov) / DEV_BSIZE; + /* File system size in 512 bytes blocks. */ + fssize = fsbtodb(fs, fs->fs_size); + return (psize <= fssize); } -- cgit v1.1 From aa8d1947b9017e09520e38f520fe26e4d03c80d6 Mon Sep 17 00:00:00 2001 From: kib Date: Sat, 5 Jan 2013 21:52:38 +0000 Subject: Use tabs for indentation. MFC after: 2 weeks --- sbin/geom/class/journal/geom_journal_ufs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/journal/geom_journal_ufs.c b/sbin/geom/class/journal/geom_journal_ufs.c index 0497beb..07d1922 100644 --- a/sbin/geom/class/journal/geom_journal_ufs.c +++ b/sbin/geom/class/journal/geom_journal_ufs.c @@ -70,9 +70,9 @@ g_journal_ufs_using_last_sector(const char *prov) fs = read_superblock(prov); if (fs == NULL) return (0); - /* Provider size in 512 bytes blocks. */ - psize = g_get_mediasize(prov) / DEV_BSIZE; - /* File system size in 512 bytes blocks. */ - fssize = fsbtodb(fs, fs->fs_size); - return (psize <= fssize); + /* Provider size in 512 bytes blocks. */ + psize = g_get_mediasize(prov) / DEV_BSIZE; + /* File system size in 512 bytes blocks. */ + fssize = fsbtodb(fs, fs->fs_size); + return (psize <= fssize); } -- cgit v1.1 From 9b2193d68972f5c42e08f1f03b60ee546de59f89 Mon Sep 17 00:00:00 2001 From: hrs Date: Tue, 8 Jan 2013 17:24:43 +0000 Subject: Fix -iface and -interface modifiers. Spotted by: Ian FREISLICH --- sbin/route/route.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 847f3ee..4637ba4 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -94,7 +94,7 @@ typedef union sockunion *sup; int pid, rtm_addrs; int s; int forcehost, forcenet, doflush, nflag, af, qflag, tflag; -int iflag, verbose, aflen = sizeof (struct sockaddr_in); +int verbose, aflen = sizeof (struct sockaddr_in); int locking, lockrest, debugonly; struct rt_metrics rt_metrics; u_long rtm_inits; @@ -107,7 +107,7 @@ static char *atalk_ntoa(struct at_addr); static void bprintf(FILE *, int, u_char *); static void flushroutes(int argc, char *argv[]); static int flushroutes_fib(int); -static int getaddr(int, char *, struct hostent **); +static int getaddr(int, char *, struct hostent **, int); static int keyword(const char *); static void inet_makenetandmask(u_long, struct sockaddr_in *, u_long); #ifdef INET6 @@ -833,34 +833,34 @@ newroute(int argc, char **argv) case K_IFA: if (!--argc) usage(NULL); - (void) getaddr(RTA_IFA, *++argv, 0); + getaddr(RTA_IFA, *++argv, 0, nrflags); break; case K_IFP: if (!--argc) usage(NULL); - (void) getaddr(RTA_IFP, *++argv, 0); + getaddr(RTA_IFP, *++argv, 0, nrflags); break; case K_GENMASK: if (!--argc) usage(NULL); - (void) getaddr(RTA_GENMASK, *++argv, 0); + getaddr(RTA_GENMASK, *++argv, 0, nrflags); break; case K_GATEWAY: if (!--argc) usage(NULL); - (void) getaddr(RTA_GATEWAY, *++argv, 0); + getaddr(RTA_GATEWAY, *++argv, 0, nrflags); break; case K_DST: if (!--argc) usage(NULL); - if (getaddr(RTA_DST, *++argv, &hp)) + if (getaddr(RTA_DST, *++argv, &hp, nrflags)) nrflags |= F_ISHOST; dest = *argv; break; case K_NETMASK: if (!--argc) usage(NULL); - (void) getaddr(RTA_NETMASK, *++argv, 0); + getaddr(RTA_NETMASK, *++argv, 0, nrflags); /* FALLTHROUGH */ case K_NET: nrflags |= F_FORCENET; @@ -895,13 +895,13 @@ newroute(int argc, char **argv) } else { if ((rtm_addrs & RTA_DST) == 0) { dest = *argv; - if (getaddr(RTA_DST, *argv, &hp)) + if (getaddr(RTA_DST, *argv, &hp, nrflags)) nrflags |= F_ISHOST; } else if ((rtm_addrs & RTA_GATEWAY) == 0) { gateway = *argv; - (void) getaddr(RTA_GATEWAY, *argv, &hp); + getaddr(RTA_GATEWAY, *argv, &hp, nrflags); } else { - (void) getaddr(RTA_NETMASK, *argv, 0); + getaddr(RTA_NETMASK, *argv, 0, nrflags); nrflags |= F_FORCENET; } } @@ -1116,7 +1116,7 @@ inet6_makenetandmask(struct sockaddr_in6 *sin6, const char *plen) * returning 1 if a host address, 0 if a network address. */ static int -getaddr(int which, char *str, struct hostent **hpp) +getaddr(int which, char *str, struct hostent **hpp, int nrflags) { sup su; struct hostent *hp; @@ -1137,7 +1137,7 @@ getaddr(int which, char *str, struct hostent **hpp) break; case RTA_GATEWAY: su = &so_gate; - if (iflag) { + if (nrflags & F_INTERFACE) { struct ifaddrs *ifap, *ifa; struct sockaddr_dl *sdl = NULL; @@ -1197,7 +1197,7 @@ getaddr(int which, char *str, struct hostent **hpp) #if 0 bzero(su, sizeof(*su)); /* for readability */ #endif - getaddr(RTA_NETMASK, str, 0); + getaddr(RTA_NETMASK, str, 0, nrflags); break; #if 0 case RTA_NETMASK: -- cgit v1.1 From e33acd92c323d70e5d6df57f002fc99962711614 Mon Sep 17 00:00:00 2001 From: ume Date: Wed, 9 Jan 2013 18:18:08 +0000 Subject: Add no_prefer_iface option. It stops treating the address on the interface as special by source address selection rule even when the interface is outgoing interface. This is desired in some situation. Requested by: hrs Reviewed by: IHANet folks including hrs MFC after: 1 week --- sbin/ifconfig/af_inet6.c | 2 ++ sbin/ifconfig/af_nd6.c | 2 +- sbin/ifconfig/ifconfig.8 | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 5911a94..b4db0f1 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -473,6 +473,8 @@ static struct cmd inet6_cmds[] = { DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags), DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags), DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags), + DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags), + DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags), DEF_CMD_ARG("pltime", setip6pltime), DEF_CMD_ARG("vltime", setip6vltime), DEF_CMD("eui64", 0, setip6eui64), diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c index 80065f6..5c46452 100644 --- a/sbin/ifconfig/af_nd6.c +++ b/sbin/ifconfig/af_nd6.c @@ -58,7 +58,7 @@ static const char rcsid[] = #define MAX_SYSCTL_TRY 5 #define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ "\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \ - "\007NO_RADR\020DEFAULTIF" + "\007NO_RADR\010NO_PREFER_IFACE\020DEFAULTIF" static int isnd6defif(int); void setnd6flags(const char *, int, int, const struct afswtch *); diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index f4c6daa..9c74980 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd November 7, 2012 +.Dd January 10, 2013 .Dt IFCONFIG 8 .Os .Sh NAME @@ -716,6 +716,13 @@ Set a flag to enable Neighbor Unreachability Detection. .It Cm -nud Clear a flag .Cm nud . +.It Cm no_prefer_iface +Set a flag to not prefer address on the interface as candidates of the +source address for outgoing packets, even when the interface is +outgoing interface. +.It Cm -no_prefer_iface +Clear a flag +.Cm no_prefer_iface . .El .Pp The following parameters are specific to cloning -- cgit v1.1 From cacaa2c24012e9867f40bd03e6d1065cce1a07b0 Mon Sep 17 00:00:00 2001 From: delphij Date: Sun, 13 Jan 2013 04:28:44 +0000 Subject: Use the right format string for line buffer. PR: bin/174910 Submitted by: Fabian Keil --- sbin/sysctl/sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 8fad089..43592b3 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -266,7 +266,7 @@ parse(const char *string, int lineno) if (!(kind & CTLFLAG_WR)) { if (kind & CTLFLAG_TUN) { - warnx("oid '%s' is a read only tunable%p", bufp, line); + warnx("oid '%s' is a read only tunable%s", bufp, line); warnx("Tunable values are set in /boot/loader.conf"); } else warnx("oid '%s' is read only%s", bufp, line); -- cgit v1.1 From 97cf52e0e84ee9755cbc28901984c0f6d7e213b2 Mon Sep 17 00:00:00 2001 From: mav Date: Tue, 15 Jan 2013 10:06:35 +0000 Subject: Allow to insert new component to geom_raid3 without specifying number. PR: kern/160562 MFC after: 2 weeks --- sbin/geom/class/raid3/geom_raid3.c | 2 +- sbin/geom/class/raid3/graid3.8 | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/raid3/geom_raid3.c b/sbin/geom/class/raid3/geom_raid3.c index 3f037cd..cd0aa65 100644 --- a/sbin/geom/class/raid3/geom_raid3.c +++ b/sbin/geom/class/raid3/geom_raid3.c @@ -76,7 +76,7 @@ struct g_command class_commands[] = { { "insert", G_FLAG_VERBOSE, NULL, { { 'h', "hardcode", NULL, G_TYPE_BOOL }, - { 'n', "number", NULL, G_TYPE_NUMBER }, + { 'n', "number", G_VAL_OPTIONAL, G_TYPE_NUMBER }, G_OPT_SENTINEL }, "[-hv] <-n number> name prov" diff --git a/sbin/geom/class/raid3/graid3.8 b/sbin/geom/class/raid3/graid3.8 index f396cc3..a82d388 100644 --- a/sbin/geom/class/raid3/graid3.8 +++ b/sbin/geom/class/raid3/graid3.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 5, 2010 +.Dd January 15, 2012 .Dt GRAID3 8 .Os .Sh NAME @@ -53,7 +53,7 @@ .Nm .Cm insert .Op Fl hv -.Fl n Ar number +.Op Fl n Ar number .Ar name .Ar prov .Nm @@ -171,6 +171,8 @@ Add the given component to the existing array, if one of the components was removed previously with the .Cm remove command or if one component is missing and will not be connected again. +If no number is given, new component will be added instead of first missed +component. .Pp Additional options include: .Bl -tag -width ".Fl h" -- cgit v1.1 From 7284572ae674f698fe5471077c053af5a269c9b4 Mon Sep 17 00:00:00 2001 From: eadler Date: Wed, 16 Jan 2013 05:03:46 +0000 Subject: Correct prefix for "locally installed things" Approved by: cperciva MFC After: 3 days --- sbin/setkey/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/setkey/Makefile b/sbin/setkey/Makefile index 03c2ea2..e2c93cc 100644 --- a/sbin/setkey/Makefile +++ b/sbin/setkey/Makefile @@ -61,7 +61,7 @@ CLEANFILES+= scriptdump y.tab.h #SCRIPTS= scriptdump -LOCALPREFIX= /usr +LOCALPREFIX= /usr/local scriptdump: scriptdump.pl sed -e 's#@LOCALPREFIX@#${LOCALPREFIX}#' < $> > scriptdump -- cgit v1.1 From d3c13df6d1c6d7707a4bcfaf5b1711c4d0621064 Mon Sep 17 00:00:00 2001 From: mav Date: Thu, 17 Jan 2013 00:50:25 +0000 Subject: For Promise/AMD metadata add support for disks with capacity above 2TiB and for volumes with sector size above 512 bytes. --- sbin/geom/class/raid/graid.8 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/raid/graid.8 b/sbin/geom/class/raid/graid.8 index 630cd01..ed33e00 100644 --- a/sbin/geom/class/raid/graid.8 +++ b/sbin/geom/class/raid/graid.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 13, 2012 +.Dd January 16, 2013 .Dt GRAID 8 .Os .Sh NAME @@ -274,7 +274,6 @@ complete it there. Do not run GEOM RAID class on migrating volumes under pain of possible data corruption! .Sh 2TiB BARRIERS -Promise metadata format does not support disks above 2TiB. NVIDIA metadata format does not support volumes above 2TiB. .Sh SYSCTL VARIABLES The following -- cgit v1.1 From ca524b1bec7c3be22335d9d865e9b3153fe0107e Mon Sep 17 00:00:00 2001 From: pfg Date: Sat, 19 Jan 2013 03:34:02 +0000 Subject: newfs_msdos: cosmetical cleanups - Simplify diagnostic messages. - Adopt lowercase first letters to make the messages more canonical. PR: bin/175404 Submitted by: Christoph Mallon Reviewed by: bde MFC after: 3 days --- sbin/newfs_msdos/newfs_msdos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sbin') diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index c2e9a35..fe1631a 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -808,7 +808,7 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct stat st; if (fstat(fd, &st)) - err(1, "Cannot get disk size"); + err(1, "cannot get disk size"); /* create a fake geometry for a file image */ ms = st.st_size; dlp.d_secsize = 512; @@ -832,18 +832,18 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, if (ioctl(fd, DIOCGDINFO, &dlp) == -1) { if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1) - errx(1, "Cannot get sector size, %s", strerror(errno)); + err(1, "cannot get sector size"); dlp.d_secperunit = ms / dlp.d_secsize; if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) { - warnx("Cannot get number of sectors per track, %s", strerror(errno)); + warn("cannot get number of sectors per track"); dlp.d_nsectors = 63; } if (bpb->bpbHeads == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { - warnx("Cannot get number of heads, %s", strerror(errno)); + warn("cannot get number of heads"); if (dlp.d_secperunit <= 63*1*1024) dlp.d_ntracks = 1; else if (dlp.d_secperunit <= 63*16*1024) -- cgit v1.1 From 2390f6ef87cdbe1d5bcd77bc3c79e90a7ad5d5fa Mon Sep 17 00:00:00 2001 From: wblock Date: Fri, 25 Jan 2013 16:33:00 +0000 Subject: Expand description of how gptboot and gptzfsboot choose a partition for booting. Reviewed by: ae MFC after: 1 week --- sbin/geom/class/part/gpart.8 | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'sbin') diff --git a/sbin/geom/class/part/gpart.8 b/sbin/geom/class/part/gpart.8 index 61f8275..8843e53 100644 --- a/sbin/geom/class/part/gpart.8 +++ b/sbin/geom/class/part/gpart.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 3, 2013 +.Dd January 25, 2013 .Dt GPART 8 .Os .Sh NAME @@ -807,34 +807,51 @@ Both types of bootstrap code are used to boot from the GUID Partition Table. First, a protective MBR is embedded into the first disk sector from the .Pa /boot/pmbr image. -It searches the GPT +It searches through the GPT for a .Cm freebsd-boot partition (see the .Sx "PARTITION TYPES" -section) in the GPT and runs the next bootstrap stage from it. +section) and runs the next bootstrap stage from it. The .Cm freebsd-boot partition should be smaller than 545 KB. +It can be located either before or after other +.Fx +partitions on the disk. There are two variants of bootstrap code to write to this partition: .Pa /boot/gptboot and .Pa /boot/gptzfsboot . .Pa /boot/gptboot is used to boot from UFS. -It searches +It searches through +.Cm freebsd-ufs +partitions in the GPT and boots from the first one with the +.Cm bootonce +attribute set. +If that attribute is not found, +.Pa /boot/gptboot +boots from the first .Cm freebsd-ufs -GPT partitions and starts +partition with the +.Cm bootme +attribute set. +If neither attribute is found, +.Pa /boot/gptboot +boots from the first +.Cm freebsd-ufs +partition. .Pa /boot/loader .Pq the third bootstrap stage -if found. -The +is loaded from the first partition that matches these conditions. .Pa /boot/gptzfsboot is used to boot from ZFS. -It searches +It searches through the GPT for .Cm freebsd-zfs -GPT partitions and starts +partitions, trying to detect ZFS pools. +After all pools are detected, .Pa /boot/zfsloader -if found. +is started from the first one found. .Pp The VTOC8 scheme does not support embedding bootstrap code. Instead, the 8 KBytes bootstrap code image @@ -945,7 +962,7 @@ The GEOM PART class can detect the same partition table visible through different GEOM providers, and some of them will be marked as corrupt. Be careful when choosing a provider for recovery. If you choose incorrectly you can destroy the metadata of another GEOM class, -e.g.\& GEOM MIRROR or GEOM LABEL. +e.g.,\& GEOM MIRROR or GEOM LABEL. .Sh SYSCTL VARIABLES The following .Xr sysctl 8 -- cgit v1.1 From 3e5ced1b98dca63d150904313752d2ee1cf72802 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 30 Jan 2013 15:21:18 +0000 Subject: 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 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) --- sbin/devd/devd.8 | 7 ++++ sbin/devd/devd.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 95 insertions(+), 14 deletions(-) (limited to 'sbin') diff --git a/sbin/devd/devd.8 b/sbin/devd/devd.8 index 7377e25..bc5092c 100644 --- a/sbin/devd/devd.8 +++ b/sbin/devd/devd.8 @@ -35,6 +35,7 @@ .Nm .Op Fl Ddn .Op Fl f Ar file +.Op Fl l Ar num .Sh DESCRIPTION The .Nm @@ -55,6 +56,12 @@ instead of the default If option .Fl f is specified more than once, the last file specified is used. +.It Fl l Ar num +Limit concurrent +.Pa /var/run/devd.pipe +connections to +.Ar num . +The default connection limit is 10. .It Fl n Do not process all pending events before becoming a daemon. Instead, call daemon right away. diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index 576dcf6..c91430f 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -814,23 +815,58 @@ create_socket(const char *name) return (fd); } +unsigned int max_clients = 10; /* Default, can be overriden on cmdline. */ +unsigned int num_clients; list clients; void notify_clients(const char *data, int len) { - list bad; - list::const_iterator i; + list::iterator i; - for (i = clients.begin(); i != clients.end(); ++i) { - if (write(*i, data, len) <= 0) { - bad.push_back(*i); + /* + * Deliver the data to all clients. Throw clients overboard at the + * first sign of trouble. This reaps clients who've died or closed + * their sockets, and also clients who are alive but failing to keep up + * (or who are maliciously not reading, to consume buffer space in + * kernel memory or tie up the limited number of available connections). + */ + for (i = clients.begin(); i != clients.end(); ) { + if (write(*i, data, len) != len) { + --num_clients; close(*i); - } + i = clients.erase(i); + } else + ++i; } +} + +void +check_clients(void) +{ + int s; + struct pollfd pfd; + list::iterator i; - for (i = bad.begin(); i != bad.end(); ++i) - clients.erase(find(clients.begin(), clients.end(), *i)); + /* + * Check all existing clients to see if any of them have disappeared. + * Normally we reap clients when we get an error trying to send them an + * event. This check eliminates the problem of an ever-growing list of + * zombie clients because we're never writing to them on a system + * without frequent device-change activity. + */ + pfd.events = 0; + for (i = clients.begin(); i != clients.end(); ) { + pfd.fd = *i; + s = poll(&pfd, 1, 0); + if ((s < 0 && s != EINTR ) || + (s > 0 && (pfd.revents & POLLHUP))) { + --num_clients; + close(*i); + i = clients.erase(i); + } else + ++i; + } } void @@ -838,9 +874,18 @@ new_client(int fd) { int s; + /* + * First go reap any zombie clients, then accept the connection, and + * shut down the read side to stop clients from consuming kernel memory + * by sending large buffers full of data we'll never read. + */ + check_clients(); s = accept(fd, NULL, NULL); - if (s != -1) + if (s != -1) { + shutdown(s, SHUT_RD); clients.push_back(s); + ++num_clients; + } } static void @@ -851,6 +896,7 @@ event_loop(void) char buffer[DEVCTL_MAXBUF]; int once = 0; int server_fd, max_fd; + int accepting; timeval tv; fd_set fds; @@ -858,6 +904,7 @@ event_loop(void) if (fd == -1) err(1, "Can't open devctl device %s", PATH_DEVCTL); server_fd = create_socket(PIPE); + accepting = 1; max_fd = max(fd, server_fd) + 1; while (1) { if (romeo_must_die) @@ -880,15 +927,38 @@ event_loop(void) once++; } } + /* + * When we've already got the max number of clients, stop + * accepting new connections (don't put server_fd in the set), + * shrink the accept() queue to reject connections quickly, and + * poll the existing clients more often, so that we notice more + * quickly when any of them disappear to free up client slots. + */ FD_ZERO(&fds); FD_SET(fd, &fds); - FD_SET(server_fd, &fds); - rv = select(max_fd, &fds, NULL, NULL, NULL); + if (num_clients < max_clients) { + if (!accepting) { + listen(server_fd, max_clients); + accepting = 1; + } + FD_SET(server_fd, &fds); + tv.tv_sec = 60; + tv.tv_usec = 0; + } else { + if (accepting) { + listen(server_fd, 0); + accepting = 0; + } + tv.tv_sec = 2; + tv.tv_usec = 0; + } + rv = select(max_fd, &fds, NULL, NULL, &tv); if (rv == -1) { if (errno == EINTR) continue; err(1, "select"); - } + } else if (rv == 0) + check_clients(); if (FD_ISSET(fd, &fds)) { rv = read(fd, buffer, sizeof(buffer) - 1); if (rv > 0) { @@ -1007,7 +1077,8 @@ gensighand(int) static void usage() { - fprintf(stderr, "usage: %s [-Ddn] [-f file]\n", getprogname()); + fprintf(stderr, "usage: %s [-Ddn] [-l connlimit] [-f file]\n", + getprogname()); exit(1); } @@ -1036,7 +1107,7 @@ main(int argc, char **argv) int ch; check_devd_enabled(); - while ((ch = getopt(argc, argv, "Ddf:n")) != -1) { + while ((ch = getopt(argc, argv, "Ddf:l:n")) != -1) { switch (ch) { case 'D': Dflag++; @@ -1047,6 +1118,9 @@ main(int argc, char **argv) case 'f': configfile = optarg; break; + case 'l': + max_clients = MAX(1, strtoul(optarg, NULL, 0)); + break; case 'n': nflag++; break; -- cgit v1.1 From 85fcf6286dd7a0721e5b300d232483d5bb13b1a8 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 30 Jan 2013 23:37:35 +0000 Subject: 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) --- sbin/devd/devd.cc | 52 +++++++++++++++++++++++++++++----------------------- sbin/devd/devd.hh | 5 +++-- 2 files changed, 32 insertions(+), 25 deletions(-) (limited to 'sbin') diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc index c91430f..46f3623 100644 --- a/sbin/devd/devd.cc +++ b/sbin/devd/devd.cc @@ -137,7 +137,7 @@ config cfg; event_proc::event_proc() : _prio(-1) { - // nothing + _epsvec.reserve(4); } event_proc::~event_proc() @@ -241,25 +241,18 @@ my_system(const char *command) bool action::do_action(config &c) { - string s = c.expand_string(_cmd); + string s = c.expand_string(_cmd.c_str()); if (Dflag) fprintf(stderr, "Executing '%s'\n", s.c_str()); my_system(s.c_str()); return (true); } -match::match(config &c, const char *var, const char *re) - : _var(var), _re("^") +match::match(config &c, const char *var, const char *re) : + _inv(re[0] == '!'), + _var(var), + _re(c.expand_string(_inv ? re + 1 : re, "^", "$")) { - if (!c.expand_string(string(re)).empty() && - c.expand_string(string(re)).at(0) == '!') { - _re.append(c.expand_string(string(re)).substr(1)); - _inv = 1; - } else { - _re.append(c.expand_string(string(re))); - _inv = 0; - } - _re.append("$"); regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE); } @@ -624,24 +617,37 @@ config::expand_one(const char *&src, string &dst) do { buffer.append(src++, 1); } while (is_id_char(*src)); - buffer.append("", 1); dst.append(get_variable(buffer.c_str())); } const string -config::expand_string(const string &s) +config::expand_string(const char *src, const char *prepend, const char *append) { - const char *src; + const char *var_at; string dst; - src = s.c_str(); - while (*src) { - if (*src == '$') - expand_one(src, dst); - else - dst.append(src++, 1); + /* + * 128 bytes is enough for 2427 of 2438 expansions that happen + * while parsing config files, as tested on 2013-01-30. + */ + dst.reserve(128); + + if (prepend != NULL) + dst = prepend; + + for (;;) { + var_at = strchr(src, '$'); + if (var_at == NULL) { + dst.append(src); + break; + } + dst.append(src, var_at - src); + src = var_at; + expand_one(src, dst); } - dst.append("", 1); + + if (append != NULL) + dst.append(append); return (dst); } diff --git a/sbin/devd/devd.hh b/sbin/devd/devd.hh index 3613216..a48d07b 100644 --- a/sbin/devd/devd.hh +++ b/sbin/devd/devd.hh @@ -90,9 +90,9 @@ public: virtual bool do_match(config &); virtual bool do_action(config &) { return true; } private: + bool _inv; std::string _var; std::string _re; - bool _inv; regex_t _regex; }; @@ -162,7 +162,8 @@ public: void pop_var_table(); void set_variable(const char *var, const char *val); const std::string &get_variable(const std::string &var); - const std::string expand_string(const std::string &var); + const std::string expand_string(const char * var, + const char * prepend = NULL, const char * append = NULL); char *set_vars(char *); void find_and_execute(char); protected: -- cgit v1.1 From 7f832c3059b3b2f864f0b1f3fac0c4ed8e268b27 Mon Sep 17 00:00:00 2001 From: glebius Date: Thu, 31 Jan 2013 08:55:21 +0000 Subject: Retire struct sockaddr_inarp. Since ARP and routing are separated, "proxy only" entries don't have any meaning, thus we don't need additional field in sockaddr to pass SIN_PROXY flag. New kernel is binary compatible with old tools, since sizes of sockaddr_inarp and sockaddr_in match, and sa_family are filled with same value. The structure declaration is left for compatibility with third party software, but in tree code no longer use it. Reviewed by: ru, andre, net@ --- sbin/route/route.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sbin') diff --git a/sbin/route/route.c b/sbin/route/route.c index 4637ba4..48f90a7 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -86,7 +86,6 @@ union sockunion { #endif struct sockaddr_at sat; struct sockaddr_dl sdl; - struct sockaddr_inarp sinarp; struct sockaddr_storage ss; /* added to avoid memory overrun */ } so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp; @@ -923,10 +922,8 @@ newroute(int argc, char **argv) flags |= RTF_HOST; if ((nrflags & F_INTERFACE) == 0) flags |= RTF_GATEWAY; - if (nrflags & F_PROXY) { - so_dst.sinarp.sin_other = SIN_PROXY; + if (nrflags & F_PROXY) flags |= RTF_ANNOUNCE; - } if (dest == NULL) dest = ""; if (gateway == NULL) -- cgit v1.1 From 204e766e8c1366763cd863b125c572e0a185fa19 Mon Sep 17 00:00:00 2001 From: delphij Date: Mon, 4 Feb 2013 19:17:15 +0000 Subject: Use stripesize as smallest block size if it's available. MFC after: 2 weeks --- sbin/recoverdisk/recoverdisk.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sbin') diff --git a/sbin/recoverdisk/recoverdisk.c b/sbin/recoverdisk/recoverdisk.c index 3a92d1d..caa8ebd 100644 --- a/sbin/recoverdisk/recoverdisk.c +++ b/sbin/recoverdisk/recoverdisk.c @@ -156,6 +156,7 @@ main(int argc, char * const argv[]) int error, state; u_char *buf; u_int sectorsize; + u_int stripesize; time_t t1, t2; struct stat sb; u_int n, snapshot = 60; @@ -201,6 +202,10 @@ main(int argc, char * const argv[]) if (error < 0) err(1, "DIOCGSECTORSIZE failed"); + error = ioctl(fdr, DIOCGSTRIPESIZE, &stripesize); + if (error == 0 && stripesize > sectorsize) + sectorsize = stripesize; + minsize = sectorsize; bigsize = (bigsize / sectorsize) * sectorsize; -- cgit v1.1 From e05b8f83c12a3cb88401b017b2931c013b8d3622 Mon Sep 17 00:00:00 2001 From: zeising Date: Tue, 5 Feb 2013 14:29:37 +0000 Subject: Bump .Dd for the change in r246121. Approved by: joel (mentor) --- sbin/devd/devd.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sbin') diff --git a/sbin/devd/devd.8 b/sbin/devd/devd.8 index bc5092c..8e33236 100644 --- a/sbin/devd/devd.8 +++ b/sbin/devd/devd.8 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 24, 2005 +.Dd January 30, 2013 .Dt DEVD 8 .Os .Sh NAME -- cgit v1.1