File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 44
55package unix
66
7+ import "fmt"
8+
79// Unveil implements the unveil syscall.
810// For more information see unveil(2).
911// Note that the special case of blocking further
1012// unveil calls is handled by UnveilBlock.
13+ //
14+ // Unveil requires OpenBSD 6.4 or later.
1115func Unveil (path string , flags string ) error {
16+ err := supportsUnveil ()
17+ if err != nil {
18+ return err
19+ }
1220 pathBytes , err := BytePtrFromString (path )
1321 if err != nil {
1422 return err
@@ -22,6 +30,28 @@ func Unveil(path string, flags string) error {
2230
2331// UnveilBlock blocks future unveil calls.
2432// For more information see unveil(2).
33+ //
34+ // Unveil requires OpenBSD 6.4 or later.
2535func UnveilBlock () error {
36+ err := supportsUnveil ()
37+ if err != nil {
38+ return err
39+ }
2640 return unveil (nil , nil )
2741}
42+
43+ // supportsUnveil checks for availability of the unveil(2) system call based
44+ // on the running OpenBSD version.
45+ func supportsUnveil () error {
46+ maj , min , err := majmin ()
47+ if err != nil {
48+ return err
49+ }
50+
51+ // unveil is not available before 6.4
52+ if maj < 6 || (maj == 6 && min <= 3 ) {
53+ return fmt .Errorf ("cannot use execpromises on OpenBSD %d.%d" , maj , min )
54+ }
55+
56+ return nil
57+ }
You can’t perform that action at this time.
0 commit comments