(cmd *cobra.Command, args []string)
| 148 | } |
| 149 | |
| 150 | func initContainer(cmd *cobra.Command, args []string) error { |
| 151 | if !utils.IsInsideContainer() { |
| 152 | var builder strings.Builder |
| 153 | fmt.Fprintf(&builder, "the 'init-container' command can only be used inside containers\n") |
| 154 | fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase) |
| 155 | |
| 156 | errMsg := builder.String() |
| 157 | return errors.New(errMsg) |
| 158 | } |
| 159 | |
| 160 | if !cmd.Flag("gid").Changed { |
| 161 | initContainerFlags.gid = initContainerFlags.uid |
| 162 | } |
| 163 | |
| 164 | utils.EnsureXdgRuntimeDirIsSet(initContainerFlags.uid) |
| 165 | |
| 166 | logrus.Debug("Creating /run/.toolboxenv") |
| 167 | |
| 168 | toolboxEnvFile, err := os.Create("/run/.toolboxenv") |
| 169 | if err != nil { |
| 170 | return errors.New("failed to create /run/.toolboxenv") |
| 171 | } |
| 172 | |
| 173 | defer toolboxEnvFile.Close() |
| 174 | |
| 175 | if toolbxDelayEntryPoint, ok := getDelayEntryPoint(); ok { |
| 176 | delayString := toolbxDelayEntryPoint.String() |
| 177 | logrus.Debugf("Adding a delay of %s", delayString) |
| 178 | time.Sleep(toolbxDelayEntryPoint) |
| 179 | } |
| 180 | |
| 181 | if toolbxFailEntryPoint, ok := getFailEntryPoint(); ok { |
| 182 | var builder strings.Builder |
| 183 | builder.WriteString("TOOLBX_FAIL_ENTRY_POINT is set") |
| 184 | if toolbxFailEntryPoint > 1 { |
| 185 | builder.WriteString("\n") |
| 186 | builder.WriteString("This environment variable should only be set when testing.") |
| 187 | } |
| 188 | |
| 189 | errMsg := builder.String() |
| 190 | return errors.New(errMsg) |
| 191 | } |
| 192 | |
| 193 | if utils.PathExists("/run/host/etc") { |
| 194 | logrus.Debug("Path /run/host/etc exists") |
| 195 | |
| 196 | if _, err := os.Readlink("/etc/host.conf"); err != nil { |
| 197 | if err := redirectPath("/etc/host.conf", |
| 198 | "/run/host/etc/host.conf", |
| 199 | false); err != nil { |
| 200 | return err |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if _, err := os.Readlink("/etc/hosts"); err != nil { |
| 205 | if err := redirectPath("/etc/hosts", |
| 206 | "/run/host/etc/hosts", |
| 207 | false); err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…