Commit Graph

6248 Commits

Author SHA1 Message Date
Ed Schouten
98c63a48e9 Perform several small cleanups to the utmpx code.
- Massively reduce BSS usage. Let futx_to_utx() dynamically allocate the
  structure. There is only a very small amount of applications out there
  that needs to use the utmpx database. Wasting 1 KB on unused
  structures makes little sense.

- Just let getutxid() search for matching ut_id's for any *PROCESS-type.
  This makes the code a bit more future-proof.

- Fix a POSIX-mistake: when reading POSIX and the OpenSolaris
  implementation, getutxline() must return USER_PROCESS and
  LOGIN_PROCESS records whose ut_lines match. When reading POSIX, it
  seems LOGIN_PROCESS should not use ut_line at the first place. I have
  reported this issue.
2010-01-17 21:40:05 +00:00
Ed Schouten
e35a88d3a6 Add forgotten break; keyword to getutxid().
We should not fall through to the ut_id comparison. Only ut_type should
be compared when using OLD_TIME, NEW_TIME, BOOT_TIME or SHUTDOWN_TIME.
2010-01-17 21:00:29 +00:00
Ed Schouten
79a7dbf111 Simplify ttyslot(3).
After comparing how other systems deal with utmp/utmpx, I noticed many
systems don't even care about ttyslot(3) anymore, since utmpx doesn't
use TTY slots anyway. We don't provide any tools to access old utmp
files anymore, so there is no use in letting applications write to a
proper offset within the utmp file.

Just let ttyslot(3) always return 0, which seems to be the default
behaviour on operating systems like Linux as well.
2010-01-17 15:43:14 +00:00
Ed Schouten
023b02dea7 Unexpose the old uname(3) function.
Nowadays uname(3) is an inline function around __xuname(3). Prevent
linkage of new binaries against this compatibility function, similar to
what I did with ttyslot(3).
2010-01-16 17:05:27 +00:00
David Xu
764ce7ce7d Also call sem_module_init in sem_close to initialize mutex
with some attributes.
2010-01-15 01:19:58 +00:00
Ed Schouten
5ab7f1fc40 Add wtmpcvt(1).
This utility allows users to convert their wtmp databases to the new
format. It makes no sense for users to keep their wtmp log files if they
are unable to view them.

It basically copies ut_line into ut_id as well. This makes it possible
for last(1) and ac(8) to match login records with their corresponding
logout record.
2010-01-14 20:58:45 +00:00
Ed Schouten
c068466245 Remove ttyslot from Symbol.map anyway.
Requested by:	kan
2010-01-14 15:20:46 +00:00
Ed Schouten
6386f4da2a Unbreak pututxline() on 32-bit architectures.
I forgot to cast the size_t's back to off_t before negating them,
causing all sorts of artifacts where the log files would grow to 2^32 -
197 bytes.

Reported by:	ume
2010-01-14 15:20:09 +00:00
Ed Schouten
d496b9d0d4 Revert the change to Symbol.map, made in r202274.
Even though we use __sym_compat(), we should list the symbol in
Symbol.map.

ttyslot() is now listed as follows, which seems to do the right thing:

| Symbol table '.dynsym' contains 2755 entries:
|    Num:    Value          Size Type    Bind   Vis      Ndx Name
|    613: 00000000000477b0   121 FUNC    GLOBAL DEFAULT   10 ttyslot@FBSD_1.0

Reported by:	kib
2010-01-14 10:00:01 +00:00
Ed Schouten
7bc9f25fd0 Don't use fseeko() to obtain the file offset.
I was a bit confused with lseek(), which returns the new offset. We
should ftello() to obtain it using stdio.
2010-01-14 08:08:55 +00:00
Ed Schouten
9457bcdc60 Add two changes that should have gone into commit r202274.
Phase out ttyslot(3).

  The ttyslot() function was originally part for SUSv1, marked LEGACY in
  SUSv2 and removed later on. This function only makes sense when using
  utmp(5), because it was used to determine the offset of the record for
  the controlling TTY. It makes little sense to keep it here, because the
  new utmpx file format doesn't index based on TTY slots.
2010-01-14 05:37:43 +00:00
Ed Schouten
88b69f52ee Phase out ttyslot(3).
The ttyslot() function was originally part for SUSv1, marked LEGACY in
SUSv2 and removed later on. This function only makes sense when using
utmp(5), because it was used to determine the offset of the record for
the controlling TTY. It makes little sense to keep it here, because the
new utmpx file format doesn't index based on TTY slots.
2010-01-14 05:35:32 +00:00
Ed Schouten
a627ac61ab Implement <utmpx.h>.
The utmpx interface is the standardized interface of the user accounting
database. The standard only defines a subset of the functions that were
present in System V-like systems.

I'd like to highlight some of the traits my implementation has:

- The standard allows the on-disk format to be different than the
  in-memory representation (struct utmpx). Most operating systems don't
  do this, but we do. This allows us to keep our ABI more stable, while
  giving us the opportunity to modify the on-disk format. It also allows
  us to use a common file format across different architectures (i.e.
  byte ordering).

- Our implementation of pututxline() also updates wtmp and lastlog (now
  called utx.log and utx.lastlogin). This means the databases are more
  likely to be in sync.

- Care must be taken that our implementation discard any fields that are
  not applicable. For example, our DEAD_PROCESS records do not hold a
  TTY name. Just a time stamp, a record identifier and a process
  identifier. It also guarantees that strings (ut_host, ut_line and
  ut_user) are null terminated. ut_id is obviously not null terminated,
  because it's not a string.

- The API and its behaviour should be conformant to POSIX, but there may
  be things that slightly deviate from the standard. This implementation
  uses separate file descriptors when writing to the log files. It also
  doesn't use getutxid() to search for a field to overwrite. It uses an
  allocation strategy similar to getutxid(), but prevents DEAD_PROCESS
  records from accumulating.

Make sure libulog doesn't overwrite the manpages shipped with our C
library. Also keep the symbol list in Symbol.map sorted.

I'll bump __FreeBSD_version later this evening. I first want to convert
everything to <utmpx.h> and get rid of <utmp.h>.
2010-01-13 17:29:55 +00:00
David Xu
41e160536a Return SEM_FAILED instead of NULL, though there are same, but the
SEM_FAILED is more suitable name.
In function, sem_close(), always set errno on error.
2010-01-13 08:53:23 +00:00
Christian Brueffer
a47698f8d6 Miscellaneous mdoc, spelling and inconsistency fixes.
PR:		142573, 142576 (mostly)
Submitted by:	brucec
MFC after:	1 week
2010-01-12 21:45:03 +00:00
David Xu
7bf27b2dde Update manuals of sem_open and sem_init.
Submitted by:	ru
2010-01-12 01:30:05 +00:00
Colin Percival
c6a96a8441 Give a less silly response to a silly request.
Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX
were handled by reading or writing (size_t)(size * nmemb) bytes; for
example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1
byte and indicate that the requested 6700417 blocks had been read.

This commit adds a check for such integer overflows, and treats them as
if an overly large request was passed to read/write; i.e., it sets errno
to EINVAL, sets the error indicator on the file, and returns a short
object count (0, to be specific).

The overflow check involves an integer division, so as a performance
optimization we check first to see if both size and nmemb are less than
2^16; if they are, no overflow is possible and we avoid the division.
We assume here that size_t is at least 32 bits; this appears to be true
on all platforms FreeBSD supports.

Although this commit fixes an integer overflow, it is not likely to have
any security implications, since any program which would be affected by
this bug fix is quite clearly already very confused.

Reviewed by:	kib
MFC after:	1 month
2010-01-10 14:30:30 +00:00
Brooks Davis
9d8e1a8300 Use the correct types to store uids and gids in the credential cache. 2010-01-09 23:36:51 +00:00
Xin LI
777f8cebf3 Add a set of manual pages for pthread[_attr]_[sg]etaffinity(3).
Reviewed by:	davidxu
MFC after:	2 weeks
2010-01-09 12:31:11 +00:00
David Xu
a455039e3a Update manual for sem_init and sem_open, restrictions of shared semaphore
and 14 characters in name length no longer exist.

Reviewed by:	deischen@
2010-01-09 05:40:46 +00:00
Warner Losh
52e0ea7a0d Merge r195030 from project/mips to head by hand
r195030 | gonzo | 2009-06-25 19:27:31 -0600 (Thu, 25 Jun 2009) | 4 lines
- Switch to libc softfloat from libgcc implementation. The problem
    with latter is that it is not complete, fpsetXXX/fpgetXXX
    functions are missing.
2010-01-09 00:01:35 +00:00
Warner Losh
87e925fb53 Merge r197800 from projects/mips to head by hand:
r197800 | gonzo | 2009-10-06 00:35:52 -0600 (Tue, 06 Oct 2009) | 3 lines
- curbrk variable for sbrk and brk should be the same
- Add correct variable names to Symbol.map
2010-01-08 23:59:04 +00:00
Warner Losh
9cd8780a69 Merge r195025 from projects/mips to head by hand:
r195025 | gonzo | 2009-06-25 19:01:50 -0600 (Thu, 25 Jun 2009) | 4 lines
- Move fpgetXXX.c/fpsetXXX.c sources to hardfloat subdir/
    to prevenmt them from being mixed up with lib/libc/softfloat
    files with the same names
2010-01-08 23:50:39 +00:00
Christian Brueffer
37dc3d28cb Remove unnecessary quoting and markup, add missing punctuation.
PR:		140494
Submitted by:	Jeremy Huddleston <jeremyhu@apple.com>, bde
MFC after:	1 week
2010-01-08 22:02:42 +00:00
Konstantin Belousov
4319da1319 Further fix grammar.
Suggested by:	alc
MFC after:	3 days
2010-01-07 21:14:46 +00:00
Christian Brueffer
44640a5251 Fix a typo and bump date for the previous commit. 2010-01-07 21:08:22 +00:00
Edward Tomasz Napierala
10302b1ade Remove BUGS section that no longer applies after recent changes to semaphore
code.

OK-ed by:	davidxu
2010-01-07 16:52:00 +00:00
Konstantin Belousov
0b56296772 Give some information on SF_MNOWAIT flag.
MFC after:	3 days
2010-01-07 13:31:00 +00:00
David Xu
323d80a0a7 Don't forget to use fourth argument if O_CREAT is set in argument oflag.
The fourth specifies initial value for the semaphore.
2010-01-07 04:15:49 +00:00
John Baldwin
8feb1ea45e Use _pthread_once() rather than _once() for localtime() and gmtime(). These
methods are only invoked when __isthreaded is true at which point it is safe
to use _pthread_once() directly.

MFC after:	1 week
2010-01-06 20:43:40 +00:00
Konstantin Belousov
f5636f881b Do not rely on behaviour undefined by ANSI C, use thunks to adapt
alphasort-like interface to the comparision function required by
qsort() and qsort_r().

For opendir() thunk and alphasort(), comment on why we deviated from
POSIX by using strcmp() instead of strcoll().

Requested and reviewed by:	bde
MFC after:	2 weeks
2010-01-05 20:20:31 +00:00
Christian Brueffer
7b331f63c5 Fix a double free().
PR:		142339
Submitted by:	Henning Petersen <henning.petersen@t-online.de>
MFC after:	2 weeks
2010-01-05 20:18:41 +00:00
David Xu
523a738f77 More cleanup, remove _libc prefix because libthr no longer has stubs
referencing them.
2010-01-05 06:40:27 +00:00
David Xu
3e18aa9869 forgot to remove SYM_FBP10. ;-) 2010-01-05 05:47:18 +00:00
David Xu
79aaab046d Remove unused macros. 2010-01-05 05:44:52 +00:00
David Xu
d802aa25d2 Don't check has_waiters twice, inline some small functions.
performance result on my machine:
	mutex     Elapsed: 902115 us; per iteration: 90 ns.
	semaphore Elapsed: 958780 us; per iteration: 95 ns.
2010-01-05 03:39:31 +00:00
David Xu
9b0f1823b5 Use umtx to implement process sharable semaphore, to make this work,
now type sema_t is a structure which can be put in a shared memory area,
and multiple processes can operate it concurrently.
User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open()
to initialize a shared semaphore.
Named semaphore uses file system and is located in /tmp directory, and its
file name is prefixed with 'SEMD', so now it is chroot or jail friendly.
In simplist cases, both for named and un-named semaphore, userland code
does not have to enter kernel to reduce/increase semaphore's count.
The semaphore is designed to be crash-safe, it means even if an application
is crashed in the middle of operating semaphore, the semaphore state is
still safely recovered by later use, there is no waiter counter maintained
by userland code.
The main semaphore code is in libc and libthr only has some necessary stubs,
this makes it possible that a non-threaded application can use semaphore
without linking to thread library.
Old semaphore implementation is kept libc to maintain binary compatibility.
The kernel ksem API is no longer used in the new implemenation.

Discussed on: threads@
2010-01-05 02:37:59 +00:00
Konstantin Belousov
4176dd5267 Modernize scandir(3) and alphasort(3) interfaces according to the IEEE
Std 1003.1-2008. Both Linux and Solaris conforms to the new definitions,
so we better follow too (older glibc used old BSDish alphasort prototype
and corresponding type of the comparision function for scandir). While
there, change the definitions of the functions to ANSI C and fix several
style issues nearby.

Remove requirement for "sys/types.h" include for functions from manpage.

POSIX also requires that alphasort(3) sorts as if strcoll(3) was used,
but leave the strcmp(3) call in the function for now.

Adapt in-tree callers of scandir(3) to new declaration. The fact that
select_sections() from catman(1) could modify supplied struct dirent is
a bug.

PR:	standards/142255
MFC after:	2 weeks
2010-01-04 15:40:17 +00:00
Ed Schouten
442aea92f6 Don't forget to clean up the file copied from the kernel sources.
MFC after:	1 week
2010-01-02 20:27:14 +00:00
Brooks Davis
a6fffd6cb0 The devices that supported EVFILT_NETDEV kqueue filters were removed in
r195175.  Remove all definitions, documentation, and usage.

fifo_misc.c:
	Remove all kqueue tests as fifo_io.c performs all those that
	would have remained.

Reviewed by:	rwatson
MFC after:	3 weeks
X-MFC note:	don't change vlan_link_state() function signature
2009-12-31 20:29:58 +00:00
John Baldwin
bac2c9636c Use _once() to initialize the pthread key for thread-local storage to hold
the results of gmtime() instead of using a pthread mutex directly.

MFC after:	1 week
2009-12-30 19:06:16 +00:00
Konstantin Belousov
d439b6c223 Document _FAST and _PRECISE clocks.
Submitted by:	Valentin Nechayev <netch segfault kiev ua>
MFC after:	3 days
2009-12-29 15:58:10 +00:00
Konstantin Belousov
5d2874abdd Document CLOCK_SECOND, add cross-reference from time(3) to clock_gettime(2).
Based on submission by:	pluknet gmail com
MFC after:	3 days
2009-12-29 14:29:08 +00:00
Konstantin Belousov
358ed16f75 Use clock_gettime(CLOCK_SECOND) instead of gettimeofday(2) for
implementation of time(3). CLOCK_SECOND is much faster.

No objections from:	phk
Submitted by:	Valentin Nechayev <netch segfault kiev ua>
MFC after:	1 week
2009-12-29 12:47:47 +00:00
Antoine Brodin
13e403fdea (S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an argument.
Fix some wrong usages.
Note: this does not affect generated binaries as this argument is not used.

PR:		137213
Submitted by:	Eygene Ryabinkin (initial version)
MFC after:	1 month
2009-12-28 22:56:30 +00:00
Markus Brueffer
78da985f4e Use a local copy of entry_d for finding matches. Otherwise, if entry_d pointed
to an entry of 'acl', all ACL entries starting with entry_d would be deleted.

Reviewed by:	trasz
Approved by:	emax (mentor)
MFC after:	3 days
2009-12-25 18:05:06 +00:00
Edwin Groothuis
1993d7fb07 MFV of tzdata2009t, r200831
zic:
- Fix URL / reference to Calendrical Calculations: Third Edition

libc/stdtime:
- Fix typo in tzfile.5 (no changes in our part)

MFC after:	1 week
2009-12-22 11:17:10 +00:00
Xin LI
280101b76e Use vsprintf instead of rolling our own.
PR:		bin/140496
Submitted by:	Jeremy Huddleston <jeremyhu apple.com>
MFC after:	1 month
2009-12-21 19:59:38 +00:00
Xin LI
d22fecc5e6 Use vsscanf instead of rolling our own.
PR:		bin/140530
Submitted by:	Jeremy Huddleston <jeremyhu apple.com>
MFC after:	1 month
2009-12-21 19:56:03 +00:00
Xin LI
c19ee5a0fb K&R -> ANSI prototype.
MFC after:	1 month
2009-12-21 19:55:05 +00:00