mirror of
https://github.com/containers/podman.git
synced 2025-11-16 11:07:44 +08:00
vendor psgo v1.2
The psgo library now be used concurrently by multiple goroutines without interferring with another. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
11
vendor/github.com/containers/psgo/internal/dev/tty.go
generated
vendored
11
vendor/github.com/containers/psgo/internal/dev/tty.go
generated
vendored
@@ -31,12 +31,9 @@ type TTY struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// cache TTYs to avoid redundant lookups
|
||||
var devices *[]TTY
|
||||
|
||||
// FindTTY return the corresponding TTY to the ttyNr or nil of non could be
|
||||
// found.
|
||||
func FindTTY(ttyNr uint64) (*TTY, error) {
|
||||
func FindTTY(ttyNr uint64, devices *[]TTY) (*TTY, error) {
|
||||
// (man 5 proc) The minor device number is contained in the combination
|
||||
// of bits 31 to 20 and 7 to 0; the major device number is in bits 15
|
||||
// to 8.
|
||||
@@ -44,7 +41,7 @@ func FindTTY(ttyNr uint64) (*TTY, error) {
|
||||
min := (ttyNr & 0xFF) | ((ttyNr >> 20) & 0xFFF)
|
||||
|
||||
if devices == nil {
|
||||
devs, err := getTTYs()
|
||||
devs, err := TTYs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,8 +67,8 @@ func minDevNum(rdev uint64) uint64 {
|
||||
return (rdev & 0xff) | ((rdev >> 12) & 0xfff00)
|
||||
}
|
||||
|
||||
// getTTYs parses /dev for tty and pts devices.
|
||||
func getTTYs() (*[]TTY, error) {
|
||||
// TTYs parses /dev for tty and pts devices.
|
||||
func TTYs() (*[]TTY, error) {
|
||||
devDir, err := os.Open("/dev/")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
5
vendor/github.com/containers/psgo/internal/proc/status.go
generated
vendored
5
vendor/github.com/containers/psgo/internal/proc/status.go
generated
vendored
@@ -21,7 +21,6 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/psgo/internal/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -207,11 +206,11 @@ func readStatusDefault(pid string) ([]string, error) {
|
||||
}
|
||||
|
||||
// ParseStatus parses the /proc/$pid/status file and returns a *Status.
|
||||
func ParseStatus(ctx *types.PsContext, pid string) (*Status, error) {
|
||||
func ParseStatus(pid string, joinUserNS bool) (*Status, error) {
|
||||
var lines []string
|
||||
var err error
|
||||
|
||||
if ctx.JoinUserNS {
|
||||
if joinUserNS {
|
||||
lines, err = readStatusUserNS(pid)
|
||||
} else {
|
||||
lines, err = readStatusDefault(pid)
|
||||
|
||||
13
vendor/github.com/containers/psgo/internal/process/process.go
generated
vendored
13
vendor/github.com/containers/psgo/internal/process/process.go
generated
vendored
@@ -21,7 +21,6 @@ import (
|
||||
|
||||
"github.com/containers/psgo/internal/host"
|
||||
"github.com/containers/psgo/internal/proc"
|
||||
"github.com/containers/psgo/internal/types"
|
||||
"github.com/opencontainers/runc/libcontainer/user"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -76,13 +75,13 @@ func LookupUID(uid string) (string, error) {
|
||||
|
||||
// New returns a new Process with the specified pid and parses the relevant
|
||||
// data from /proc and /dev.
|
||||
func New(ctx *types.PsContext, pid string) (*Process, error) {
|
||||
func New(pid string, joinUserNS bool) (*Process, error) {
|
||||
p := Process{Pid: pid}
|
||||
|
||||
if err := p.parseStat(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := p.parseStatus(ctx); err != nil {
|
||||
if err := p.parseStatus(joinUserNS); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := p.parseCmdLine(); err != nil {
|
||||
@@ -103,10 +102,10 @@ func New(ctx *types.PsContext, pid string) (*Process, error) {
|
||||
}
|
||||
|
||||
// FromPIDs creates a new Process for each pid.
|
||||
func FromPIDs(ctx *types.PsContext, pids []string) ([]*Process, error) {
|
||||
func FromPIDs(pids []string, joinUserNS bool) ([]*Process, error) {
|
||||
processes := []*Process{}
|
||||
for _, pid := range pids {
|
||||
p, err := New(ctx, pid)
|
||||
p, err := New(pid, joinUserNS)
|
||||
if err != nil {
|
||||
if os.IsNotExist(errors.Cause(err)) {
|
||||
// proc parsing is racy
|
||||
@@ -131,8 +130,8 @@ func (p *Process) parseStat() error {
|
||||
}
|
||||
|
||||
// parseStatus parses /proc/$pid/status.
|
||||
func (p *Process) parseStatus(ctx *types.PsContext) error {
|
||||
s, err := proc.ParseStatus(ctx, p.Pid)
|
||||
func (p *Process) parseStatus(joinUserNS bool) error {
|
||||
s, err := proc.ParseStatus(p.Pid, joinUserNS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
22
vendor/github.com/containers/psgo/internal/types/types.go
generated
vendored
22
vendor/github.com/containers/psgo/internal/types/types.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
// Copyright 2018 psgo authors
|
||||
//
|
||||
// Licensed 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 types
|
||||
|
||||
// PsContext controls some internals of the psgo library.
|
||||
type PsContext struct {
|
||||
// JoinUserNS will force /proc and /dev parsing from within each PIDs
|
||||
// user namespace.
|
||||
JoinUserNS bool
|
||||
}
|
||||
Reference in New Issue
Block a user