opencontainers / opencontainers/runc

libcontainer: provide an option to disable `saveStates`

Open
#3,722 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
13.5k
Forks
2.3k
Avg merge
2d 8h
Merged PRs (30d)
30

Description

In libcontainer/container_linux.go there is a function called saveStates() which will write a state.json file to the filesystem. The function is called by updateState() so every time a container is run the file will be generated, though it may be not mandatory in some use cases.

Although libcontainer seems to be only intended for runc, an OCI runtime implementation, I still wonder if there are any posibilities that it can provide an option for those who only uses libcontainer as part of their programs to disable the state.json file writing behavior?

func (c *Container) saveState(s *State) (retErr error) {
	tmpFile, err := os.CreateTemp(c.root, "state-")
	if err != nil {
		return err
	}

	defer func() {
		if retErr != nil {
			tmpFile.Close()
			os.Remove(tmpFile.Name())
		}
	}()

	err = utils.WriteJSON(tmpFile, s)
	if err != nil {
		return err
	}
	err = tmpFile.Close()
	if err != nil {
		return err
	}

	stateFilePath := filepath.Join(c.root, stateFilename)
	return os.Rename(tmpFile.Name(), stateFilePath)
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading libcontainer/container_linux.go, especially updateState() and saveState(), to understand how state.json is written during container runs. Determine an appropriate option for callers that use libcontainer directly, then verify that disabling the behavior avoids the file write without changing the default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.