Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
wendelin.core
Commits
af3c514e
Commit
af3c514e
authored
Oct 27, 2024
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b15ad994
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
9 deletions
+54
-9
wcfs/wcfs.go
wcfs/wcfs.go
+54
-9
No files found.
wcfs/wcfs.go
View file @
af3c514e
...
...
@@ -492,6 +492,7 @@ import (
stdlog
"log"
"math"
"os"
"os/user"
"runtime"
"sort"
"strings"
...
...
@@ -516,7 +517,6 @@ import (
"github.com/johncgriffin/overflow"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/fuse/nodefs"
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"
"github.com/pkg/errors"
...
...
@@ -748,11 +748,11 @@ type Stats struct {
type
Client
struct
{
proc
*
os
.
Process
// Holds process to send signals to
info
types
.
ProcessInfo
// Provides information about process
user
types
.
UserInfo
// Provides information about the user that owns the client process
user
*
user
.
User
// Provides information about the user that owns the client process
}
func
(
client
Client
)
Format
()
string
{
return
fmt
.
Sprintf
(
"process(PID=%v;
exe=%v;UID=%v)"
,
client
.
info
.
PID
,
client
.
info
.
Exe
,
client
.
user
.
UID
)
return
fmt
.
Sprintf
(
"process(PID=%v;
name=%v;user=%v)"
,
client
.
info
.
PID
,
client
.
info
.
Name
,
client
.
user
.
Username
)
}
func
debugClient
(
client
Client
,
format
string
,
argv
...
interface
{})
{
...
...
@@ -2018,6 +2018,45 @@ func (wnode *WatchNode) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fus
return
node
,
err2LogStatus
(
err
)
}
func
getProcessInfo
(
p
*
os
.
Process
)
(
types
.
ProcessInfo
,
error
)
{
pid
:=
p
.
Pid
bpath
:=
fmt
.
Sprintf
(
"/proc/%v/"
,
pid
)
comm
,
err
:=
os
.
ReadFile
(
bpath
+
"comm"
)
if
err
!=
nil
{
return
types
.
ProcessInfo
{},
err
}
pinfo
:=
&
types
.
ProcessInfo
{
Name
:
strings
.
TrimSuffix
(
string
(
comm
[
:
]),
"
\n
"
),
PID
:
pid
,
}
return
*
pinfo
,
nil
}
func
getProcessUserInfo
(
p
*
os
.
Process
)
(
*
user
.
User
,
error
)
{
pid
:=
p
.
Pid
bpath
:=
fmt
.
Sprintf
(
"/proc/%v/"
,
pid
)
status
,
err
:=
os
.
ReadFile
(
bpath
+
"status"
)
if
err
!=
nil
{
return
nil
,
err
}
lines
:=
strings
.
SplitN
(
string
(
status
[
:
]),
"
\n
"
,
-
1
)
var
uid
string
for
_
,
line
:=
range
lines
{
words
:=
strings
.
SplitN
(
line
,
"
\t
"
,
-
1
)
if
words
[
0
]
==
"Uid:"
{
uid
=
words
[
1
]
}
}
u
,
err
:=
user
.
LookupId
(
uid
)
if
err
!=
nil
{
u
=
&
user
.
User
{
Uid
:
uid
,
Username
:
"???"
+
uid
}
}
return
u
,
nil
}
func
(
wnode
*
WatchNode
)
open
(
flags
uint32
,
fctx
*
fuse
.
Context
)
(
_
nodefs
.
File
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"/head/watch: open"
)
...
...
@@ -2032,15 +2071,21 @@ func (wnode *WatchNode) open(flags uint32, fctx *fuse.Context) (_ nodefs.File, e
}
// fetch info of client process for logging
syslog_proc
,
err
:=
sysinfo
.
Process
(
proc
.
Pid
)
if
err
!=
nil
{
return
nil
,
err
}
proc_info
,
err
:=
syslog_proc
.
Info
()
// XXX Can't use because /proc/PID/exe is only available to user
// (setting capacities doesn't help).
// syslog_proc, err := sysinfo.Process(proc.Pid)
// if err != nil {
// return nil, err
// }
// proc_info, err := syslog_proc.Info()
// if err != nil {
// return nil, err
// }
proc_info
,
err
:=
getProcessInfo
(
proc
)
if
err
!=
nil
{
return
nil
,
err
}
user_info
,
err
:=
syslog_proc
.
User
(
)
user_info
,
err
:=
getProcessUserInfo
(
proc
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment