简体   繁体   English

执行屏幕命令,返回“无法使目录'/ var / run / screen':文件存在”

[英]Execute screen command returning `Cannot make directory '/var/run/screen': File exists`

I've no idea what is happening. 我不知道发生了什么。 I can run any other shell command through the exec() command and it works fine. 我可以通过exec()命令运行任何其他shell命令,并且可以正常运行。 It's clearly something to do with permissions somewhere, but I'm unsure what. 显然,这与某处的权限有关,但是我不确定。 I've tried this on many different servers and some of them work fine and some don't. 我已经在许多不同的服务器上进行了尝试,其中一些服务器工作正常,而有些则无法。 All were running CentOS. 所有人都在运行CentOS。 Safe mode is always off. 安全模式始终关闭。

This is the code I'm trying to get to work: 这是我要开始工作的代码:

<?php
error_reporting(E_ALL);

if( ini_get('safe_mode') ){
   echo "safe mode is on";
}else{
   echo "safe mode is not on";
}
echo "\n\n";

echo "Start Server.....\n";

//exec("screen -clean", $err, $err1);
//exec("mkdir /var/test/tewst/");

exec("screen -dms test1 mkdir /var/test/test1/", $err, $err1);

print_r($err);
echo "\n" . $err1;
echo "\nCommands sent...";

?>

All thats returned is this: 返回的所有内容是这样的:

safe mode is not on

Start Server.....
Array
(
    [0] => Cannot make directory '/var/run/screen': File exists
)

1
Commands sent...

Can anyone please shed some light on this at all? 任何人都可以对此有所了解吗?

Update: This was caused by SELinux. 更新:这是由SELinux引起的。

-- -

Turns out it was some weird file system/user permissions error. 原来这是一些奇怪的文件系统/用户权限错误。 After running ls -al /var/run through the exec() command in PHP, it returned this: 通过PHP中的exec()命令运行ls -al /var/run之后,它返回以下内容:

total 52
drwxrwxrwx. 23 root   root   4096 Oct 12 15:13 .
drwxr-xr-x. 22 root   root   4096 Oct 10 08:50 ..
d??????????  ? ?      ?         ?            ? ConsoleKit
drwxr-xr-x.  2 root   root   4096 Oct 11 18:13 abrt
-rw-r--r--.  1 root   root      5 Oct 11 18:13 abrtd.pid
-??????????  ? ?      ?         ?            ? acpid.pid
s??????????  ? ?      ?         ?            ? acpid.socket
-??????????  ? ?      ?         ?            ? atd.pid
-??????????  ? ?      ?         ?            ? auditd.pid
-??????????  ? ?      ?         ?            ? autofs-running
p??????????  ? ?      ?         ?            ? autofs.fifo-misc
p??????????  ? ?      ?         ?            ? autofs.fifo-net
-??????????  ? ?      ?         ?            ? autofs.pid
drwxr-xr-x.  2 root   root   4096 Feb 22  2013 certmonger
-??????????  ? ?      ?         ?            ? certmonger.pid
d??????????  ? ?      ?         ?            ? console
-??????????  ? ?      ?         ?            ? cron.reboot
-??????????  ? ?      ?         ?            ? crond.pid
d??????????  ? ?      ?         ?            ? cups
-??????????  ? ?      ?         ?            ? cupsd.pid
drwxr-xr-x.  2 root   root   4096 Oct 11 18:13 dbus
drwxr-xr-x.  2 root   root   4096 Feb 21  2013 faillock
d??????????  ? ?      ?         ?            ? hald
-??????????  ? ?      ?         ?            ? haldaemon.pid
drwx--x---.  2 root   apache 4096 Oct 12 15:26 httpd
d??????????  ? ?      ?         ?            ? lvm
s??????????  ? ?      ?         ?            ? mcelog-client
-??????????  ? ?      ?         ?            ? mcelog.pid
d??????????  ? ?      ?         ?            ? mdadm
-??????????  ? ?      ?         ?            ? messagebus.pid
drwxr-xr-x.  2 mysql  mysql  4096 Oct 11 18:13 mysqld
drwxrwxr-x.  2 root   root   4096 Feb 22  2013 netreport
d??????????  ? ?      ?         ?            ? plymouth
d??????????  ? ?      ?         ?            ? pm-utils
d??????????  ? ?      ?         ?            ? portreserve
-??????????  ? ?      ?         ?            ? rpc.statd.pid
-??????????  ? ?      ?         ?            ? rpcbind.lock
-??????????  ? ?      ?         ?            ? rpcbind.pid
s??????????  ? ?      ?         ?            ? rpcbind.sock
d??????????  ? ?      ?         ?            ? saslauthd
d??????????  ? ?      ?         ?            ? screen
d??????????  ? ?      ?         ?            ? sepermit
drwxr-xr-x.  2 root   root   4096 May 10 05:06 setrans
-??????????  ? ?      ?         ?            ? sm-notify.pid
-??????????  ? ?      ?         ?            ? sshd.pid
-??????????  ? ?      ?         ?            ? syslogd.pid
-??????????  ? ?      ?         ?            ? utmp
drwxr-xr-x.  2 root   root   4096 Feb 21  2013 winbindd

I fixed it by deleting the directory and making the /var/run permissions 0777. This meant that the web server user could create the directory and use it as expected. 我通过删除目录并设置/var/run权限0777来修复它。这意味着Web服务器用户可以创建目录并按预期使用它。

rm /var/run/screen -R -f
chmod 0777 /var/run

I still don't know why this has happened, nor why there are question marks all over the place in the ls command. 我仍然不知道为什么会发生这种情况,也不知道为什么ls命令中到处都有问号。 If anyone sees this and knows, please leave a comment or answer explaining why. 如果有人看到并知道,请发表评论或回答以说明原因。 It will be a big help, since I know have more errors. 这将是很大的帮助,因为我知道会有更多的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM