id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,600 | h2non/filetype | types/types.go | Get | func Get(ext string) Type {
kind := Types[ext]
if kind.Extension != "" {
return kind
}
return Unknown
} | go | func Get(ext string) Type {
kind := Types[ext]
if kind.Extension != "" {
return kind
}
return Unknown
} | [
"func",
"Get",
"(",
"ext",
"string",
")",
"Type",
"{",
"kind",
":=",
"Types",
"[",
"ext",
"]",
"\n",
"if",
"kind",
".",
"Extension",
"!=",
"\"",
"\"",
"{",
"return",
"kind",
"\n",
"}",
"\n",
"return",
"Unknown",
"\n",
"}"
] | // Get retrieves a Type by extension | [
"Get",
"retrieves",
"a",
"Type",
"by",
"extension"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/types.go#L12-L18 |
18,601 | h2non/filetype | filetype.go | AddType | func AddType(ext, mime string) types.Type {
return types.NewType(ext, mime)
} | go | func AddType(ext, mime string) types.Type {
return types.NewType(ext, mime)
} | [
"func",
"AddType",
"(",
"ext",
",",
"mime",
"string",
")",
"types",
".",
"Type",
"{",
"return",
"types",
".",
"NewType",
"(",
"ext",
",",
"mime",
")",
"\n",
"}"
] | // AddType registers a new file type | [
"AddType",
"registers",
"a",
"new",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L26-L28 |
18,602 | h2non/filetype | filetype.go | Is | func Is(buf []byte, ext string) bool {
kind, ok := types.Types[ext]
if ok {
return IsType(buf, kind)
}
return false
} | go | func Is(buf []byte, ext string) bool {
kind, ok := types.Types[ext]
if ok {
return IsType(buf, kind)
}
return false
} | [
"func",
"Is",
"(",
"buf",
"[",
"]",
"byte",
",",
"ext",
"string",
")",
"bool",
"{",
"kind",
",",
"ok",
":=",
"types",
".",
"Types",
"[",
"ext",
"]",
"\n",
"if",
"ok",
"{",
"return",
"IsType",
"(",
"buf",
",",
"kind",
")",
"\n",
"}",
"\n",
"re... | // Is checks if a given buffer matches with the given file type extension | [
"Is",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"file",
"type",
"extension"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L31-L37 |
18,603 | h2non/filetype | filetype.go | IsType | func IsType(buf []byte, kind types.Type) bool {
matcher := matchers.Matchers[kind]
if matcher == nil {
return false
}
return matcher(buf) != types.Unknown
} | go | func IsType(buf []byte, kind types.Type) bool {
matcher := matchers.Matchers[kind]
if matcher == nil {
return false
}
return matcher(buf) != types.Unknown
} | [
"func",
"IsType",
"(",
"buf",
"[",
"]",
"byte",
",",
"kind",
"types",
".",
"Type",
")",
"bool",
"{",
"matcher",
":=",
"matchers",
".",
"Matchers",
"[",
"kind",
"]",
"\n",
"if",
"matcher",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"retur... | // IsType checks if a given buffer matches with the given file type | [
"IsType",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L45-L51 |
18,604 | h2non/filetype | filetype.go | IsMIME | func IsMIME(buf []byte, mime string) bool {
for _, kind := range types.Types {
if kind.MIME.Value == mime {
matcher := matchers.Matchers[kind]
return matcher(buf) != types.Unknown
}
}
return false
} | go | func IsMIME(buf []byte, mime string) bool {
for _, kind := range types.Types {
if kind.MIME.Value == mime {
matcher := matchers.Matchers[kind]
return matcher(buf) != types.Unknown
}
}
return false
} | [
"func",
"IsMIME",
"(",
"buf",
"[",
"]",
"byte",
",",
"mime",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"kind",
":=",
"range",
"types",
".",
"Types",
"{",
"if",
"kind",
".",
"MIME",
".",
"Value",
"==",
"mime",
"{",
"matcher",
":=",
"matchers",
... | // IsMIME checks if a given buffer matches with the given MIME type | [
"IsMIME",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"MIME",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L54-L62 |
18,605 | h2non/filetype | filetype.go | IsSupported | func IsSupported(ext string) bool {
for name := range Types {
if name == ext {
return true
}
}
return false
} | go | func IsSupported(ext string) bool {
for name := range Types {
if name == ext {
return true
}
}
return false
} | [
"func",
"IsSupported",
"(",
"ext",
"string",
")",
"bool",
"{",
"for",
"name",
":=",
"range",
"Types",
"{",
"if",
"name",
"==",
"ext",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsSupported checks if a given file extension is supported | [
"IsSupported",
"checks",
"if",
"a",
"given",
"file",
"extension",
"is",
"supported"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L65-L72 |
18,606 | h2non/filetype | filetype.go | IsMIMESupported | func IsMIMESupported(mime string) bool {
for _, m := range Types {
if m.MIME.Value == mime {
return true
}
}
return false
} | go | func IsMIMESupported(mime string) bool {
for _, m := range Types {
if m.MIME.Value == mime {
return true
}
}
return false
} | [
"func",
"IsMIMESupported",
"(",
"mime",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"Types",
"{",
"if",
"m",
".",
"MIME",
".",
"Value",
"==",
"mime",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
... | // IsMIMESupported checks if a given MIME type is supported | [
"IsMIMESupported",
"checks",
"if",
"a",
"given",
"MIME",
"type",
"is",
"supported"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L75-L82 |
18,607 | h2non/filetype | types/mime.go | NewMIME | func NewMIME(mime string) MIME {
kind, subtype := splitMime(mime)
return MIME{Type: kind, Subtype: subtype, Value: mime}
} | go | func NewMIME(mime string) MIME {
kind, subtype := splitMime(mime)
return MIME{Type: kind, Subtype: subtype, Value: mime}
} | [
"func",
"NewMIME",
"(",
"mime",
"string",
")",
"MIME",
"{",
"kind",
",",
"subtype",
":=",
"splitMime",
"(",
"mime",
")",
"\n",
"return",
"MIME",
"{",
"Type",
":",
"kind",
",",
"Subtype",
":",
"subtype",
",",
"Value",
":",
"mime",
"}",
"\n",
"}"
] | // Creates a new MIME type | [
"Creates",
"a",
"new",
"MIME",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/mime.go#L11-L14 |
18,608 | h2non/filetype | matchers/matchers.go | NewMatcher | func NewMatcher(kind types.Type, fn Matcher) TypeMatcher {
matcher := func(buf []byte) types.Type {
if fn(buf) {
return kind
}
return types.Unknown
}
Matchers[kind] = matcher
// prepend here so any user defined matchers get added first
MatcherKeys = append([]types.Type{kind}, MatcherKeys...)
return matcher
} | go | func NewMatcher(kind types.Type, fn Matcher) TypeMatcher {
matcher := func(buf []byte) types.Type {
if fn(buf) {
return kind
}
return types.Unknown
}
Matchers[kind] = matcher
// prepend here so any user defined matchers get added first
MatcherKeys = append([]types.Type{kind}, MatcherKeys...)
return matcher
} | [
"func",
"NewMatcher",
"(",
"kind",
"types",
".",
"Type",
",",
"fn",
"Matcher",
")",
"TypeMatcher",
"{",
"matcher",
":=",
"func",
"(",
"buf",
"[",
"]",
"byte",
")",
"types",
".",
"Type",
"{",
"if",
"fn",
"(",
"buf",
")",
"{",
"return",
"kind",
"\n",... | // Create and register a new type matcher function | [
"Create",
"and",
"register",
"a",
"new",
"type",
"matcher",
"function"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/matchers.go#L24-L36 |
18,609 | h2non/filetype | types/type.go | NewType | func NewType(ext, mime string) Type {
t := Type{
MIME: NewMIME(mime),
Extension: ext,
}
return Add(t)
} | go | func NewType(ext, mime string) Type {
t := Type{
MIME: NewMIME(mime),
Extension: ext,
}
return Add(t)
} | [
"func",
"NewType",
"(",
"ext",
",",
"mime",
"string",
")",
"Type",
"{",
"t",
":=",
"Type",
"{",
"MIME",
":",
"NewMIME",
"(",
"mime",
")",
",",
"Extension",
":",
"ext",
",",
"}",
"\n",
"return",
"Add",
"(",
"t",
")",
"\n",
"}"
] | // NewType creates a new Type | [
"NewType",
"creates",
"a",
"new",
"Type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/type.go#L10-L16 |
18,610 | h2non/filetype | matchers/isobmff/isobmff.go | IsISOBMFF | func IsISOBMFF(buf []byte) bool {
if len(buf) < 16 || string(buf[4:8]) != "ftyp" {
return false
}
if ftypLength := binary.BigEndian.Uint32(buf[0:4]); len(buf) < int(ftypLength) {
return false
}
return true
} | go | func IsISOBMFF(buf []byte) bool {
if len(buf) < 16 || string(buf[4:8]) != "ftyp" {
return false
}
if ftypLength := binary.BigEndian.Uint32(buf[0:4]); len(buf) < int(ftypLength) {
return false
}
return true
} | [
"func",
"IsISOBMFF",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"16",
"||",
"string",
"(",
"buf",
"[",
"4",
":",
"8",
"]",
")",
"!=",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"ftypLe... | // IsISOBMFF checks whether the given buffer represents ISO Base Media File Format data | [
"IsISOBMFF",
"checks",
"whether",
"the",
"given",
"buffer",
"represents",
"ISO",
"Base",
"Media",
"File",
"Format",
"data"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/isobmff/isobmff.go#L6-L16 |
18,611 | h2non/filetype | matchers/isobmff/isobmff.go | GetFtyp | func GetFtyp(buf []byte) (string, string, []string) {
ftypLength := binary.BigEndian.Uint32(buf[0:4])
majorBrand := string(buf[8:12])
minorVersion := string(buf[12:16])
compatibleBrands := []string{}
for i := 16; i < int(ftypLength); i += 4 {
compatibleBrands = append(compatibleBrands, string(buf[i:i+4]))
}
return majorBrand, minorVersion, compatibleBrands
} | go | func GetFtyp(buf []byte) (string, string, []string) {
ftypLength := binary.BigEndian.Uint32(buf[0:4])
majorBrand := string(buf[8:12])
minorVersion := string(buf[12:16])
compatibleBrands := []string{}
for i := 16; i < int(ftypLength); i += 4 {
compatibleBrands = append(compatibleBrands, string(buf[i:i+4]))
}
return majorBrand, minorVersion, compatibleBrands
} | [
"func",
"GetFtyp",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"string",
",",
"[",
"]",
"string",
")",
"{",
"ftypLength",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"0",
":",
"4",
"]",
")",
"\n\n",
"majorBrand",
... | // GetFtyp returns the major brand, minor version and compatible brands of the ISO-BMFF data | [
"GetFtyp",
"returns",
"the",
"major",
"brand",
"minor",
"version",
"and",
"compatible",
"brands",
"of",
"the",
"ISO",
"-",
"BMFF",
"data"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/isobmff/isobmff.go#L19-L31 |
18,612 | h2non/filetype | match.go | Match | func Match(buf []byte) (types.Type, error) {
length := len(buf)
if length == 0 {
return types.Unknown, ErrEmptyBuffer
}
for _, kind := range *MatcherKeys {
checker := Matchers[kind]
match := checker(buf)
if match != types.Unknown && match.Extension != "" {
return match, nil
}
}
return types.Unknown, nil
} | go | func Match(buf []byte) (types.Type, error) {
length := len(buf)
if length == 0 {
return types.Unknown, ErrEmptyBuffer
}
for _, kind := range *MatcherKeys {
checker := Matchers[kind]
match := checker(buf)
if match != types.Unknown && match.Extension != "" {
return match, nil
}
}
return types.Unknown, nil
} | [
"func",
"Match",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"length",
":=",
"len",
"(",
"buf",
")",
"\n",
"if",
"length",
"==",
"0",
"{",
"return",
"types",
".",
"Unknown",
",",
"ErrEmptyBuffer",
"\n",
"... | // Match infers the file type of a given buffer inspecting its magic numbers signature | [
"Match",
"infers",
"the",
"file",
"type",
"of",
"a",
"given",
"buffer",
"inspecting",
"its",
"magic",
"numbers",
"signature"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L21-L36 |
18,613 | h2non/filetype | match.go | MatchFile | func MatchFile(filepath string) (types.Type, error) {
file, err := os.Open(filepath)
if err != nil {
return types.Unknown, err
}
defer file.Close()
return MatchReader(file)
} | go | func MatchFile(filepath string) (types.Type, error) {
file, err := os.Open(filepath)
if err != nil {
return types.Unknown, err
}
defer file.Close()
return MatchReader(file)
} | [
"func",
"MatchFile",
"(",
"filepath",
"string",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"Unknown",
",",
... | // MatchFile infers a file type for a file | [
"MatchFile",
"infers",
"a",
"file",
"type",
"for",
"a",
"file"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L44-L52 |
18,614 | h2non/filetype | match.go | AddMatcher | func AddMatcher(fileType types.Type, matcher matchers.Matcher) matchers.TypeMatcher {
return matchers.NewMatcher(fileType, matcher)
} | go | func AddMatcher(fileType types.Type, matcher matchers.Matcher) matchers.TypeMatcher {
return matchers.NewMatcher(fileType, matcher)
} | [
"func",
"AddMatcher",
"(",
"fileType",
"types",
".",
"Type",
",",
"matcher",
"matchers",
".",
"Matcher",
")",
"matchers",
".",
"TypeMatcher",
"{",
"return",
"matchers",
".",
"NewMatcher",
"(",
"fileType",
",",
"matcher",
")",
"\n",
"}"
] | // AddMatcher registers a new matcher type | [
"AddMatcher",
"registers",
"a",
"new",
"matcher",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L67-L69 |
18,615 | h2non/filetype | match.go | Matches | func Matches(buf []byte) bool {
kind, _ := Match(buf)
return kind != types.Unknown
} | go | func Matches(buf []byte) bool {
kind, _ := Match(buf)
return kind != types.Unknown
} | [
"func",
"Matches",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Match",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // Matches checks if the given buffer matches with some supported file type | [
"Matches",
"checks",
"if",
"the",
"given",
"buffer",
"matches",
"with",
"some",
"supported",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L72-L75 |
18,616 | h2non/filetype | match.go | MatchMap | func MatchMap(buf []byte, matchers matchers.Map) types.Type {
for kind, matcher := range matchers {
if matcher(buf) {
return kind
}
}
return types.Unknown
} | go | func MatchMap(buf []byte, matchers matchers.Map) types.Type {
for kind, matcher := range matchers {
if matcher(buf) {
return kind
}
}
return types.Unknown
} | [
"func",
"MatchMap",
"(",
"buf",
"[",
"]",
"byte",
",",
"matchers",
"matchers",
".",
"Map",
")",
"types",
".",
"Type",
"{",
"for",
"kind",
",",
"matcher",
":=",
"range",
"matchers",
"{",
"if",
"matcher",
"(",
"buf",
")",
"{",
"return",
"kind",
"\n",
... | // MatchMap performs a file matching against a map of match functions | [
"MatchMap",
"performs",
"a",
"file",
"matching",
"against",
"a",
"map",
"of",
"match",
"functions"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L78-L85 |
18,617 | coreos/go-systemd | sdjournal/read.go | NewJournalReader | func NewJournalReader(config JournalReaderConfig) (*JournalReader, error) {
// use simpleMessageFormatter as default formatter.
if config.Formatter == nil {
config.Formatter = simpleMessageFormatter
}
r := &JournalReader{
formatter: config.Formatter,
}
// Open the journal
var err error
if config.Path != "" {
r.journal, err = NewJournalFromDir(config.Path)
} else {
r.journal, err = NewJournal()
}
if err != nil {
return nil, err
}
// Add any supplied matches
for _, m := range config.Matches {
if err = r.journal.AddMatch(m.String()); err != nil {
return nil, err
}
}
// Set the start position based on options
if config.Since != 0 {
// Start based on a relative time
start := time.Now().Add(config.Since)
if err := r.journal.SeekRealtimeUsec(uint64(start.UnixNano() / 1000)); err != nil {
return nil, err
}
} else if config.NumFromTail != 0 {
// Start based on a number of lines before the tail
if err := r.journal.SeekTail(); err != nil {
return nil, err
}
// Move the read pointer into position near the tail. Go one further than
// the option so that the initial cursor advancement positions us at the
// correct starting point.
skip, err := r.journal.PreviousSkip(config.NumFromTail + 1)
if err != nil {
return nil, err
}
// If we skipped fewer lines than expected, we have reached journal start.
// Thus, we seek to head so that next invocation can read the first line.
if skip != config.NumFromTail+1 {
if err := r.journal.SeekHead(); err != nil {
return nil, err
}
}
} else if config.Cursor != "" {
// Start based on a custom cursor
if err := r.journal.SeekCursor(config.Cursor); err != nil {
return nil, err
}
}
return r, nil
} | go | func NewJournalReader(config JournalReaderConfig) (*JournalReader, error) {
// use simpleMessageFormatter as default formatter.
if config.Formatter == nil {
config.Formatter = simpleMessageFormatter
}
r := &JournalReader{
formatter: config.Formatter,
}
// Open the journal
var err error
if config.Path != "" {
r.journal, err = NewJournalFromDir(config.Path)
} else {
r.journal, err = NewJournal()
}
if err != nil {
return nil, err
}
// Add any supplied matches
for _, m := range config.Matches {
if err = r.journal.AddMatch(m.String()); err != nil {
return nil, err
}
}
// Set the start position based on options
if config.Since != 0 {
// Start based on a relative time
start := time.Now().Add(config.Since)
if err := r.journal.SeekRealtimeUsec(uint64(start.UnixNano() / 1000)); err != nil {
return nil, err
}
} else if config.NumFromTail != 0 {
// Start based on a number of lines before the tail
if err := r.journal.SeekTail(); err != nil {
return nil, err
}
// Move the read pointer into position near the tail. Go one further than
// the option so that the initial cursor advancement positions us at the
// correct starting point.
skip, err := r.journal.PreviousSkip(config.NumFromTail + 1)
if err != nil {
return nil, err
}
// If we skipped fewer lines than expected, we have reached journal start.
// Thus, we seek to head so that next invocation can read the first line.
if skip != config.NumFromTail+1 {
if err := r.journal.SeekHead(); err != nil {
return nil, err
}
}
} else if config.Cursor != "" {
// Start based on a custom cursor
if err := r.journal.SeekCursor(config.Cursor); err != nil {
return nil, err
}
}
return r, nil
} | [
"func",
"NewJournalReader",
"(",
"config",
"JournalReaderConfig",
")",
"(",
"*",
"JournalReader",
",",
"error",
")",
"{",
"// use simpleMessageFormatter as default formatter.",
"if",
"config",
".",
"Formatter",
"==",
"nil",
"{",
"config",
".",
"Formatter",
"=",
"sim... | // NewJournalReader creates a new JournalReader with configuration options that are similar to the
// systemd journalctl tool's iteration and filtering features. | [
"NewJournalReader",
"creates",
"a",
"new",
"JournalReader",
"with",
"configuration",
"options",
"that",
"are",
"similar",
"to",
"the",
"systemd",
"journalctl",
"tool",
"s",
"iteration",
"and",
"filtering",
"features",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L67-L130 |
18,618 | coreos/go-systemd | sdjournal/read.go | Rewind | func (r *JournalReader) Rewind() error {
r.msgReader = nil
return r.journal.SeekHead()
} | go | func (r *JournalReader) Rewind() error {
r.msgReader = nil
return r.journal.SeekHead()
} | [
"func",
"(",
"r",
"*",
"JournalReader",
")",
"Rewind",
"(",
")",
"error",
"{",
"r",
".",
"msgReader",
"=",
"nil",
"\n",
"return",
"r",
".",
"journal",
".",
"SeekHead",
"(",
")",
"\n",
"}"
] | // Rewind attempts to rewind the JournalReader to the first entry. | [
"Rewind",
"attempts",
"to",
"rewind",
"the",
"JournalReader",
"to",
"the",
"first",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L192-L195 |
18,619 | coreos/go-systemd | sdjournal/read.go | Follow | func (r *JournalReader) Follow(until <-chan time.Time, writer io.Writer) error {
// Process journal entries and events. Entries are flushed until the tail or
// timeout is reached, and then we wait for new events or the timeout.
var msg = make([]byte, 64*1<<(10))
var waitCh = make(chan int, 1)
var waitGroup sync.WaitGroup
defer waitGroup.Wait()
process:
for {
c, err := r.Read(msg)
if err != nil && err != io.EOF {
return err
}
select {
case <-until:
return ErrExpired
default:
}
if c > 0 {
if _, err = writer.Write(msg[:c]); err != nil {
return err
}
continue process
}
// We're at the tail, so wait for new events or time out.
// Holds journal events to process. Tightly bounded for now unless there's a
// reason to unblock the journal watch routine more quickly.
for {
waitGroup.Add(1)
go func() {
status := r.journal.Wait(100 * time.Millisecond)
waitCh <- status
waitGroup.Done()
}()
select {
case <-until:
return ErrExpired
case e := <-waitCh:
switch e {
case SD_JOURNAL_NOP:
// the journal did not change since the last invocation
case SD_JOURNAL_APPEND, SD_JOURNAL_INVALIDATE:
continue process
default:
if e < 0 {
return fmt.Errorf("received error event: %d", e)
}
log.Printf("received unknown event: %d\n", e)
}
}
}
}
} | go | func (r *JournalReader) Follow(until <-chan time.Time, writer io.Writer) error {
// Process journal entries and events. Entries are flushed until the tail or
// timeout is reached, and then we wait for new events or the timeout.
var msg = make([]byte, 64*1<<(10))
var waitCh = make(chan int, 1)
var waitGroup sync.WaitGroup
defer waitGroup.Wait()
process:
for {
c, err := r.Read(msg)
if err != nil && err != io.EOF {
return err
}
select {
case <-until:
return ErrExpired
default:
}
if c > 0 {
if _, err = writer.Write(msg[:c]); err != nil {
return err
}
continue process
}
// We're at the tail, so wait for new events or time out.
// Holds journal events to process. Tightly bounded for now unless there's a
// reason to unblock the journal watch routine more quickly.
for {
waitGroup.Add(1)
go func() {
status := r.journal.Wait(100 * time.Millisecond)
waitCh <- status
waitGroup.Done()
}()
select {
case <-until:
return ErrExpired
case e := <-waitCh:
switch e {
case SD_JOURNAL_NOP:
// the journal did not change since the last invocation
case SD_JOURNAL_APPEND, SD_JOURNAL_INVALIDATE:
continue process
default:
if e < 0 {
return fmt.Errorf("received error event: %d", e)
}
log.Printf("received unknown event: %d\n", e)
}
}
}
}
} | [
"func",
"(",
"r",
"*",
"JournalReader",
")",
"Follow",
"(",
"until",
"<-",
"chan",
"time",
".",
"Time",
",",
"writer",
"io",
".",
"Writer",
")",
"error",
"{",
"// Process journal entries and events. Entries are flushed until the tail or",
"// timeout is reached, and the... | // Follow synchronously follows the JournalReader, writing each new journal entry to writer. The
// follow will continue until a single time.Time is received on the until channel. | [
"Follow",
"synchronously",
"follows",
"the",
"JournalReader",
"writing",
"each",
"new",
"journal",
"entry",
"to",
"writer",
".",
"The",
"follow",
"will",
"continue",
"until",
"a",
"single",
"time",
".",
"Time",
"is",
"received",
"on",
"the",
"until",
"channel"... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L199-L257 |
18,620 | coreos/go-systemd | sdjournal/read.go | simpleMessageFormatter | func simpleMessageFormatter(entry *JournalEntry) (string, error) {
msg, ok := entry.Fields["MESSAGE"]
if !ok {
return "", fmt.Errorf("no MESSAGE field present in journal entry")
}
usec := entry.RealtimeTimestamp
timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))
return fmt.Sprintf("%s %s\n", timestamp, msg), nil
} | go | func simpleMessageFormatter(entry *JournalEntry) (string, error) {
msg, ok := entry.Fields["MESSAGE"]
if !ok {
return "", fmt.Errorf("no MESSAGE field present in journal entry")
}
usec := entry.RealtimeTimestamp
timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))
return fmt.Sprintf("%s %s\n", timestamp, msg), nil
} | [
"func",
"simpleMessageFormatter",
"(",
"entry",
"*",
"JournalEntry",
")",
"(",
"string",
",",
"error",
")",
"{",
"msg",
",",
"ok",
":=",
"entry",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
"."... | // simpleMessageFormatter is the default formatter.
// It returns a string representing the current journal entry in a simple format which
// includes the entry timestamp and MESSAGE field. | [
"simpleMessageFormatter",
"is",
"the",
"default",
"formatter",
".",
"It",
"returns",
"a",
"string",
"representing",
"the",
"current",
"journal",
"entry",
"in",
"a",
"simple",
"format",
"which",
"includes",
"the",
"entry",
"timestamp",
"and",
"MESSAGE",
"field",
... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L262-L272 |
18,621 | coreos/go-systemd | dbus/methods.go | KillUnit | func (c *Conn) KillUnit(name string, signal int32) {
c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store()
} | go | func (c *Conn) KillUnit(name string, signal int32) {
c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"KillUnit",
"(",
"name",
"string",
",",
"signal",
"int32",
")",
"{",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
",",
"\"",
"\"",
",",
"signal",
")",
".",
"Store",
"(",
")",
"\n... | // KillUnit takes the unit name and a UNIX signal number to send. All of the unit's
// processes are killed. | [
"KillUnit",
"takes",
"the",
"unit",
"name",
"and",
"a",
"UNIX",
"signal",
"number",
"to",
"send",
".",
"All",
"of",
"the",
"unit",
"s",
"processes",
"are",
"killed",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L143-L145 |
18,622 | coreos/go-systemd | dbus/methods.go | ResetFailedUnit | func (c *Conn) ResetFailedUnit(name string) error {
return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
} | go | func (c *Conn) ResetFailedUnit(name string) error {
return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ResetFailedUnit",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
")",
".",
"Store",
"(",
")",
"\n",
"}"
] | // ResetFailedUnit resets the "failed" state of a specific unit. | [
"ResetFailedUnit",
"resets",
"the",
"failed",
"state",
"of",
"a",
"specific",
"unit",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L148-L150 |
18,623 | coreos/go-systemd | dbus/methods.go | SystemState | func (c *Conn) SystemState() (*Property, error) {
var err error
var prop dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
if err != nil {
return nil, err
}
return &Property{Name: "SystemState", Value: prop}, nil
} | go | func (c *Conn) SystemState() (*Property, error) {
var err error
var prop dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
if err != nil {
return nil, err
}
return &Property{Name: "SystemState", Value: prop}, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SystemState",
"(",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"prop",
"dbus",
".",
"Variant",
"\n\n",
"obj",
":=",
"c",
".",
"sysconn",
".",
"Object",
"(",
"\"",
"\"... | // SystemState returns the systemd state. Equivalent to `systemctl is-system-running`. | [
"SystemState",
"returns",
"the",
"systemd",
"state",
".",
"Equivalent",
"to",
"systemctl",
"is",
"-",
"system",
"-",
"running",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L153-L164 |
18,624 | coreos/go-systemd | dbus/methods.go | getProperties | func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
var err error
var props map[string]dbus.Variant
if !path.IsValid() {
return nil, fmt.Errorf("invalid unit name: %v", path)
}
obj := c.sysconn.Object("org.freedesktop.systemd1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
if err != nil {
return nil, err
}
out := make(map[string]interface{}, len(props))
for k, v := range props {
out[k] = v.Value()
}
return out, nil
} | go | func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
var err error
var props map[string]dbus.Variant
if !path.IsValid() {
return nil, fmt.Errorf("invalid unit name: %v", path)
}
obj := c.sysconn.Object("org.freedesktop.systemd1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
if err != nil {
return nil, err
}
out := make(map[string]interface{}, len(props))
for k, v := range props {
out[k] = v.Value()
}
return out, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"getProperties",
"(",
"path",
"dbus",
".",
"ObjectPath",
",",
"dbusInterface",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"prop... | // getProperties takes the unit path and returns all of its dbus object properties, for the given dbus interface | [
"getProperties",
"takes",
"the",
"unit",
"path",
"and",
"returns",
"all",
"of",
"its",
"dbus",
"object",
"properties",
"for",
"the",
"given",
"dbus",
"interface"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L167-L187 |
18,625 | coreos/go-systemd | dbus/methods.go | GetServiceProperty | func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) {
return c.getProperty(service, "org.freedesktop.systemd1.Service", propertyName)
} | go | func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) {
return c.getProperty(service, "org.freedesktop.systemd1.Service", propertyName)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetServiceProperty",
"(",
"service",
"string",
",",
"propertyName",
"string",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"return",
"c",
".",
"getProperty",
"(",
"service",
",",
"\"",
"\"",
",",
"propertyName",... | // GetServiceProperty returns property for given service name and property name | [
"GetServiceProperty",
"returns",
"property",
"for",
"given",
"service",
"name",
"and",
"property",
"name"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L223-L225 |
18,626 | coreos/go-systemd | dbus/methods.go | ListUnitsFiltered | func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
} | go | func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitsFiltered",
"(",
"states",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitStatus",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitsInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",... | // ListUnitsFiltered returns an array with units filtered by state.
// It takes a list of units' statuses to filter. | [
"ListUnitsFiltered",
"returns",
"an",
"array",
"with",
"units",
"filtered",
"by",
"state",
".",
"It",
"takes",
"a",
"list",
"of",
"units",
"statuses",
"to",
"filter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L302-L304 |
18,627 | coreos/go-systemd | dbus/methods.go | ListUnitsByPatterns | func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
} | go | func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitsByPatterns",
"(",
"states",
"[",
"]",
"string",
",",
"patterns",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitStatus",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitsInternal",
"(",
"c",
".",
"syso... | // ListUnitsByPatterns returns an array with units.
// It takes a list of units' statuses and names to filter.
// Note that units may be known by multiple names at the same time,
// and hence there might be more unit names loaded than actual units behind them. | [
"ListUnitsByPatterns",
"returns",
"an",
"array",
"with",
"units",
".",
"It",
"takes",
"a",
"list",
"of",
"units",
"statuses",
"and",
"names",
"to",
"filter",
".",
"Note",
"that",
"units",
"may",
"be",
"known",
"by",
"multiple",
"names",
"at",
"the",
"same"... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L310-L312 |
18,628 | coreos/go-systemd | dbus/methods.go | ListUnitFiles | func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
} | go | func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitFiles",
"(",
")",
"(",
"[",
"]",
"UnitFile",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitFilesInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
")",
".",
"Store",
")"... | // ListUnitFiles returns an array of all available units on disk. | [
"ListUnitFiles",
"returns",
"an",
"array",
"of",
"all",
"available",
"units",
"on",
"disk",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L355-L357 |
18,629 | coreos/go-systemd | dbus/methods.go | ListUnitFilesByPatterns | func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
} | go | func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitFilesByPatterns",
"(",
"states",
"[",
"]",
"string",
",",
"patterns",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitFile",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitFilesInternal",
"(",
"c",
".",
... | // ListUnitFilesByPatterns returns an array of all available units on disk matched the patterns. | [
"ListUnitFilesByPatterns",
"returns",
"an",
"array",
"of",
"all",
"available",
"units",
"on",
"disk",
"matched",
"the",
"patterns",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L360-L362 |
18,630 | coreos/go-systemd | dbus/methods.go | unitName | func unitName(dpath dbus.ObjectPath) string {
return pathBusUnescape(path.Base(string(dpath)))
} | go | func unitName(dpath dbus.ObjectPath) string {
return pathBusUnescape(path.Base(string(dpath)))
} | [
"func",
"unitName",
"(",
"dpath",
"dbus",
".",
"ObjectPath",
")",
"string",
"{",
"return",
"pathBusUnescape",
"(",
"path",
".",
"Base",
"(",
"string",
"(",
"dpath",
")",
")",
")",
"\n",
"}"
] | // unitName returns the unescaped base element of the supplied escaped path | [
"unitName",
"returns",
"the",
"unescaped",
"base",
"element",
"of",
"the",
"supplied",
"escaped",
"path"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L592-L594 |
18,631 | coreos/go-systemd | unit/option.go | NewUnitOption | func NewUnitOption(section, name, value string) *UnitOption {
return &UnitOption{Section: section, Name: name, Value: value}
} | go | func NewUnitOption(section, name, value string) *UnitOption {
return &UnitOption{Section: section, Name: name, Value: value}
} | [
"func",
"NewUnitOption",
"(",
"section",
",",
"name",
",",
"value",
"string",
")",
"*",
"UnitOption",
"{",
"return",
"&",
"UnitOption",
"{",
"Section",
":",
"section",
",",
"Name",
":",
"name",
",",
"Value",
":",
"value",
"}",
"\n",
"}"
] | // NewUnitOption returns a new UnitOption instance with pre-set values. | [
"NewUnitOption",
"returns",
"a",
"new",
"UnitOption",
"instance",
"with",
"pre",
"-",
"set",
"values",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L29-L31 |
18,632 | coreos/go-systemd | unit/option.go | Match | func (uo *UnitOption) Match(other *UnitOption) bool {
return uo.Section == other.Section &&
uo.Name == other.Name &&
uo.Value == other.Value
} | go | func (uo *UnitOption) Match(other *UnitOption) bool {
return uo.Section == other.Section &&
uo.Name == other.Name &&
uo.Value == other.Value
} | [
"func",
"(",
"uo",
"*",
"UnitOption",
")",
"Match",
"(",
"other",
"*",
"UnitOption",
")",
"bool",
"{",
"return",
"uo",
".",
"Section",
"==",
"other",
".",
"Section",
"&&",
"uo",
".",
"Name",
"==",
"other",
".",
"Name",
"&&",
"uo",
".",
"Value",
"==... | // Match compares two UnitOptions and returns true if they are identical. | [
"Match",
"compares",
"two",
"UnitOptions",
"and",
"returns",
"true",
"if",
"they",
"are",
"identical",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L38-L42 |
18,633 | coreos/go-systemd | unit/option.go | AllMatch | func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
length := len(u1)
if length != len(u2) {
return false
}
for i := 0; i < length; i++ {
if !u1[i].Match(u2[i]) {
return false
}
}
return true
} | go | func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
length := len(u1)
if length != len(u2) {
return false
}
for i := 0; i < length; i++ {
if !u1[i].Match(u2[i]) {
return false
}
}
return true
} | [
"func",
"AllMatch",
"(",
"u1",
"[",
"]",
"*",
"UnitOption",
",",
"u2",
"[",
"]",
"*",
"UnitOption",
")",
"bool",
"{",
"length",
":=",
"len",
"(",
"u1",
")",
"\n",
"if",
"length",
"!=",
"len",
"(",
"u2",
")",
"{",
"return",
"false",
"\n",
"}",
"... | // AllMatch compares two slices of UnitOptions and returns true if they are
// identical. | [
"AllMatch",
"compares",
"two",
"slices",
"of",
"UnitOptions",
"and",
"returns",
"true",
"if",
"they",
"are",
"identical",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L46-L59 |
18,634 | coreos/go-systemd | dbus/dbus.go | needsEscape | func needsEscape(i int, b byte) bool {
// Escape everything that is not a-z-A-Z-0-9
// Also escape 0-9 if it's the first character
return strings.IndexByte(alphanum, b) == -1 ||
(i == 0 && strings.IndexByte(num, b) != -1)
} | go | func needsEscape(i int, b byte) bool {
// Escape everything that is not a-z-A-Z-0-9
// Also escape 0-9 if it's the first character
return strings.IndexByte(alphanum, b) == -1 ||
(i == 0 && strings.IndexByte(num, b) != -1)
} | [
"func",
"needsEscape",
"(",
"i",
"int",
",",
"b",
"byte",
")",
"bool",
"{",
"// Escape everything that is not a-z-A-Z-0-9",
"// Also escape 0-9 if it's the first character",
"return",
"strings",
".",
"IndexByte",
"(",
"alphanum",
",",
"b",
")",
"==",
"-",
"1",
"||",... | // needsEscape checks whether a byte in a potential dbus ObjectPath needs to be escaped | [
"needsEscape",
"checks",
"whether",
"a",
"byte",
"in",
"a",
"potential",
"dbus",
"ObjectPath",
"needs",
"to",
"be",
"escaped"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L37-L42 |
18,635 | coreos/go-systemd | dbus/dbus.go | PathBusEscape | func PathBusEscape(path string) string {
// Special case the empty string
if len(path) == 0 {
return "_"
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if needsEscape(i, c) {
e := fmt.Sprintf("_%x", c)
n = append(n, []byte(e)...)
} else {
n = append(n, c)
}
}
return string(n)
} | go | func PathBusEscape(path string) string {
// Special case the empty string
if len(path) == 0 {
return "_"
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if needsEscape(i, c) {
e := fmt.Sprintf("_%x", c)
n = append(n, []byte(e)...)
} else {
n = append(n, c)
}
}
return string(n)
} | [
"func",
"PathBusEscape",
"(",
"path",
"string",
")",
"string",
"{",
"// Special case the empty string",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"n",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"i",
":=... | // PathBusEscape sanitizes a constituent string of a dbus ObjectPath using the
// rules that systemd uses for serializing special characters. | [
"PathBusEscape",
"sanitizes",
"a",
"constituent",
"string",
"of",
"a",
"dbus",
"ObjectPath",
"using",
"the",
"rules",
"that",
"systemd",
"uses",
"for",
"serializing",
"special",
"characters",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L46-L62 |
18,636 | coreos/go-systemd | dbus/dbus.go | pathBusUnescape | func pathBusUnescape(path string) string {
if path == "_" {
return ""
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if c == '_' && i+2 < len(path) {
res, err := hex.DecodeString(path[i+1 : i+3])
if err == nil {
n = append(n, res...)
}
i += 2
} else {
n = append(n, c)
}
}
return string(n)
} | go | func pathBusUnescape(path string) string {
if path == "_" {
return ""
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if c == '_' && i+2 < len(path) {
res, err := hex.DecodeString(path[i+1 : i+3])
if err == nil {
n = append(n, res...)
}
i += 2
} else {
n = append(n, c)
}
}
return string(n)
} | [
"func",
"pathBusUnescape",
"(",
"path",
"string",
")",
"string",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"n",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"... | // pathBusUnescape is the inverse of PathBusEscape. | [
"pathBusUnescape",
"is",
"the",
"inverse",
"of",
"PathBusEscape",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L65-L83 |
18,637 | coreos/go-systemd | dbus/subscription.go | SubscribeUnits | func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustom(interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil)
} | go | func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustom(interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SubscribeUnits",
"(",
"interval",
"time",
".",
"Duration",
")",
"(",
"<-",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"<-",
"chan",
"error",
")",
"{",
"return",
"c",
".",
"SubscribeUnitsCustom",
"(",... | // SubscribeUnits returns two unbuffered channels which will receive all changed units every
// interval. Deleted units are sent as nil. | [
"SubscribeUnits",
"returns",
"two",
"unbuffered",
"channels",
"which",
"will",
"receive",
"all",
"changed",
"units",
"every",
"interval",
".",
"Deleted",
"units",
"are",
"sent",
"as",
"nil",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L99-L101 |
18,638 | coreos/go-systemd | dbus/subscription.go | SubscribeUnitsCustom | func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
old := make(map[string]*UnitStatus)
statusChan := make(chan map[string]*UnitStatus, buffer)
errChan := make(chan error, buffer)
go func() {
for {
timerChan := time.After(interval)
units, err := c.ListUnits()
if err == nil {
cur := make(map[string]*UnitStatus)
for i := range units {
if filterUnit != nil && filterUnit(units[i].Name) {
continue
}
cur[units[i].Name] = &units[i]
}
// add all new or changed units
changed := make(map[string]*UnitStatus)
for n, u := range cur {
if oldU, ok := old[n]; !ok || isChanged(oldU, u) {
changed[n] = u
}
delete(old, n)
}
// add all deleted units
for oldN := range old {
changed[oldN] = nil
}
old = cur
if len(changed) != 0 {
statusChan <- changed
}
} else {
errChan <- err
}
<-timerChan
}
}()
return statusChan, errChan
} | go | func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
old := make(map[string]*UnitStatus)
statusChan := make(chan map[string]*UnitStatus, buffer)
errChan := make(chan error, buffer)
go func() {
for {
timerChan := time.After(interval)
units, err := c.ListUnits()
if err == nil {
cur := make(map[string]*UnitStatus)
for i := range units {
if filterUnit != nil && filterUnit(units[i].Name) {
continue
}
cur[units[i].Name] = &units[i]
}
// add all new or changed units
changed := make(map[string]*UnitStatus)
for n, u := range cur {
if oldU, ok := old[n]; !ok || isChanged(oldU, u) {
changed[n] = u
}
delete(old, n)
}
// add all deleted units
for oldN := range old {
changed[oldN] = nil
}
old = cur
if len(changed) != 0 {
statusChan <- changed
}
} else {
errChan <- err
}
<-timerChan
}
}()
return statusChan, errChan
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SubscribeUnitsCustom",
"(",
"interval",
"time",
".",
"Duration",
",",
"buffer",
"int",
",",
"isChanged",
"func",
"(",
"*",
"UnitStatus",
",",
"*",
"UnitStatus",
")",
"bool",
",",
"filterUnit",
"func",
"(",
"string",
"... | // SubscribeUnitsCustom is like SubscribeUnits but lets you specify the buffer
// size of the channels, the comparison function for detecting changes and a filter
// function for cutting down on the noise that your channel receives. | [
"SubscribeUnitsCustom",
"is",
"like",
"SubscribeUnits",
"but",
"lets",
"you",
"specify",
"the",
"buffer",
"size",
"of",
"the",
"channels",
"the",
"comparison",
"function",
"for",
"detecting",
"changes",
"and",
"a",
"filter",
"function",
"for",
"cutting",
"down",
... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L106-L153 |
18,639 | coreos/go-systemd | dbus/subscription.go | cleanIgnore | func (c *Conn) cleanIgnore() {
now := time.Now().UnixNano()
if c.subStateSubscriber.cleanIgnore < now {
c.subStateSubscriber.cleanIgnore = now + cleanIgnoreInterval
for p, t := range c.subStateSubscriber.ignore {
if t < now {
delete(c.subStateSubscriber.ignore, p)
}
}
}
} | go | func (c *Conn) cleanIgnore() {
now := time.Now().UnixNano()
if c.subStateSubscriber.cleanIgnore < now {
c.subStateSubscriber.cleanIgnore = now + cleanIgnoreInterval
for p, t := range c.subStateSubscriber.ignore {
if t < now {
delete(c.subStateSubscriber.ignore, p)
}
}
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"cleanIgnore",
"(",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"if",
"c",
".",
"subStateSubscriber",
".",
"cleanIgnore",
"<",
"now",
"{",
"c",
".",
"subStateSubscriber",
... | // without this, ignore would grow unboundedly over time | [
"without",
"this",
"ignore",
"would",
"grow",
"unboundedly",
"over",
"time"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L278-L289 |
18,640 | coreos/go-systemd | dbus/subscription_set.go | Subscribe | func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustom(time.Second, 0,
mismatchUnitStatus,
func(unit string) bool { return s.filter(unit) },
)
} | go | func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustom(time.Second, 0,
mismatchUnitStatus,
func(unit string) bool { return s.filter(unit) },
)
} | [
"func",
"(",
"s",
"*",
"SubscriptionSet",
")",
"Subscribe",
"(",
")",
"(",
"<-",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"<-",
"chan",
"error",
")",
"{",
"// TODO: Make fully evented by using systemd 209 with properties changed values",
"return",
... | // Subscribe starts listening for dbus events for all of the units in the set.
// Returns channels identical to conn.SubscribeUnits. | [
"Subscribe",
"starts",
"listening",
"for",
"dbus",
"events",
"for",
"all",
"of",
"the",
"units",
"in",
"the",
"set",
".",
"Returns",
"channels",
"identical",
"to",
"conn",
".",
"SubscribeUnits",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription_set.go#L34-L40 |
18,641 | coreos/go-systemd | dbus/subscription_set.go | mismatchUnitStatus | func mismatchUnitStatus(u1, u2 *UnitStatus) bool {
return u1.Name != u2.Name ||
u1.Description != u2.Description ||
u1.LoadState != u2.LoadState ||
u1.ActiveState != u2.ActiveState ||
u1.SubState != u2.SubState
} | go | func mismatchUnitStatus(u1, u2 *UnitStatus) bool {
return u1.Name != u2.Name ||
u1.Description != u2.Description ||
u1.LoadState != u2.LoadState ||
u1.ActiveState != u2.ActiveState ||
u1.SubState != u2.SubState
} | [
"func",
"mismatchUnitStatus",
"(",
"u1",
",",
"u2",
"*",
"UnitStatus",
")",
"bool",
"{",
"return",
"u1",
".",
"Name",
"!=",
"u2",
".",
"Name",
"||",
"u1",
".",
"Description",
"!=",
"u2",
".",
"Description",
"||",
"u1",
".",
"LoadState",
"!=",
"u2",
"... | // mismatchUnitStatus returns true if the provided UnitStatus objects
// are not equivalent. false is returned if the objects are equivalent.
// Only the Name, Description and state-related fields are used in
// the comparison. | [
"mismatchUnitStatus",
"returns",
"true",
"if",
"the",
"provided",
"UnitStatus",
"objects",
"are",
"not",
"equivalent",
".",
"false",
"is",
"returned",
"if",
"the",
"objects",
"are",
"equivalent",
".",
"Only",
"the",
"Name",
"Description",
"and",
"state",
"-",
... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription_set.go#L51-L57 |
18,642 | coreos/go-systemd | unit/serialize.go | Serialize | func Serialize(opts []*UnitOption) io.Reader {
var buf bytes.Buffer
if len(opts) == 0 {
return &buf
}
// Index of sections -> ordered options
idx := map[string][]*UnitOption{}
// Separately preserve order in which sections were seen
sections := []string{}
for _, opt := range opts {
sec := opt.Section
if _, ok := idx[sec]; !ok {
sections = append(sections, sec)
}
idx[sec] = append(idx[sec], opt)
}
for i, sect := range sections {
writeSectionHeader(&buf, sect)
writeNewline(&buf)
opts := idx[sect]
for _, opt := range opts {
writeOption(&buf, opt)
writeNewline(&buf)
}
if i < len(sections)-1 {
writeNewline(&buf)
}
}
return &buf
} | go | func Serialize(opts []*UnitOption) io.Reader {
var buf bytes.Buffer
if len(opts) == 0 {
return &buf
}
// Index of sections -> ordered options
idx := map[string][]*UnitOption{}
// Separately preserve order in which sections were seen
sections := []string{}
for _, opt := range opts {
sec := opt.Section
if _, ok := idx[sec]; !ok {
sections = append(sections, sec)
}
idx[sec] = append(idx[sec], opt)
}
for i, sect := range sections {
writeSectionHeader(&buf, sect)
writeNewline(&buf)
opts := idx[sect]
for _, opt := range opts {
writeOption(&buf, opt)
writeNewline(&buf)
}
if i < len(sections)-1 {
writeNewline(&buf)
}
}
return &buf
} | [
"func",
"Serialize",
"(",
"opts",
"[",
"]",
"*",
"UnitOption",
")",
"io",
".",
"Reader",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"len",
"(",
"opts",
")",
"==",
"0",
"{",
"return",
"&",
"buf",
"\n",
"}",
"\n\n",
"// Index of sections ... | // Serialize encodes all of the given UnitOption objects into a
// unit file. When serialized the options are sorted in their
// supplied order but grouped by section. | [
"Serialize",
"encodes",
"all",
"of",
"the",
"given",
"UnitOption",
"objects",
"into",
"a",
"unit",
"file",
".",
"When",
"serialized",
"the",
"options",
"are",
"sorted",
"in",
"their",
"supplied",
"order",
"but",
"grouped",
"by",
"section",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/serialize.go#L25-L59 |
18,643 | coreos/go-systemd | sdjournal/journal.go | NewJournal | func NewJournal() (j *Journal, err error) {
j = &Journal{}
sd_journal_open, err := getFunction("sd_journal_open")
if err != nil {
return nil, err
}
r := C.my_sd_journal_open(sd_journal_open, &j.cjournal, C.SD_JOURNAL_LOCAL_ONLY)
if r < 0 {
return nil, fmt.Errorf("failed to open journal: %d", syscall.Errno(-r))
}
return j, nil
} | go | func NewJournal() (j *Journal, err error) {
j = &Journal{}
sd_journal_open, err := getFunction("sd_journal_open")
if err != nil {
return nil, err
}
r := C.my_sd_journal_open(sd_journal_open, &j.cjournal, C.SD_JOURNAL_LOCAL_ONLY)
if r < 0 {
return nil, fmt.Errorf("failed to open journal: %d", syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournal",
"(",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // NewJournal returns a new Journal instance pointing to the local journal | [
"NewJournal",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"the",
"local",
"journal"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L406-L421 |
18,644 | coreos/go-systemd | sdjournal/journal.go | NewJournalFromDir | func NewJournalFromDir(path string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_directory, err := getFunction("sd_journal_open_directory")
if err != nil {
return nil, err
}
p := C.CString(path)
defer C.free(unsafe.Pointer(p))
r := C.my_sd_journal_open_directory(sd_journal_open_directory, &j.cjournal, p, 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journal in directory %q: %d", path, syscall.Errno(-r))
}
return j, nil
} | go | func NewJournalFromDir(path string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_directory, err := getFunction("sd_journal_open_directory")
if err != nil {
return nil, err
}
p := C.CString(path)
defer C.free(unsafe.Pointer(p))
r := C.my_sd_journal_open_directory(sd_journal_open_directory, &j.cjournal, p, 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journal in directory %q: %d", path, syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournalFromDir",
"(",
"path",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_directory",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if"... | // NewJournalFromDir returns a new Journal instance pointing to a journal residing
// in a given directory. | [
"NewJournalFromDir",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"a",
"journal",
"residing",
"in",
"a",
"given",
"directory",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L425-L442 |
18,645 | coreos/go-systemd | sdjournal/journal.go | NewJournalFromFiles | func NewJournalFromFiles(paths ...string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_files, err := getFunction("sd_journal_open_files")
if err != nil {
return nil, err
}
// by making the slice 1 elem too long, we guarantee it'll be null-terminated
cPaths := make([]*C.char, len(paths)+1)
for idx, path := range paths {
p := C.CString(path)
cPaths[idx] = p
defer C.free(unsafe.Pointer(p))
}
r := C.my_sd_journal_open_files(sd_journal_open_files, &j.cjournal, &cPaths[0], 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journals in paths %q: %d", paths, syscall.Errno(-r))
}
return j, nil
} | go | func NewJournalFromFiles(paths ...string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_files, err := getFunction("sd_journal_open_files")
if err != nil {
return nil, err
}
// by making the slice 1 elem too long, we guarantee it'll be null-terminated
cPaths := make([]*C.char, len(paths)+1)
for idx, path := range paths {
p := C.CString(path)
cPaths[idx] = p
defer C.free(unsafe.Pointer(p))
}
r := C.my_sd_journal_open_files(sd_journal_open_files, &j.cjournal, &cPaths[0], 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journals in paths %q: %d", paths, syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournalFromFiles",
"(",
"paths",
"...",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_files",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n"... | // NewJournalFromFiles returns a new Journal instance pointing to a journals residing
// in a given files. | [
"NewJournalFromFiles",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"a",
"journals",
"residing",
"in",
"a",
"given",
"files",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L446-L468 |
18,646 | coreos/go-systemd | sdjournal/journal.go | Close | func (j *Journal) Close() error {
sd_journal_close, err := getFunction("sd_journal_close")
if err != nil {
return err
}
j.mu.Lock()
C.my_sd_journal_close(sd_journal_close, j.cjournal)
j.mu.Unlock()
return nil
} | go | func (j *Journal) Close() error {
sd_journal_close, err := getFunction("sd_journal_close")
if err != nil {
return err
}
j.mu.Lock()
C.my_sd_journal_close(sd_journal_close, j.cjournal)
j.mu.Unlock()
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Close",
"(",
")",
"error",
"{",
"sd_journal_close",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock... | // Close closes a journal opened with NewJournal. | [
"Close",
"closes",
"a",
"journal",
"opened",
"with",
"NewJournal",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L471-L482 |
18,647 | coreos/go-systemd | sdjournal/journal.go | AddMatch | func (j *Journal) AddMatch(match string) error {
sd_journal_add_match, err := getFunction("sd_journal_add_match")
if err != nil {
return err
}
m := C.CString(match)
defer C.free(unsafe.Pointer(m))
j.mu.Lock()
r := C.my_sd_journal_add_match(sd_journal_add_match, j.cjournal, unsafe.Pointer(m), C.size_t(len(match)))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add match: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddMatch(match string) error {
sd_journal_add_match, err := getFunction("sd_journal_add_match")
if err != nil {
return err
}
m := C.CString(match)
defer C.free(unsafe.Pointer(m))
j.mu.Lock()
r := C.my_sd_journal_add_match(sd_journal_add_match, j.cjournal, unsafe.Pointer(m), C.size_t(len(match)))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add match: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddMatch",
"(",
"match",
"string",
")",
"error",
"{",
"sd_journal_add_match",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",... | // AddMatch adds a match by which to filter the entries of the journal. | [
"AddMatch",
"adds",
"a",
"match",
"by",
"which",
"to",
"filter",
"the",
"entries",
"of",
"the",
"journal",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L485-L503 |
18,648 | coreos/go-systemd | sdjournal/journal.go | AddDisjunction | func (j *Journal) AddDisjunction() error {
sd_journal_add_disjunction, err := getFunction("sd_journal_add_disjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_disjunction(sd_journal_add_disjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddDisjunction() error {
sd_journal_add_disjunction, err := getFunction("sd_journal_add_disjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_disjunction(sd_journal_add_disjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddDisjunction",
"(",
")",
"error",
"{",
"sd_journal_add_disjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"... | // AddDisjunction inserts a logical OR in the match list. | [
"AddDisjunction",
"inserts",
"a",
"logical",
"OR",
"in",
"the",
"match",
"list",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L506-L521 |
18,649 | coreos/go-systemd | sdjournal/journal.go | AddConjunction | func (j *Journal) AddConjunction() error {
sd_journal_add_conjunction, err := getFunction("sd_journal_add_conjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_conjunction(sd_journal_add_conjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a conjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddConjunction() error {
sd_journal_add_conjunction, err := getFunction("sd_journal_add_conjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_conjunction(sd_journal_add_conjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a conjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddConjunction",
"(",
")",
"error",
"{",
"sd_journal_add_conjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"... | // AddConjunction inserts a logical AND in the match list. | [
"AddConjunction",
"inserts",
"a",
"logical",
"AND",
"in",
"the",
"match",
"list",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L524-L539 |
18,650 | coreos/go-systemd | sdjournal/journal.go | FlushMatches | func (j *Journal) FlushMatches() {
sd_journal_flush_matches, err := getFunction("sd_journal_flush_matches")
if err != nil {
return
}
j.mu.Lock()
C.my_sd_journal_flush_matches(sd_journal_flush_matches, j.cjournal)
j.mu.Unlock()
} | go | func (j *Journal) FlushMatches() {
sd_journal_flush_matches, err := getFunction("sd_journal_flush_matches")
if err != nil {
return
}
j.mu.Lock()
C.my_sd_journal_flush_matches(sd_journal_flush_matches, j.cjournal)
j.mu.Unlock()
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"FlushMatches",
"(",
")",
"{",
"sd_journal_flush_matches",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
... | // FlushMatches flushes all matches, disjunctions and conjunctions. | [
"FlushMatches",
"flushes",
"all",
"matches",
"disjunctions",
"and",
"conjunctions",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L542-L551 |
18,651 | coreos/go-systemd | sdjournal/journal.go | Next | func (j *Journal) Next() (uint64, error) {
sd_journal_next, err := getFunction("sd_journal_next")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next(sd_journal_next, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) Next() (uint64, error) {
sd_journal_next, err := getFunction("sd_journal_next")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next(sd_journal_next, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Next",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
... | // Next advances the read pointer into the journal by one entry. | [
"Next",
"advances",
"the",
"read",
"pointer",
"into",
"the",
"journal",
"by",
"one",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L554-L569 |
18,652 | coreos/go-systemd | sdjournal/journal.go | NextSkip | func (j *Journal) NextSkip(skip uint64) (uint64, error) {
sd_journal_next_skip, err := getFunction("sd_journal_next_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next_skip(sd_journal_next_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) NextSkip(skip uint64) (uint64, error) {
sd_journal_next_skip, err := getFunction("sd_journal_next_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next_skip(sd_journal_next_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"NextSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
... | // NextSkip advances the read pointer by multiple entries at once,
// as specified by the skip parameter. | [
"NextSkip",
"advances",
"the",
"read",
"pointer",
"by",
"multiple",
"entries",
"at",
"once",
"as",
"specified",
"by",
"the",
"skip",
"parameter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L573-L588 |
18,653 | coreos/go-systemd | sdjournal/journal.go | Previous | func (j *Journal) Previous() (uint64, error) {
sd_journal_previous, err := getFunction("sd_journal_previous")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous(sd_journal_previous, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) Previous() (uint64, error) {
sd_journal_previous, err := getFunction("sd_journal_previous")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous(sd_journal_previous, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Previous",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
... | // Previous sets the read pointer into the journal back by one entry. | [
"Previous",
"sets",
"the",
"read",
"pointer",
"into",
"the",
"journal",
"back",
"by",
"one",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L591-L606 |
18,654 | coreos/go-systemd | sdjournal/journal.go | PreviousSkip | func (j *Journal) PreviousSkip(skip uint64) (uint64, error) {
sd_journal_previous_skip, err := getFunction("sd_journal_previous_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous_skip(sd_journal_previous_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) PreviousSkip(skip uint64) (uint64, error) {
sd_journal_previous_skip, err := getFunction("sd_journal_previous_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous_skip(sd_journal_previous_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"PreviousSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // PreviousSkip sets back the read pointer by multiple entries at once,
// as specified by the skip parameter. | [
"PreviousSkip",
"sets",
"back",
"the",
"read",
"pointer",
"by",
"multiple",
"entries",
"at",
"once",
"as",
"specified",
"by",
"the",
"skip",
"parameter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L610-L625 |
18,655 | coreos/go-systemd | sdjournal/journal.go | SetDataThreshold | func (j *Journal) SetDataThreshold(threshold uint64) error {
sd_journal_set_data_threshold, err := getFunction("sd_journal_set_data_threshold")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_set_data_threshold(sd_journal_set_data_threshold, j.cjournal, C.size_t(threshold))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to set data threshold: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) SetDataThreshold(threshold uint64) error {
sd_journal_set_data_threshold, err := getFunction("sd_journal_set_data_threshold")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_set_data_threshold(sd_journal_set_data_threshold, j.cjournal, C.size_t(threshold))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to set data threshold: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"SetDataThreshold",
"(",
"threshold",
"uint64",
")",
"error",
"{",
"sd_journal_set_data_threshold",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // SetDataThreshold sets the data field size threshold for data returned by
// GetData. To retrieve the complete data fields this threshold should be
// turned off by setting it to 0, so that the library always returns the
// complete data objects. | [
"SetDataThreshold",
"sets",
"the",
"data",
"field",
"size",
"threshold",
"for",
"data",
"returned",
"by",
"GetData",
".",
"To",
"retrieve",
"the",
"complete",
"data",
"fields",
"this",
"threshold",
"should",
"be",
"turned",
"off",
"by",
"setting",
"it",
"to",
... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L795-L810 |
18,656 | coreos/go-systemd | sdjournal/journal.go | Wait | func (j *Journal) Wait(timeout time.Duration) int {
var to uint64
sd_journal_wait, err := getFunction("sd_journal_wait")
if err != nil {
return -1
}
if timeout == IndefiniteWait {
// sd_journal_wait(3) calls for a (uint64_t) -1 to be passed to signify
// indefinite wait, but using a -1 overflows our C.uint64_t, so we use an
// equivalent hex value.
to = 0xffffffffffffffff
} else {
to = uint64(timeout / time.Microsecond)
}
j.mu.Lock()
r := C.my_sd_journal_wait(sd_journal_wait, j.cjournal, C.uint64_t(to))
j.mu.Unlock()
return int(r)
} | go | func (j *Journal) Wait(timeout time.Duration) int {
var to uint64
sd_journal_wait, err := getFunction("sd_journal_wait")
if err != nil {
return -1
}
if timeout == IndefiniteWait {
// sd_journal_wait(3) calls for a (uint64_t) -1 to be passed to signify
// indefinite wait, but using a -1 overflows our C.uint64_t, so we use an
// equivalent hex value.
to = 0xffffffffffffffff
} else {
to = uint64(timeout / time.Microsecond)
}
j.mu.Lock()
r := C.my_sd_journal_wait(sd_journal_wait, j.cjournal, C.uint64_t(to))
j.mu.Unlock()
return int(r)
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Wait",
"(",
"timeout",
"time",
".",
"Duration",
")",
"int",
"{",
"var",
"to",
"uint64",
"\n\n",
"sd_journal_wait",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // Wait will synchronously wait until the journal gets changed. The maximum time
// this call sleeps may be controlled with the timeout parameter. If
// sdjournal.IndefiniteWait is passed as the timeout parameter, Wait will
// wait indefinitely for a journal change. | [
"Wait",
"will",
"synchronously",
"wait",
"until",
"the",
"journal",
"gets",
"changed",
".",
"The",
"maximum",
"time",
"this",
"call",
"sleeps",
"may",
"be",
"controlled",
"with",
"the",
"timeout",
"parameter",
".",
"If",
"sdjournal",
".",
"IndefiniteWait",
"is... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L997-L1018 |
18,657 | coreos/go-systemd | sdjournal/journal.go | GetUsage | func (j *Journal) GetUsage() (uint64, error) {
var out C.uint64_t
sd_journal_get_usage, err := getFunction("sd_journal_get_usage")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_get_usage(sd_journal_get_usage, j.cjournal, &out)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to get journal disk space usage: %d", syscall.Errno(-r))
}
return uint64(out), nil
} | go | func (j *Journal) GetUsage() (uint64, error) {
var out C.uint64_t
sd_journal_get_usage, err := getFunction("sd_journal_get_usage")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_get_usage(sd_journal_get_usage, j.cjournal, &out)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to get journal disk space usage: %d", syscall.Errno(-r))
}
return uint64(out), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"GetUsage",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"out",
"C",
".",
"uint64_t",
"\n\n",
"sd_journal_get_usage",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
... | // GetUsage returns the journal disk space usage, in bytes. | [
"GetUsage",
"returns",
"the",
"journal",
"disk",
"space",
"usage",
"in",
"bytes",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L1021-L1038 |
18,658 | coreos/go-systemd | sdjournal/journal.go | GetUniqueValues | func (j *Journal) GetUniqueValues(field string) ([]string, error) {
var result []string
sd_journal_query_unique, err := getFunction("sd_journal_query_unique")
if err != nil {
return nil, err
}
sd_journal_enumerate_unique, err := getFunction("sd_journal_enumerate_unique")
if err != nil {
return nil, err
}
sd_journal_restart_unique, err := getFunction("sd_journal_restart_unique")
if err != nil {
return nil, err
}
j.mu.Lock()
defer j.mu.Unlock()
f := C.CString(field)
defer C.free(unsafe.Pointer(f))
r := C.my_sd_journal_query_unique(sd_journal_query_unique, j.cjournal, f)
if r < 0 {
return nil, fmt.Errorf("failed to query journal: %d", syscall.Errno(-r))
}
// Implements the SD_JOURNAL_FOREACH_UNIQUE macro from sd-journal.h
var d unsafe.Pointer
var l C.size_t
C.my_sd_journal_restart_unique(sd_journal_restart_unique, j.cjournal)
for {
r = C.my_sd_journal_enumerate_unique(sd_journal_enumerate_unique, j.cjournal, &d, &l)
if r == 0 {
break
}
if r < 0 {
return nil, fmt.Errorf("failed to read message field: %d", syscall.Errno(-r))
}
msg := C.GoStringN((*C.char)(d), C.int(l))
kv := strings.SplitN(msg, "=", 2)
if len(kv) < 2 {
return nil, fmt.Errorf("failed to parse field")
}
result = append(result, kv[1])
}
return result, nil
} | go | func (j *Journal) GetUniqueValues(field string) ([]string, error) {
var result []string
sd_journal_query_unique, err := getFunction("sd_journal_query_unique")
if err != nil {
return nil, err
}
sd_journal_enumerate_unique, err := getFunction("sd_journal_enumerate_unique")
if err != nil {
return nil, err
}
sd_journal_restart_unique, err := getFunction("sd_journal_restart_unique")
if err != nil {
return nil, err
}
j.mu.Lock()
defer j.mu.Unlock()
f := C.CString(field)
defer C.free(unsafe.Pointer(f))
r := C.my_sd_journal_query_unique(sd_journal_query_unique, j.cjournal, f)
if r < 0 {
return nil, fmt.Errorf("failed to query journal: %d", syscall.Errno(-r))
}
// Implements the SD_JOURNAL_FOREACH_UNIQUE macro from sd-journal.h
var d unsafe.Pointer
var l C.size_t
C.my_sd_journal_restart_unique(sd_journal_restart_unique, j.cjournal)
for {
r = C.my_sd_journal_enumerate_unique(sd_journal_enumerate_unique, j.cjournal, &d, &l)
if r == 0 {
break
}
if r < 0 {
return nil, fmt.Errorf("failed to read message field: %d", syscall.Errno(-r))
}
msg := C.GoStringN((*C.char)(d), C.int(l))
kv := strings.SplitN(msg, "=", 2)
if len(kv) < 2 {
return nil, fmt.Errorf("failed to parse field")
}
result = append(result, kv[1])
}
return result, nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"GetUniqueValues",
"(",
"field",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"string",
"\n\n",
"sd_journal_query_unique",
",",
"err",
":=",
"getFunction",
"(",
"\"",
... | // GetUniqueValues returns all unique values for a given field. | [
"GetUniqueValues",
"returns",
"all",
"unique",
"values",
"for",
"a",
"given",
"field",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L1041-L1095 |
18,659 | coreos/go-systemd | activation/files.go | Files | func Files(unsetEnv bool) []*os.File {
if unsetEnv {
defer os.Unsetenv("LISTEN_PID")
defer os.Unsetenv("LISTEN_FDS")
defer os.Unsetenv("LISTEN_FDNAMES")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
}
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
if err != nil || nfds == 0 {
return nil
}
names := strings.Split(os.Getenv("LISTEN_FDNAMES"), ":")
files := make([]*os.File, 0, nfds)
for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ {
syscall.CloseOnExec(fd)
name := "LISTEN_FD_" + strconv.Itoa(fd)
offset := fd - listenFdsStart
if offset < len(names) && len(names[offset]) > 0 {
name = names[offset]
}
files = append(files, os.NewFile(uintptr(fd), name))
}
return files
} | go | func Files(unsetEnv bool) []*os.File {
if unsetEnv {
defer os.Unsetenv("LISTEN_PID")
defer os.Unsetenv("LISTEN_FDS")
defer os.Unsetenv("LISTEN_FDNAMES")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
}
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
if err != nil || nfds == 0 {
return nil
}
names := strings.Split(os.Getenv("LISTEN_FDNAMES"), ":")
files := make([]*os.File, 0, nfds)
for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ {
syscall.CloseOnExec(fd)
name := "LISTEN_FD_" + strconv.Itoa(fd)
offset := fd - listenFdsStart
if offset < len(names) && len(names[offset]) > 0 {
name = names[offset]
}
files = append(files, os.NewFile(uintptr(fd), name))
}
return files
} | [
"func",
"Files",
"(",
"unsetEnv",
"bool",
")",
"[",
"]",
"*",
"os",
".",
"File",
"{",
"if",
"unsetEnv",
"{",
"defer",
"os",
".",
"Unsetenv",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"os",
".",
"Unsetenv",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"os",
... | // Files returns a slice containing a `os.File` object for each
// file descriptor passed to this process via systemd fd-passing protocol.
//
// The order of the file descriptors is preserved in the returned slice.
// `unsetEnv` is typically set to `true` in order to avoid clashes in
// fd usage and to avoid leaking environment flags to child processes. | [
"Files",
"returns",
"a",
"slice",
"containing",
"a",
"os",
".",
"File",
"object",
"for",
"each",
"file",
"descriptor",
"passed",
"to",
"this",
"process",
"via",
"systemd",
"fd",
"-",
"passing",
"protocol",
".",
"The",
"order",
"of",
"the",
"file",
"descrip... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/files.go#L36-L67 |
18,660 | coreos/go-systemd | journal/journal.go | Enabled | func Enabled() bool {
onceConn.Do(initConn)
if (*net.UnixConn)(atomic.LoadPointer(&unixConnPtr)) == nil {
return false
}
if _, err := net.Dial("unixgram", journalSocket); err != nil {
return false
}
return true
} | go | func Enabled() bool {
onceConn.Do(initConn)
if (*net.UnixConn)(atomic.LoadPointer(&unixConnPtr)) == nil {
return false
}
if _, err := net.Dial("unixgram", journalSocket); err != nil {
return false
}
return true
} | [
"func",
"Enabled",
"(",
")",
"bool",
"{",
"onceConn",
".",
"Do",
"(",
"initConn",
")",
"\n\n",
"if",
"(",
"*",
"net",
".",
"UnixConn",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"unixConnPtr",
")",
")",
"==",
"nil",
"{",
"return",
"false",
"... | // Enabled checks whether the local systemd journal is available for logging. | [
"Enabled",
"checks",
"whether",
"the",
"local",
"systemd",
"journal",
"is",
"available",
"for",
"logging",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L73-L85 |
18,661 | coreos/go-systemd | journal/journal.go | isSocketSpaceError | func isSocketSpaceError(err error) bool {
opErr, ok := err.(*net.OpError)
if !ok || opErr == nil {
return false
}
sysErr, ok := opErr.Err.(*os.SyscallError)
if !ok || sysErr == nil {
return false
}
return sysErr.Err == syscall.EMSGSIZE || sysErr.Err == syscall.ENOBUFS
} | go | func isSocketSpaceError(err error) bool {
opErr, ok := err.(*net.OpError)
if !ok || opErr == nil {
return false
}
sysErr, ok := opErr.Err.(*os.SyscallError)
if !ok || sysErr == nil {
return false
}
return sysErr.Err == syscall.EMSGSIZE || sysErr.Err == syscall.ENOBUFS
} | [
"func",
"isSocketSpaceError",
"(",
"err",
"error",
")",
"bool",
"{",
"opErr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"net",
".",
"OpError",
")",
"\n",
"if",
"!",
"ok",
"||",
"opErr",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"sysErr",... | // isSocketSpaceError checks whether the error is signaling
// an "overlarge message" condition. | [
"isSocketSpaceError",
"checks",
"whether",
"the",
"error",
"is",
"signaling",
"an",
"overlarge",
"message",
"condition",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L184-L196 |
18,662 | coreos/go-systemd | journal/journal.go | initConn | func initConn() {
autobind, err := net.ResolveUnixAddr("unixgram", "")
if err != nil {
return
}
sock, err := net.ListenUnixgram("unixgram", autobind)
if err != nil {
return
}
atomic.StorePointer(&unixConnPtr, unsafe.Pointer(sock))
} | go | func initConn() {
autobind, err := net.ResolveUnixAddr("unixgram", "")
if err != nil {
return
}
sock, err := net.ListenUnixgram("unixgram", autobind)
if err != nil {
return
}
atomic.StorePointer(&unixConnPtr, unsafe.Pointer(sock))
} | [
"func",
"initConn",
"(",
")",
"{",
"autobind",
",",
"err",
":=",
"net",
".",
"ResolveUnixAddr",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"sock",
",",
"err",
":=",
"net",
".",
"Listen... | // initConn initializes the global `unixConnPtr` socket.
// It is meant to be called exactly once, at program startup. | [
"initConn",
"initializes",
"the",
"global",
"unixConnPtr",
"socket",
".",
"It",
"is",
"meant",
"to",
"be",
"called",
"exactly",
"once",
"at",
"program",
"startup",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/journal/journal.go#L213-L225 |
18,663 | coreos/go-systemd | machine1/dbus.go | GetMachine | func (c *Conn) GetMachine(name string) (dbus.ObjectPath, error) {
return c.getPath("GetMachine", name)
} | go | func (c *Conn) GetMachine(name string) (dbus.ObjectPath, error) {
return c.getPath("GetMachine", name)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetMachine",
"(",
"name",
"string",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPath",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // GetMachine gets a specific container with systemd-machined | [
"GetMachine",
"gets",
"a",
"specific",
"container",
"with",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L114-L116 |
18,664 | coreos/go-systemd | machine1/dbus.go | GetMachineByPID | func (c *Conn) GetMachineByPID(pid uint) (dbus.ObjectPath, error) {
return c.getPath("GetMachineByPID", pid)
} | go | func (c *Conn) GetMachineByPID(pid uint) (dbus.ObjectPath, error) {
return c.getPath("GetMachineByPID", pid)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetMachineByPID",
"(",
"pid",
"uint",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPath",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"}"
] | // GetMachineByPID gets a machine specified by a PID from systemd-machined | [
"GetMachineByPID",
"gets",
"a",
"machine",
"specified",
"by",
"a",
"PID",
"from",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L124-L126 |
18,665 | coreos/go-systemd | machine1/dbus.go | DescribeMachine | func (c *Conn) DescribeMachine(name string) (machineProps map[string]interface{}, err error) {
var dbusProps map[string]dbus.Variant
path, pathErr := c.GetMachine(name)
if pathErr != nil {
return nil, pathErr
}
obj := c.conn.Object("org.freedesktop.machine1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, "").Store(&dbusProps)
if err != nil {
return nil, err
}
machineProps = make(map[string]interface{}, len(dbusProps))
for key, val := range dbusProps {
machineProps[key] = val.Value()
}
return
} | go | func (c *Conn) DescribeMachine(name string) (machineProps map[string]interface{}, err error) {
var dbusProps map[string]dbus.Variant
path, pathErr := c.GetMachine(name)
if pathErr != nil {
return nil, pathErr
}
obj := c.conn.Object("org.freedesktop.machine1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, "").Store(&dbusProps)
if err != nil {
return nil, err
}
machineProps = make(map[string]interface{}, len(dbusProps))
for key, val := range dbusProps {
machineProps[key] = val.Value()
}
return
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"DescribeMachine",
"(",
"name",
"string",
")",
"(",
"machineProps",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"var",
"dbusProps",
"map",
"[",
"string",
"]",
"dbus",
".",
"Vari... | // DescribeMachine gets the properties of a machine | [
"DescribeMachine",
"gets",
"the",
"properties",
"of",
"a",
"machine"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L134-L150 |
18,666 | coreos/go-systemd | machine1/dbus.go | KillMachine | func (c *Conn) KillMachine(name, who string, sig syscall.Signal) error {
return c.object.Call(dbusInterface+".KillMachine", 0, name, who, sig).Err
} | go | func (c *Conn) KillMachine(name, who string, sig syscall.Signal) error {
return c.object.Call(dbusInterface+".KillMachine", 0, name, who, sig).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"KillMachine",
"(",
"name",
",",
"who",
"string",
",",
"sig",
"syscall",
".",
"Signal",
")",
"error",
"{",
"return",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"name",
... | // KillMachine sends a signal to a machine | [
"KillMachine",
"sends",
"a",
"signal",
"to",
"a",
"machine"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L153-L155 |
18,667 | coreos/go-systemd | machine1/dbus.go | TerminateMachine | func (c *Conn) TerminateMachine(name string) error {
return c.object.Call(dbusInterface+".TerminateMachine", 0, name).Err
} | go | func (c *Conn) TerminateMachine(name string) error {
return c.object.Call(dbusInterface+".TerminateMachine", 0, name).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateMachine",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"name",
")",
".",
"Err",
"\n",
"}"
] | // TerminateMachine causes systemd-machined to terminate a machine, killing its processes | [
"TerminateMachine",
"causes",
"systemd",
"-",
"machined",
"to",
"terminate",
"a",
"machine",
"killing",
"its",
"processes"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L158-L160 |
18,668 | coreos/go-systemd | machine1/dbus.go | RegisterMachine | func (c *Conn) RegisterMachine(name string, id []byte, service string, class string, pid int, root_directory string) error {
return c.object.Call(dbusInterface+".RegisterMachine", 0, name, id, service, class, uint32(pid), root_directory).Err
} | go | func (c *Conn) RegisterMachine(name string, id []byte, service string, class string, pid int, root_directory string) error {
return c.object.Call(dbusInterface+".RegisterMachine", 0, name, id, service, class, uint32(pid), root_directory).Err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RegisterMachine",
"(",
"name",
"string",
",",
"id",
"[",
"]",
"byte",
",",
"service",
"string",
",",
"class",
"string",
",",
"pid",
"int",
",",
"root_directory",
"string",
")",
"error",
"{",
"return",
"c",
".",
"o... | // RegisterMachine registers the container with the systemd-machined | [
"RegisterMachine",
"registers",
"the",
"container",
"with",
"the",
"systemd",
"-",
"machined"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L163-L165 |
18,669 | coreos/go-systemd | machine1/dbus.go | ListMachines | func (c *Conn) ListMachines() ([]MachineStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListMachines", 0).Store(&result); err != nil {
return nil, err
}
machs := []MachineStatus{}
for _, i := range result {
machine, err := machineFromInterfaces(i)
if err != nil {
return nil, err
}
machs = append(machs, *machine)
}
return machs, nil
} | go | func (c *Conn) ListMachines() ([]MachineStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListMachines", 0).Store(&result); err != nil {
return nil, err
}
machs := []MachineStatus{}
for _, i := range result {
machine, err := machineFromInterfaces(i)
if err != nil {
return nil, err
}
machs = append(machs, *machine)
}
return machs, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListMachines",
"(",
")",
"(",
"[",
"]",
"MachineStatus",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"o... | // ListMachines returns an array of all currently running machines. | [
"ListMachines",
"returns",
"an",
"array",
"of",
"all",
"currently",
"running",
"machines",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L193-L209 |
18,670 | coreos/go-systemd | machine1/dbus.go | ListImages | func (c *Conn) ListImages() ([]ImageStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListImages", 0).Store(&result); err != nil {
return nil, err
}
images := []ImageStatus{}
for _, i := range result {
image, err := imageFromInterfaces(i)
if err != nil {
return nil, err
}
images = append(images, *image)
}
return images, nil
} | go | func (c *Conn) ListImages() ([]ImageStatus, error) {
result := make([][]interface{}, 0)
if err := c.object.Call(dbusInterface+".ListImages", 0).Store(&result); err != nil {
return nil, err
}
images := []ImageStatus{}
for _, i := range result {
image, err := imageFromInterfaces(i)
if err != nil {
return nil, err
}
images = append(images, *image)
}
return images, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListImages",
"(",
")",
"(",
"[",
"]",
"ImageStatus",
",",
"error",
")",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"objec... | // ListImages returns an array of all currently available images. | [
"ListImages",
"returns",
"an",
"array",
"of",
"all",
"currently",
"available",
"images",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/machine1/dbus.go#L249-L265 |
18,671 | coreos/go-systemd | unit/deserialize.go | Deserialize | func Deserialize(f io.Reader) (opts []*UnitOption, err error) {
lexer, optchan, errchan := newLexer(f)
go lexer.lex()
for opt := range optchan {
opts = append(opts, &(*opt))
}
err = <-errchan
return opts, err
} | go | func Deserialize(f io.Reader) (opts []*UnitOption, err error) {
lexer, optchan, errchan := newLexer(f)
go lexer.lex()
for opt := range optchan {
opts = append(opts, &(*opt))
}
err = <-errchan
return opts, err
} | [
"func",
"Deserialize",
"(",
"f",
"io",
".",
"Reader",
")",
"(",
"opts",
"[",
"]",
"*",
"UnitOption",
",",
"err",
"error",
")",
"{",
"lexer",
",",
"optchan",
",",
"errchan",
":=",
"newLexer",
"(",
"f",
")",
"\n",
"go",
"lexer",
".",
"lex",
"(",
")... | // Deserialize parses a systemd unit file into a list of UnitOption objects. | [
"Deserialize",
"parses",
"a",
"systemd",
"unit",
"file",
"into",
"a",
"list",
"of",
"UnitOption",
"objects",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/deserialize.go#L47-L57 |
18,672 | coreos/go-systemd | login1/dbus.go | Close | func (c *Conn) Close() {
if c == nil {
return
}
if c.conn != nil {
c.conn.Close()
}
} | go | func (c *Conn) Close() {
if c == nil {
return
}
if c.conn != nil {
c.conn.Close()
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"conn",
"!=",
"nil",
"{",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Close closes the dbus connection | [
"Close",
"closes",
"the",
"dbus",
"connection"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L49-L57 |
18,673 | coreos/go-systemd | login1/dbus.go | GetSession | func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
var out interface{}
if err := c.object.Call(dbusInterface+".GetSession", 0, id).Store(&out); err != nil {
return "", err
}
ret, ok := out.(dbus.ObjectPath)
if !ok {
return "", fmt.Errorf("failed to typecast session to ObjectPath")
}
return ret, nil
} | go | func (c *Conn) GetSession(id string) (dbus.ObjectPath, error) {
var out interface{}
if err := c.object.Call(dbusInterface+".GetSession", 0, id).Store(&out); err != nil {
return "", err
}
ret, ok := out.(dbus.ObjectPath)
if !ok {
return "", fmt.Errorf("failed to typecast session to ObjectPath")
}
return ret, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetSession",
"(",
"id",
"string",
")",
"(",
"dbus",
".",
"ObjectPath",
",",
"error",
")",
"{",
"var",
"out",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",... | // GetSession may be used to get the session object path for the session with the specified ID. | [
"GetSession",
"may",
"be",
"used",
"to",
"get",
"the",
"session",
"object",
"path",
"for",
"the",
"session",
"with",
"the",
"specified",
"ID",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L159-L171 |
18,674 | coreos/go-systemd | login1/dbus.go | ListSessions | func (c *Conn) ListSessions() ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}
ret := []Session{}
for _, el := range out {
session, err := sessionFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *session)
}
return ret, nil
} | go | func (c *Conn) ListSessions() ([]Session, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListSessions", 0).Store(&out); err != nil {
return nil, err
}
ret := []Session{}
for _, el := range out {
session, err := sessionFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *session)
}
return ret, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListSessions",
"(",
")",
"(",
"[",
"]",
"Session",
",",
"error",
")",
"{",
"out",
":=",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
... | // ListSessions returns an array with all current sessions. | [
"ListSessions",
"returns",
"an",
"array",
"with",
"all",
"current",
"sessions",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L174-L189 |
18,675 | coreos/go-systemd | login1/dbus.go | ListUsers | func (c *Conn) ListUsers() ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}
ret := []User{}
for _, el := range out {
user, err := userFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *user)
}
return ret, nil
} | go | func (c *Conn) ListUsers() ([]User, error) {
out := [][]interface{}{}
if err := c.object.Call(dbusInterface+".ListUsers", 0).Store(&out); err != nil {
return nil, err
}
ret := []User{}
for _, el := range out {
user, err := userFromInterfaces(el)
if err != nil {
return nil, err
}
ret = append(ret, *user)
}
return ret, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUsers",
"(",
")",
"(",
"[",
"]",
"User",
",",
"error",
")",
"{",
"out",
":=",
"[",
"]",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"object",
".",
"Call",
"(",
"dbus... | // ListUsers returns an array with all currently logged in users. | [
"ListUsers",
"returns",
"an",
"array",
"with",
"all",
"currently",
"logged",
"in",
"users",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L192-L207 |
18,676 | coreos/go-systemd | login1/dbus.go | LockSession | func (c *Conn) LockSession(id string) {
c.object.Call(dbusInterface+".LockSession", 0, id)
} | go | func (c *Conn) LockSession(id string) {
c.object.Call(dbusInterface+".LockSession", 0, id)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"LockSession",
"(",
"id",
"string",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"id",
")",
"\n",
"}"
] | // LockSession asks the session with the specified ID to activate the screen lock. | [
"LockSession",
"asks",
"the",
"session",
"with",
"the",
"specified",
"ID",
"to",
"activate",
"the",
"screen",
"lock",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L210-L212 |
18,677 | coreos/go-systemd | login1/dbus.go | TerminateSession | func (c *Conn) TerminateSession(id string) {
c.object.Call(dbusInterface+".TerminateSession", 0, id)
} | go | func (c *Conn) TerminateSession(id string) {
c.object.Call(dbusInterface+".TerminateSession", 0, id)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateSession",
"(",
"id",
"string",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"id",
")",
"\n",
"}"
] | // TerminateSession forcibly terminate one specific session. | [
"TerminateSession",
"forcibly",
"terminate",
"one",
"specific",
"session",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L220-L222 |
18,678 | coreos/go-systemd | login1/dbus.go | TerminateUser | func (c *Conn) TerminateUser(uid uint32) {
c.object.Call(dbusInterface+".TerminateUser", 0, uid)
} | go | func (c *Conn) TerminateUser(uid uint32) {
c.object.Call(dbusInterface+".TerminateUser", 0, uid)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"TerminateUser",
"(",
"uid",
"uint32",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"uid",
")",
"\n",
"}"
] | // TerminateUser forcibly terminates all processes of a user. | [
"TerminateUser",
"forcibly",
"terminates",
"all",
"processes",
"of",
"a",
"user",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L225-L227 |
18,679 | coreos/go-systemd | login1/dbus.go | Reboot | func (c *Conn) Reboot(askForAuth bool) {
c.object.Call(dbusInterface+".Reboot", 0, askForAuth)
} | go | func (c *Conn) Reboot(askForAuth bool) {
c.object.Call(dbusInterface+".Reboot", 0, askForAuth)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Reboot",
"(",
"askForAuth",
"bool",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"askForAuth",
")",
"\n",
"}"
] | // Reboot asks logind for a reboot optionally asking for auth. | [
"Reboot",
"asks",
"logind",
"for",
"a",
"reboot",
"optionally",
"asking",
"for",
"auth",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L230-L232 |
18,680 | coreos/go-systemd | login1/dbus.go | Inhibit | func (c *Conn) Inhibit(what, who, why, mode string) (*os.File, error) {
var fd dbus.UnixFD
err := c.object.Call(dbusInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(fd), "inhibit"), nil
} | go | func (c *Conn) Inhibit(what, who, why, mode string) (*os.File, error) {
var fd dbus.UnixFD
err := c.object.Call(dbusInterface+".Inhibit", 0, what, who, why, mode).Store(&fd)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(fd), "inhibit"), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Inhibit",
"(",
"what",
",",
"who",
",",
"why",
",",
"mode",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"var",
"fd",
"dbus",
".",
"UnixFD",
"\n\n",
"err",
":=",
"c",
".",
"object",
... | // Inhibit takes inhibition lock in logind. | [
"Inhibit",
"takes",
"inhibition",
"lock",
"in",
"logind",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L235-L244 |
18,681 | coreos/go-systemd | login1/dbus.go | Subscribe | func (c *Conn) Subscribe(members ...string) chan *dbus.Signal {
for _, member := range members {
c.conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
fmt.Sprintf("type='signal',interface='org.freedesktop.login1.Manager',member='%s'", member))
}
ch := make(chan *dbus.Signal, 10)
c.conn.Signal(ch)
return ch
} | go | func (c *Conn) Subscribe(members ...string) chan *dbus.Signal {
for _, member := range members {
c.conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
fmt.Sprintf("type='signal',interface='org.freedesktop.login1.Manager',member='%s'", member))
}
ch := make(chan *dbus.Signal, 10)
c.conn.Signal(ch)
return ch
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Subscribe",
"(",
"members",
"...",
"string",
")",
"chan",
"*",
"dbus",
".",
"Signal",
"{",
"for",
"_",
",",
"member",
":=",
"range",
"members",
"{",
"c",
".",
"conn",
".",
"BusObject",
"(",
")",
".",
"Call",
"... | // Subscribe to signals on the logind dbus | [
"Subscribe",
"to",
"signals",
"on",
"the",
"logind",
"dbus"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L247-L255 |
18,682 | coreos/go-systemd | login1/dbus.go | PowerOff | func (c *Conn) PowerOff(askForAuth bool) {
c.object.Call(dbusInterface+".PowerOff", 0, askForAuth)
} | go | func (c *Conn) PowerOff(askForAuth bool) {
c.object.Call(dbusInterface+".PowerOff", 0, askForAuth)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"PowerOff",
"(",
"askForAuth",
"bool",
")",
"{",
"c",
".",
"object",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
",",
"askForAuth",
")",
"\n",
"}"
] | // PowerOff asks logind for a power off optionally asking for auth. | [
"PowerOff",
"asks",
"logind",
"for",
"a",
"power",
"off",
"optionally",
"asking",
"for",
"auth",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/login1/dbus.go#L258-L260 |
18,683 | coreos/go-systemd | activation/listeners.go | ListenersWithNames | func ListenersWithNames() (map[string][]net.Listener, error) {
files := Files(true)
listeners := map[string][]net.Listener{}
for _, f := range files {
if pc, err := net.FileListener(f); err == nil {
current, ok := listeners[f.Name()]
if !ok {
listeners[f.Name()] = []net.Listener{pc}
} else {
listeners[f.Name()] = append(current, pc)
}
f.Close()
}
}
return listeners, nil
} | go | func ListenersWithNames() (map[string][]net.Listener, error) {
files := Files(true)
listeners := map[string][]net.Listener{}
for _, f := range files {
if pc, err := net.FileListener(f); err == nil {
current, ok := listeners[f.Name()]
if !ok {
listeners[f.Name()] = []net.Listener{pc}
} else {
listeners[f.Name()] = append(current, pc)
}
f.Close()
}
}
return listeners, nil
} | [
"func",
"ListenersWithNames",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"files",
":=",
"Files",
"(",
"true",
")",
"\n",
"listeners",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
... | // ListenersWithNames maps a listener name to a set of net.Listener instances. | [
"ListenersWithNames",
"maps",
"a",
"listener",
"name",
"to",
"a",
"set",
"of",
"net",
".",
"Listener",
"instances",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L42-L58 |
18,684 | coreos/go-systemd | activation/listeners.go | TLSListeners | func TLSListeners(tlsConfig *tls.Config) ([]net.Listener, error) {
listeners, err := Listeners()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for i, l := range listeners {
// Activate TLS only for TCP sockets
if l.Addr().Network() == "tcp" {
listeners[i] = tls.NewListener(l, tlsConfig)
}
}
}
return listeners, err
} | go | func TLSListeners(tlsConfig *tls.Config) ([]net.Listener, error) {
listeners, err := Listeners()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for i, l := range listeners {
// Activate TLS only for TCP sockets
if l.Addr().Network() == "tcp" {
listeners[i] = tls.NewListener(l, tlsConfig)
}
}
}
return listeners, err
} | [
"func",
"TLSListeners",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"listeners",
",",
"err",
":=",
"Listeners",
"(",
")",
"\n\n",
"if",
"listeners",
"==",
"nil",
"||",
"err",
"!=",
... | // TLSListeners returns a slice containing a net.listener for each matching TCP socket type
// passed to this process.
// It uses default Listeners func and forces TCP sockets handlers to use TLS based on tlsConfig. | [
"TLSListeners",
"returns",
"a",
"slice",
"containing",
"a",
"net",
".",
"listener",
"for",
"each",
"matching",
"TCP",
"socket",
"type",
"passed",
"to",
"this",
"process",
".",
"It",
"uses",
"default",
"Listeners",
"func",
"and",
"forces",
"TCP",
"sockets",
"... | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L63-L80 |
18,685 | coreos/go-systemd | activation/listeners.go | TLSListenersWithNames | func TLSListenersWithNames(tlsConfig *tls.Config) (map[string][]net.Listener, error) {
listeners, err := ListenersWithNames()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for _, ll := range listeners {
// Activate TLS only for TCP sockets
for i, l := range ll {
if l.Addr().Network() == "tcp" {
ll[i] = tls.NewListener(l, tlsConfig)
}
}
}
}
return listeners, err
} | go | func TLSListenersWithNames(tlsConfig *tls.Config) (map[string][]net.Listener, error) {
listeners, err := ListenersWithNames()
if listeners == nil || err != nil {
return nil, err
}
if tlsConfig != nil && err == nil {
for _, ll := range listeners {
// Activate TLS only for TCP sockets
for i, l := range ll {
if l.Addr().Network() == "tcp" {
ll[i] = tls.NewListener(l, tlsConfig)
}
}
}
}
return listeners, err
} | [
"func",
"TLSListenersWithNames",
"(",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"listeners",
",",
"err",
":=",
"ListenersWithNames",
"(",
")",
"\n\n",
"if",
"l... | // TLSListenersWithNames maps a listener name to a net.Listener with
// the associated TLS configuration. | [
"TLSListenersWithNames",
"maps",
"a",
"listener",
"name",
"to",
"a",
"net",
".",
"Listener",
"with",
"the",
"associated",
"TLS",
"configuration",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/activation/listeners.go#L84-L103 |
18,686 | pkg/sftp | request-example.go | InMemHandler | func InMemHandler() Handlers {
root := &root{
files: make(map[string]*memFile),
}
root.memFile = newMemFile("/", true)
return Handlers{root, root, root, root}
} | go | func InMemHandler() Handlers {
root := &root{
files: make(map[string]*memFile),
}
root.memFile = newMemFile("/", true)
return Handlers{root, root, root, root}
} | [
"func",
"InMemHandler",
"(",
")",
"Handlers",
"{",
"root",
":=",
"&",
"root",
"{",
"files",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"memFile",
")",
",",
"}",
"\n",
"root",
".",
"memFile",
"=",
"newMemFile",
"(",
"\"",
"\"",
",",
"true",
... | // InMemHandler returns a Hanlders object with the test handlers. | [
"InMemHandler",
"returns",
"a",
"Hanlders",
"object",
"with",
"the",
"test",
"handlers",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-example.go#L20-L26 |
18,687 | pkg/sftp | request-example.go | newMemFile | func newMemFile(name string, isdir bool) *memFile {
return &memFile{
name: name,
modtime: time.Now(),
isdir: isdir,
}
} | go | func newMemFile(name string, isdir bool) *memFile {
return &memFile{
name: name,
modtime: time.Now(),
isdir: isdir,
}
} | [
"func",
"newMemFile",
"(",
"name",
"string",
",",
"isdir",
"bool",
")",
"*",
"memFile",
"{",
"return",
"&",
"memFile",
"{",
"name",
":",
"name",
",",
"modtime",
":",
"time",
".",
"Now",
"(",
")",
",",
"isdir",
":",
"isdir",
",",
"}",
"\n",
"}"
] | // factory to make sure modtime is set | [
"factory",
"to",
"make",
"sure",
"modtime",
"is",
"set"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request-example.go#L212-L218 |
18,688 | pkg/sftp | request.go | requestFromPacket | func requestFromPacket(ctx context.Context, pkt hasPath) *Request {
method := requestMethod(pkt)
request := NewRequest(method, pkt.getPath())
request.ctx, request.cancelCtx = context.WithCancel(ctx)
switch p := pkt.(type) {
case *sshFxpOpenPacket:
request.Flags = p.Pflags
case *sshFxpSetstatPacket:
request.Flags = p.Flags
request.Attrs = p.Attrs.([]byte)
case *sshFxpRenamePacket:
request.Target = cleanPath(p.Newpath)
case *sshFxpSymlinkPacket:
request.Target = cleanPath(p.Linkpath)
}
return request
} | go | func requestFromPacket(ctx context.Context, pkt hasPath) *Request {
method := requestMethod(pkt)
request := NewRequest(method, pkt.getPath())
request.ctx, request.cancelCtx = context.WithCancel(ctx)
switch p := pkt.(type) {
case *sshFxpOpenPacket:
request.Flags = p.Pflags
case *sshFxpSetstatPacket:
request.Flags = p.Flags
request.Attrs = p.Attrs.([]byte)
case *sshFxpRenamePacket:
request.Target = cleanPath(p.Newpath)
case *sshFxpSymlinkPacket:
request.Target = cleanPath(p.Linkpath)
}
return request
} | [
"func",
"requestFromPacket",
"(",
"ctx",
"context",
".",
"Context",
",",
"pkt",
"hasPath",
")",
"*",
"Request",
"{",
"method",
":=",
"requestMethod",
"(",
"pkt",
")",
"\n",
"request",
":=",
"NewRequest",
"(",
"method",
",",
"pkt",
".",
"getPath",
"(",
")... | // New Request initialized based on packet data | [
"New",
"Request",
"initialized",
"based",
"on",
"packet",
"data"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L44-L61 |
18,689 | pkg/sftp | request.go | NewRequest | func NewRequest(method, path string) *Request {
return &Request{Method: method, Filepath: cleanPath(path),
state: state{RWMutex: new(sync.RWMutex)}}
} | go | func NewRequest(method, path string) *Request {
return &Request{Method: method, Filepath: cleanPath(path),
state: state{RWMutex: new(sync.RWMutex)}}
} | [
"func",
"NewRequest",
"(",
"method",
",",
"path",
"string",
")",
"*",
"Request",
"{",
"return",
"&",
"Request",
"{",
"Method",
":",
"method",
",",
"Filepath",
":",
"cleanPath",
"(",
"path",
")",
",",
"state",
":",
"state",
"{",
"RWMutex",
":",
"new",
... | // NewRequest creates a new Request object. | [
"NewRequest",
"creates",
"a",
"new",
"Request",
"object",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L64-L67 |
18,690 | pkg/sftp | request.go | copy | func (r *Request) copy() *Request {
r.state.Lock()
defer r.state.Unlock()
r2 := new(Request)
*r2 = *r
return r2
} | go | func (r *Request) copy() *Request {
r.state.Lock()
defer r.state.Unlock()
r2 := new(Request)
*r2 = *r
return r2
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"copy",
"(",
")",
"*",
"Request",
"{",
"r",
".",
"state",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"Unlock",
"(",
")",
"\n",
"r2",
":=",
"new",
"(",
"Request",
")",
"\n",
"*",
"r2",
... | // shallow copy of existing request | [
"shallow",
"copy",
"of",
"existing",
"request"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L70-L76 |
18,691 | pkg/sftp | request.go | Context | func (r *Request) Context() context.Context {
if r.ctx != nil {
return r.ctx
}
return context.Background()
} | go | func (r *Request) Context() context.Context {
if r.ctx != nil {
return r.ctx
}
return context.Background()
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"Context",
"(",
")",
"context",
".",
"Context",
"{",
"if",
"r",
".",
"ctx",
"!=",
"nil",
"{",
"return",
"r",
".",
"ctx",
"\n",
"}",
"\n",
"return",
"context",
".",
"Background",
"(",
")",
"\n",
"}"
] | // Context returns the request's context. To change the context,
// use WithContext.
//
// The returned context is always non-nil; it defaults to the
// background context.
//
// For incoming server requests, the context is canceled when the
// request is complete or the client's connection closes. | [
"Context",
"returns",
"the",
"request",
"s",
"context",
".",
"To",
"change",
"the",
"context",
"use",
"WithContext",
".",
"The",
"returned",
"context",
"is",
"always",
"non",
"-",
"nil",
";",
"it",
"defaults",
"to",
"the",
"background",
"context",
".",
"Fo... | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L86-L91 |
18,692 | pkg/sftp | request.go | WithContext | func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r2 := r.copy()
r2.ctx = ctx
r2.cancelCtx = nil
return r2
} | go | func (r *Request) WithContext(ctx context.Context) *Request {
if ctx == nil {
panic("nil context")
}
r2 := r.copy()
r2.ctx = ctx
r2.cancelCtx = nil
return r2
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"Request",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"r2",
":=",
"r",
".",
"copy",
"(",
")",
"\n",
... | // WithContext returns a copy of r with its context changed to ctx.
// The provided ctx must be non-nil. | [
"WithContext",
"returns",
"a",
"copy",
"of",
"r",
"with",
"its",
"context",
"changed",
"to",
"ctx",
".",
"The",
"provided",
"ctx",
"must",
"be",
"non",
"-",
"nil",
"."
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L95-L103 |
18,693 | pkg/sftp | request.go | lsNext | func (r *Request) lsNext() int64 {
r.state.RLock()
defer r.state.RUnlock()
return r.state.lsoffset
} | go | func (r *Request) lsNext() int64 {
r.state.RLock()
defer r.state.RUnlock()
return r.state.lsoffset
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"lsNext",
"(",
")",
"int64",
"{",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"r",
".",
"state",
".",
"lsoffset",
"\n",
"}"
] | // Returns current offset for file list | [
"Returns",
"current",
"offset",
"for",
"file",
"list"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L106-L110 |
18,694 | pkg/sftp | request.go | lsInc | func (r *Request) lsInc(offset int64) {
r.state.Lock()
defer r.state.Unlock()
r.state.lsoffset = r.state.lsoffset + offset
} | go | func (r *Request) lsInc(offset int64) {
r.state.Lock()
defer r.state.Unlock()
r.state.lsoffset = r.state.lsoffset + offset
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"lsInc",
"(",
"offset",
"int64",
")",
"{",
"r",
".",
"state",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"state",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"state",
".",
"lsoffset",
"=",
"r",
".",
"s... | // Increases next offset | [
"Increases",
"next",
"offset"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L113-L117 |
18,695 | pkg/sftp | request.go | open | func (r *Request) open(h Handlers, pkt requestPacket) responsePacket {
flags := r.Pflags()
var err error
switch {
case flags.Write, flags.Append, flags.Creat, flags.Trunc:
r.Method = "Put"
r.state.writerAt, err = h.FilePut.Filewrite(r)
case flags.Read:
r.Method = "Get"
r.state.readerAt, err = h.FileGet.Fileread(r)
default:
return statusFromError(pkt, errors.New("bad file flags"))
}
if err != nil {
return statusFromError(pkt, err)
}
return &sshFxpHandlePacket{ID: pkt.id(), Handle: r.handle}
} | go | func (r *Request) open(h Handlers, pkt requestPacket) responsePacket {
flags := r.Pflags()
var err error
switch {
case flags.Write, flags.Append, flags.Creat, flags.Trunc:
r.Method = "Put"
r.state.writerAt, err = h.FilePut.Filewrite(r)
case flags.Read:
r.Method = "Get"
r.state.readerAt, err = h.FileGet.Fileread(r)
default:
return statusFromError(pkt, errors.New("bad file flags"))
}
if err != nil {
return statusFromError(pkt, err)
}
return &sshFxpHandlePacket{ID: pkt.id(), Handle: r.handle}
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"open",
"(",
"h",
"Handlers",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"flags",
":=",
"r",
".",
"Pflags",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"{",
"case",
"flags",
".",
"Write"... | // Additional initialization for Open packets | [
"Additional",
"initialization",
"for",
"Open",
"packets"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L174-L191 |
18,696 | pkg/sftp | request.go | fileget | func fileget(h FileReader, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileget", r)
r.state.RLock()
reader := r.state.readerAt
r.state.RUnlock()
if reader == nil {
return statusFromError(pkt, errors.New("unexpected read packet"))
}
_, offset, length := packetData(pkt)
data := make([]byte, clamp(length, maxTxPacket))
n, err := reader.ReadAt(data, offset)
// only return EOF erro if no data left to read
if err != nil && (err != io.EOF || n == 0) {
return statusFromError(pkt, err)
}
return &sshFxpDataPacket{
ID: pkt.id(),
Length: uint32(n),
Data: data[:n],
}
} | go | func fileget(h FileReader, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileget", r)
r.state.RLock()
reader := r.state.readerAt
r.state.RUnlock()
if reader == nil {
return statusFromError(pkt, errors.New("unexpected read packet"))
}
_, offset, length := packetData(pkt)
data := make([]byte, clamp(length, maxTxPacket))
n, err := reader.ReadAt(data, offset)
// only return EOF erro if no data left to read
if err != nil && (err != io.EOF || n == 0) {
return statusFromError(pkt, err)
}
return &sshFxpDataPacket{
ID: pkt.id(),
Length: uint32(n),
Data: data[:n],
}
} | [
"func",
"fileget",
"(",
"h",
"FileReader",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"//fmt.Println(\"fileget\", r)",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"reader",
":=",
"r",
".",
"state",
".",
"readerA... | // wrap FileReader handler | [
"wrap",
"FileReader",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L207-L228 |
18,697 | pkg/sftp | request.go | fileput | func fileput(h FileWriter, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileput", r)
r.state.RLock()
writer := r.state.writerAt
r.state.RUnlock()
if writer == nil {
return statusFromError(pkt, errors.New("unexpected write packet"))
}
data, offset, _ := packetData(pkt)
_, err := writer.WriteAt(data, offset)
return statusFromError(pkt, err)
} | go | func fileput(h FileWriter, r *Request, pkt requestPacket) responsePacket {
//fmt.Println("fileput", r)
r.state.RLock()
writer := r.state.writerAt
r.state.RUnlock()
if writer == nil {
return statusFromError(pkt, errors.New("unexpected write packet"))
}
data, offset, _ := packetData(pkt)
_, err := writer.WriteAt(data, offset)
return statusFromError(pkt, err)
} | [
"func",
"fileput",
"(",
"h",
"FileWriter",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"//fmt.Println(\"fileput\", r)",
"r",
".",
"state",
".",
"RLock",
"(",
")",
"\n",
"writer",
":=",
"r",
".",
"state",
".",
"writerA... | // wrap FileWriter handler | [
"wrap",
"FileWriter",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L231-L243 |
18,698 | pkg/sftp | request.go | filecmd | func filecmd(h FileCmder, r *Request, pkt requestPacket) responsePacket {
switch p := pkt.(type) {
case *sshFxpFsetstatPacket:
r.Flags = p.Flags
r.Attrs = p.Attrs.([]byte)
}
err := h.Filecmd(r)
return statusFromError(pkt, err)
} | go | func filecmd(h FileCmder, r *Request, pkt requestPacket) responsePacket {
switch p := pkt.(type) {
case *sshFxpFsetstatPacket:
r.Flags = p.Flags
r.Attrs = p.Attrs.([]byte)
}
err := h.Filecmd(r)
return statusFromError(pkt, err)
} | [
"func",
"filecmd",
"(",
"h",
"FileCmder",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"switch",
"p",
":=",
"pkt",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sshFxpFsetstatPacket",
":",
"r",
".",
"Flags",
"=",
"p",
... | // wrap FileCmder handler | [
"wrap",
"FileCmder",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L260-L269 |
18,699 | pkg/sftp | request.go | filelist | func filelist(h FileLister, r *Request, pkt requestPacket) responsePacket {
var err error
lister := r.getLister()
if lister == nil {
return statusFromError(pkt, errors.New("unexpected dir packet"))
}
offset := r.lsNext()
finfo := make([]os.FileInfo, MaxFilelist)
n, err := lister.ListAt(finfo, offset)
r.lsInc(int64(n))
// ignore EOF as we only return it when there are no results
finfo = finfo[:n] // avoid need for nil tests below
switch r.Method {
case "List":
if err != nil && err != io.EOF {
return statusFromError(pkt, err)
}
if err == io.EOF && n == 0 {
return statusFromError(pkt, io.EOF)
}
dirname := filepath.ToSlash(path.Base(r.Filepath))
ret := &sshFxpNamePacket{ID: pkt.id()}
for _, fi := range finfo {
ret.NameAttrs = append(ret.NameAttrs, sshFxpNameAttr{
Name: fi.Name(),
LongName: runLs(dirname, fi),
Attrs: []interface{}{fi},
})
}
return ret
default:
err = errors.Errorf("unexpected method: %s", r.Method)
return statusFromError(pkt, err)
}
} | go | func filelist(h FileLister, r *Request, pkt requestPacket) responsePacket {
var err error
lister := r.getLister()
if lister == nil {
return statusFromError(pkt, errors.New("unexpected dir packet"))
}
offset := r.lsNext()
finfo := make([]os.FileInfo, MaxFilelist)
n, err := lister.ListAt(finfo, offset)
r.lsInc(int64(n))
// ignore EOF as we only return it when there are no results
finfo = finfo[:n] // avoid need for nil tests below
switch r.Method {
case "List":
if err != nil && err != io.EOF {
return statusFromError(pkt, err)
}
if err == io.EOF && n == 0 {
return statusFromError(pkt, io.EOF)
}
dirname := filepath.ToSlash(path.Base(r.Filepath))
ret := &sshFxpNamePacket{ID: pkt.id()}
for _, fi := range finfo {
ret.NameAttrs = append(ret.NameAttrs, sshFxpNameAttr{
Name: fi.Name(),
LongName: runLs(dirname, fi),
Attrs: []interface{}{fi},
})
}
return ret
default:
err = errors.Errorf("unexpected method: %s", r.Method)
return statusFromError(pkt, err)
}
} | [
"func",
"filelist",
"(",
"h",
"FileLister",
",",
"r",
"*",
"Request",
",",
"pkt",
"requestPacket",
")",
"responsePacket",
"{",
"var",
"err",
"error",
"\n",
"lister",
":=",
"r",
".",
"getLister",
"(",
")",
"\n",
"if",
"lister",
"==",
"nil",
"{",
"return... | // wrap FileLister handler | [
"wrap",
"FileLister",
"handler"
] | 5bcd86d72480cb6de4bc5804f832e27855ba033f | https://github.com/pkg/sftp/blob/5bcd86d72480cb6de4bc5804f832e27855ba033f/request.go#L272-L309 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.