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

From: Date: Sat, 17 Nov 2018 14:19:48 +0000
Subject: Bug #77168 [NEW]: chgrp returns true but doesn't immediately change the group
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217996@lists.php.net to get a copy of this message
From: rkaiser at gmail dot com Operating system: CentOS 7 PHP version: 7.0.32 Package: POSIX related Bug Type: Bug Bug description:chgrp returns true but doesn't immediately change the group 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 bug report at https://bugs.php.net/bug.php?id=77168&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77168&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77168&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77168&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77168&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77168&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77168&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77168&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77168&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77168&r=support Expected behavior: https://bugs.php.net/fix.php?id=77168&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77168&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77168&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77168&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77168&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77168&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77168&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77168&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77168&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77168&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77168&r=mysqlcfg

« previous php.bugs (#217996) next »