ID: 48576 Comment by: sjoerd-php at linuxonly dot nl Reported By: yolcoyama at gmail dot com Status: Open Bug Type: Filesystem function related Operating System: Linux ubo 2.6.28-11-generic PHP Version: 5.2.9 New Comment:
Thank you for your bug report. On my system, crontab returns 1, as shown by these commands: crontab -l -u USER; echo $? This thus means that PHP returns the correct exit status. Instead, the system() system call behaves strangely. You can show this by compiling a program which returns 1 in its main loop and call that program using system(). It will return 256 as return status. Python documents this somewhat better than the C++ system call: [It will] return a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced. Previous Comments: ------------------------------------------------------------------------ [2009-06-17 06:35:23] yolcoyama at gmail dot com Description: ------------ Trying to install crontab with PHP cli, system (and passthru) function returned error-code of "1" with output "no crontab for USER" (USER should be replaced with real system user to whom crontab should be installed). the code is: $ php -r '$c="crontab -u USER -l";system($c,$status); printf("%s (%d)\n",$c,$status);' the output is: no crontab for USER crontab -u USER -l (1) Since no crontab is been installed for the USER, the output was expected, but I don't think error code should be 1 for this. For comparison, python and c++ both returns 256 of error code for this error ("no crontab for USER be installed"). According to an error code definition of unix system (in ubuntu, /usr/include/asm-generic/errno-base.h and errno.h), 1 be translated as "permission denied". Followings are comparison code and result for other languages. They returned error number 256 but PHP. * c++ #include <iostream> #include <cstdlib> using namespace std; int main(int argc,char *argv[]){ string cmnd("crontab -u USER -l"); int errcode=system(cmnd.data()); printf( "%s (%d)\n", cmnd.data(), errcode ); return 0; } r...@server2:~/diary# ./a.out no crontab for USER crontab -u USER -l (256) * python r...@server2:~/diary# python -c 'import os; c="crontab -u USER -l"; print "%s (%d)" % (c, os.system(c))' no crontab for USER crontab -u USER -l (256) * php r...@server2:~/diary# php -r '$c="crontab -u USER -l";system($c,$status); printf("%s (%d)\n",$c,$status);' no crontab for USER crontab -u USER -l (1) * error number refference r...@server2:~/diary# awk '/[\x20\t]+1[\x20\t]+/' /usr/include/asm-generic/errno-base.h #define EPERM 1 // Operation not permitted Reproduce code: --------------- # make sure there's NO crontab installed for USER. $ php -r '$c="crontab -u USER -l";system($c,$status); printf("%s (%d)\n",$c,$status);' Expected result: ---------------- Output: no crontab for USER crontab -u USER -l (256) Actual result: -------------- Output: no crontab for USER crontab -u USER -l (1) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48576&edit=1