69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package leech
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// The bug is a bare-bones interface
|
|
// describing basic methods that a Leech
|
|
// should exhibit.
|
|
type bug interface {
|
|
// Pid will return a process id.
|
|
Pid() int
|
|
// Process will return a pointer
|
|
// to the internal process.
|
|
Process() *Process
|
|
// ProcStatus will return the Process's status,
|
|
// seen at (Meta) -> status (Status).
|
|
ProcStatus() Status
|
|
// Meta will return the process metadata.
|
|
Meta() *Meta
|
|
// Start will start the process.
|
|
Start() bool
|
|
// TODO: (@bfu4) Can we pipe into a terminal?
|
|
// Attach(*term.Terminal)
|
|
}
|
|
|
|
type Leech struct {
|
|
// The Leech's meta (metadata).
|
|
meta *Meta
|
|
// The process id of the leech.
|
|
pid int
|
|
// The synchronization mutex.
|
|
mu *sync.Mutex
|
|
}
|
|
|
|
// SetProcData will set a leech's current process data.
|
|
func (l *Leech) SetProcData(data *ProcessData) {
|
|
if l.meta.status > Dead {
|
|
// Seriously, dude.
|
|
return
|
|
}
|
|
// Let's not allow access to ~anyone~ during this operation.
|
|
l.mu.Lock()
|
|
l.meta.process.data = data
|
|
l.mu.Unlock()
|
|
}
|
|
|
|
// Start will start a leech's process.
|
|
func (l *Leech) Start() bool {
|
|
l.mu.Lock()
|
|
defer l.mu.Unlock()
|
|
l.meta.Process().Daemonize()
|
|
if l.meta.process.status > Zombie {
|
|
l.meta.pid = l.meta.Process().internal.Pid
|
|
l.pid = l.meta.pid
|
|
}
|
|
return l.meta.Process().IsDaemon()
|
|
}
|
|
|
|
// Meta returns the metadata.
|
|
func (l *Leech) Meta() *Meta {
|
|
return l.meta
|
|
}
|
|
|
|
// Pid returns the process id.
|
|
func (l *Leech) Pid() int {
|
|
return l.pid
|
|
}
|