Commit Graph

1481 Commits

Author SHA1 Message Date
Ed Schouten
bcc7f0f408 Remove pseudo-terminals from ttys(5).
When we had utmp(5), we had to list all the psuedo-terminals in ttys(5)
to make ttyslot(3) function properly. Now that pututxline(3) deals with
slot allocation internally (not based on TTY names), we don't need to
list all the TTYs on the system in ttys(5) to make user accounting work
properly.

This patch removes all the entries from the /etc/ttys files, but also
the pts(4) entries that were appended implicitly, which was added in
r154838.
2010-01-27 11:54:42 +00:00
Ed Schouten
89c3567d32 Improve the ttyname(3) manual page.
- Remove unrelated references to tty(5).
- Remove unneeded relation with FILE *.
- Add better cross references.
2010-01-24 14:44:05 +00:00
Ed Schouten
9d98195dc3 EMPTY records don't have a timestamp. 2010-01-23 17:58:40 +00:00
Antoine Brodin
dd554467bb Reapply r201145 to lib/libc/gen/sem.c 2010-01-23 12:48:46 +00:00
Ed Schouten
a7607816bf Just ignore the timestamps given to pututxline().
I've noticed many applications do a bad job at timekeeping, for several
reasons:

- Applications like screen(1) don't update time records when restoring
  the old user login record.
- Many applications only set ut_tv.tv_sec, not ut_tv.tv_usec.

This causes many problems for tools such as ac(8), which require the
timestamps to be properly ordered. This is why I've decided to let the
utmpx code obtain valid timestamps itself.
2010-01-23 08:43:21 +00:00
Ed Schouten
f5ec5ddec2 English nitpicking.
Submitted by:	jmallett
2010-01-22 05:19:51 +00:00
Ed Schouten
5b2e6b2a90 Describe why pututxline() doesn't entirely conform to standards. 2010-01-22 05:09:10 +00:00
Ed Schouten
d17ad825d6 Remove comments about breaking the specification.
I've discussed this issue with the Austin Group and it will be fixed in
future revisions of the specification. The issue was that ut_line fields
weren't supposed to be valid for LOGIN_PROCESS entries, while
getutxline() would try to match these records anyway.

They also agreed on our way of implementing pututxline() without
getutxid() (which other operating systems also do), but unfortunately
they disagreed with our way of replacing DEAD_PROCESS entries, which is
a pity. The current specification allows the utmpx database to become
infinitely big over time.

See also:	http://austingroupbugs.net/view.php?id=213#c378
2010-01-22 04:53:08 +00:00
Andrey A. Chernov
5fc5e42a2e Style: reword comment.
Submitted by:   bde
2010-01-20 11:59:46 +00:00
Andrey A. Chernov
e5732e1803 For alphasort() add reference to strcoll(3) 2010-01-20 11:55:14 +00:00
Andrey A. Chernov
e5c9c8533d Style: rename internal function to opendir_compar()
Pointed by:     bde
2010-01-20 07:36:29 +00:00
Andrey A. Chernov
888ee87295 Style: remove extra empty line in the comment.
Pointed by:     bde
2010-01-20 07:27:56 +00:00
Ed Schouten
26f87cc6ff Revert r202447 by re-exposing the old uname(3) function.
It makes hardly any sense to expose a symbol which should only be
provided for binary compatibility, but it seems we don't have a lot of
choice here. There are many autoconf scripts out there that try to
create a binary that links against the old symbol to see whether
uname(3) is present. These scripts fail to detect uname(3) now.

It should be noted that the behaviour we implement is not against the
standards:

| The following shall be declared as a function and may also be defined
| as a macro:
|
| int uname(struct utsname *);
2010-01-19 23:07:12 +00:00
Andrey A. Chernov
b9a74f2ad5 Double checking my commit I found that comment saying that
POSIX 2008 and XSI 7require strcoll() for opendir() is not true.
I can't find such requirement in POSIX 2008 and XSI 7.

So, back out that part of my commit, returning old strcmp(), and remove
this misleading comment.
2010-01-18 13:44:44 +00:00
David Xu
4c1c132bf4 preserve errno when processing error cases. 2010-01-18 10:29:04 +00:00
Andrey A. Chernov
dcdafd0e92 a) Use strcoll() in opendir() and alphasort() as POSIX 2008 requires.
It also matches now how our 'ls' works for years.

b) Remove comment expressed 2 fears:
 1) One just simple describe how strcoll() works in _any_ context,
 not for directories only. Are we plan to remove strcoll() from everything
 just because it is little more complex than strcmp()? I doubt, and
 directories give nothing different here. Moreover, strcoll() used
 in 'ls' for years and nobody complaints yet.

 2) Plain wrong statement about undefined strcoll() behaviour. strcoll()
 always gives predictable results, falling back to strcmp() on any
 trouble, see strcoll(3).

No objections from -current list discussion.
2010-01-18 10:17:51 +00:00
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
David Xu
7bf27b2dde Update manuals of sem_open and sem_init.
Submitted by:	ru
2010-01-12 01:30:05 +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
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
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
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
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
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
Jilles Tjoelker
461e296c49 sem_init(3): document process shared semaphores and their restrictions 2009-12-08 20:48:06 +00:00
Ed Schouten
2c201a9afe Fix many "function declaration isn't a prototype" warnings in libc.
I've only fixed code that seems to be written by `us'. There are still
many warnings like this present in resolv/, rpc/, stdtime/ and yp/.
2009-12-05 19:31:38 +00:00
Ed Schouten
dc29acd1a9 Don't let the C library depend on <utmp.h>.
The maximum length of a username has nothing to do with the size of the
username in the utmp files. Use MAXLOGNAME, which is defined as 17
(UT_USERSIZE + 1).
2009-12-05 19:04:21 +00:00
Ed Schouten
bbbe3054ff Remove warnings from exec.c.
The entries in the argv array are not const themselves, but sometimes we
want to fill in const values. Just make the array const and use
__DECONST() to make it const for the execve()-call itself.

Also convert the only K&R prototype to ANSI.
2009-12-05 18:55:16 +00:00
Ed Schouten
fd5e54d661 Use ANSI C prototypes inside termios.
While there, add a missing __unused to hide a warning in tcsetbreak().
2009-12-05 18:53:04 +00:00
Ed Schouten
86b6b655e4 Remove (hidden) warning about missing prototypes for fdevname(3). 2009-12-05 18:51:44 +00:00