// checkSessionClearSyntax - Check syntax of 'session clear sid'.
775693
func checkSessionClearSyntax(ctx *cli.Context) {
	if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
		cli.ShowCommandHelpAndExit(ctx, "clear", 1) // last argument is exit code
	}
}
375896
func (pder *MemProvider) SessionExist(sid string) bool {
	pder.lock.RLock()
	defer pder.lock.RUnlock()
	if _, ok := pder.sessions[sid]; ok {
		return true
	}
	return false
}
656126
func ClearSession(config *Config, timeout time.Duration) error {
	// copy config
	newConfig := *config
	newConfig.CleanSession = true

	// create client
	client := New()

	// connect to broker
	future, err := client.Connect(&newConfig)
	if err != nil {
		return err
	}

	// wait for future
	err = future.Wait(timeout)
	if err != nil {
		return err
	}

	// disconnect
	err = client.Disconnect()
	if err != nil {
		return err
	}

	return nil
}
414569
func (s *Session) ClearCache() (err error) {
	if err = s.isActionable(); err != nil {
		return
	}
	_, err = synchronousEvent(s.c, s, s.w, Event{Name: EventNameSessionCmdClearCache, TargetID: s.id}, EventNameSessionEventClearedCache)
	return
}
86245
func (c *Client) DeleteSession(namespace, id string) error {
	if namespace == "" {
		return trace.BadParameter(MissingNamespaceError)
	}
	_, err := c.Delete(c.Endpoint("namespaces", namespace, "sessions", id))
	return trace.Wrap(err)
}
1156462
func (p *Process) CheckAndClearManualStopRequest() bool {
	p.conn.manualStopMutex.Lock()
	msr := p.manualStopRequested
	p.manualStopRequested = false
	p.conn.manualStopMutex.Unlock()
	return msr
}
1325202
func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) {
	sysVar := SysVars[key]
	if sysVar == nil {
		return "", false, UnknownSystemVar.GenWithStackByArgs(key)
	}
	// For virtual system variables:
	switch sysVar.Name {
	case TiDBCurrentTS:
		return fmt.Sprintf("%d", s.TxnCtx.StartTS), true, nil
	case TiDBGeneralLog:
		return fmt.Sprintf("%d", atomic.LoadUint32(&ProcessGeneralLog)), true, nil
	case TiDBConfig:
		conf := config.GetGlobalConfig()
		j, err := json.MarshalIndent(conf, "", "\t")
		if err != nil {
			return "", false, err
		}
		return string(j), true, nil
	case TiDBForcePriority:
		return mysql.Priority2Str[mysql.PriorityEnum(atomic.LoadInt32(&ForcePriority))], true, nil
	case TiDBSlowLogThreshold:
		return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.SlowThreshold), 10), true, nil
	case TiDBDDLSlowOprThreshold:
		return strconv.FormatUint(uint64(atomic.LoadUint32(&DDLSlowOprThreshold)), 10), true, nil
	case TiDBQueryLogMaxLen:
		return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.QueryLogMaxLen), 10), true, nil
	case PluginDir:
		return config.GetGlobalConfig().Plugin.Dir, true, nil
	case PluginLoad:
		return config.GetGlobalConfig().Plugin.Load, true, nil
	case TiDBCheckMb4ValueInUTF8:
		return BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8), true, nil
	}
	sVal, ok := s.systems[key]
	if ok {
		return sVal, true, nil
	}
	if sysVar.Scope&ScopeGlobal == 0 {
		// None-Global variable can use pre-defined default value.
		return sysVar.Value, true, nil
	}
	return "", false, nil
}
78879
func checkSessionResumeSyntax(ctx *cli.Context) {
	if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
		cli.ShowCommandHelpAndExit(ctx, "resume", 1) // last argument is exit code
	}
}
764987
func (u *User) DeleteSessions(db *sqlx.DB) error {
	q := `DELETE FROM sessions WHERE userid=$1`
	_, err := db.Exec(q, u.ID)
	if err != nil && err != sql.ErrNoRows {
		return err
	}
	return nil
}
1357922
func (s *UpdateRecordsInput) SetSyncSessionToken(v string) *UpdateRecordsInput {
	s.SyncSessionToken = &v
	return s
}
1347597
func (handle *ContextHandle) validateSession(currentSession mPkcs11.SessionHandle) mPkcs11.SessionHandle {

	handle.lock.RLock()

	e := handle.detectErrorCondition(currentSession)

	switch e {
	case errSlotIDChanged,
		mPkcs11.Error(mPkcs11.CKR_OBJECT_HANDLE_INVALID),
		mPkcs11.Error(mPkcs11.CKR_SESSION_HANDLE_INVALID),
		mPkcs11.Error(mPkcs11.CKR_SESSION_CLOSED),
		mPkcs11.Error(mPkcs11.CKR_TOKEN_NOT_PRESENT),
		mPkcs11.Error(mPkcs11.CKR_DEVICE_ERROR),
		mPkcs11.Error(mPkcs11.CKR_GENERAL_ERROR),
		mPkcs11.Error(mPkcs11.CKR_USER_NOT_LOGGED_IN):

		logger.Warnf("Found error condition [%s], attempting to recreate pkcs11 context and re-login....", e)

		handle.lock.RUnlock()
		handle.lock.Lock()
		defer handle.lock.Unlock()

		handle.disposePKCS11Ctx()

		//create new context
		newCtx := handle.createNewPKCS11Ctx()
		if newCtx == nil {
			logger.Warn("Failed to recreate new pkcs11 context for given library")
			return 0
		}

		//find slot
		slot, found := handle.findSlot(newCtx)
		if !found {
			logger.Warnf("Unable to find slot for label :%s", handle.label)
			return 0
		}
		logger.Debug("got the slot ", slot)

		//open new session for given slot
		newSession, err := createNewSession(newCtx, slot)
		if err != nil {
			logger.Fatalf("OpenSession [%s]\n", err)
			return 0
		}
		logger.Debugf("Recreated new pkcs11 session %+v on slot %d\n", newSession, slot)

		//login with new session
		err = newCtx.Login(newSession, mPkcs11.CKU_USER, handle.pin)
		if err != nil && err != mPkcs11.Error(mPkcs11.CKR_USER_ALREADY_LOGGED_IN) {
			logger.Warnf("Unable to login with new session :%s", newSession)
			return 0
		}

		handle.sendNotification()

		handle.ctx = newCtx
		handle.slot = slot
		handle.sessions = make(chan mPkcs11.SessionHandle, handle.opts.sessionCacheSize)

		logger.Infof("Able to login with recreated session successfully")
		return newSession

	case mPkcs11.Error(mPkcs11.CKR_DEVICE_MEMORY),
		mPkcs11.Error(mPkcs11.CKR_DEVICE_REMOVED):
		handle.lock.RUnlock()
		panic(fmt.Sprintf("PKCS11 Session failure: [%s]", e))

	default:
		handle.lock.RUnlock()
		// default should be a valid session or valid error, return session as it is
		return currentSession
	}
}
483707
func Clear(w http.ResponseWriter, r *http.Request, sess *sessions.Session) {
	// Delete the map if it doesn't exist
	if _, ok := sess.Values[TokenName]; ok {
		delete(sess.Values, TokenName)
		sess.Save(r, w)
	}
}
785042
func (i *iscsiConnectionInfo) sessionBase(deviceName string) (string, error) {
	lnkPath := filepath.Join(sysfsBlock, deviceName)
	lnkRealPath, err := os.Readlink(lnkPath)
	if err != nil {
		return "", err
	}
	fullPath, err := filepath.Abs(filepath.Join(sysfsBlock, lnkRealPath))
	if err != nil {
		return "", err
	}
	segments := strings.SplitN(fullPath[1:], "/", -1)
	if len(segments) != 9 {
		// iscsi block devices look like:
		// /sys/devices/platform/host2/session1/target2:0:0/2:0:0:1/block/sda
		return "", errors.Errorf("not an iscsi device")
	}
	if _, err := os.Stat(filepath.Join(sysfsiSCSIHost, segments[3])); err != nil {
		return "", errors.Errorf("not an iscsi device")
	}
	sessionPath := filepath.Join(sysfsiSCSISession, segments[4])
	if _, err := os.Stat(sessionPath); err != nil {
		return "", errors.Errorf("session does not exits")
	}
	return sessionPath, nil
}
1129616
func checkShareListSyntax(ctx *cli.Context) {
	args := ctx.Args()
	if !args.Present() || (args.First() != "upload" && args.First() != "download") {
		cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code.
	}
}
1331361
func (l *logOnceType) cleanupRoutine() {
	for {
		l.Lock()
		l.IDMap = make(map[interface{}]error)
		l.Unlock()

		time.Sleep(30 * time.Minute)
	}
}
1264649
func (c *Crowd) InvalidateSession(token string) error {
	c.Client.Jar = c.cookies
	req, err := http.NewRequest("DELETE", c.url+"rest/usermanagement/1/session/"+token, nil)
	if err != nil {
		return err
	}
	req.SetBasicAuth(c.user, c.passwd)
	req.Header.Set("Accept", "application/xml")
	req.Header.Set("Content-Type", "application/xml")
	resp, err := c.Client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != 204 {
		return fmt.Errorf("request failed: %s", resp.Status)
	}

	return nil
}
289124
func (session *SafeSession) Reset() {
	if session == nil || session.Session == nil {
		return
	}
	session.mu.Lock()
	defer session.mu.Unlock()
	session.mustRollback = false
	session.autocommitState = notAutocommittable
	session.Session.InTransaction = false
	session.SingleDb = false
	session.ShardSessions = nil
}