Technical article 105022

logname(C) fails with the error message "could not find entry in /etc/utmp".

OpenServer 5.0.0

Written · Last revised

Problem

I am developing software, which by means of using inetd(ADMN), waits for an incoming connection from an X.25 network (for example) and creates a login session on SCO OpenServer 5.

My software worked fine on previous SCO operating system releases
(Version 4.2-based and earlier).  However, on SCO OpenServer
Release 5, although the login is successfully performed and a
shell is started, the logname(C) utility fails with this error
message:
could not find entry in /etc/utmp

However, if I use the SCO UNIX Operating System Version 4.2 version of logname(C) on this SCO OpenServer 5 system, this older utility does work correctly.

Has logname(C) changed in SCO OpenServer Release 5?

Cause

The behavior of logname(C) has changed:

1. In SCO UNIX System V/386 Release 3.2 Operating System Version 4.2, it uses the name of the controlling tty of the login process to look up the /etc/utmp entry or, if there is no controlling tty, it uses instead the user ID to look up the user name in the file /etc/passwd (see passwd(F)).

2. In SCO OpenServer Release 5, it uses the session ID of the process to look up the necessary /etc/utmp entry.

My server process is started by the inetd(ADMN) daemon whenever
the SCO system receives an incoming X.25 connection and it will
then execute fork(S) to create a child process.  This child sets
up the entry in /etc/utmp (see utmp(F)) with the "ut_pid" field
containing the process ID of this child process (which is not
necessarily the same as its session ID), and then calls exec(S)
to execute the login(M) process.  Upon termination of this X.25
login process, the parent process receives a SIGCLD signal(S) and
then cleans up the /etc/utmp entry and terminates.

Solution

In SCO OpenServer Release 5, logname(C) uses the getlogin(S)
library call which now scans the /etc/utmp file looking for an
entry where the field "ut_pid' in the utmp(F) structure matches
the session ID of the calling process.  The session ID can be
considered to be the ID of the process which owns all of the
process groups in this session.

The utmp entry for this X.25 login process should therefore have been set up with the "ut_pid" field containing the session ID for this process.

The session ID of a process can be obtained by calling the getsid(S)
system call.  Similarly, a new session (and process group) can be
created by calling the setsid(S) system call.

This change in behavior to the logname(C) utility was made to conform to the Posix/XPG4 standard.

This behavioral change can also be demonstrated in the following way:

Note: "sco_OSr5" is an SCO OpenServer 5 system and "sco_OSr3" is an SCO Open Desktop 3.0, that is SCO UNIX Version 4.2-based, system and both systems have been set up for root user equivalence (see the SSL article in the "SEE ALSO" section for details on how to configure this feature).

sco_OSr5# id
uid=0(root) gid=3(sys) groups=3(sys),0(root),1(other)
sco_OSr5# rcmd sco_OSr3 logname
root

This rcmd(TC) command on the "sco_OSr3" system succeeds despite there being no controlling tty, no utmp entry (this invocation of the rcmd(TC) command does not update the /etc/utmp file) and no session ID for this process (session ID's were not supported in SCO UNIX Version 4.2-based systems), since the user name is looked up in the /etc/passwd file according to the user ID being used.

sco_OSr3# id
uid=0(root) gid=1(other)

sco_OSr3# rcmd sco_OSr5 logname logname: could not find entry in /etc/utmp

This rcmd(TC) command fails on the "sco_OSr5" system since, although
this process has an associated session ID, there is no utmp entry
which has a "ut_pid" value matching this session ID (again, this
invocation of the rcmd(TC) command does not update the /etc/utmp
file).  This is correct behavior according to the POSIX/XPG4
specification.
NOTE:     By default, a process which is a session leader is also a process
          group leader.  However, it is not necessarily the case that a process
          group leader is always a session leader.

See also

TA107735, "How to set up user equivalence between two systems."

From the Xinuos technical article database, record 105022. Reproduced with permission. The original is at www.sco.com/ta/105022, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.