@@ -38,9 +38,10 @@ const (
3838)
3939
4040type Ldconfig struct {
41- ldconfigPath string
42- inRoot string
43- directories []string
41+ ldconfigPath string
42+ inRoot string
43+ isDebianLikeHost bool
44+ directories []string
4445}
4546
4647// NewRunner creates an exec.Cmd that can be used to run ldconfig.
@@ -50,6 +51,9 @@ func NewRunner(id string, ldconfigPath string, containerRoot string, additionala
5051 "--ldconfig-path" , strings .TrimPrefix (config .NormalizeLDConfigPath ("@" + ldconfigPath ), "@" ),
5152 "--container-root" , containerRoot ,
5253 }
54+ if isDebian () {
55+ args = append (args , "--is-debian-like-host" )
56+ }
5357 args = append (args , additionalargs ... )
5458
5559 return createReexecCommand (args )
@@ -74,6 +78,7 @@ func NewFromArgs(args ...string) (*Ldconfig, error) {
7478 fs := flag .NewFlagSet (args [1 ], flag .ExitOnError )
7579 ldconfigPath := fs .String ("ldconfig-path" , "" , "the path to ldconfig on the host" )
7680 containerRoot := fs .String ("container-root" , "" , "the path in which ldconfig must be run" )
81+ isDebianLikeHost := fs .Bool ("is-debian-like-host" , false , "the hook is running from a Debian-like host" )
7782 if err := fs .Parse (args [1 :]); err != nil {
7883 return nil , err
7984 }
@@ -86,9 +91,10 @@ func NewFromArgs(args ...string) (*Ldconfig, error) {
8691 }
8792
8893 l := & Ldconfig {
89- ldconfigPath : * ldconfigPath ,
90- inRoot : * containerRoot ,
91- directories : fs .Args (),
94+ ldconfigPath : * ldconfigPath ,
95+ inRoot : * containerRoot ,
96+ isDebianLikeHost : * isDebianLikeHost ,
97+ directories : fs .Args (),
9298 }
9399 return l , nil
94100}
@@ -106,6 +112,12 @@ func (l *Ldconfig) UpdateLDCache() error {
106112 "-f" , "/etc/ld.so.conf" ,
107113 "-C" , "/etc/ld.so.cache" ,
108114 }
115+ // If we are running in a non-debian container on a debian host we also
116+ // need to add the system directories for non-debian hosts to the list of
117+ // folders processed by ldconfig.
118+ if l .isDebianLikeHost && ! isDebian () {
119+ args = append (args , "/lib64" , "/usr/lib64" )
120+ }
109121
110122 if err := createLdsoconfdFile (ldsoconfdFilenamePattern , l .directories ... ); err != nil {
111123 return fmt .Errorf ("failed to update ld.so.conf.d: %w" , err )
@@ -114,6 +126,14 @@ func (l *Ldconfig) UpdateLDCache() error {
114126 return SafeExec (ldconfigPath , args , nil )
115127}
116128
129+ func isDebian () bool {
130+ info , err := os .Stat ("/etc/debian_version" )
131+ if err != nil {
132+ return false
133+ }
134+ return ! info .IsDir ()
135+ }
136+
117137func (l * Ldconfig ) prepareRoot () (string , error ) {
118138 // To prevent leaking the parent proc filesystem, we create a new proc mount
119139 // in the specified root.
0 commit comments