// Copyright (c) 2017, Andrey Nering // See LICENSE for licensing information //go:build unix package interp import ( "context" "errors" "os/user" "strconv" "syscall" "golang.org/x/sys/unix" "mvdan.cc/sh/v3/syntax" ) func mkfifo(path string, mode uint32) error { return unix.Mkfifo(path, mode) } // defaultAccess is similar to checking the permission bits from [io/fs.FileInfo], // but it also takes into account the current user's role. func defaultAccess(ctx context.Context, path string, mode AccessMode) error { return unix.Access(path, uint32(mode)) } // unTestOwnOrGrp implements the -O and -G unary tests. If the file does not // exist, or the current user cannot be retrieved, returns false. func (r *Runner) unTestOwnOrGrp(ctx context.Context, op syntax.UnTestOperator, x string) bool { info, err := r.stat(ctx, x) if err != nil { return false } u, err := user.Current() if err != nil { return false } if op == syntax.TsUsrOwn { uid, _ := strconv.Atoi(u.Uid) return uint32(uid) == info.Sys().(*syscall.Stat_t).Uid } gid, _ := strconv.Atoi(u.Gid) return uint32(gid) == info.Sys().(*syscall.Stat_t).Gid } type waitStatus = syscall.WaitStatus // isENOEXEC reports whether the kernel refused to execute a file // with ENOEXEC, e.g. a script without a shebang line. func isENOEXEC(err error) bool { return errors.Is(err, syscall.ENOEXEC) } // isETXTBSY reports whether the kernel refused to execute a file // with ETXTBSY, i.e. a process holds it open for writing. func isETXTBSY(err error) bool { return errors.Is(err, syscall.ETXTBSY) }