/
dmtcp.go
89 lines (73 loc) · 2.31 KB
/
dmtcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) Contributors to the Apptainer project, established as
// Apptainer a Series of LF Projects LLC.
// For website terms of use, trademark policy, privacy policy and other
// project policies see https://lfprojects.org/policies
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package dmtcp
import (
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/apptainer/apptainer/internal/pkg/buildcfg"
"github.com/apptainer/apptainer/internal/pkg/checkpoint"
"github.com/apptainer/apptainer/internal/pkg/util/paths"
"github.com/apptainer/apptainer/pkg/sylog"
"gopkg.in/yaml.v2"
)
const (
containerStatepath = "/.checkpoint"
portFile = "coord.port"
logFile = "coord.log"
)
const (
dmtcpPath = "dmtcp"
)
func dmtcpDir() string {
return filepath.Join(checkpoint.StatePath(), dmtcpPath)
}
type Config struct {
Bins []string `yaml:"bins"`
Libs []string `yaml:"libs"`
}
func parseConfig() (*Config, error) {
confPath := filepath.Join(buildcfg.APPTAINER_CONFDIR, "dmtcp-conf.yaml")
buf, err := os.ReadFile(confPath)
if err != nil {
return nil, err
}
var c Config
err = yaml.Unmarshal(buf, &c)
if err != nil {
return nil, err
}
return &c, nil
}
func GetPaths() ([]string, []string, error) {
conf, err := parseConfig()
if err != nil {
return nil, nil, err
}
libs, bins, err := paths.Resolve(append(conf.Bins, conf.Libs...))
if err != nil {
return nil, nil, err
}
var usrBins []string
for _, bin := range bins {
usrBin := filepath.Join("/usr/bin", filepath.Base(bin))
usrBins = append(usrBins, strings.Join([]string{bin, usrBin}, ":"))
}
return usrBins, libs, nil
}
// QuickInstallationCheck is a quick smoke test to see if dmtcp is installed
// on the host for injection by checking for one of the well known dmtcp
// executables in the PATH. If not found a warning is emitted.
func QuickInstallationCheck() {
_, err := exec.LookPath("dmtcp_launch")
if err == nil {
return
}
sylog.Warningf("Unable to locate a dmtcp installation, some functionality may not work as expected. Please ensure a dmtcp installation exists or install it following instructions here: https://github.com/dmtcp/dmtcp/blob/master/INSTALL.md")
}