forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auditbeat: Split common tty definitions (elastic#42004)
No functional changes, just move tty things to a common place so that the upcoming system/process provider can use it. Last of the PRs to split common code for the new system/process provider (I promise).
- Loading branch information
1 parent
f45b2b0
commit d7d79d3
Showing
8 changed files
with
123 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package tty | ||
|
||
type TTYType int | ||
|
||
const ( | ||
TTYUnknown TTYType = iota | ||
Pts | ||
TTY | ||
TTYConsole | ||
) | ||
|
||
const ( | ||
ptsMinMajor = 136 | ||
ptsMaxMajor = 143 | ||
ttyMajor = 4 | ||
consoleMaxMinor = 63 | ||
ttyMaxMinor = 255 | ||
) | ||
|
||
type TTYDev struct { | ||
Minor uint32 | ||
Major uint32 | ||
Winsize TTYWinsize | ||
Termios TTYTermios | ||
} | ||
|
||
type TTYWinsize struct { | ||
Rows uint16 | ||
Cols uint16 | ||
} | ||
|
||
type TTYTermios struct { | ||
CIflag uint32 | ||
COflag uint32 | ||
CLflag uint32 | ||
CCflag uint32 | ||
} | ||
|
||
// interactiveFromTTY returns if this is an interactive tty device. | ||
func InteractiveFromTTY(tty TTYDev) bool { | ||
return TTYUnknown != GetTTYType(tty.Major, tty.Minor) | ||
} | ||
|
||
// getTTYType returns the type of a TTY device based on its major and minor numbers. | ||
func GetTTYType(major uint32, minor uint32) TTYType { | ||
if major >= ptsMinMajor && major <= ptsMaxMajor { | ||
return Pts | ||
} | ||
|
||
if ttyMajor == major { | ||
if minor <= consoleMaxMinor { | ||
return TTYConsole | ||
} else if minor > consoleMaxMinor && minor <= ttyMaxMinor { | ||
return TTY | ||
} | ||
} | ||
|
||
return TTYUnknown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.