blob: fed431952c8b21f7d4f0ee3f5425acc495a60d78 [file] [log] [blame]
Lorenz Brunf95909d2019-09-11 19:48:26 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package sysfs
18
19import (
20 "bufio"
21 "io"
22 "os"
23 "strings"
24)
25
26func ReadUevents(filename string) (map[string]string, error) {
27 f, err := os.Open(filename)
28 if err != nil {
29 return nil, err
30 }
31 defer f.Close()
32 ueventMap := make(map[string]string)
33 reader := bufio.NewReader(f)
34 for {
35 name, err := reader.ReadString(byte('='))
36 if err == io.EOF {
37 break
38 } else if err != nil {
39 return nil, err
40 }
41 value, err := reader.ReadString(byte('\n'))
42 if err == io.EOF {
43 continue
44 } else if err != nil {
45 return nil, err
46 }
47 ueventMap[strings.Trim(name, "=")] = strings.TrimSpace(value)
48 }
49 return ueventMap, nil
50}