sg_get_user_stats(3)

NAME
sg_get_user_stats, sg_get_user_stats_r, sg_free_user_stats - get the current logged in users

SYNOPSIS
\FC#include <statgrab.h>\F[]

\FCsg_user_stats *sg_get_user_stats\F[]
\FC(size_t *entries);\F[]

\FCsg_user_stats *sg_get_user_stats_r\F[]
\FC(size_t *entries);\F[]

\FCsg_error sg_free_user_stats\F[]
\FC(sg_user_stats *data);\F[]

DESCRIPTION
The user statistics module delivers some information about logged on users. Each logon is treated separately. Both statistic get functions, \FCsg_get_user_stats\F[]() and \FCsg_get_user_stats_r\F[](), return a vector of \FCsg_user_stats\F[] with \FCentries\F[] elements.

API Shortcut
function | returns | data owner
sg_get_user_stats | \FCsg_user_stats\F[] * | libstatgrab (thread local)
sg_get_user_stats_r | \FCsg_user_stats\F[] * | caller

The \FCsg_user_stats\F[] vector received from \FCsg_get_user_stats_r\F[]() must be freed using \FCsg_free_user_stats\F[]() when not needed any more. The caller is responsible for doing it.

RETURN VALUES
The structure returned is of type \FCsg_user_stats\F[].

\FC
typedef struct {
        char *login_name;
        char *record_id;
        size_t record_id_size;
        char *device;
        char *hostname;
        pid_t pid;
        time_t login_time;
        time_t systime;
} sg_user_stats;
    \F[]

\FClogin_name\F[]
    The username which was used to log in

\FCrecord_id\F[]
    Record identifier of host database containing login information (not necessarily 0-terminated)

\FCrecord_id_size\F[]
    Size of the record identifier

\FCdevice\F[]
    Device name (eg. "pts/0") of the tty assigned to the login session

\FChostname\F[]
    (remote) Hostname from where the user is logged on, eg. "infoterm7.some.kind.of.domain.local", "localhost", "10.42.17.4" or ":0.0" (in case it's a local logon via new xterm)

\FCpid\F[]
    Process identifier of the process which made the entry to the logged on users database

\FClogin_time\F[]
    Timestamp (time in seconds since epoch) when the user logged on

\FCsystime\F[]
    The timestamp when the above stats where collected in seconds since epoch

SEE ALSO
statgrab(3)

WEBSITE
⟨https://libstatgrab.org/⟩