sys

package
v0.0.0-...-7eb09aa Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: GPL-3.0 Imports: 16 Imported by: 4

Documentation

Overview

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var TermEcho bool = true // keep track of the latest change to terminal echo  made by SetTermEcho function

Functions

func ErrorExit

func ErrorExit(template string, stuff ...interface{}) int

Print the message to stderr and exit the program with status 1. The function does not return, however it is defined to have a return value to help with coding style.

func Exec

func Exec(stdin io.Reader, stdout, stderr io.Writer, programName string, programArgs ...string) (exitStatus int,
	stdoutStr, stderrStr string, execErr error)

Run an external program, wait till it finishes execution, eventually return its exit status. Optionally return the program output only if stdout/stderr are left nil.

func GetHostnameAndIP

func GetHostnameAndIP() (hostname string, ip string)

Make a best effort at determining this computer's host name (FQDN preferred) and IP address.

func Input

func Input(mandatory bool, defaultHint string, format string, values ...interface{}) string

Print a prompt in stdout and return a trimmed line read from stdin. If mandatory switch is turned on, the function will keep asking for an input if default hint is unavailable.

func InputAbsFilePath

func InputAbsFilePath(mandatory bool, defaultHint string, format string, values ...interface{}) string

Print a prompt in stdout and return a file path (must exist be absolute) read from stdin.

func InputBool

func InputBool(defaultHint bool, format string, values ...interface{}) bool

Print a prompt in stdout and return a boolean value read from stdin.

func InputInt

func InputInt(mandatory bool, defaultHint, lowerLimit, upperLimit int, format string, values ...interface{}) int

Print a prompt in stdout and return an integer read from stdin.

func InputPassword

func InputPassword(mandatory bool, defaultHint string, format string, values ...interface{}) string

Disable terminal echo and read a password input from stdin, then re-enable terminal echo.

func LockMem

func LockMem()

Lock all program memory into main memory to prevent sensitive data from leaking into swap.

func SetTermEcho

func SetTermEcho(echo bool)

Enable or disable terminal echo.

func SystemctlDisableStop

func SystemctlDisableStop(svc string) error

SystemctlStop uses systemctl command to disable and stop a service.

func SystemctlEnableRestart

func SystemctlEnableRestart(svc string) error

Cal systemctl enable and then systemctl start on thing. Panic on error.

func SystemctlEnableStart

func SystemctlEnableStart(svc string) error

Cal systemctl enable and then systemctl start on the service.

func SystemctlGetMainPID

func SystemctlGetMainPID(svc string) (mainPID int)

Cal systemctl to get main PID of a service. Return 0 on failure.

func SystemctlIsRunning

func SystemctlIsRunning(svc string) bool

Return true only if systemctl suggests that the thing is running.

func SystemctlStart

func SystemctlStart(svc string) error

Call systemctl start on the service.

func SystemctlStop

func SystemctlStop(svc string) error

SystemctlStop uses systemctl command to stop a service.

func WalkProcs

func WalkProcs(fun func(cmdLine []string) bool) error

Run function on all running processes that are exposed via /proc.

Types

type Sysconfig

type Sysconfig struct {
	AllValues []*SysconfigEntry // All key-value pairs in the orignal order.
	KeyValue  map[string]*SysconfigEntry
}

Key-value pairs of a sysconfig file. It is able to convert back to original text in the original key order.

func ParseSysconfig

func ParseSysconfig(input string) (*Sysconfig, error)

Read sysconfig text and parse the text into memory structures.

func ParseSysconfigFile

func ParseSysconfigFile(fileName string, autoCreate bool) (*Sysconfig, error)

Read sysconfig file and parse the file content into memory structures.

func (*Sysconfig) GetBool

func (conf *Sysconfig) GetBool(key string, defaultValue bool) bool

Return bool value that belongs to the key, or the default value if key does not exist. True values are "yes" or "true".

func (*Sysconfig) GetInt

func (conf *Sysconfig) GetInt(key string, defaultValue int) int

Return integer value that belongs to the key, or the default if the key does not exist or value is not an integer.

func (*Sysconfig) GetIntArray

func (conf *Sysconfig) GetIntArray(key string, defaultValue []int) (ret []int)

Assume the key carries a space-separated array of integers, return the array. Discard malformed integers.

func (*Sysconfig) GetString

func (conf *Sysconfig) GetString(key, defaultValue string) string

Return string value that belongs to the key, or the default value if the key does not exist.

func (*Sysconfig) GetStringArray

func (conf *Sysconfig) GetStringArray(key string, defaultValue []string) (ret []string)

Assume the key carries a space-separated array value, return the value array.

func (*Sysconfig) GetUint64

func (conf *Sysconfig) GetUint64(key string, defaultValue uint64) uint64

Return uint64 value that belongs to the key, or the default if the key does not exist or value is not an integer.

func (*Sysconfig) Set

func (conf *Sysconfig) Set(key string, value interface{})

Set value for a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetIntArray

func (conf *Sysconfig) SetIntArray(key string, values []int)

Give a space-separated integer array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetStrArray

func (conf *Sysconfig) SetStrArray(key string, values []string)

Give a space-separated string array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) ToText

func (conf *Sysconfig) ToText() string

Convert key-value pairs back into text. Values are always surrounded by double-quotes.

type SysconfigEntry

type SysconfigEntry struct {
	LeadingComments []string // The comment lines leading to the key-value pair, including prefix '#', excluding end-of-line.
	Key             string   // The key.
	Value           string   // The value, excluding '=' character and double-quotes. Values will always come in double-quotes when converted to text.
}

A single key-value pair in sysconfig file.

Jump to

Keyboard shortcuts

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