Skip to content
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

V6 chown函数异常 #5437

Closed
warmbook opened this issue Aug 4, 2024 · 9 comments
Closed

V6 chown函数异常 #5437

warmbook opened this issue Aug 4, 2024 · 9 comments

Comments

@warmbook
Copy link

warmbook commented Aug 4, 2024

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.
    chown($logFile,'nobody');

  2. What did you expect to see?
    文件所有者应改为 nobody

  3. What did you see instead?
    文件所有者依然是root,并出现以下提示:
    Warning: chown(): Unable to find uid for nobody in ......
    open(......) failed. Error: Permission denied[13]

  4. What version of Swoole are you using (show your php --ri swoole)?
    swoole V6

  5. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    Linux iZuf68ujmphbn8maxiqqp6Z 5.10.134-12.2.al8.x86_64 编译出错 #1 SMP Thu Oct 27 10:07:15 CST 2022 x86_64 x86_64 x86_64 GNU/Linux

@NathanFreeman
Copy link
Member

检查一下是否有nobody这个用户

@warmbook
Copy link
Author

warmbook commented Aug 4, 2024

@NathanFreeman nobody 是一个特殊的id,问题是在5.1.3上是好的, @jingjingxyk 基于6.0构建的这个swoole-cli后就出问题了

@jingjingxyk
Copy link
Contributor

在你的运行环境中,执行如下shell 命令 确认是否有输出

id -u  nobody 

swoole-cli v6
https://github.com/jingjingxyk/swoole-cli/releases/tag/swoole-cli-v0.0.8

swoole v6 最大的区别就是 需要PHP 启用 ZTS (Zend Thread Safe) 环境

@jingjingxyk
Copy link
Contributor

试试 把 nobody 换成 nobody 对应的uid

chown https://www.php.net/manual/zh/function.chown.php

@warmbook
Copy link
Author

warmbook commented Aug 5, 2024

@jingjingxyk 把 nobody 换成 nobody 对应的uid确实不报错了,但是感觉这不是长久之计吧?每台设备都要单独改代码

@jingjingxyk
Copy link
Contributor

jingjingxyk commented Aug 5, 2024

@jingjingxyk 把 nobody 换成 nobody 对应的uid确实不报错了,但是感觉这不是长久之计吧?每台设备都要单独改代码

使用 posix_getpwnam("nobody")

$uid = -1;
$userinfo = posix_getpwnam("nobody");
if ($userinfo !== false) {
    var_dump($userinfo);
    $uid = $userinfo ['uid'];
} else {
    throw new Exception(' no found user nobody ! ');
}

@matyhtf matyhtf closed this as completed Aug 7, 2024
@warmbook
Copy link
Author

warmbook commented Aug 8, 2024

不行,PHP代码中调用posix_getpwnam返回值是false,但是控制台执行id -u nobody有值 @jingjingxyk

@warmbook
Copy link
Author

warmbook commented Aug 8, 2024

@matyhtf 麻烦再开一下呢,问题还没有解决

@matyhtf
Copy link
Member

matyhtf commented Aug 20, 2024

建议 strace 追踪一下,swoole 中没有影响 posix_getpwnamchown 的逻辑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants