critical impact:
getlogin, getlogin_r - functional difference (CrCh202)
Problem description
The getlogin and getlogin_r functions are different in Tru64 UNIX and HP-UX.
The getlogin function returns the login name of the user associated with the current session; getlogin_r function is the reentrant version. The following list summarizes the differences:
On HP-UX, the login name is obtained by using the getlogin or getlogin_r functions, which get it from the /etc/utmp file. On Tru64 UNIX, the login name is obtained by using the getlogin and getlogin_r functions, which get it directly from the kernel.
On HP-UX, at least one of the standard input, standard output, or standard error must be a terminal; on Tru64 UNIX, it is not required.
On HP-UX, when getlogin_r fails, it returns the error number and does not set errno. On Tru64 UNIX, the function returns the error number and sets errno.
On HP-UX, when a bad address is passed to the first parameter, name, in getlogin_r, it returns EINVAL. On Tru64 UNIX, the function returns EFAULT.
On HP-UX, when the name parameter in getlogin_r points to a string that is too long, the function returns ERANGE. On Tru64 UNIX, the function sets errno to 0 and sets name to the length specified in the len argument.
- On HP-UX, getlogin returns NULL and sets errno to ENOTTY if the program is invoked through a remote shell(rsh or remsh); on Tru64 UNIX, it returns the remote account name.
The following HP-UX error codes are not returned by either getlogin or getlogin_r on Tru64 UNIX:
[EACCES] - Access permission to read the /etc/utmp file, or to get the status of the terminal device file, was denied.
[EMFILE] - Too many file descriptors are in use by this process.
[ENFILE] - Too many file descriptors are in use on the system.
[ENOENT] - The /etc/utmp file or the terminal device file cannot be found.
[ENOTTY] - None of the standard input, standard output, or standard error is a terminal, or for the first of these that is a terminal, no current login is registered on that terminal, or the session leader process of the calling process has no controlling terminal.
[ESRCH] - The session leader process of the calling process is no longer running.
Although HP-UX returns utmp file-related errors that Tru64 UNIX does not, most are inconsequential. Only [ENFILE] and [EMFILE] are significant. Tru64 UNIX applications need to be aware that getlogin and getlogin_r will not work when all available file descriptors are used. Identifiers
 getlogin |
 getlogin_r |
|
|
See also
Solution description
Review the applicable manpages and code.
The documented differences might affect your application. Review the applicable manpages and your code to determine if unexpected behavior will result. See also
Problem summary
| classifications |
source types |
OS release |
severity |
type |
| KN, SEC |
C, C++ |
any HP-UX 11i version |
critical |
changed |
|