php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48576 Wrong error number returned by system, passthru functions
Submitted: 2009-06-17 06:35 UTC Modified: 2009-07-29 23:44 UTC
From: yolcoyama at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.9 OS: Linux ubo 2.6.28-11-generic
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yolcoyama at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-17 06:35 UTC] 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;
}

root@server2:~/diary# ./a.out
no crontab for USER
crontab -u USER -l (256)

* python
root@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
root@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
root@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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-23 19:42 UTC] sjoerd-php at linuxonly dot nl
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.
 [2009-07-29 23:44 UTC] jani@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC