代码拉取完成,页面将自动刷新
同步操作将从 tupelo-shen/mysnapd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2020 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package backend
import (
"gitee.com/mysnapcore/mysnapd/cmd/snaplock"
"gitee.com/mysnapcore/mysnapd/cmd/snaplock/runinhibit"
"gitee.com/mysnapcore/mysnapd/osutil"
"gitee.com/mysnapcore/mysnapd/snap"
)
func (b Backend) RunInhibitSnapForUnlink(info *snap.Info, hint runinhibit.Hint, decision func() error) (lock *osutil.FileLock, err error) {
// A process may be created after the soft refresh done upon
// the request to refresh a snap. If such process is alive by
// the time this code is reached the refresh process is stopped.
// Grab per-snap lock to prevent new processes from starting. This is
// sufficient to perform the check, even though individual processes
// may fork or exit, we will have per-security-tag information about
// what is running.
lock, err = snaplock.OpenLock(info.InstanceName())
if err != nil {
return nil, err
}
// Keep a copy of lock, so that we can close it in the function below.
// The regular lock variable is assigned to by return, due to the named
// return values.
lockToClose := lock
defer func() {
// If we have a lock but we are returning an error then unlock the lock
// by closing it.
if lockToClose != nil && err != nil {
lockToClose.Close()
}
}()
if err := lock.Lock(); err != nil {
return nil, err
}
//
if err := decision(); err != nil {
return nil, err
}
// Decision function did not fail so we can, while we still hold the snap
// lock, install the snap run inhibition hint, returning the snap lock to
// the caller.
//
// XXX: should we move this logic to the place that calls the "soft"
// check instead? Doing so would somewhat change the semantic of soft
// and hard checks, as it would effectively make hard check a no-op,
// but it might provide a nicer user experience.
if err := runinhibit.LockWithHint(info.InstanceName(), hint); err != nil {
return nil, err
}
return lock, nil
}
// WithSnapLock executes given action with the snap lock held.
//
// The lock is also used by snap-confine during pre-snap mount namespace
// initialization. Holding it allows to ensure mutual exclusion during the
// process of preparing a new snap app or hook processes. It does not prevent
// existing application or hook processes from forking.
//
// Note that this is not a method of the Backend type, so that it can be
// invoked from doInstall, which does not have access to a backend object.
func WithSnapLock(info *snap.Info, action func() error) error {
lock, err := snaplock.OpenLock(info.InstanceName())
if err != nil {
return err
}
// Closing the lock also unlocks it, if locked.
defer lock.Close()
if err := lock.Lock(); err != nil {
return err
}
return action()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。