Skip to content

Commit

Permalink
log initiated
Browse files Browse the repository at this point in the history
  • Loading branch information
logeshkrish committed Jan 12, 2021
1 parent d3ed2a5 commit 4d51e89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Binary file removed cmd/gpctl
Binary file not shown.
5 changes: 3 additions & 2 deletions trace/startTrace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ func PortList(delay int, pid string, slog *logrus.Entry) (Network, error) {

/* Edit trace.log and get file list */

func GetDependFiles(pid string, slog *logrus.Entry) []string {
func GetDependFiles(pid string, slog *logrus.Entry) ([]string, error) {
var trace_files []string
file, err := os.Open("~/.sail/" + pid + "trace.log")
if err != nil {
slog.Printf("trace/startTrace Error: File Open error")
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
Expand All @@ -162,7 +163,7 @@ func GetDependFiles(pid string, slog *logrus.Entry) []string {
}
}
trace_files = append(trace_files, "/etc/group", "/etc/passwd")
return trace_files
return trace_files, nil
}

/* Check if substr present in slice */
Expand Down
22 changes: 18 additions & 4 deletions trace/trace_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
cmd "github.com/gopaddle-io/sail/util/cmd"
context "github.com/gopaddle-io/sail/util/context"
json_util "github.com/gopaddle-io/sail/util/json"
clog "github.com/gopaddle-io/sail/util/log"
log "github.com/gopaddle-io/sail/util/log"
)

func GetList_noreq(requestID string) ([]listProcess.Process, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
processes, err := listProcess.ProcessList(sCxt.Log)
Expand All @@ -40,6 +42,7 @@ func GetPorts_noreq(requestID string) (startTrace.Network, error) {
return network, nil
}
func GetFilesPkg_noreq(pid, requestID string) (startTrace.FilesPkg, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
file, err := os.Open("~/.sail/" + pid + "/files.log")
Expand All @@ -56,7 +59,8 @@ func GetFilesPkg_noreq(pid, requestID string) (startTrace.FilesPkg, error) {
}

// packages
file, err = os.Open("~/.sail/" + pid + "/packages.log")
home := os.Getenv("HOME")
file, err = os.Open(home + "/.sail/" + pid + "/packages.log")
var pkg []string
if err != nil {
sCxt.Log.Println("module:sail", "requestID:"+requestID)
Expand All @@ -78,6 +82,7 @@ func GetFilesPkg_noreq(pid, requestID string) (startTrace.FilesPkg, error) {
}

func NfsMounts_noreq(requestID string) ([]startTrace.Nfs, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
nfs_list, err := startTrace.GetNfsMounts(sCxt.Log)
Expand All @@ -87,6 +92,7 @@ func NfsMounts_noreq(requestID string) ([]startTrace.Nfs, error) {
return nfs_list, nil
}
func GetEnvVariables_noreq(pid, requestID string) (startTrace.EnvList, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
env_list, err := startTrace.GetEnv(pid, sCxt.Log)
Expand All @@ -105,6 +111,7 @@ func GetStartCmd_noreq() startTrace.Start {
return startTrace.GetStartCmd()
}
func StartTracing_noreq(pid string, trace_time int, requestID string) (string, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
os_family, os_name, os_ver, err := cmd.GetOS()
Expand Down Expand Up @@ -220,13 +227,17 @@ func StartTracing_noreq(pid string, trace_time int, requestID string) (string, e
json.Unmarshal([]byte(os_string), &os_details)

sCxt.Log.Println("File and Package list making")
file_list := startTrace.GetDependFiles(pid, sCxt.Log)
file_list, err := startTrace.GetDependFiles(pid, sCxt.Log)
if err != nil {
return "", err
}
pkg_list := startTrace.GetDependPackages(os_details.Osname, file_list, sCxt.Log)

sort.Strings(file_list)

/* Packages */
file, err := os.OpenFile("~/.sail/"+pid+"/packages.log", os.O_APPEND|os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
home := os.Getenv("HOME")
file, err := os.OpenFile(home+"/.sail/"+pid+"/packages.log", os.O_APPEND|os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
sCxt.Log.Printf("failed creating file: %s", err)
return "", err
Expand All @@ -242,7 +253,8 @@ func StartTracing_noreq(pid string, trace_time int, requestID string) (string, e
file.Close()

/* Files */
file, err = os.OpenFile("~/.sail/"+pid+"/files.log", os.O_APPEND|os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)

file, err = os.OpenFile(home+"/.sail/"+pid+"/files.log", os.O_APPEND|os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
sCxt.Log.Printf("failed creating file: %s", err)
return "", err
Expand Down Expand Up @@ -294,6 +306,7 @@ func DockerCreate_noreq(osname string, osver string, imagename string, requestID
}

func DockerCopy_noreq(dirs []string, requestID string) (string, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
/* Copy User Defined Files */
Expand All @@ -317,6 +330,7 @@ func DockerCopy_noreq(dirs []string, requestID string) (string, error) {
}

func FinalImageCreate_noreq(workdir string, imagename string, requestID string) (string, error) {
clog.Init()
log := log.Log("module:sail", "requestID:"+requestID)
sCxt := NewSailContext(log, requestID)
/* User name */
Expand Down

0 comments on commit 4d51e89

Please sign in to comment.