Commit Graph

8239 Commits

Author SHA1 Message Date
Diomidis Spinellis
f88b45d7df Prevent buffer overflow when forcibly terminating an escape character.
Obtained from:	OpenBSD
Note: In the case of a full buffer the OpenBSD implementation will
leave in the format string an invalid escape sequence.  This appears
to be harmless with our C library, but according to C99 this can
cause undefined behavior.

MFC after:      2 weeks
2006-12-03 17:50:21 +00:00
Diomidis Spinellis
34785a9fc0 Correct handling of format strings with escaped % specifications.
Note: It would be nice to be able to implement getformat() using
fmtcheck(3), but fmtcheck does not distinguish between signed and
unsigned types, a facility jot needs to perform range checks on its
output.

Submitted by:   Per Kristian Hove
MFC after:	2 weeks
2006-12-03 17:05:04 +00:00
Giorgos Keramidas
d2d6d8d537 The sigconv.awk script generates a sigdesc.h header file, which
contains a sigdec[] vector of structures, but the generated output is
missing braces around the initializer of each struct, which
triggers warnings in WARNS=3:

src/usr.bin/top/sigdesc.h:10: warning: missing braces around initializer
src/usr.bin/top/sigdesc.h:10: warning: (near initialization for `sigdesc[0]')

  * Fix the sigconv.awk script to generate a header with initializers
    which look better.

  * Add rules to usr.bin/top/Makefile that rebuilds a new sigconv.h
    header which matches the correct signal set from the build-time
    version of `${DESTDIR}/usr/include/signal.h' (so sigconv.h doesn't
    get stale once changes are made to the header).

  * Remove the old sigconv.h header, now that it is autoupdated at
    build time.

  * Various Makefile style fixes (the committed Makefile was kindly
    submitted by Ruslan):

    - Reorder .PATH, PROG, SRCS and CFLAGS to match style.Makefile(5)
    - Split off the generated sources (sigdesc.h top.local.h) in an
      SRCS+= line of their own.
    - Add entries to CLEANFILES near the rules that generate the
      respective files.
    - Move the explicit rule which builds top.1 after the implicit
      rules which generate its dependencies.

Reviewed by:	ru, bde
Submitted by:	ru (Makefile)
MFC after:	2 weeks
2006-12-01 07:01:19 +00:00
Ruslan Ermilov
bad4d172b4 - Revert signedness type changes to "struct vmtotal"; by making
them unsigned I made the possible overflows hard to detect,
  and it only saved 1 bit which isn't principal, even less now
  that the underlying issue with the total of virtual memory has
  been fixed.  (For the record, it will overflow with >=2T of
  VM total, with 32-bit ints used to keep counters in pages.)

- While here, fix printing of other "struct vmtotal" members
  such as t_rq, t_dw, t_pw, and t_sw as they are also signed.

Reviewed by:	bde
MFC after:	3 days
2006-11-28 12:46:02 +00:00
Yaroslav Tykhiy
d3985f17d4 Back out rev. 1.17: arch-dependent WARNS level.
The policy is that the WARNS level should characterize the
quality of a piece of code irrespective of any conditions.
Otherwise the code doesn't deserve the WARNS level assigned.

Requested by:	ru
2006-11-27 21:30:38 +00:00
Yaroslav Tykhiy
65b02a0f4b Consistently mark percentage scales as such.
PR:		bin/101975
MFC after:	3 days
2006-11-27 20:19:05 +00:00
Yaroslav Tykhiy
04f7f23bf8 Don't shadow globals.
Found by:       WARNS=6
MFC after:      3 days
2006-11-27 19:50:50 +00:00
Yaroslav Tykhiy
da67074ec6 We should return the name in cp, not printf it.
Found by:	WARNS=6
MFC after:	3 days
2006-11-27 19:48:45 +00:00
Yaroslav Tykhiy
c3d6542fd0 systat(1) reaches WARNS=6 on i386 and amd64. This is good
for catching general regressions in future.  Unfortunately,
it still displays some problems at WARNS=6 on architectures
with stricter alignment requirements, e.g., ia64.
2006-11-27 17:54:28 +00:00
Yaroslav Tykhiy
599cc46d95 The logic of fetchnetstat_sysctl() isn't too complex: if idx is 0,
we set and use xtp; if idx is 1, we set and use xip; the other cases
are impossible.  However, GCC cannot see that xip and xtp are always
initialized before use because they are initialized and used in
different if/else blocks.  So setting them to NULL at the very
beginning won't hurt.
2006-11-27 17:34:40 +00:00
Yaroslav Tykhiy
6549e8c62e + WARNS=4 reminds that nlist.n_name isn't const.
+ Use C99 initializers to be WARNS-clean.
+ The last element in a namelist should have its n_name set to NULL,
  not to an empty string.
2006-11-27 17:24:36 +00:00
Yaroslav Tykhiy
9540596e83 Don't discard a const qualifier from constant strings. 2006-11-27 17:01:31 +00:00
Yaroslav Tykhiy
2506efa78c Remove a wrong "const" qualifier.
Spotted by:	WARNS=6
2006-11-27 16:59:08 +00:00
Yaroslav Tykhiy
dfaa9125d8 Add the Tera scale factor, which is an easy job now.
More scale factors would overflow the command line where
the help for "scale" were shown.
2006-11-27 16:33:44 +00:00
Yaroslav Tykhiy
afe7b9fbb5 Stop exposing things that can be private to convtbl.c. 2006-11-27 16:23:09 +00:00
Yaroslav Tykhiy
aee371e363 Keep all convtbl-related constants and strings in convtbl.[ch]. 2006-11-27 16:14:32 +00:00
Yaroslav Tykhiy
f5d4751c8a Allow for large scale factors. C99 warrants that
ULLONG_MAX is not less than 2^64-1; and uintmax_t
cannot be more narrow than unsigned long long.
This allows for scale factors up to Exa inclusively.

Use plain int for the scale index to be consistent
with ifcmds.c and enum.
2006-11-27 15:26:26 +00:00
Yaroslav Tykhiy
41af362198 Return back one initializer, it is needed. 2006-11-27 15:14:50 +00:00
Yaroslav Tykhiy
f301488570 + Drop useless initializers.
+ style(9).
2006-11-27 15:11:30 +00:00
Yaroslav Tykhiy
ce1bff762d Drop useless #includes. 2006-11-27 14:48:46 +00:00
Yaroslav Tykhiy
0230383747 Use C99 initializers so that we don't really have to worry
about the order of related things at several places.
2006-11-27 14:18:54 +00:00
Yaroslav Tykhiy
ab5c9a0d0a C can enumerate things for us. 2006-11-27 14:16:40 +00:00
Yaroslav Tykhiy
00603ea268 There is no reason to use __inline here because we are rather far
from a path critical to performance.
2006-11-26 20:14:47 +00:00
Yaroslav Tykhiy
a3736d312c Don't overflow from the gigabyte scale to the bit scale if the
number to auto-scale is >= 1024 Gb.  Could be triggered on arches
where ifdata counters had 64 bits.

Reported by:	Miroslav Slavkov on -net
MFC after:	3 days
2006-11-26 20:08:40 +00:00
Yaroslav Tykhiy
91857186f2 The real contents of this file were repeated twice.
The repetition was harmless due to a usual #ifndef _FOO_H_ wrapper.
Fortunately, nobody started to hack the second copy,
so just remove it from the file.

MFC after:	3 days
2006-11-26 19:25:10 +00:00
Ruslan Ermilov
8af480aec1 - When building world WITHOUT_LIBPTHREAD, link libthr to libpthread.
- Don't build ngctl(8) and cached(8) if threading libs aren't built.
- Fix various issues in a cached(8) makefile.
2006-11-26 14:36:34 +00:00
Yaroslav Tykhiy
a6afe5ada8 Fix and extend the -j option to pkill/pgrep WRT the jail
wildcard specifications.  Earlier the only wildcard syntax
was "-j 0" for "any jail".  There were at least
two shortcomings in it:  First, jail ID 0 was abused; it
meant "no jail" in other utils, e.g., ps(1).  Second, it
was impossible to match processed not in jail, which could
be useful to rc.d developers.  Therefore a new syntax is
introduced: "-j any" means any jail while "-j none" means
out of jail.  The old syntax is preserved for compatibility,
but now it's deprecated because it's limited and confusing.

Update the respective regression tests.  While I'm here,
make the tests more complex but sensitive:  Start several
processes, some in jail and some out of jail, so we can
detect that only the right processes are killed by pkill
or matched by pgrep.

Reviewed by:	gad, pjd
MFC after:	1 week
2006-11-23 11:55:17 +00:00
Ruslan Ermilov
20739dfa44 Fix the format specifier suitable for uintmax_t. 2006-11-23 11:51:23 +00:00
Ruslan Ermilov
9623c97258 Oops, fix the format specifier to what was intended. 2006-11-23 11:47:34 +00:00
Greg Lehey
9f238ea6d9 Bump document date.
Nitpicked by:   ru
MFC after:	1 week
2006-11-23 05:08:06 +00:00
Greg Lehey
eb29cfdd00 usage: Include the - in the x flag.
main: Make -x set the hexdump; there's no obvious reason to toggle it.

Nitpicked by:   ru
MFC after:	1 week
2006-11-23 05:07:32 +00:00
Greg Lehey
9a2a66f1bb Add option -x to display output values in hex in addition to decimal. 2006-11-23 00:20:54 +00:00
Maxim Konovalov
0d4d06c9d7 o Check that -w width is not above maximum. Use DWIDTH instead of
hardcoded constant.

Reported by:	Gruzicki Wlodek on BugTraq
Obtained from:	NetBSD, OpenBSD
MFC after:	1 week
2006-11-22 21:05:17 +00:00
Ruslan Ermilov
5c88a11e6e - Fix types of "struct vmmeter" members so they are unsigned.
- Fix overflow bugs in sysctl(8), systat(1), and vmstat(8)
  when printing values of "struct vmmeter" in kilobytes as
  they don't necessarily fit into 32 bits.  (Fix sysctl(8)
  reporting of a total virtual memory; it's in pages too.)
2006-11-20 16:04:41 +00:00
Giorgos Keramidas
d2d77d2aee In revision 1.14 I broke the -4 and -6 options of sockstat(1).
Using either one of the two would result in an empty protos[]
array, and no sockets were actually listed:

  % sockstat -4
  USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
  % sockstat -6
  USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
  %

Fix this bug by tweaking appropriately the logic of handling opt_4,
opt_6, opt_u and protos_defined.

Submitted by:	des
Pointy hat:	keramida
2006-11-12 19:03:39 +00:00
Giorgos Keramidas
1f3d67aade Add support for filtering sockets by protocol type. The default
behavior of sockstat(1) will still be to show "udp", "tcp" and
"divert" protocols, but we can now provide a (comma-separated)
list of protocols, as in:

    % sockstat -P tcp

to list only TCP sockets, or we can filter more than one protocol
by separating the protocol names with a comma:

    % sockstat -P tcp,udp

Protocol names are parsed with getprotobyname(3), so any protocol
whose name is listed in `/etc/protocols' should work fine.

Submitted by:	Josh Carroll <josh.carroll@psualum.com>
Approved by:	des
2006-11-11 22:11:54 +00:00
Dag-Erling Smørgrav
1bac3abc07 Try to preserve ownership and permissions when replacing an existing file.
PR:		bin/104702
Submitted by:	Kevin Day <toasty@dragondata.com>
MFC after:	1 week
2006-11-10 22:05:41 +00:00
Bruce Evans
1f575ce8f9 Don't always print a space character in show_stat(), since a space
shouldn't be printed after the last column.  This restores the
formatting to 79 columns.
2006-11-08 15:15:05 +00:00
Frank J. Laszlo
f1f6c4b25e Add my birthdate to the calendar.
Approved by:	flz (mentor)
2006-11-07 14:35:34 +00:00
Bruce Evans
8dbbff5b81 Second stage of unbreaking thr formatting of the NICE field: decode the
priority class and use this to:

- print "-" instead of a garbage value for ithreads.  Print "-" instead
  of the unused nice value for kthreads which are (mis)classified as
  PRI_TIMESHARE.  For such threads, the nice value can be set to nonzero
  by root, but it is never used (at least by the 4bsd scheduler).  For
  ithreads, we didn't even print the unused value.

- print "i<priority>" and "r<priority>" instead of a biased "<priority>"
  for idletime and realtime threads,  Here <priority> is the priority
  parameter to idprio/rtprio(1).  Just add the prefix and remove the
  bias for now.  <priority> has been stored indirectly in the kernel
  since 2001/02/12, and even the kernel cannot recover the original
  value in all cases.  Here we need to handle more cases than pri_to_rtp(),
  but actually handle fewer cases, and end up printing garbage after
  a thread changes its current priority while in the kernel.

- for idletime and realtime threads, if they are kthreads then add a prefix
  of "k" to the previous string.

- for idletime and realtime threads, if they in the FIFO scheduling class
  then add a suffix of "F" to the previous string (if it fits; the other
  parts of the string are sure to fit unless <priority> is garbage).
2006-11-07 10:03:10 +00:00
Diomidis Spinellis
3241f274f1 Style facelift.
- Reduce the number of global variables
- Make global objects static
- Use bool consistently
- Sort getopt arguments and their processing
- Add function comments
- Change notlast != 0 into !last
2006-11-06 15:58:35 +00:00
Tom Rhodes
df449c3551 Add needed hyphens, note the KTRACE kernel option, bump doc date.
PR:		85186
Submitted by:	garys
2006-11-06 15:17:50 +00:00
Diomidis Spinellis
7d71f06cb4 Use a more sensible default of 1 or -1 when only the start and
end values are specified.

PR:		bin/68981
Submitted by:	Stefan `Sec` Zehl
MFC after:	2 weeks
2006-11-06 15:11:50 +00:00
Diomidis Spinellis
d129c68a14 Do What I Mean when the user asks for random integers or characters.
Up to now jot would fail to generate the last character in the range
or skew the integer distribution in a way that would generate the numbers
in the range's limits with half the probability of the rest.

This modification fixes the program, rather than documenting the
strange behavior, as suggested in docs/54879.

Also, correctly specify the range of random(3).

PR:		docs/54879
MFC after:	2 weeks
2006-11-06 13:55:11 +00:00
Diomidis Spinellis
fee14f30e9 Avoid negative array indices: an empty string can also be used
to specify a default value.
2006-11-06 11:03:43 +00:00
Diomidis Spinellis
1ab8c5be60 See also arc4random
PR:		docs/54879
MFC after:	2 weeks
2006-11-06 10:39:49 +00:00
Diomidis Spinellis
a26a66124e Restore jot's ability to use a seed for producing a deterministic
sequence of random numbers.
This functionality was lost in revision 1.9 when the random number
generator was switched to arc4random.

PR:		docs/54879
MFC after:	2 weeks
2006-11-06 10:30:29 +00:00
Diomidis Spinellis
55f965ae6a Replace obscure aliases through pointers with plain variables.
MFC after:	2 weeks
2006-11-06 09:15:21 +00:00
Diomidis Spinellis
d737ec1ad4 Merge code in common cases.
Verified by:	New regression tests in tools/regression/usr.bin/jot
MFC after:	2 weeks
2006-11-06 08:47:41 +00:00
Diomidis Spinellis
afe53a4950 Replace opaque numeric bit flag values with #defined identifiers.
While there, add some missing FALLTHROUGH comments.

Verified with:	cmp(1) on the executable
MFC after:	2 weeks
2006-11-06 07:26:16 +00:00