all: rename variables with lowercase-l/uppercase-I
See http://go/no-ell Signed-off-by: Alex Chan <alexc@tailscale.com> Updates #cleanup Change-Id: I8c976b51ce7a60f06315048b1920516129cc1d5d
This commit is contained in:
@@ -182,16 +182,16 @@ func doWithMachinePolicyLocked(t *testing.T, f func()) {
|
||||
f()
|
||||
}
|
||||
|
||||
func doWithCustomEnterLeaveFuncs(t *testing.T, f func(l *PolicyLock), enter func(bool) (policyLockHandle, error), leave func(policyLockHandle) error) {
|
||||
func doWithCustomEnterLeaveFuncs(t *testing.T, f func(*PolicyLock), enter func(bool) (policyLockHandle, error), leave func(policyLockHandle) error) {
|
||||
t.Helper()
|
||||
|
||||
l := NewMachinePolicyLock()
|
||||
l.enterFn, l.leaveFn = enter, leave
|
||||
lock := NewMachinePolicyLock()
|
||||
lock.enterFn, lock.leaveFn = enter, leave
|
||||
t.Cleanup(func() {
|
||||
if err := l.Close(); err != nil {
|
||||
if err := lock.Close(); err != nil {
|
||||
t.Fatalf("(*PolicyLock).Close failed: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
f(l)
|
||||
f(lock)
|
||||
}
|
||||
|
||||
@@ -127,32 +127,32 @@ func NewUserPolicyLock(token windows.Token) (*PolicyLock, error) {
|
||||
return lock, nil
|
||||
}
|
||||
|
||||
// Lock locks l.
|
||||
// It returns [ErrInvalidLockState] if l has a zero value or has already been closed,
|
||||
// Lock locks lk.
|
||||
// It returns [ErrInvalidLockState] if lk has a zero value or has already been closed,
|
||||
// [ErrLockRestricted] if the lock cannot be acquired due to a restriction in place,
|
||||
// or a [syscall.Errno] if the underlying Group Policy lock cannot be acquired.
|
||||
//
|
||||
// As a special case, it fails with [windows.ERROR_ACCESS_DENIED]
|
||||
// if l is a user policy lock, and the corresponding user is not logged in
|
||||
// if lk is a user policy lock, and the corresponding user is not logged in
|
||||
// interactively at the time of the call.
|
||||
func (l *PolicyLock) Lock() error {
|
||||
func (lk *PolicyLock) Lock() error {
|
||||
if policyLockRestricted.Load() > 0 {
|
||||
return ErrLockRestricted
|
||||
}
|
||||
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.lockCnt.Add(2)&1 == 0 {
|
||||
lk.mu.Lock()
|
||||
defer lk.mu.Unlock()
|
||||
if lk.lockCnt.Add(2)&1 == 0 {
|
||||
// The lock cannot be acquired because it has either never been properly
|
||||
// created or its Close method has already been called. However, we need
|
||||
// to call Unlock to both decrement lockCnt and leave the underlying
|
||||
// CriticalPolicySection if we won the race with another goroutine and
|
||||
// now own the lock.
|
||||
l.Unlock()
|
||||
lk.Unlock()
|
||||
return ErrInvalidLockState
|
||||
}
|
||||
|
||||
if l.handle != 0 {
|
||||
if lk.handle != 0 {
|
||||
// The underlying CriticalPolicySection is already acquired.
|
||||
// It is an R-Lock (with the W-counterpart owned by the Group Policy service),
|
||||
// meaning that it can be acquired by multiple readers simultaneously.
|
||||
@@ -160,20 +160,20 @@ func (l *PolicyLock) Lock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return l.lockSlow()
|
||||
return lk.lockSlow()
|
||||
}
|
||||
|
||||
// lockSlow calls enterCriticalPolicySection to acquire the underlying GP read lock.
|
||||
// It waits for either the lock to be acquired, or for the Close method to be called.
|
||||
//
|
||||
// l.mu must be held.
|
||||
func (l *PolicyLock) lockSlow() (err error) {
|
||||
func (lk *PolicyLock) lockSlow() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
// Decrement the counter if the lock cannot be acquired,
|
||||
// and complete the pending close request if we're the last owner.
|
||||
if l.lockCnt.Add(-2) == 0 {
|
||||
l.closeInternal()
|
||||
if lk.lockCnt.Add(-2) == 0 {
|
||||
lk.closeInternal()
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -190,12 +190,12 @@ func (l *PolicyLock) lockSlow() (err error) {
|
||||
resultCh := make(chan policyLockResult)
|
||||
|
||||
go func() {
|
||||
closing := l.closing
|
||||
if l.scope == UserPolicy && l.token != 0 {
|
||||
closing := lk.closing
|
||||
if lk.scope == UserPolicy && lk.token != 0 {
|
||||
// Impersonate the user whose critical policy section we want to acquire.
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
if err := impersonateLoggedOnUser(l.token); err != nil {
|
||||
if err := impersonateLoggedOnUser(lk.token); err != nil {
|
||||
initCh <- err
|
||||
return
|
||||
}
|
||||
@@ -209,10 +209,10 @@ func (l *PolicyLock) lockSlow() (err error) {
|
||||
close(initCh)
|
||||
|
||||
var machine bool
|
||||
if l.scope == MachinePolicy {
|
||||
if lk.scope == MachinePolicy {
|
||||
machine = true
|
||||
}
|
||||
handle, err := l.enterFn(machine)
|
||||
handle, err := lk.enterFn(machine)
|
||||
|
||||
send_result:
|
||||
for {
|
||||
@@ -226,7 +226,7 @@ func (l *PolicyLock) lockSlow() (err error) {
|
||||
// The lock is being closed, and we lost the race to l.closing
|
||||
// it the calling goroutine.
|
||||
if err == nil {
|
||||
l.leaveFn(handle)
|
||||
lk.leaveFn(handle)
|
||||
}
|
||||
break send_result
|
||||
default:
|
||||
@@ -247,21 +247,21 @@ func (l *PolicyLock) lockSlow() (err error) {
|
||||
select {
|
||||
case result := <-resultCh:
|
||||
if result.err == nil {
|
||||
l.handle = result.handle
|
||||
lk.handle = result.handle
|
||||
}
|
||||
return result.err
|
||||
case <-l.closing:
|
||||
case <-lk.closing:
|
||||
return ErrInvalidLockState
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock unlocks l.
|
||||
// It panics if l is not locked on entry to Unlock.
|
||||
func (l *PolicyLock) Unlock() {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
func (lk *PolicyLock) Unlock() {
|
||||
lk.mu.Lock()
|
||||
defer lk.mu.Unlock()
|
||||
|
||||
lockCnt := l.lockCnt.Add(-2)
|
||||
lockCnt := lk.lockCnt.Add(-2)
|
||||
if lockCnt < 0 {
|
||||
panic("negative lockCnt")
|
||||
}
|
||||
@@ -273,33 +273,33 @@ func (l *PolicyLock) Unlock() {
|
||||
return
|
||||
}
|
||||
|
||||
if l.handle != 0 {
|
||||
if lk.handle != 0 {
|
||||
// Impersonation is not required to unlock a critical policy section.
|
||||
// The handle we pass determines which mutex will be unlocked.
|
||||
leaveCriticalPolicySection(l.handle)
|
||||
l.handle = 0
|
||||
leaveCriticalPolicySection(lk.handle)
|
||||
lk.handle = 0
|
||||
}
|
||||
|
||||
if lockCnt == 0 {
|
||||
// Complete the pending close request if there's no more readers.
|
||||
l.closeInternal()
|
||||
lk.closeInternal()
|
||||
}
|
||||
}
|
||||
|
||||
// Close releases resources associated with l.
|
||||
// It is a no-op for the machine policy lock.
|
||||
func (l *PolicyLock) Close() error {
|
||||
lockCnt := l.lockCnt.Load()
|
||||
func (lk *PolicyLock) Close() error {
|
||||
lockCnt := lk.lockCnt.Load()
|
||||
if lockCnt&1 == 0 {
|
||||
// The lock has never been initialized, or close has already been called.
|
||||
return nil
|
||||
}
|
||||
|
||||
close(l.closing)
|
||||
close(lk.closing)
|
||||
|
||||
// Unset the LSB to indicate a pending close request.
|
||||
for !l.lockCnt.CompareAndSwap(lockCnt, lockCnt&^int32(1)) {
|
||||
lockCnt = l.lockCnt.Load()
|
||||
for !lk.lockCnt.CompareAndSwap(lockCnt, lockCnt&^int32(1)) {
|
||||
lockCnt = lk.lockCnt.Load()
|
||||
}
|
||||
|
||||
if lockCnt != 0 {
|
||||
@@ -307,16 +307,16 @@ func (l *PolicyLock) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return l.closeInternal()
|
||||
return lk.closeInternal()
|
||||
}
|
||||
|
||||
func (l *PolicyLock) closeInternal() error {
|
||||
if l.token != 0 {
|
||||
if err := l.token.Close(); err != nil {
|
||||
func (lk *PolicyLock) closeInternal() error {
|
||||
if lk.token != 0 {
|
||||
if err := lk.token.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
l.token = 0
|
||||
lk.token = 0
|
||||
}
|
||||
l.closing = nil
|
||||
lk.closing = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -256,8 +256,8 @@ func checkDomainAccount(username string) (sanitizedUserName string, isDomainAcco
|
||||
// errors.Is to check for it. When capLevel == CapCreateProcess, the logon
|
||||
// enforces the user's logon hours policy (when present).
|
||||
func (ls *lsaSession) logonAs(srcName string, u *user.User, capLevel CapabilityLevel) (token windows.Token, err error) {
|
||||
if l := len(srcName); l == 0 || l > _TOKEN_SOURCE_LENGTH {
|
||||
return 0, fmt.Errorf("%w, actual length is %d", ErrBadSrcName, l)
|
||||
if ln := len(srcName); ln == 0 || ln > _TOKEN_SOURCE_LENGTH {
|
||||
return 0, fmt.Errorf("%w, actual length is %d", ErrBadSrcName, ln)
|
||||
}
|
||||
if err := checkASCII(srcName); err != nil {
|
||||
return 0, fmt.Errorf("%w: %v", ErrBadSrcName, err)
|
||||
|
||||
@@ -938,10 +938,10 @@ func mergeEnv(existingEnv []string, extraEnv map[string]string) []string {
|
||||
result = append(result, strings.Join([]string{k, v}, "="))
|
||||
}
|
||||
|
||||
slices.SortFunc(result, func(l, r string) int {
|
||||
kl, _, _ := strings.Cut(l, "=")
|
||||
kr, _, _ := strings.Cut(r, "=")
|
||||
return strings.Compare(kl, kr)
|
||||
slices.SortFunc(result, func(a, b string) int {
|
||||
ka, _, _ := strings.Cut(a, "=")
|
||||
kb, _, _ := strings.Cut(b, "=")
|
||||
return strings.Compare(ka, kb)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ func (sib *StartupInfoBuilder) Resolve() (startupInfo *windows.StartupInfo, inhe
|
||||
// Always create a Unicode environment.
|
||||
createProcessFlags = windows.CREATE_UNICODE_ENVIRONMENT
|
||||
|
||||
if l := uint32(len(sib.attrs)); l > 0 {
|
||||
attrCont, err := windows.NewProcThreadAttributeList(l)
|
||||
if ln := uint32(len(sib.attrs)); ln > 0 {
|
||||
attrCont, err := windows.NewProcThreadAttributeList(ln)
|
||||
if err != nil {
|
||||
return nil, false, 0, err
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ func checkContiguousBuffer[T any, BU BufUnit](t *testing.T, extra []BU, pt *T, p
|
||||
if gotLen := int(ptLen); gotLen != expectedLen {
|
||||
t.Errorf("allocation length got %d, want %d", gotLen, expectedLen)
|
||||
}
|
||||
if l := len(slcs); l != 1 {
|
||||
t.Errorf("len(slcs) got %d, want 1", l)
|
||||
if ln := len(slcs); ln != 1 {
|
||||
t.Errorf("len(slcs) got %d, want 1", ln)
|
||||
}
|
||||
if len(extra) == 0 && slcs[0] != nil {
|
||||
t.Error("slcs[0] got non-nil, want nil")
|
||||
|
||||
Reference in New Issue
Block a user