utmp

package module
v2.0.0-...-1d180b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

README

Package utmp

The utmp package provides functionality to read and manipulate utmp entries in Go. It is a wrapper for the C function getuntent(). The package includes structs and methods to work with the utmp file, which contains information about user login sessions and terminated processes.

It is recommended to refer to the utmp manual (man utmp) for a deeper understanding of the utmp entries and their fields.

Types

type Utmp

Type Utmp is a struct that represents a utmp entry. It contains various fields to store information such as the entry type, process ID, device, user ID, username, hostname, exit status, session ID, timestamp, login time, and IPv6 address.

type Utmp struct {
	Type      int
	Pid       int
	Device    string
	Id        string
	Username  string
	HostName  string
	Exit      exit_status
	Session   int
	Seconds   int64
	MicroSecs int64
	Login     time.Time
	AddrV6    [4]int
}
type Users

Type Users holds all the historical data since boot time which includes logged out users and terminated processes. This data is stored in AllUsers. To filter out the historical data to show only the currently logged in users, LiveUsers has been defined.

type Users struct {
    AllUsers []Utmp  // All users including logged out users
    LiveUsers []Utmp // Utmp Type 7 users, see man Utmo
}
type exit_status

Type exit_status is a struct that represents the exit status of a terminated process. It has two fields: e_termination and e_exit, which store the termination and exit values, respectively.

type exit_status struct {
	e_termination int16
	e_exit        int16
}

Functions

ReadUtmp

ReadUtmp reads the utmp file and returns type Users.

func ReadUtmp() Users {
	...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Users

type Users struct {
	AllUsers  []Utmp // All users including logged out users
	LiveUsers []Utmp // Utmp Type 7 users, see man Utmo
}

func ReadUtmp

func ReadUtmp() Users

Read the utmp file

type Utmp

type Utmp struct {
	Type      int
	Pid       int
	Device    string
	Id        string
	Username  string
	HostName  string
	Exit      exit_status
	Session   int
	Seconds   int64
	MicroSecs int64
	Login     time.Time // added to make it easier getting the time
	AddrV6    [4]int    // issue?
}

man utmp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL