Skip to content

Commit

Permalink
Merge pull request #3 from just-containers/issue-309
Browse files Browse the repository at this point in the history
Issue 309
  • Loading branch information
jprjr authored Jan 17, 2021
2 parents 22edd94 + f3797fa commit acf226b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package/info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package=s6-overlay-preinit
version=1.0.3
version=1.0.4
category=admin
package_macro_name=S6_OVERLAY_PREINIT
16 changes: 11 additions & 5 deletions src/s6-overlay-preinit/s6-overlay-preinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,27 @@ int main (void)
}
}

/* requirement: /var/run/s6 must be owned by current user */
/* requirement: /var/run/s6 must be owned by current user,
* if (and only if) current user != root */
uid_t uid = getuid() ,
gid = getgid() ,
euid = geteuid() ;

struct stat s6stat ;
if(stat(VAR_RUN_S6, &s6stat) == -1)
{
strerr_diefu2sys(111, "stat ", VAR_RUN_S6) ;
}

uid_t uid = getuid() ,
gid = getgid() ;
/* only call chown if uid/gid are not from current user */
if(s6stat.st_uid != uid || s6stat.st_gid != gid)
{
if (chown(VAR_RUN_S6, uid, gid) == -1)
if (euid == 0) /* chown will fail if we're not root */
{
strerr_diefu2sys(111, "chown ", VAR_RUN_S6) ;
if (chown(VAR_RUN_S6, uid, gid) == -1)
{
strerr_diefu2sys(111, "chown ", VAR_RUN_S6) ;
}
}
}

Expand Down

0 comments on commit acf226b

Please sign in to comment.