diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal.go | 47 | ||||
-rw-r--r-- | libpod/container_internal_linux.go | 31 | ||||
-rw-r--r-- | libpod/container_internal_test.go | 48 |
3 files changed, 23 insertions, 103 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index aa6448f4a..927b71b2b 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -25,7 +25,6 @@ import ( opentracing "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "golang.org/x/text/language" kwait "k8s.io/apimachinery/pkg/util/wait" ) @@ -34,15 +33,6 @@ const ( artifactsDir = "artifacts" ) -var ( - // localeToLanguageMap maps from locale values to language tags. - localeToLanguageMap = map[string]string{ - "": "und-u-va-posix", - "c": "und-u-va-posix", - "posix": "und-u-va-posix", - } -) - // rootFsSize gets the size of the container's root filesystem // A container FS is split into two parts. The first is the top layer, a // mutable layer, and the rest is the RootFS: the set of immutable layers @@ -1285,48 +1275,15 @@ func (c *Container) saveSpec(spec *spec.Spec) error { return nil } -// localeToLanguage translates POSIX locale strings to BCP 47 language tags. -func localeToLanguage(locale string) string { - locale = strings.Replace(strings.SplitN(locale, ".", 2)[0], "_", "-", 1) - langString, ok := localeToLanguageMap[strings.ToLower(locale)] - if !ok { - langString = locale - } - return langString -} - // Warning: precreate hooks may alter 'config' in place. func (c *Container) setupOCIHooks(ctx context.Context, config *spec.Spec) (extensionStageHooks map[string][]spec.Hook, err error) { - var locale string - var ok bool - for _, envVar := range []string{ - "LC_ALL", - "LC_COLLATE", - "LANG", - } { - locale, ok = os.LookupEnv(envVar) - if ok { - break - } - } - - langString := localeToLanguage(locale) - lang, err := language.Parse(langString) - if err != nil { - logrus.Warnf("failed to parse language %q: %s", langString, err) - lang, err = language.Parse("und-u-va-posix") - if err != nil { - return nil, err - } - } - allHooks := make(map[string][]spec.Hook) if c.runtime.config.HooksDir == nil { if rootless.IsRootless() { return nil, nil } for _, hDir := range []string{hooks.DefaultDir, hooks.OverrideDir} { - manager, err := hooks.New(ctx, []string{hDir}, []string{"precreate", "poststop"}, lang) + manager, err := hooks.New(ctx, []string{hDir}, []string{"precreate", "poststop"}) if err != nil { if os.IsNotExist(err) { continue @@ -1345,7 +1302,7 @@ func (c *Container) setupOCIHooks(ctx context.Context, config *spec.Spec) (exten } } } else { - manager, err := hooks.New(ctx, c.runtime.config.HooksDir, []string{"precreate", "poststop"}, lang) + manager, err := hooks.New(ctx, c.runtime.config.HooksDir, []string{"precreate", "poststop"}) if err != nil { if os.IsNotExist(err) { logrus.Warnf("Requested OCI hooks directory %q does not exist", c.runtime.config.HooksDir) diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index eeffa4705..f352b188e 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -504,17 +504,9 @@ func (c *Container) checkpointRestoreSupported() (err error) { return nil } -func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (err error) { - if err := c.checkpointRestoreSupported(); err != nil { - return err - } - - if c.state.State != ContainerStateRunning { - return errors.Wrapf(ErrCtrStateInvalid, "%q is not running, cannot checkpoint", c.state.State) - } - +func (c *Container) checkpointRestoreLabelLog(fileName string) (err error) { // Create the CRIU log file and label it - dumpLog := filepath.Join(c.bundlePath(), "dump.log") + dumpLog := filepath.Join(c.bundlePath(), fileName) logFile, err := os.OpenFile(dumpLog, os.O_CREATE, 0600) if err != nil { @@ -524,6 +516,21 @@ func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointO if err = label.SetFileLabel(dumpLog, c.MountLabel()); err != nil { return errors.Wrapf(err, "failed to label CRIU log file %q", dumpLog) } + return nil +} + +func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (err error) { + if err := c.checkpointRestoreSupported(); err != nil { + return err + } + + if c.state.State != ContainerStateRunning { + return errors.Wrapf(ErrCtrStateInvalid, "%q is not running, cannot checkpoint", c.state.State) + } + + if err := c.checkpointRestoreLabelLog("dump.log"); err != nil { + return err + } if err := c.runtime.ociRuntime.checkpointContainer(c, options); err != nil { return err @@ -577,6 +584,10 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti return errors.Wrapf(err, "A complete checkpoint for this container cannot be found, cannot restore") } + if err := c.checkpointRestoreLabelLog("restore.log"); err != nil { + return err + } + // Read network configuration from checkpoint // Currently only one interface with one IP is supported. networkStatusFile, err := os.Open(filepath.Join(c.bundlePath(), "network.status")) diff --git a/libpod/container_internal_test.go b/libpod/container_internal_test.go index 1654af929..f1e2b70a7 100644 --- a/libpod/container_internal_test.go +++ b/libpod/container_internal_test.go @@ -17,54 +17,6 @@ import ( // hookPath is the path to an example hook executable. var hookPath string -func TestLocaleToLanguage(t *testing.T) { - for _, testCase := range []struct { - locale string - language string - }{ - { - locale: "", - language: "und-u-va-posix", - }, - { - locale: "C", - language: "und-u-va-posix", - }, - { - locale: "POSIX", - language: "und-u-va-posix", - }, - { - locale: "c", - language: "und-u-va-posix", - }, - { - locale: "en", - language: "en", - }, - { - locale: "en_US", - language: "en-US", - }, - { - locale: "en.UTF-8", - language: "en", - }, - { - locale: "en_US.UTF-8", - language: "en-US", - }, - { - locale: "does-not-exist", - language: "does-not-exist", - }, - } { - t.Run(testCase.locale, func(t *testing.T) { - assert.Equal(t, testCase.language, localeToLanguage(testCase.locale)) - }) - } -} - func TestPostDeleteHooks(t *testing.T) { ctx := context.Background() dir, err := ioutil.TempDir("", "libpod_test_") |