()
| 94 | } |
| 95 | |
| 96 | func processEnvironment() (map[string]string, error) { |
| 97 | idx := 2 |
| 98 | for ; idx < len(os.Args); idx++ { |
| 99 | if os.Args[idx] == "--process" { |
| 100 | break |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if idx >= len(os.Args)-1 || os.Args[idx] != "--process" { |
| 105 | return nil, errors.New("env: option --process required") |
| 106 | } |
| 107 | |
| 108 | specFile := os.Args[idx+1] |
| 109 | f, err := os.OpenFile(specFile, os.O_RDONLY, 0o644) |
| 110 | if err != nil { |
| 111 | return nil, fmt.Errorf("env: failed to open %s: %w", specFile, err) |
| 112 | } |
| 113 | |
| 114 | b, err := io.ReadAll(f) |
| 115 | if err != nil { |
| 116 | return nil, fmt.Errorf("env: failed to read spec from %q", specFile) |
| 117 | } |
| 118 | var spec specs.Process |
| 119 | if err := json.Unmarshal(b, &spec); err != nil { |
| 120 | return nil, fmt.Errorf("env: failed to unmarshal spec from %q: %w", specFile, err) |
| 121 | } |
| 122 | |
| 123 | // XXX: env vars can be specified multiple times, but we only keep one |
| 124 | env := make(map[string]string) |
| 125 | for _, e := range spec.Env { |
| 126 | k, v, _ := strings.Cut(e, "=") |
| 127 | env[k] = v |
| 128 | } |
| 129 | |
| 130 | return env, nil |
| 131 | } |
no test coverage detected
searching dependent graphs…