Skip to content

Commit

Permalink
First step in fixing genuinetools#334
Browse files Browse the repository at this point in the history
reexec.Init() wasn't called in img's main, while buildkit solver
enventually reexec'd in the registered initialization function
"docker-untar"

This is a quick-and-dirty fix to prevent an unecessary namespace unshare
  • Loading branch information
lel-amri committed Apr 12, 2021
1 parent 5b90868 commit b409d1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions internal/unshare/unshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,20 @@ void nsexec(void)
/* Should never be reached. */
bail("should never be reached");
}


/*
* FIXME(lel-amri): This is a quick-and-dirty fix
* up to "End of the quick-and-dirty fix #1".
*/
int is_careless_reexec(int argc, char** argv)
{
if (argc < 1)
return 1;
if (!strncmp(argv[0], "docker-untar", 13))
return 1;
return 0;
}
/*
* End of the quick-and-dirty fix #1
*/
6 changes: 4 additions & 2 deletions internal/unshare/unshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package unshare
/*
#cgo CFLAGS: -Wall
extern void nsexec();
void __attribute__((constructor)) init(void) {
nsexec();
extern int is_careless_reexec(int, char**);
void __attribute__((constructor)) init(int argc, char** argv) {
if (!is_careless_reexec(argc, argv))
nsexec();
}
*/
import "C"
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/genuinetools/img/version"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
dockerreexec "github.com/docker/docker/pkg/reexec"
)

const (
Expand Down Expand Up @@ -50,6 +51,10 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
`

func main() {
if dockerreexec.Init() {
return
}

var printVersionAndExit bool

cmd := &cobra.Command{
Expand Down

0 comments on commit b409d1e

Please sign in to comment.