Bug #77168 [Com]: chgrp returns true but doesn't immediately change the group

From: Date: Sat, 17 Nov 2018 14:25:06 +0000
Subject: Bug #77168 [Com]: chgrp returns true but doesn't immediately change the group
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217997@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77168&edit=1 ID: 77168 Comment by: spam2 at rhsoft dot net Reported by: rkaiser at gmail dot com Summary: chgrp returns true but doesn't immediately change the group Status: Open Type: Bug Package: POSIX related Operating System: CentOS 7 PHP Version: 7.0.32 Block user comment: N Private report: N New Comment: posix_* are system calls and PHP is hardly repsonsilble what the underlying OS gives back - sounds more like some caching in glibc Previous Comments: ------------------------------------------------------------------------ [2018-11-17 14:19:48] rkaiser at gmail dot com Description: ------------ Note: I only have PHP 7.0.5 CLI to test, not 7.0.32 Even though chgrp($file, $user) returns true, if you immediately check the permissions via posix_getgrgid(filegroup($file)) nothing has changed. Re-running the script immediately shows the group has changed. So maybe there is a time lag or file lock involved. Seems that chown() behaves normally. Test script: --------------- - log in as root - make sure you have an "apache" user, or any other user works too - echo "stuff" > my.log - run the following <?php $logpath = "./my.log"; $owner = posix_getpwuid(fileowner($logpath)); $group = posix_getgrgid(filegroup($logpath)); if ($owner['name'] != 'apache' || $group['name'] != 'apache') { // Attempt to fix the perms if (!chown($logpath, "apache")) throw new exception("Cannot change owner of %s to apache", $logpath); if (!chgrp($logpath, "apache")) throw new exception("Cannot change group of %s to apache", $logpath); // Even though chgrp() returned true, the permissions might not have actually changed. Or else posix_getgrgid(filegroup($logpath)) is incorrect. $owner = posix_getpwuid(fileowner($logpath)); $group = posix_getgrgid(filegroup($logpath)); if ($owner['name'] != 'apache' || $group['name'] != 'apache') throw new exception(sprintf("Wrong permissions on %s - user:group is %s:%s. Try re-running.\n", $logpath, $owner['name'], $group['name'])); } Expected result: ---------------- The call to posix_getgrgid(filegroup($logpath)) would reflect the group change that was just made. Actual result: -------------- It doesn't reflect the group change that was made. Re-running the script works fine. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77168&edit=1

« previous php.bugs (#217997) next »