repo stringlengths 5 67 | sha stringlengths 40 40 | path stringlengths 4 234 | url stringlengths 85 339 | language stringclasses 6
values | split stringclasses 3
values | doc stringlengths 3 51.2k | sign stringlengths 5 8.01k | problem stringlengths 13 51.2k | output stringlengths 0 3.87M |
|---|---|---|---|---|---|---|---|---|---|
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L183-L191 | go | train | // containsAllKeyValues returns true if the actualKVs contains all of the key-value
// pairs listed in requiredKVs, otherwise it returns false. | func containsAllKeyValues(actualKVs []*v1alpha.KeyValue, requiredKVs []*v1alpha.KeyValue) bool | // containsAllKeyValues returns true if the actualKVs contains all of the key-value
// pairs listed in requiredKVs, otherwise it returns false.
func containsAllKeyValues(actualKVs []*v1alpha.KeyValue, requiredKVs []*v1alpha.KeyValue) bool | {
for _, requiredKV := range requiredKVs {
actualValue, ok := findInKeyValues(actualKVs, requiredKV.Key)
if !ok || actualValue != requiredKV.Value {
return false
}
}
return true
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L210-L299 | go | train | // satisfiesPodFilter returns true if the pod satisfies the filter.
// The pod, filter must not be nil. | func satisfiesPodFilter(pod v1alpha.Pod, filter v1alpha.PodFilter) bool | // satisfiesPodFilter returns true if the pod satisfies the filter.
// The pod, filter must not be nil.
func satisfiesPodFilter(pod v1alpha.Pod, filter v1alpha.PodFilter) bool | {
// Filter according to the ID.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(pod.Id) {
return false
}
}
// Filter according to the state.
if len(filter.States) > 0 {
foundState := false
for _, state := range filter.States {
if pod.State == state {
foundState = true
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L303-L315 | go | train | // satisfiesAnyPodFilters returns true if any of the filter conditions is satisfied
// by the pod, or there's no filters. | func satisfiesAnyPodFilters(pod *v1alpha.Pod, filters []*v1alpha.PodFilter) bool | // satisfiesAnyPodFilters returns true if any of the filter conditions is satisfied
// by the pod, or there's no filters.
func satisfiesAnyPodFilters(pod *v1alpha.Pod, filters []*v1alpha.PodFilter) bool | {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesPodFilter(*pod, *filter) {
return true
}
}
return false
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L328-L367 | go | train | // getPodCgroup gets the cgroup path for a pod. This can be done in one of a couple ways:
//
// 1) stage1-coreos
//
// This one can be tricky because after machined registration, the cgroup might change.
// For these flavors, the cgroup it will end up in after machined moves it is
// written to a file named `subcgroup`... | func getPodCgroup(p *pkgPod.Pod, pid int) (string, error) | // getPodCgroup gets the cgroup path for a pod. This can be done in one of a couple ways:
//
// 1) stage1-coreos
//
// This one can be tricky because after machined registration, the cgroup might change.
// For these flavors, the cgroup it will end up in after machined moves it is
// written to a file named `subcgroup`... | {
// Note, this file should always exist if the pid is known since it is
// written before the pid file
// The contents are of the form:
// machined-registration (whether it has happened or not, but if stage1 plans to do so):
// 'machine.slice/machine-rkt\x2dbfb67ff1\x2dc745\x2d4aec\x2db1e1\x2d7ce85a1fd42b.scop... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L370-L393 | go | train | // getApplist returns a list of apps in the pod. | func getApplist(manifest *schema.PodManifest) []*v1alpha.App | // getApplist returns a list of apps in the pod.
func getApplist(manifest *schema.PodManifest) []*v1alpha.App | {
var apps []*v1alpha.App
for _, app := range manifest.Apps {
img := &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Vers... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L396-L406 | go | train | // getNetworks returns the list of the info of the network that the pod belongs to. | func getNetworks(p *pkgPod.Pod) []*v1alpha.Network | // getNetworks returns the list of the info of the network that the pod belongs to.
func getNetworks(p *pkgPod.Pod) []*v1alpha.Network | {
var networks []*v1alpha.Network
for _, n := range p.Nets {
networks = append(networks, &v1alpha.Network{
Name: n.NetName,
// There will be IPv6 support soon so distinguish between v4 and v6
Ipv4: n.IP.String(),
})
}
return networks
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L419-L456 | go | train | // fillStaticAppInfo will modify the 'v1pod' in place with the information retrieved with 'pod'.
// Today, these information are static and will not change during the pod's lifecycle. | func fillStaticAppInfo(store *imagestore.Store, pod *pkgPod.Pod, v1pod *v1alpha.Pod) error | // fillStaticAppInfo will modify the 'v1pod' in place with the information retrieved with 'pod'.
// Today, these information are static and will not change during the pod's lifecycle.
func fillStaticAppInfo(store *imagestore.Store, pod *pkgPod.Pod, v1pod *v1alpha.Pod) error | {
var errlist []error
// Fill static app image info.
for _, app := range v1pod.Apps {
// Fill app's image info.
app.Image = &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk stor... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L484-L513 | go | train | // getBasicPod returns v1alpha.Pod with basic pod information. | func (s *v1AlphaAPIServer) getBasicPod(p *pkgPod.Pod) *v1alpha.Pod | // getBasicPod returns v1alpha.Pod with basic pod information.
func (s *v1AlphaAPIServer) getBasicPod(p *pkgPod.Pod) *v1alpha.Pod | {
mtime, mtimeErr := getPodManifestModTime(p)
if mtimeErr != nil {
stderr.PrintE(fmt.Sprintf("failed to read the pod manifest's mtime for pod %q", p.UUID), mtimeErr)
}
// Couldn't use pod.uuid directly as it's a pointer.
itemValue, found := s.podCache.Get(p.UUID.String())
if found && mtimeErr == nil {
cache... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L518-L612 | go | train | // fillPodDetails fills the v1pod's dynamic info in place, e.g. the pod's state,
// the pod's network info, the apps' state, etc. Such information can change
// during the lifecycle of the pod, so we need to read it in every request. | func fillPodDetails(store *imagestore.Store, p *pkgPod.Pod, v1pod *v1alpha.Pod) | // fillPodDetails fills the v1pod's dynamic info in place, e.g. the pod's state,
// the pod's network info, the apps' state, etc. Such information can change
// during the lifecycle of the pod, so we need to read it in every request.
func fillPodDetails(store *imagestore.Store, p *pkgPod.Pod, v1pod *v1alpha.Pod) | {
v1pod.Pid = -1
switch p.State() {
case pkgPod.Embryo:
v1pod.State = v1alpha.PodState_POD_STATE_EMBRYO
// When a pod is in embryo state, there is not much
// information to return.
return
case pkgPod.Preparing:
v1pod.State = v1alpha.PodState_POD_STATE_PREPARING
case pkgPod.AbortedPrepare:
v1pod.Stat... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L654-L688 | go | train | // aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha.Image object. | func aciInfoToV1AlphaAPIImage(store *imagestore.Store, aciInfo *imagestore.ACIInfo) (*v1alpha.Image, error) | // aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha.Image object.
func aciInfoToV1AlphaAPIImage(store *imagestore.Store, aciInfo *imagestore.ACIInfo) (*v1alpha.Image, error) | {
manifest, err := store.GetImageManifestJSON(aciInfo.BlobKey)
if err != nil {
stderr.PrintE("failed to read the image manifest", err)
return nil, err
}
var im schema.ImageManifest
if err = json.Unmarshal(manifest, &im); err != nil {
stderr.PrintE("failed to unmarshal image manifest", err)
return nil, er... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L716-L784 | go | train | // satisfiesImageFilter returns true if the image satisfies the filter.
// The image, filter must not be nil. | func satisfiesImageFilter(image v1alpha.Image, filter v1alpha.ImageFilter) bool | // satisfiesImageFilter returns true if the image satisfies the filter.
// The image, filter must not be nil.
func satisfiesImageFilter(image v1alpha.Image, filter v1alpha.ImageFilter) bool | {
// Filter according to the IDs.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(image.Id) {
return false
}
}
// Filter according to the image full names.
if len(filter.FullNames) > 0 {
s := set.NewString(filter.FullNames...)
if !s.Has(image.Name) {
return false
}
}
// ... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L788-L799 | go | train | // satisfiesAnyImageFilters returns true if any of the filter conditions is satisfied
// by the image, or there's no filters. | func satisfiesAnyImageFilters(image *v1alpha.Image, filters []*v1alpha.ImageFilter) bool | // satisfiesAnyImageFilters returns true if any of the filter conditions is satisfied
// by the image, or there's no filters.
func satisfiesAnyImageFilters(image *v1alpha.Image, filters []*v1alpha.ImageFilter) bool | {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesImageFilter(*image, *filter) {
return true
}
}
return false
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L831-L852 | go | train | // getImageInfo returns the image info of a given image ID.
// It will first try to read the image info from cache.
// - If the image exists in cache:
// - If the image exists on disk, then return it directly.
// - Otherwise, return nil.
// - Else, try to return the image from disk. | func (s *v1AlphaAPIServer) getImageInfo(imageID string) (*v1alpha.Image, error) | // getImageInfo returns the image info of a given image ID.
// It will first try to read the image info from cache.
// - If the image exists in cache:
// - If the image exists on disk, then return it directly.
// - Otherwise, return nil.
// - Else, try to return the image from disk.
func (s *v1AlphaAPIServer) getIm... | {
item, found := s.imgCache.Get(imageID)
if found {
image := item.(*imageCacheItem).image
// Check if the image has been removed.
if found := s.store.HasFullKey(image.Id); !found {
s.imgCache.Remove(imageID)
return nil, fmt.Errorf("no such image with ID %q", imageID)
}
return copyImage(image), nil
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L855-L868 | go | train | // getImageInfoFromDisk for a given image ID, returns the *v1alpha.Image object. | func (s *v1AlphaAPIServer) getImageInfoFromDisk(store *imagestore.Store, imageID string) (*v1alpha.Image, error) | // getImageInfoFromDisk for a given image ID, returns the *v1alpha.Image object.
func (s *v1AlphaAPIServer) getImageInfoFromDisk(store *imagestore.Store, imageID string) (*v1alpha.Image, error) | {
aciInfo, err := store.GetACIInfoWithBlobKey(imageID)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get ACI info for image %q", imageID), err)
return nil, err
}
image, err := aciInfoToV1AlphaAPIImage(store, aciInfo)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to convert ACI to v1alphaAPIImage... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L902-L941 | go | train | // Open one or more listening sockets, then start the gRPC server | func runAPIService(cmd *cobra.Command, args []string) (exit int) | // Open one or more listening sockets, then start the gRPC server
func runAPIService(cmd *cobra.Command, args []string) (exit int) | {
// Set up the signal handler here so we can make sure the
// signals are caught after print the starting message.
signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM)
stderr.Print("API service starting...")
listeners, err := openAPISockets()
if err != nil {
stderr.PrintE("Failed to open sockets", err)
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/api_service.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L947-L978 | go | train | // Open API sockets based on command line parameters and
// the magic environment variable from systemd
//
// see sd_listen_fds(3) | func openAPISockets() ([]net.Listener, error) | // Open API sockets based on command line parameters and
// the magic environment variable from systemd
//
// see sd_listen_fds(3)
func openAPISockets() ([]net.Listener, error) | {
listeners := []net.Listener{}
fds := systemdFDs(true) // Try to get the socket fds from systemd
if len(fds) > 0 {
if flagAPIServiceListenAddr != "" {
return nil, fmt.Errorf("started under systemd.socket(5), but --listen passed! Quitting.")
}
stderr.Printf("Listening on %d systemd-provided socket(s)\n",... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L206-L349 | go | train | // SetupAppIO prepares all properties related to streams (stdin/stdout/stderr) and TTY
// for an application service unit.
//
// It works according to the following steps:
// 1. short-circuit interactive pods and legacy systemd, for backward compatibility
// 2. parse app-level annotations to determine stdin/stdout/st... | func (uw *UnitWriter) SetupAppIO(p *stage1commontypes.Pod, ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) []*unit.UnitOption | // SetupAppIO prepares all properties related to streams (stdin/stdout/stderr) and TTY
// for an application service unit.
//
// It works according to the following steps:
// 1. short-circuit interactive pods and legacy systemd, for backward compatibility
// 2. parse app-level annotations to determine stdin/stdout/st... | {
if uw.err != nil {
return opts
}
if p.Interactive {
opts = append(opts, unit.NewUnitOption("Service", "StandardInput", "tty"))
opts = append(opts, unit.NewUnitOption("Service", "StandardOutput", "tty"))
opts = append(opts, unit.NewUnitOption("Service", "StandardError", "tty"))
return opts
}
flavor, ... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L367-L387 | go | train | // WriteUnit writes a systemd unit in the given path with the given unit options
// if no previous error occurred. | func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) | // WriteUnit writes a systemd unit in the given path with the given unit options
// if no previous error occurred.
func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) | {
if uw.err != nil {
return
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
defer file.Close()
if _, err = io.Copy(file, unit.Serialize(opts)); err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L392-L439 | go | train | // writeShutdownService writes a shutdown.service unit with the given unit options
// if no previous error occurred.
// exec specifies how systemctl should be invoked, i.e. ExecStart, or ExecStop. | func (uw *UnitWriter) writeShutdownService(exec string, opts ...*unit.UnitOption) | // writeShutdownService writes a shutdown.service unit with the given unit options
// if no previous error occurred.
// exec specifies how systemctl should be invoked, i.e. ExecStart, or ExecStop.
func (uw *UnitWriter) writeShutdownService(exec string, opts ...*unit.UnitOption) | {
if uw.err != nil {
return
}
flavor, systemdVersion, err := GetFlavor(uw.p)
if err != nil {
uw.err = errwrap.Wrap(errors.New("failed to create shutdown service"), err)
return
}
opts = append(opts, []*unit.UnitOption{
// The default stdout is /dev/console (the tty created by nspawn).
// But the tty m... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L442-L450 | go | train | // Activate actives the given unit in the given wantPath. | func (uw *UnitWriter) Activate(unit, wantPath string) | // Activate actives the given unit in the given wantPath.
func (uw *UnitWriter) Activate(unit, wantPath string) | {
if uw.err != nil {
return
}
if err := os.Symlink(path.Join("..", unit), wantPath); err != nil && !os.IsExist(err) {
uw.err = errwrap.Wrap(errors.New("failed to link service want"), err)
}
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L458-L509 | go | train | // AppUnit sets up the main systemd service unit for the application. | func (uw *UnitWriter) AppUnit(ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) | // AppUnit sets up the main systemd service unit for the application.
func (uw *UnitWriter) AppUnit(ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) | {
if uw.err != nil {
return
}
if len(ra.App.Exec) == 0 {
uw.err = fmt.Errorf(`image %q has an empty "exec" (try --exec=BINARY)`,
uw.p.AppNameToImageName(ra.Name))
return
}
pa, err := prepareApp(uw.p, ra)
if err != nil {
uw.err = err
return
}
appName := ra.Name.String()
imgName := uw.p.AppNameT... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L512-L734 | go | train | // appSystemdUnit sets up an application for isolation via systemd | func (uw *UnitWriter) appSystemdUnit(pa *preparedApp, binPath string, opts []*unit.UnitOption) []*unit.UnitOption | // appSystemdUnit sets up an application for isolation via systemd
func (uw *UnitWriter) appSystemdUnit(pa *preparedApp, binPath string, opts []*unit.UnitOption) []*unit.UnitOption | {
if uw.err != nil {
return nil
}
flavor, systemdVersion, err := GetFlavor(uw.p)
if err != nil {
uw.err = errwrap.Wrap(errors.New("unable to determine stage1 flavor"), err)
return nil
}
ra := pa.app
app := ra.App
appName := ra.Name
imgName := uw.p.AppNameToImageName(ra.Name)
podAbsRoot, err := filep... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L737-L764 | go | train | // AppReaperUnit writes an app reaper service unit for the given app in the given path using the given unit options. | func (uw *UnitWriter) AppReaperUnit(appName types.ACName, binPath string, opts ...*unit.UnitOption) | // AppReaperUnit writes an app reaper service unit for the given app in the given path using the given unit options.
func (uw *UnitWriter) AppReaperUnit(appName types.ACName, binPath string, opts ...*unit.UnitOption) | {
if uw.err != nil {
return
}
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s Reaper", appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "false"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "Before", "halt... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L767-L786 | go | train | // AppSocketUnits writes a stream socket-unit for the given app in the given path. | func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, streamName string, opts ...*unit.UnitOption) | // AppSocketUnits writes a stream socket-unit for the given app in the given path.
func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, streamName string, opts ...*unit.UnitOption) | {
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s socket for %s", streamName, appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "no"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "RefuseManualStart", "yes"),
u... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/units.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L792-L797 | go | train | // appendOptionsList updates an existing unit options list appending
// an array of new properties, one entry at a time.
// This is the preferred method to avoid hitting line length limits
// in unit files. Target property must support multi-line entries. | func appendOptionsList(opts []*unit.UnitOption, section, property, prefix string, vals ...string) []*unit.UnitOption | // appendOptionsList updates an existing unit options list appending
// an array of new properties, one entry at a time.
// This is the preferred method to avoid hitting line length limits
// in unit files. Target property must support multi-line entries.
func appendOptionsList(opts []*unit.UnitOption, section, propert... | {
for _, v := range vals {
opts = append(opts, unit.NewUnitOption(section, property, fmt.Sprintf("%s%s", prefix, v)))
}
return opts
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | lib/app.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L38-L46 | go | train | // AppsForPod returns the apps of the pod with the given uuid in the given data directory.
// If appName is non-empty, then only the app with the given name will be returned. | func AppsForPod(uuid, dataDir string, appName string) ([]*v1.App, error) | // AppsForPod returns the apps of the pod with the given uuid in the given data directory.
// If appName is non-empty, then only the app with the given name will be returned.
func AppsForPod(uuid, dataDir string, appName string) ([]*v1.App, error) | {
p, err := pkgPod.PodFromUUIDString(dataDir, uuid)
if err != nil {
return nil, err
}
defer p.Close()
return appsForPod(p, appName, appStateInMutablePod)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | lib/app.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L73-L116 | go | train | // newApp constructs the App object with the runtime app and pod manifest. | func newApp(ra *schema.RuntimeApp, podManifest *schema.PodManifest, pod *pkgPod.Pod, appState appStateFunc) (*v1.App, error) | // newApp constructs the App object with the runtime app and pod manifest.
func newApp(ra *schema.RuntimeApp, podManifest *schema.PodManifest, pod *pkgPod.Pod, appState appStateFunc) (*v1.App, error) | {
app := &v1.App{
Name: ra.Name.String(),
ImageID: ra.Image.ID.String(),
UserAnnotations: ra.App.UserAnnotations,
UserLabels: ra.App.UserLabels,
}
podVols := podManifest.Volumes
podVolsByName := make(map[types.ACName]types.Volume, len(podVols))
for i := range podManifest.Volumes {... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | lib/app.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L200-L237 | go | train | // appStateInImmutablePod infers most App state from the Pod itself, since all apps are created and destroyed with the Pod | func appStateInImmutablePod(app *v1.App, pod *pkgPod.Pod) error | // appStateInImmutablePod infers most App state from the Pod itself, since all apps are created and destroyed with the Pod
func appStateInImmutablePod(app *v1.App, pod *pkgPod.Pod) error | {
app.State = appStateFromPod(pod)
t, err := pod.CreationTime()
if err != nil {
return err
}
createdAt := t.UnixNano()
app.CreatedAt = &createdAt
code, err := pod.AppExitCode(app.Name)
if err == nil {
// there is an exit code, it is definitely Exited
app.State = v1.AppStateExited
exitCode := int32(co... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/common/types/pod.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L80-L87 | go | train | // AppNameToImageName takes the name of an app in the Pod and returns the name
// of the app's image. The mapping between these two is populated when a Pod is
// loaded (using LoadPod). | func (p *Pod) AppNameToImageName(appName types.ACName) types.ACIdentifier | // AppNameToImageName takes the name of an app in the Pod and returns the name
// of the app's image. The mapping between these two is populated when a Pod is
// loaded (using LoadPod).
func (p *Pod) AppNameToImageName(appName types.ACName) types.ACIdentifier | {
image, ok := p.Images[appName.String()]
if !ok {
// This should be impossible as we have updated the map in LoadPod().
panic(fmt.Sprintf("No images for app %q", appName.String()))
}
return image.Name
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/common/types/pod.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L91-L99 | go | train | // SaveRuntime persists just the runtime state. This should be called when the
// pod is started. | func (p *Pod) SaveRuntime() error | // SaveRuntime persists just the runtime state. This should be called when the
// pod is started.
func (p *Pod) SaveRuntime() error | {
path := filepath.Join(p.Root, RuntimeConfigPath)
buf, err := json.Marshal(p.RuntimePod)
if err != nil {
return err
}
return ioutil.WriteFile(path, buf, 0644)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/common/types/pod.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L102-L113 | go | train | // LoadPodManifest loads a Pod Manifest. | func LoadPodManifest(root string) (*schema.PodManifest, error) | // LoadPodManifest loads a Pod Manifest.
func LoadPodManifest(root string) (*schema.PodManifest, error) | {
buf, err := ioutil.ReadFile(common.PodManifestPath(root))
if err != nil {
return nil, errwrap.Wrap(errors.New("failed reading pod manifest"), err)
}
pm := &schema.PodManifest{}
if err := json.Unmarshal(buf, pm); err != nil {
return nil, errwrap.Wrap(errors.New("failed unmarshalling pod manifest"), err)
}
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/common/types/pod.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L117-L179 | go | train | // LoadPod loads a Pod Manifest (as prepared by stage0), the runtime data, and
// its associated Application Manifests, under $root/stage1/opt/stage1/$apphash | func LoadPod(root string, uuid *types.UUID, rp *RuntimePod) (*Pod, error) | // LoadPod loads a Pod Manifest (as prepared by stage0), the runtime data, and
// its associated Application Manifests, under $root/stage1/opt/stage1/$apphash
func LoadPod(root string, uuid *types.UUID, rp *RuntimePod) (*Pod, error) | {
p := &Pod{
Root: root,
UUID: *uuid,
Images: make(map[string]*schema.ImageManifest),
UidRange: *user.NewBlankUidRange(),
}
// Unserialize runtime parameters
if rp != nil {
p.RuntimePod = *rp
} else {
buf, err := ioutil.ReadFile(filepath.Join(p.Root, RuntimeConfigPath))
if err != nil {
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/fetcher.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L46-L59 | go | train | // FetchImages uses FetchImage to attain a list of image hashes | func (f *Fetcher) FetchImages(al *apps.Apps) error | // FetchImages uses FetchImage to attain a list of image hashes
func (f *Fetcher) FetchImages(al *apps.Apps) error | {
return al.Walk(func(app *apps.App) error {
d, err := DistFromImageString(app.Image)
if err != nil {
return err
}
h, err := f.FetchImage(d, app.Image, app.Asc)
if err != nil {
return err
}
app.ImageID = *h
return nil
})
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/fetcher.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L66-L99 | go | train | // FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fet... | func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) | // FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fet... | {
ensureLogger(f.Debug)
db := &distBundle{
dist: d,
image: image,
}
a := f.getAsc(ascPath)
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return nil, err
}
if f.WithDeps {
err = f.fetchImageDeps(hash)
if err != nil {
return nil, err
}
}
// we need to be able to do a chroot and access... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/fetcher.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L112-L131 | go | train | // fetchImageDeps will recursively fetch all the image dependencies | func (f *Fetcher) fetchImageDeps(hash string) error | // fetchImageDeps will recursively fetch all the image dependencies
func (f *Fetcher) fetchImageDeps(hash string) error | {
imgsl := list.New()
seen := map[string]dist.Distribution{}
f.addImageDeps(hash, imgsl, seen)
for el := imgsl.Front(); el != nil; el = el.Next() {
a := &asc{}
d := el.Value.(*dist.Appc)
str := d.String()
db := &distBundle{
dist: d,
image: str,
}
hash, err := f.fetchSingleImage(db, a)
if err !... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/fetcher.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L286-L299 | go | train | // TODO(sgotti) I'm not sure setting default os and arch also for image
// dependencies is correct since it may break noarch dependencies. Reference:
// https://github.com/rkt/rkt/pull/2317 | func (db *distBundle) setAppDefaults() error | // TODO(sgotti) I'm not sure setting default os and arch also for image
// dependencies is correct since it may break noarch dependencies. Reference:
// https://github.com/rkt/rkt/pull/2317
func (db *distBundle) setAppDefaults() error | {
app := db.dist.(*dist.Appc).App()
if _, ok := app.Labels["arch"]; !ok {
app.Labels["arch"] = common.GetArch()
}
if _, ok := app.Labels["os"]; !ok {
app.Labels["os"] = common.GetOS()
}
if err := types.IsValidOSArch(app.Labels, stage0.ValidOSArch); err != nil {
return errwrap.Wrap(fmt.Errorf("invalid Appc ... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L35-L42 | go | train | // New creates a new Logger with no Log flags set. | func New(out io.Writer, prefix string, debug bool) *Logger | // New creates a new Logger with no Log flags set.
func New(out io.Writer, prefix string, debug bool) *Logger | {
l := &Logger{
debug: debug,
Logger: log.New(out, prefix, 0),
}
l.SetFlags(0)
return l
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L49-L56 | go | train | // NewLogSet returns a set of Loggers for commonly used output streams: errors,
// diagnostics, stdout. The error and stdout streams should generally never be
// suppressed. diagnostic can be suppressed by setting the output to
// ioutil.Discard. If an output destination is not needed, one can simply
// discard it by a... | func NewLogSet(prefix string, debug bool) (stderr, diagnostic, stdout *Logger) | // NewLogSet returns a set of Loggers for commonly used output streams: errors,
// diagnostics, stdout. The error and stdout streams should generally never be
// suppressed. diagnostic can be suppressed by setting the output to
// ioutil.Discard. If an output destination is not needed, one can simply
// discard it by a... | {
stderr = New(os.Stderr, prefix, debug)
diagnostic = New(os.Stderr, prefix, debug)
// Debug not used for stdout.
stdout = New(os.Stdout, prefix, false)
return stderr, diagnostic, stdout
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L64-L78 | go | train | // SetFlags is a wrapper around log.SetFlags that adds and removes, ": " to and
// from a prefix. This is needed because ": " is only added by golang's log
// package if either of the Lshortfile or Llongfile flags are set. | func (l *Logger) SetFlags(flag int) | // SetFlags is a wrapper around log.SetFlags that adds and removes, ": " to and
// from a prefix. This is needed because ": " is only added by golang's log
// package if either of the Lshortfile or Llongfile flags are set.
func (l *Logger) SetFlags(flag int) | {
l.Logger.SetFlags(flag)
// Only proceed if we've actually got a prefix
if l.Prefix() == "" {
return
}
const clnSpc = ": "
if flag&(log.Lshortfile|log.Llongfile) != 0 {
l.SetPrefix(strings.TrimSuffix(l.Prefix(), clnSpc))
} else {
l.SetPrefix(l.Prefix() + clnSpc)
}
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L105-L107 | go | train | // PrintE prints the msg and its error message(s). | func (l *Logger) PrintE(msg string, e error) | // PrintE prints the msg and its error message(s).
func (l *Logger) PrintE(msg string, e error) | {
l.Print(l.formatErr(e, msg))
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L110-L112 | go | train | // Error is a convenience function for printing errors without a message. | func (l *Logger) Error(e error) | // Error is a convenience function for printing errors without a message.
func (l *Logger) Error(e error) | {
l.Print(l.formatErr(e, ""))
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L115-L117 | go | train | // Errorf is a convenience function for formatting and printing errors. | func (l *Logger) Errorf(format string, a ...interface{}) | // Errorf is a convenience function for formatting and printing errors.
func (l *Logger) Errorf(format string, a ...interface{}) | {
l.Print(l.formatErr(fmt.Errorf(format, a...), ""))
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L120-L123 | go | train | // FatalE prints a string and error then calls os.Exit(254). | func (l *Logger) FatalE(msg string, e error) | // FatalE prints a string and error then calls os.Exit(254).
func (l *Logger) FatalE(msg string, e error) | {
l.Print(l.formatErr(e, msg))
os.Exit(254)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L126-L129 | go | train | // Fatalf prints an error then calls os.Exit(254). | func (l *Logger) Fatalf(format string, a ...interface{}) | // Fatalf prints an error then calls os.Exit(254).
func (l *Logger) Fatalf(format string, a ...interface{}) | {
l.Print(l.formatErr(fmt.Errorf(format, a...), ""))
os.Exit(254)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/log/log.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L132-L134 | go | train | // PanicE prints a string and error then calls panic. | func (l *Logger) PanicE(msg string, e error) | // PanicE prints a string and error then calls panic.
func (l *Logger) PanicE(msg string, e error) | {
l.Panic(l.formatErr(e, msg))
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | tools/common/util.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/util.go#L45-L47 | go | train | // Warn is just a shorter version of a formatted printing to
// stderr. It appends a newline for you. | func Warn(format string, values ...interface{}) | // Warn is just a shorter version of a formatted printing to
// stderr. It appends a newline for you.
func Warn(format string, values ...interface{}) | {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s%c", format, '\n'), values...)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | tools/common/util.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/util.go#L63-L71 | go | train | // MapFilesToDirectories creates one entry for each file and directory
// passed. Result is a kind of cross-product. For files f1 and f2 and
// directories d1 and d2, the returned list will contain d1/f1 d2/f1
// d1/f2 d2/f2.
//
// The "files" part might be a bit misleading - you can pass a list of
// symlinks or direc... | func MapFilesToDirectories(files, dirs []string) []string | // MapFilesToDirectories creates one entry for each file and directory
// passed. Result is a kind of cross-product. For files f1 and f2 and
// directories d1 and d2, the returned list will contain d1/f1 d2/f1
// d1/f2 d2/f2.
//
// The "files" part might be a bit misleading - you can pass a list of
// symlinks or direc... | {
mapped := make([]string, 0, len(files)*len(dirs))
for _, f := range files {
for _, d := range dirs {
mapped = append(mapped, filepath.Join(d, f))
}
}
return mapped
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | tools/common/util.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/util.go#L75-L81 | go | train | // MustAbs returns an absolute path. It works like filepath.Abs, but
// panics if it fails. | func MustAbs(dir string) string | // MustAbs returns an absolute path. It works like filepath.Abs, but
// panics if it fails.
func MustAbs(dir string) string | {
absDir, err := filepath.Abs(dir)
if err != nil {
panic(fmt.Sprintf("Failed to get absolute path of a directory %q: %v\n", dir, err))
}
return filepath.Clean(absDir)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/attach.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/attach.go#L119-L183 | go | train | // createStage1AttachFlags parses an attach stage0 CLI "--mode" flag and
// returns options suited for stage1/attach entrypoint invocation | func createStage1AttachFlags(attachMode string) ([]string, error) | // createStage1AttachFlags parses an attach stage0 CLI "--mode" flag and
// returns options suited for stage1/attach entrypoint invocation
func createStage1AttachFlags(attachMode string) ([]string, error) | {
attachArgs := []string{}
// list mode: just print endpoints
if attachMode == "list" {
attachArgs = append(attachArgs, "--action=list")
return attachArgs, nil
}
// auto-attach mode: stage1-attach will figure out endpoints
if attachMode == "auto" || attachMode == "" {
attachArgs = append(attachArgs, "--a... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/status.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L126-L141 | go | train | // parseDuration converts the given string s to a duration value.
// If it is empty string or a true boolean value according to strconv.ParseBool, a negative duration is returned.
// If the boolean value is false, a 0 duration is returned.
// If the string s is a duration value, then it is returned.
// It returns an er... | func parseDuration(s string) (time.Duration, error) | // parseDuration converts the given string s to a duration value.
// If it is empty string or a true boolean value according to strconv.ParseBool, a negative duration is returned.
// If the boolean value is false, a 0 duration is returned.
// If the string s is a duration value, then it is returned.
// It returns an er... | {
if s == "" {
return time.Duration(-1), nil
}
b, err := strconv.ParseBool(s)
switch {
case err != nil:
return time.ParseDuration(s)
case b:
return time.Duration(-1), nil
}
return time.Duration(0), nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/status.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L144-L150 | go | train | // newContext returns a new context with timeout t if t > 0. | func newContext(t time.Duration) context.Context | // newContext returns a new context with timeout t if t > 0.
func newContext(t time.Duration) context.Context | {
ctx := context.Background()
if t > 0 {
ctx, _ = context.WithTimeout(ctx, t)
}
return ctx
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/status.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L153-L168 | go | train | // getExitStatuses returns a map of the statuses of the pod. | func getExitStatuses(p *pkgPod.Pod) (map[string]int, error) | // getExitStatuses returns a map of the statuses of the pod.
func getExitStatuses(p *pkgPod.Pod) (map[string]int, error) | {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, err
}
stats := make(map[string]int)
for _, app := range manifest.Apps {
exitCode, err := p.AppExitCode(app.Name.String())
if err != nil {
continue
}
stats[app.Name.String()] = exitCode
}
return stats, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/status.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L171-L240 | go | train | // printStatus prints the pod's pid and per-app status codes | func printStatus(p *pkgPod.Pod) error | // printStatus prints the pod's pid and per-app status codes
func printStatus(p *pkgPod.Pod) error | {
if flagFormat != outputFormatTabbed {
pod, err := lib.NewPodFromInternalPod(p)
if err != nil {
return fmt.Errorf("error converting pod: %v", err)
}
switch flagFormat {
case outputFormatJSON:
result, err := json.Marshal(pod)
if err != nil {
return fmt.Errorf("error marshaling the pod: %v", err... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage0/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/common.go#L48-L109 | go | train | // Run wraps the execution of a stage1 entrypoint which
// requires crossing the stage0/stage1/stage2 boundary during its execution,
// by setting up proper environment variables for enter. | func (ce CrossingEntrypoint) Run() error | // Run wraps the execution of a stage1 entrypoint which
// requires crossing the stage0/stage1/stage2 boundary during its execution,
// by setting up proper environment variables for enter.
func (ce CrossingEntrypoint) Run() error | {
enterCmd, err := getStage1Entrypoint(ce.PodPath, enterEntrypoint)
if err != nil {
return errwrap.Wrap(errors.New("error determining 'enter' entrypoint"), err)
}
previousDir, err := os.Getwd()
if err != nil {
return err
}
if err := os.Chdir(ce.PodPath); err != nil {
return errwrap.Wrap(errors.New("fail... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage0/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/common.go#L113-L207 | go | train | // generateRuntimeApp merges runtime information from the image manifest and from
// runtime configuration overrides, returning a full configuration for a runtime app | func generateRuntimeApp(appRunConfig *apps.App, am *schema.ImageManifest, podMounts []schema.Mount) (schema.RuntimeApp, error) | // generateRuntimeApp merges runtime information from the image manifest and from
// runtime configuration overrides, returning a full configuration for a runtime app
func generateRuntimeApp(appRunConfig *apps.App, am *schema.ImageManifest, podMounts []schema.Mount) (schema.RuntimeApp, error) | {
ra := schema.RuntimeApp{
App: am.App,
Image: schema.RuntimeImage{
Name: &am.Name,
ID: appRunConfig.ImageID,
Labels: am.Labels,
},
Mounts: MergeMounts(podMounts, appRunConfig.Mounts),
ReadOnlyRootFS: appRunConfig.ReadOnlyRootFS,
}
appName, err := types.NewACName(appRunConfig.Name... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L103-L109 | go | train | // useCached checks if downloadTime plus maxAge is before/after the current time.
// return true if the cached image should be used, false otherwise. | func useCached(downloadTime time.Time, maxAge int) bool | // useCached checks if downloadTime plus maxAge is before/after the current time.
// return true if the cached image should be used, false otherwise.
func useCached(downloadTime time.Time, maxAge int) bool | {
freshnessLifetime := int(time.Now().Sub(downloadTime).Seconds())
if maxAge > 0 && freshnessLifetime < maxAge {
return true
}
return false
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L113-L117 | go | train | // ascURLFromImgURL creates a URL to a signature file from passed URL
// to an image. | func ascURLFromImgURL(u *url.URL) *url.URL | // ascURLFromImgURL creates a URL to a signature file from passed URL
// to an image.
func ascURLFromImgURL(u *url.URL) *url.URL | {
copy := *u
copy.Path = ascPathFromImgPath(copy.Path)
return ©
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L126-L132 | go | train | // printIdentities prints a message that signature was verified. | func printIdentities(entity *openpgp.Entity) | // printIdentities prints a message that signature was verified.
func printIdentities(entity *openpgp.Entity) | {
lines := []string{"signature verified:"}
for _, v := range entity.Identities {
lines = append(lines, fmt.Sprintf(" %s", v.Name))
}
log.Print(strings.Join(lines, "\n"))
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/common.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L135-L203 | go | train | // DistFromImageString return the distribution for the given input image string | func DistFromImageString(is string) (dist.Distribution, error) | // DistFromImageString return the distribution for the given input image string
func DistFromImageString(is string) (dist.Distribution, error) | {
u, err := url.Parse(is)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("failed to parse image url %q", is), err)
}
// Convert user friendly image string names to internal distribution URIs
// file:///full/path/to/aci/file.aci -> archive:aci:file%3A%2F%2F%2Ffull%2Fpath%2Fto%2Faci%2Ffile.aci
switch u.Sch... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/distribution/cimd.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/cimd.go#L34-L51 | go | train | // parseCIMD parses the given url and returns a cimd. | func parseCIMD(u *url.URL) (*cimd, error) | // parseCIMD parses the given url and returns a cimd.
func parseCIMD(u *url.URL) (*cimd, error) | {
if u.Scheme != Scheme {
return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
}
parts := strings.SplitN(u.Opaque, ":", 3)
if len(parts) < 3 {
return nil, fmt.Errorf("malformed distribution uri: %q", u.String())
}
version, err := strconv.ParseUint(strings.TrimPrefix(parts[1], "v="), 10, 32)
if err != ... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | pkg/distribution/cimd.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/cimd.go#L54-L56 | go | train | // NewCIMDString creates a new cimd URL string. | func NewCIMDString(typ Type, version uint32, data string) string | // NewCIMDString creates a new cimd URL string.
func NewCIMDString(typ Type, version uint32, data string) string | {
return fmt.Sprintf("%s:%s:v=%d:%s", Scheme, typ, version, data)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/export.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L164-L199 | go | train | // getApp returns the app to export
// If one was supplied in the flags then it's returned if present
// If the PM contains a single app, that app is returned
// If the PM has multiple apps, the names are printed and an error is returned | func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) | // getApp returns the app to export
// If one was supplied in the flags then it's returned if present
// If the PM contains a single app, that app is returned
// If the PM has multiple apps, the names are printed and an error is returned
func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) | {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, errwrap.Wrap(errors.New("problem getting the pod's manifest"), err)
}
apps := manifest.Apps
if flagExportAppName != "" {
exportAppName, err := types.NewACName(flagExportAppName)
if err != nil {
return nil, err
}
for _, ra := range ap... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/export.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L202-L240 | go | train | // mountOverlay mounts the app from the overlay-rendered pod to the destination directory. | func mountOverlay(pod *pkgPod.Pod, app *schema.RuntimeApp, dest string) error | // mountOverlay mounts the app from the overlay-rendered pod to the destination directory.
func mountOverlay(pod *pkgPod.Pod, app *schema.RuntimeApp, dest string) error | {
if _, err := os.Stat(dest); err != nil {
return err
}
s, err := imagestore.NewStore(getDataDir())
if err != nil {
return errwrap.Wrap(errors.New("cannot open store"), err)
}
ts, err := treestore.NewStore(treeStoreDir(), s)
if err != nil {
return errwrap.Wrap(errors.New("cannot open treestore"), err)
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/export.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L244-L306 | go | train | // buildAci builds a target aci from the root directory using any uid shift
// information from uidRange. | func buildAci(root, manifestPath, target string, uidRange *user.UidRange) (e error) | // buildAci builds a target aci from the root directory using any uid shift
// information from uidRange.
func buildAci(root, manifestPath, target string, uidRange *user.UidRange) (e error) | {
mode := os.O_CREATE | os.O_WRONLY
if flagOverwriteACI {
mode |= os.O_TRUNC
} else {
mode |= os.O_EXCL
}
aciFile, err := os.OpenFile(target, mode, 0644)
if err != nil {
if os.IsExist(err) {
return errors.New("target file exists (try --overwrite)")
} else {
return errwrap.Wrap(fmt.Errorf("unable to... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/rkt.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/rkt.go#L176-L188 | go | train | // runWrapper returns a func(cmd *cobra.Command, args []string) that internally
// will add command function return code and the reinsertion of the "--" flag
// terminator. | func runWrapper(cf func(cmd *cobra.Command, args []string) (exit int)) func(cmd *cobra.Command, args []string) | // runWrapper returns a func(cmd *cobra.Command, args []string) that internally
// will add command function return code and the reinsertion of the "--" flag
// terminator.
func runWrapper(cf func(cmd *cobra.Command, args []string) (exit int)) func(cmd *cobra.Command, args []string) | {
return func(cmd *cobra.Command, args []string) {
cpufile, memfile, err := startProfile()
if err != nil {
stderr.PrintE("cannot setup profiling", err)
cmdExitCode = 254
return
}
defer stopProfile(cpufile, memfile)
cmdExitCode = cf(cmd, args)
}
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/rkt.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/rkt.go#L192-L202 | go | train | // ensureSuperuser will error out if the effective UID of the current process
// is not zero. Otherwise, it will invoke the supplied cobra command. | func ensureSuperuser(cf func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) | // ensureSuperuser will error out if the effective UID of the current process
// is not zero. Otherwise, it will invoke the supplied cobra command.
func ensureSuperuser(cf func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) | {
return func(cmd *cobra.Command, args []string) {
if os.Geteuid() != 0 {
stderr.Print("cannot run as unprivileged user")
cmdExitCode = 254
return
}
cf(cmd, args)
}
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/seccomp.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L58-L107 | go | train | // generateSeccompFilter computes the concrete seccomp filter from the isolators | func generateSeccompFilter(p *stage1commontypes.Pod, pa *preparedApp) (*seccompFilter, error) | // generateSeccompFilter computes the concrete seccomp filter from the isolators
func generateSeccompFilter(p *stage1commontypes.Pod, pa *preparedApp) (*seccompFilter, error) | {
sf := seccompFilter{}
seenIsolators := 0
for _, i := range pa.app.App.Isolators {
var flag string
var err error
if seccomp, ok := i.Value().(types.LinuxSeccompSet); ok {
seenIsolators++
// By appc spec, only one seccomp isolator per app is allowed
if seenIsolators > 1 {
return nil, ErrTooManySe... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/seccomp.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L110-L132 | go | train | // seccompUnitOptions converts a concrete seccomp filter to systemd unit options | func seccompUnitOptions(opts []*unit.UnitOption, sf *seccompFilter) ([]*unit.UnitOption, error) | // seccompUnitOptions converts a concrete seccomp filter to systemd unit options
func seccompUnitOptions(opts []*unit.UnitOption, sf *seccompFilter) ([]*unit.UnitOption, error) | {
if sf == nil {
return opts, nil
}
if sf.errno != "" {
opts = append(opts, unit.NewUnitOption("Service", "SystemCallErrorNumber", sf.errno))
}
var filterPrefix string
switch sf.mode {
case ModeWhitelist:
filterPrefix = sdWhitelistPrefix
case ModeBlacklist:
filterPrefix = sdBlacklistPrefix
default:
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/init/common/seccomp.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L136-L202 | go | train | // parseLinuxSeccompSet gets an appc LinuxSeccompSet and returns an array
// of values suitable for systemd SystemCallFilter. | func parseLinuxSeccompSet(p *stage1commontypes.Pod, s types.LinuxSeccompSet) (syscallFilter []string, flag string, err error) | // parseLinuxSeccompSet gets an appc LinuxSeccompSet and returns an array
// of values suitable for systemd SystemCallFilter.
func parseLinuxSeccompSet(p *stage1commontypes.Pod, s types.LinuxSeccompSet) (syscallFilter []string, flag string, err error) | {
for _, item := range s.Set() {
if item[0] == '@' {
// Wildcards
wildcard := strings.SplitN(string(item), "/", 2)
if len(wildcard) != 2 {
continue
}
scope := wildcard[0]
name := wildcard[1]
switch scope {
case "@appc.io":
// appc-reserved wildcards
switch name {
case "all":
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/app_rm/app_rm.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_rm/app_rm.go#L56-L88 | go | train | // This is a multi-step entrypoint. It starts in stage0 context then invokes
// itself again in stage1 context to perform further cleanup at pod level. | func main() | // This is a multi-step entrypoint. It starts in stage0 context then invokes
// itself again in stage1 context to perform further cleanup at pod level.
func main() | {
flag.Parse()
stage1initcommon.InitDebug(debug)
log, diag, _ = rktlog.NewLogSet("app-rm", debug)
if !debug {
diag.SetOutput(ioutil.Discard)
}
appName, err := types.NewACName(flagApp)
if err != nil {
log.FatalE("invalid app name", err)
}
enterCmd := stage1common.PrepareEnterCmd(false)
switch flagStag... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/app_rm/app_rm.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_rm/app_rm.go#L96-L151 | go | train | // cleanupStage0 is the default initial step for rm entrypoint, which takes
// care of cleaning up resources in stage0 and calling into stage1 by:
// 1. ensuring that the service has been stopped
// 2. removing unit files
// 3. calling itself in stage1 for further cleanups
// 4. calling `systemctl daemon-reload` in... | func cleanupStage0(appName *types.ACName, enterCmd []string) error | // cleanupStage0 is the default initial step for rm entrypoint, which takes
// care of cleaning up resources in stage0 and calling into stage1 by:
// 1. ensuring that the service has been stopped
// 2. removing unit files
// 3. calling itself in stage1 for further cleanups
// 4. calling `systemctl daemon-reload` in... | {
args := enterCmd
args = append(args, "/usr/bin/systemctl")
args = append(args, "is-active")
args = append(args, appName.String())
cmd := exec.Cmd{
Path: args[0],
Args: args,
}
// rely only on the output, since is-active returns non-zero for inactive units
out, _ := cmd.Output()
switch string(out) {
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | stage1/app_rm/app_rm.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_rm/app_rm.go#L155-L176 | go | train | // cleanupStage1 is meant to be executed in stage1 context. It inspects pod systemd-pid1 mountinfo to
// find all remaining mountpoints for appName and proceed to clean them up. | func cleanupStage1(appName *types.ACName, enterCmd []string) error | // cleanupStage1 is meant to be executed in stage1 context. It inspects pod systemd-pid1 mountinfo to
// find all remaining mountpoints for appName and proceed to clean them up.
func cleanupStage1(appName *types.ACName, enterCmd []string) error | {
// TODO(lucab): re-evaluate once/if we support systemd as non-pid1 (eg. host pid-ns inheriting)
mnts, err := mountinfo.ParseMounts(1)
if err != nil {
return err
}
appRootFs := filepath.Join("/opt/stage2", appName.String(), "rootfs")
mnts = mnts.Filter(mountinfo.HasPrefix(appRootFs))
// soft-errors here, st... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L102-L115 | go | train | // renameExited renames exited pods to the exitedGarbage directory | func renameExited() error | // renameExited renames exited pods to the exitedGarbage directory
func renameExited() error | {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeRunDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.Exited {
stderr.Printf("moving pod %q to garbage", p.UUID)
if err := p.ToExitedGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err != nil {
retur... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L118-L144 | go | train | // emptyExitedGarbage discards sufficiently aged pods from exitedGarbageDir() | func emptyExitedGarbage(gracePeriod time.Duration) error | // emptyExitedGarbage discards sufficiently aged pods from exitedGarbageDir()
func emptyExitedGarbage(gracePeriod time.Duration) error | {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeExitedGarbageDir, func(p *pkgPod.Pod) {
gp := p.Path()
st := &syscall.Stat_t{}
if err := syscall.Lstat(gp, st); err != nil {
if err != syscall.ENOENT {
stderr.PrintE(fmt.Sprintf("unable to stat %q, ignoring", gp), err)
}
return
}
if expir... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L147-L159 | go | train | // renameAborted renames failed prepares to the garbage directory | func renameAborted() error | // renameAborted renames failed prepares to the garbage directory
func renameAborted() error | {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludePrepareDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.AbortedPrepare {
stderr.Printf("moving failed prepare %q to garbage", p.UUID)
if err := p.ToGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L162-L183 | go | train | // renameExpired renames expired prepared pods to the garbage directory | func renameExpired(preparedExpiration time.Duration) error | // renameExpired renames expired prepared pods to the garbage directory
func renameExpired(preparedExpiration time.Duration) error | {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludePreparedDir, func(p *pkgPod.Pod) {
st := &syscall.Stat_t{}
pp := p.Path()
if err := syscall.Lstat(pp, st); err != nil {
if err != syscall.ENOENT {
stderr.PrintE(fmt.Sprintf("unable to stat %q, ignoring", pp), err)
}
return
}
if expiration... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L186-L199 | go | train | // emptyGarbage discards everything from garbageDir() | func emptyGarbage() error | // emptyGarbage discards everything from garbageDir()
func emptyGarbage() error | {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeGarbageDir, func(p *pkgPod.Pod) {
if err := p.ExclusiveLock(); err != nil {
return
}
stdout.Printf("Garbage collecting pod %q", p.UUID)
deletePod(p)
}); err != nil {
return err
}
return nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L207-L246 | go | train | // mountPodStage1 tries to remount stage1 image overlay in case
// it is not anymore available in place (e.g. a reboot happened
// in-between). If an overlay mount is already there, we assume
// stage1 image is properly in place and we don't perform any
// further actions. A boolean is returned to signal whether a
// a... | func mountPodStage1(ts *treestore.Store, p *pkgPod.Pod) (bool, error) | // mountPodStage1 tries to remount stage1 image overlay in case
// it is not anymore available in place (e.g. a reboot happened
// in-between). If an overlay mount is already there, we assume
// stage1 image is properly in place and we don't perform any
// further actions. A boolean is returned to signal whether a
// a... | {
if !p.UsesOverlay() {
return false, nil
}
s1Id, err := p.GetStage1TreeStoreID()
if err != nil {
return false, errwrap.Wrap(errors.New("error getting stage1 treeStoreID"), err)
}
s1rootfs := ts.GetRootFS(s1Id)
stage1Dir := common.Stage1RootfsPath(p.Path())
if mounts, err := mountinfo.ParseMounts(0); err... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/gc.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L251-L316 | go | train | // deletePod cleans up files and resource associated with the pod
// pod must be under exclusive lock and be in either ExitedGarbage
// or Garbage state | func deletePod(p *pkgPod.Pod) bool | // deletePod cleans up files and resource associated with the pod
// pod must be under exclusive lock and be in either ExitedGarbage
// or Garbage state
func deletePod(p *pkgPod.Pod) bool | {
podState := p.State()
if podState != pkgPod.ExitedGarbage && podState != pkgPod.Garbage && podState != pkgPod.ExitedDeleting {
stderr.Errorf("non-garbage pod %q (status %q), skipped", p.UUID, p.State())
return false
}
if podState == pkgPod.ExitedGarbage {
s, err := imagestore.NewStore(storeDir())
if err... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L283-L289 | go | train | // backupDB backs up current database. | func (s *Store) backupDB() error | // backupDB backs up current database.
func (s *Store) backupDB() error | {
if os.Geteuid() != 0 {
return ErrDBUpdateNeedsRoot
}
backupsDir := filepath.Join(s.dir, "db-backups")
return backup.CreateBackup(s.dbDir(), backupsDir, backupsNumber)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L298-L304 | go | train | // TODO(sgotti), unexport this and provide other functions for external users
// TmpFile returns an *os.File local to the same filesystem as the Store, or
// any error encountered | func (s *Store) TmpFile() (*os.File, error) | // TODO(sgotti), unexport this and provide other functions for external users
// TmpFile returns an *os.File local to the same filesystem as the Store, or
// any error encountered
func (s *Store) TmpFile() (*os.File, error) | {
dir, err := s.TmpDir()
if err != nil {
return nil, err
}
return ioutil.TempFile(dir, "")
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L311-L325 | go | train | // TODO(sgotti), unexport this and provide other functions for external users
// TmpNamedFile returns an *os.File with the specified name local to the same
// filesystem as the Store, or any error encountered. If the file already
// exists it will return the existing file in read/write mode with the cursor
// at the en... | func (s Store) TmpNamedFile(name string) (*os.File, error) | // TODO(sgotti), unexport this and provide other functions for external users
// TmpNamedFile returns an *os.File with the specified name local to the same
// filesystem as the Store, or any error encountered. If the file already
// exists it will return the existing file in read/write mode with the cursor
// at the en... | {
dir, err := s.TmpDir()
if err != nil {
return nil, err
}
fname := filepath.Join(dir, name)
_, err = os.Stat(fname)
if os.IsNotExist(err) {
return os.Create(fname)
}
if err != nil {
return nil, err
}
return os.OpenFile(fname, os.O_RDWR|os.O_APPEND, 0644)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L330-L336 | go | train | // TODO(sgotti), unexport this and provide other functions for external users
// TmpDir creates and returns dir local to the same filesystem as the Store,
// or any error encountered | func (s *Store) TmpDir() (string, error) | // TODO(sgotti), unexport this and provide other functions for external users
// TmpDir creates and returns dir local to the same filesystem as the Store,
// or any error encountered
func (s *Store) TmpDir() (string, error) | {
dir := filepath.Join(s.dir, "tmp")
if err := os.MkdirAll(dir, defaultPathPerm); err != nil {
return "", err
}
return dir, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L341-L370 | go | train | // ResolveKey resolves a partial key (of format `sha512-0c45e8c0ab2`) to a full
// key by considering the key a prefix and using the store for resolution.
// If the key is longer than the full key length, it is first truncated. | func (s *Store) ResolveKey(key string) (string, error) | // ResolveKey resolves a partial key (of format `sha512-0c45e8c0ab2`) to a full
// key by considering the key a prefix and using the store for resolution.
// If the key is longer than the full key length, it is first truncated.
func (s *Store) ResolveKey(key string) (string, error) | {
if !strings.HasPrefix(key, hashPrefix) {
return "", fmt.Errorf("wrong key prefix")
}
if len(key) < minlenKey {
return "", fmt.Errorf("image ID too short")
}
if len(key) > lenKey {
key = key[:lenKey]
}
var aciInfos []*ACIInfo
err := s.db.Do(func(tx *sql.Tx) error {
var err error
aciInfos, err = Get... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L374-L394 | go | train | // ResolveName resolves an image name to a list of full keys and using the
// store for resolution. | func (s *Store) ResolveName(name string) ([]string, bool, error) | // ResolveName resolves an image name to a list of full keys and using the
// store for resolution.
func (s *Store) ResolveName(name string) ([]string, bool, error) | {
var (
aciInfos []*ACIInfo
found bool
)
err := s.db.Do(func(tx *sql.Tx) error {
var err error
aciInfos, found, err = GetACIInfosWithName(tx, name)
return err
})
if err != nil {
return nil, found, errwrap.Wrap(errors.New("error retrieving ACI Infos"), err)
}
keys := make([]string, len(aciInfos))... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L431-L500 | go | train | // WriteACI takes an ACI encapsulated in an io.Reader, decompresses it if
// necessary, and then stores it in the store under a key based on the image ID
// (i.e. the hash of the uncompressed ACI)
// latest defines if the aci has to be marked as the latest. For example an ACI
// discovered without asking for a specific... | func (s *Store) WriteACI(r io.ReadSeeker, fetchInfo ACIFetchInfo) (string, error) | // WriteACI takes an ACI encapsulated in an io.Reader, decompresses it if
// necessary, and then stores it in the store under a key based on the image ID
// (i.e. the hash of the uncompressed ACI)
// latest defines if the aci has to be marked as the latest. For example an ACI
// discovered without asking for a specific... | {
// We need to allow the store's setgid bits (if any) to propagate, so
// disable umask
um := syscall.Umask(0)
defer syscall.Umask(um)
dr, err := aci.NewCompressedReader(r)
if err != nil {
return "", errwrap.Wrap(errors.New("error decompressing image"), err)
}
defer dr.Close()
// Write the decompressed i... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L506-L551 | go | train | // RemoveACI removes the ACI with the given key. It firstly removes the aci
// infos inside the db, then it tries to remove the non transactional data.
// If some error occurs removing some non transactional data a
// StoreRemovalError is returned. | func (s *Store) RemoveACI(key string) error | // RemoveACI removes the ACI with the given key. It firstly removes the aci
// infos inside the db, then it tries to remove the non transactional data.
// If some error occurs removing some non transactional data a
// StoreRemovalError is returned.
func (s *Store) RemoveACI(key string) error | {
imageKeyLock, err := lock.ExclusiveKeyLock(s.imageLockDir, key)
if err != nil {
return errwrap.Wrap(errors.New("error locking image"), err)
}
defer imageKeyLock.Close()
// Firstly remove aciinfo and remote from the db in an unique transaction.
// remote needs to be removed or a GetRemote will return a blobK... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L555-L570 | go | train | // GetRemote tries to retrieve a remote with the given ACIURL.
// If remote doesn't exist, it returns ErrRemoteNotFound error. | func (s *Store) GetRemote(aciURL string) (*Remote, error) | // GetRemote tries to retrieve a remote with the given ACIURL.
// If remote doesn't exist, it returns ErrRemoteNotFound error.
func (s *Store) GetRemote(aciURL string) (*Remote, error) | {
var remote *Remote
err := s.db.Do(func(tx *sql.Tx) error {
var err error
remote, err = GetRemote(tx, aciURL)
return err
})
if err != nil {
return nil, err
}
return remote, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L573-L578 | go | train | // WriteRemote adds or updates the provided Remote. | func (s *Store) WriteRemote(remote *Remote) error | // WriteRemote adds or updates the provided Remote.
func (s *Store) WriteRemote(remote *Remote) error | {
err := s.db.Do(func(tx *sql.Tx) error {
return WriteRemote(tx, remote)
})
return err
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L582-L598 | go | train | // GetImageManifestJSON gets the ImageManifest JSON bytes with the
// specified key. | func (s *Store) GetImageManifestJSON(key string) ([]byte, error) | // GetImageManifestJSON gets the ImageManifest JSON bytes with the
// specified key.
func (s *Store) GetImageManifestJSON(key string) ([]byte, error) | {
key, err := s.ResolveKey(key)
if err != nil {
return nil, errwrap.Wrap(errors.New("error resolving image ID"), err)
}
keyLock, err := lock.SharedKeyLock(s.imageLockDir, key)
if err != nil {
return nil, errwrap.Wrap(errors.New("error locking image"), err)
}
defer keyLock.Close()
imj, err := s.stores[imag... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L601-L611 | go | train | // GetImageManifest gets the ImageManifest with the specified key. | func (s *Store) GetImageManifest(key string) (*schema.ImageManifest, error) | // GetImageManifest gets the ImageManifest with the specified key.
func (s *Store) GetImageManifest(key string) (*schema.ImageManifest, error) | {
imj, err := s.GetImageManifestJSON(key)
if err != nil {
return nil, err
}
var im *schema.ImageManifest
if err = json.Unmarshal(imj, &im); err != nil {
return nil, errwrap.Wrap(errors.New("error unmarshalling image manifest"), err)
}
return im, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L619-L681 | go | train | // GetACI retrieves the ACI that best matches the provided app name and labels.
// The returned value is the blob store key of the retrieved ACI.
// If there are multiple matching ACIs choose the latest one (defined as the
// last one imported in the store).
// If no version label is requested, ACIs marked as latest in... | func (s *Store) GetACI(name types.ACIdentifier, labels types.Labels) (string, error) | // GetACI retrieves the ACI that best matches the provided app name and labels.
// The returned value is the blob store key of the retrieved ACI.
// If there are multiple matching ACIs choose the latest one (defined as the
// last one imported in the store).
// If no version label is requested, ACIs marked as latest in... | {
var curaciinfo *ACIInfo
versionRequested := false
if _, ok := labels.Get("version"); ok {
versionRequested = true
}
var aciinfos []*ACIInfo
err := s.db.Do(func(tx *sql.Tx) error {
var err error
aciinfos, _, err = GetACIInfosWithName(tx, name.String())
return err
})
if err != nil {
return "", err
... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L756-L758 | go | train | // HasFullKey returns whether the image with the given key exists on the disk by
// checking if the image manifest kv store contains the key. | func (s *Store) HasFullKey(key string) bool | // HasFullKey returns whether the image with the given key exists on the disk by
// checking if the image manifest kv store contains the key.
func (s *Store) HasFullKey(key string) bool | {
return s.stores[imageManifestType].Has(key)
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | store/imagestore/store.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/store.go#L766-L771 | go | train | // keyToString takes a key and returns a shortened and prefixed hexadecimal string version | func keyToString(k []byte) string | // keyToString takes a key and returns a shortened and prefixed hexadecimal string version
func keyToString(k []byte) string | {
if len(k) != lenHash {
panic(fmt.Sprintf("bad hash passed to hashToKey: %x", k))
}
return fmt.Sprintf("%s%x", hashPrefix, k)[0:lenKey]
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/image/downloader.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/downloader.go#L54-L86 | go | train | // Download tries to fetch the passed URL and write the contents into
// a given writeSyncer instance. | func (d *downloader) Download(u *url.URL, out writeSyncer) error | // Download tries to fetch the passed URL and write the contents into
// a given writeSyncer instance.
func (d *downloader) Download(u *url.URL, out writeSyncer) error | {
client, err := d.Session.Client()
if err != nil {
return err
}
req, err := d.Session.Request(u)
if err != nil {
return err
}
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if stopNow, err := d.Session.HandleStatus(res); stopNow || err != nil {
return err
}
reade... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/enter.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/enter.go#L128-L153 | go | train | // getAppName returns the app name to enter
// If one was supplied in the flags then it's simply returned
// If the PM contains a single app, that app's name is returned
// If the PM has multiple apps, the names are printed and an error is returned | func getAppName(p *pkgPod.Pod) (*types.ACName, error) | // getAppName returns the app name to enter
// If one was supplied in the flags then it's simply returned
// If the PM contains a single app, that app's name is returned
// If the PM has multiple apps, the names are printed and an error is returned
func getAppName(p *pkgPod.Pod) (*types.ACName, error) | {
if flagAppName != "" {
return types.NewACName(flagAppName)
}
// figure out the app name, or show a list if multiple are present
_, m, err := p.PodManifest()
if err != nil {
return nil, errwrap.Wrap(errors.New("error reading pod manifest"), err)
}
switch len(m.Apps) {
case 0:
return nil, fmt.Errorf("p... |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | rkt/enter.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/enter.go#L156-L166 | go | train | // getEnterArgv returns the argv to use for entering the pod | func getEnterArgv(p *pkgPod.Pod, cmdArgs []string) ([]string, error) | // getEnterArgv returns the argv to use for entering the pod
func getEnterArgv(p *pkgPod.Pod, cmdArgs []string) ([]string, error) | {
var argv []string
if len(cmdArgs) < 2 {
stderr.Printf("no command specified, assuming %q", defaultCmd)
argv = []string{defaultCmd}
} else {
argv = cmdArgs[1:]
}
return argv, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | common/cgroup/v1/cgroup.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/cgroup/v1/cgroup.go#L36-L47 | go | train | // mountFsRO remounts the given mountPoint using the given flags read-only. | func mountFsRO(m fs.Mounter, mountPoint string, flags uintptr) error | // mountFsRO remounts the given mountPoint using the given flags read-only.
func mountFsRO(m fs.Mounter, mountPoint string, flags uintptr) error | {
flags = flags |
syscall.MS_BIND |
syscall.MS_REMOUNT |
syscall.MS_RDONLY
if err := m.Mount(mountPoint, mountPoint, "", flags, ""); err != nil {
return errwrap.Wrap(fmt.Errorf("error remounting read-only %q", mountPoint), err)
}
return nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | common/cgroup/v1/cgroup.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/cgroup/v1/cgroup.go#L81-L94 | go | train | // GetEnabledCgroups returns a map with the enabled cgroup controllers grouped by
// hierarchy | func GetEnabledCgroups() (map[int][]string, error) | // GetEnabledCgroups returns a map with the enabled cgroup controllers grouped by
// hierarchy
func GetEnabledCgroups() (map[int][]string, error) | {
cgroupsFile, err := os.Open("/proc/cgroups")
if err != nil {
return nil, err
}
defer cgroupsFile.Close()
cgroups, err := parseCgroups(cgroupsFile)
if err != nil {
return nil, errwrap.Wrap(errors.New("error parsing /proc/cgroups"), err)
}
return cgroups, nil
} |
rkt/rkt | 0c8765619cae3391a9ffa12c8dbd12ba7a475eb8 | common/cgroup/v1/cgroup.go | https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/cgroup/v1/cgroup.go#L99-L106 | go | train | // GetControllerDirs takes a map with the enabled cgroup controllers grouped by
// hierarchy and returns the directory names as they should be in
// /sys/fs/cgroup | func GetControllerDirs(cgroups map[int][]string) []string | // GetControllerDirs takes a map with the enabled cgroup controllers grouped by
// hierarchy and returns the directory names as they should be in
// /sys/fs/cgroup
func GetControllerDirs(cgroups map[int][]string) []string | {
var controllers []string
for _, cs := range cgroups {
controllers = append(controllers, strings.Join(cs, ","))
}
return controllers
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.