Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Lock] fix lock file permissions #27903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2018

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Jul 9, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? see discussion below
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

See this comment. Since we are using r+ now to fix an issue on Solaris, we also need to change the file permissions when the lock file is created for the first time. Otherwise

fopen($fileName, 'r+')

will fail due to the file permissions and while

fopen($fileName, 'r')

will work, the subsequent locking will again fail on Solaris.

Changing the file permissions to 0666 fixes this issue. However any lock file that was generated prior to this change will still cause issues and would need to be manually deleted. Usually the default sys_get_temp_dir() location is used for the lock files and usually these files are purged periodically, so it probably won't matter that much. But it still might cause some confusion since it will not be transparent, why the file lock failed on Solaris systems.

@fritzmg fritzmg changed the title fix file lock permissions fix lock file permissions Jul 9, 2018
@fritzmg fritzmg changed the title fix lock file permissions [Lock] fix lock file permissions Jul 9, 2018
@xabbuh xabbuh added the Lock label Jul 9, 2018
@@ -81,7 +81,7 @@ private function lock(Key $key, $blocking)
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
if (!$handle = fopen($fileName, 'r+') ?: fopen($fileName, 'r')) {
if ($handle = fopen($fileName, 'x')) {
chmod($fileName, 0444);
chmod($fileName, 0666);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0644?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that should suffice of course.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so as that would prohibit locks across different users, wouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh good point
@nicolas-grekas what do you think? Should we change it back to 0666?

@nicolas-grekas nicolas-grekas force-pushed the fix-file-lock-permissions branch from d4b4776 to 23481a1 Compare July 9, 2018 12:45
@nicolas-grekas
Copy link
Member

Thank you @fritzmg.

@nicolas-grekas nicolas-grekas merged commit 23481a1 into symfony:3.4 Jul 9, 2018
nicolas-grekas added a commit that referenced this pull request Jul 9, 2018
This PR was squashed before being merged into the 3.4 branch (closes #27903).

Discussion
----------

[Lock] fix lock file permissions

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | see discussion below
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See [this comment](#27668 (comment)). Since we are using `r+` now to fix an issue on Solaris, we also need to change the file permissions when the lock file is created for the first time. Otherwise
```php
fopen($fileName, 'r+')
```
will fail due to the file permissions and while
```php
fopen($fileName, 'r')
```
will work, the subsequent locking will again fail on Solaris.

Changing the file permissions to `0666` fixes this issue. __However__ any lock file that was generated _prior_ to this change will still cause issues and would need to be manually deleted. Usually the default `sys_get_temp_dir()` location is used for the lock files and _usually_ these files are purged periodically, so it probably won't matter that much. But it still might cause some confusion since it will not be transparent, why the file lock failed on Solaris systems.

Commits
-------

23481a1 [Lock] fix lock file permissions
nicolas-grekas added a commit that referenced this pull request Jul 9, 2018
This PR was squashed before being merged into the 2.8 branch (closes #27904).

Discussion
----------

[Filesystem] fix lock file permissions

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | see linked discussion
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

See #27903

Commits
-------

7a68fea [Filesystem] fix lock file permissions
@fritzmg fritzmg deleted the fix-file-lock-permissions branch July 9, 2018 12:49
@fritzmg
Copy link
Contributor Author

fritzmg commented Jul 10, 2018

Just so that the discussion does not get lost: @nicolas-grekas I think we should use 0666 after all. Imagine two users using the same application on the same server. If that application does not generate a unique path/name for its lock file, only the user who first creates the lock file will be able to use it (on Solaris).

@nicolas-grekas
Copy link
Member

I fixed it to 0666 directly in the branch.

This was referenced Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants