OSE - C++ Library User Guide

Graham Dumpleton
Dumpleton Software Consulting Pty Limited
PO BOX 3150
Parramatta, 2124
N.S.W, Australia
email: grahamd@nms.otc.com.au

Table of Contents

Interfacing to UNIX
OSE - C++ Library User GuideInterfacing to UNIX

Interfacing to UNIX

1 UNIX Specific Features

A number of classes are provided which are specific to the UNIX operating system. These relate to aspects of the environment in which an application is executing, or features available in the environment for controlling a process. The first group of classes are OUX_User and OUX_Group. These provide information about the user and group a process is running as. They also allow information about arbitrary users and groups to be obtained. The next class is OUX_SignalBlock. This class provides a portable mechanism for blocking signals on different variants of the UNIX operating system.

2 Users and Groups

To obtain information about a user the OUX_User class is used. To obtain information about the user a process is executing as, the null constructor us used.

  OUX_User user;
cout << user.name() << endl; // login name
cout << user.fullname() << endl; // real name
cout << user.uid() << endl; // user id
cout << user.gid() << endl; // group id
The class provides member functions for accessing the commonly used fields kept for a user in the UNIX password file.

To obtain information about a specific user the constructor can be passed the users login name, their user ID or a passwd file entry. If the information passed to the constructor does not describe a valid user the `isValid()' function will return OTCLIB_FALSE.

  OUX_User user("root");
if (user.isValid())
...
To obtain information about a UNIX group, the OUX_Group class is used. To obtain information about the group a process is executing as, the null constructor is used.

  OUX_Group group;
cout << group.name() << endl; // group name
cout << group.gid() << endl; // group id
OTC_Iterator<OTC_String> iter; // group members
iter = group.members();
for (iter.reset(); iter.isValid(); iter.next())
cout << iter.item() << endl;
Whether a user is a member of a group can be determined by using the `isMember()' member function.

  if (group.isMember("root"))
...
Information about a particular group can be obtained by passing the constructor either a group name, group ID or a group file entry. The `isValid()' member function will return OTCLIB_TRUE if the constructor arguments described a valid group.

Note that on some variants of UNIX, use of OUX_User and OUX_Group will result in the status of the system functions `getpwent()' and `getgrent()' being changed. Therefore, avoid using these system functions to consult successive entries in the passwd and group files at the same time as using the OUX_User and OUX_Group classes.

3 Blocking Signals

The method for blocking signals differs between versions of UNIX derived from BSD and versions derived from SYSV. The OUX_SignalBlock class provides a single interface for blocking signals, hiding the differences between the different versions of UNIX.

To use the class the list of signals to be blocked is passed to the constructor as a bit mask. If no argument is passed to the constructor, all signals which can be blocked, are blocked. The signals are unblocked when the instance of the OUX_SignalBlock class is destroyed.

  if (...)
{
OUX_SignalBlock block(SIGUSR1|SIGUSR2);
...
}