forked from rosa/hakurei
internal/uevent: optionally pass UUID during coldboot
This enables rejection of non-coldboot synthetic events. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// synthAdd is prepared bytes written to uevent to cause a synthetic add event
|
||||
@@ -26,6 +27,7 @@ var synthAdd = []byte(KOBJ_ADD.String())
|
||||
func Coldboot(
|
||||
ctx context.Context,
|
||||
pathname string,
|
||||
uuid *UUID,
|
||||
visited chan<- string,
|
||||
handleWalkErr func(error) error,
|
||||
) error {
|
||||
@@ -39,6 +41,11 @@ func Coldboot(
|
||||
}
|
||||
}
|
||||
|
||||
add := synthAdd
|
||||
if uuid != nil {
|
||||
add = slices.Concat(add, []byte{' '}, []byte(uuid.String()))
|
||||
}
|
||||
|
||||
return filepath.WalkDir(filepath.Join(pathname, "devices"), func(
|
||||
path string,
|
||||
d fs.DirEntry,
|
||||
@@ -54,7 +61,7 @@ func Coldboot(
|
||||
if d.IsDir() || d.Name() != "uevent" {
|
||||
return nil
|
||||
}
|
||||
if err = os.WriteFile(path, synthAdd, 0); err != nil {
|
||||
if err = os.WriteFile(path, add, 0); err != nil {
|
||||
return handleWalkErr(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user