Skip to content

Commit

Permalink
chore: remove redundant comments, add todos, etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Feb 2, 2025
1 parent 454336f commit 59c5322
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 52 deletions.
4 changes: 2 additions & 2 deletions internal/anosys/ioprio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"golang.org/x/sys/unix"
)

var IOPrioClassMapping = map[specs.IOPriorityClass]int{
var ioprioClassMapping = map[specs.IOPriorityClass]int{
specs.IOPRIO_CLASS_RT: 1,
specs.IOPRIO_CLASS_BE: 2,
specs.IOPRIO_CLASS_IDLE: 3,
Expand All @@ -27,7 +27,7 @@ func SetIOPriority(ioprio *specs.LinuxIOPriority) error {
}

func ioprioToInt(iop *specs.LinuxIOPriority) (int, error) {
class, ok := IOPrioClassMapping[iop.Class]
class, ok := ioprioClassMapping[iop.Class]
if !ok {
return 0, fmt.Errorf("unknown ioprio class: %s", iop.Class)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/anosys/masked_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

func MountMaskedPaths(paths []string) error {
for _, path := range paths {
f, err := os.Stat(path)
for _, p := range paths {
f, err := os.Stat(p)
if err != nil {
// if it's not there, there's nothing to mask; skip it
continue
Expand All @@ -19,7 +19,7 @@ func MountMaskedPaths(paths []string) error {
if f.IsDir() {
if err := syscall.Mount(
"tmpfs",
path,
p,
"tmpfs",
unix.MS_RDONLY,
"",
Expand All @@ -29,7 +29,7 @@ func MountMaskedPaths(paths []string) error {
} else {
if err := syscall.Mount(
"/dev/null",
path,
p,
"bind",
unix.MS_BIND,
"",
Expand Down
10 changes: 5 additions & 5 deletions internal/anosys/readonly_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

func MountReadonlyPaths(paths []string) error {
for _, path := range paths {
for _, p := range paths {
if err := syscall.Mount(
path,
path,
p,
p,
"",
unix.MS_REC|unix.MS_BIND,
"",
Expand All @@ -20,8 +20,8 @@ func MountReadonlyPaths(paths []string) error {
}

if err := syscall.Mount(
path,
path,
p,
p,
"",
unix.MS_NOSUID|unix.MS_NODEV|unix.MS_NOEXEC|
unix.MS_BIND|unix.MS_REMOUNT|unix.MS_RDONLY,
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/cli/create.go

package cli

import (
Expand Down
4 changes: 0 additions & 4 deletions internal/cli/delete.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// internal/cli/delete.go

package cli

import (
"fmt"

"github.com/nixpig/anocir/internal/operations"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +23,6 @@ func deleteCmd() *cobra.Command {
ID: containerID,
Force: force,
}); err != nil {
logrus.Errorf("delete operation failed: %s", err)
return fmt.Errorf("delete: %w", err)
}

Expand Down
2 changes: 0 additions & 2 deletions internal/cli/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

"github.com/nixpig/anocir/internal/operations"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -34,7 +33,6 @@ func featuresCmd() *cobra.Command {
if _, err := cmd.OutOrStdout().Write(
formattedFeatures.Bytes(),
); err != nil {
logrus.Errorf("features operation failed: %s", err)
return fmt.Errorf("features: %w", err)
}

Expand Down
6 changes: 1 addition & 5 deletions internal/cli/kill.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// internal/cli/kill.go

package cli

import (
"fmt"

"github.com/nixpig/anocir/internal/operations"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -24,15 +21,14 @@ func killCmd() *cobra.Command {
ID: containerID,
Signal: signal,
}); err != nil {
logrus.Errorf("kill operation failed: %s", err)
return fmt.Errorf("kill: %w", err)
}

return nil
},
}

// TODO: do something with this
// TODO: figure out why Docker needs this and implement it
cmd.Flags().BoolP("all", "a", false, "Kill all (Docker??)")

return cmd
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/reexec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/cli/reexec.go

package cli

import (
Expand All @@ -20,6 +18,7 @@ func reexecCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
containerID := args[0]

// TODO: figure out a cleaner way of passing the console socket fd
var consoleSocketFD *int
if cmd.Flags().Changed("console-socket-fd") {
flag, _ := cmd.Flags().GetInt("console-socket-fd")
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/cli/root.go

package cli

import (
Expand All @@ -20,6 +18,7 @@ func RootCmd() *cobra.Command {
Version: "0.0.1",
SilenceUsage: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// TODO: move all this logging stuff out into separate
logfile, _ := cmd.Flags().GetString("log")
if _, err := os.Stat(logfile); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(logfile), os.ModeDir); err != nil {
Expand Down Expand Up @@ -72,7 +71,7 @@ func RootCmd() *cobra.Command {
"/var/log/anocir/log.txt",
"Location of log file",
)
// cmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug logging")
cmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug logging")

cmd.CompletionOptions.HiddenDefaultCmd = true

Expand Down
2 changes: 0 additions & 2 deletions internal/cli/start.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/cli/start.go

package cli

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/state.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/cli/state.go

package cli

import (
Expand Down
15 changes: 6 additions & 9 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import (
"syscall"
"time"

"github.com/sirupsen/logrus"

"github.com/nixpig/anocir/internal/anosys"
"github.com/nixpig/anocir/internal/hooks"
"github.com/nixpig/anocir/internal/terminal"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -144,16 +143,13 @@ func (c *Container) Init() error {
}

if c.ConsoleSocketFD != nil {
csfd := strconv.Itoa(*c.ConsoleSocketFD)
args = append(args, "--console-socket-fd", csfd)
fd := strconv.Itoa(*c.ConsoleSocketFD)
args = append(args, "--console-socket-fd", fd)
}

args = append(args, c.State.ID)

cmd := exec.Command(
"/proc/self/exe",
args...,
)
cmd := exec.Command("/proc/self/exe", args...)

listener, err := net.Listen(
"unix",
Expand Down Expand Up @@ -382,7 +378,7 @@ func (c *Container) Reexec() error {
}

if c.ConsoleSocketFD != nil && c.Spec.Process.Terminal {

// TODO: move this out into function in terminal package?
target := filepath.Join(c.rootFS(), "dev/console")

if _, err := os.Stat(target); os.IsNotExist(err) {
Expand All @@ -407,6 +403,7 @@ func (c *Container) Reexec() error {
}

// wait a sec for init sock to be ready before dialing
// this is nasty - must be a better way
for i := 0; i < 10; i++ {
if _, err := os.Stat(filepath.Join(
containerRootDir,
Expand Down
2 changes: 0 additions & 2 deletions internal/operations/create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/operations/create.go

package operations

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/operations/delete.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/operations/delete.go

package operations

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/operations/kill.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/operations/kill.go

package operations

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/operations/start.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/operations/start.go

package operations

import (
Expand Down
2 changes: 0 additions & 2 deletions internal/operations/state.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// internal/operations/state.go

package operations

import (
Expand Down

0 comments on commit 59c5322

Please sign in to comment.