php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6104 popen returns -1
Submitted: 2000-08-11 06:23 UTC Modified: 2002-12-14 03:49 UTC
From: Alan at Halachmi dot net Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.1pl2 OS: Solaris 8
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: Alan at Halachmi dot net
New email:
PHP Version: OS:

 

 [2000-08-11 06:23 UTC] Alan at Halachmi dot net
This code snippit from horde.lib (www.horde.org):                                              
                                                                                
 // Finally, send the mail.                                                     
        if (@is_executable($default->path_to_sendmail)) {                       
                $mail = popen("$default->path_to_sendmail -i -f$from --  $recipients", 'w');                                                             
                $result  = fputs($mail, $bhdrs . $hdrs);                        
                echo "1: " . $result;                                           
                $result += fputs($mail, "\n");  // trailing \n to end the       
headers section                                                                 
                echo "2: " . $result;                                           
                $result += fputs($mail, $body);                                 
                echo "3: " . $result;                                           
                if (pclose($mail) != 0)                                         
                        $result = 0; 
	  echo "4: " . $result;                                         
        } else {                                                                
                if (empty($envelope['To'])) $envelope['To'] = '';               
                if (empty($envelope['Subject'])) $envelope['Subject'] = '';     
                if (mail($envelope['To'], $envelope['Subject'], $body, $hdrs .  
 $mhdrs))                                                                        
                        $result = 1;                                            
                else                                                            
                        $result = 0;                                                                                       
        }                                                                       
                                                                                
Yields the following output:                                                    
1: 345                                                                          
2: 346                                                                          
3: 354                                                                          
4: 0                                                                            
                                                                                
The return value of pclose() is not the exit status of the program, but a value  as returned by waitpid() of wait4().  I've run what the popen command-line calls by hand using truss, and sendmail is returning exit(0).  So, I dug a bit further... pclose($mail) is returning -1.  Any ideas on how I can track down why?  This function is not reported to be misbehaving on other platforms.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-20 09:18 UTC] jmoore@php.net
Sounds like an incorrect popen call to me (Its returning false not -1) try this instead:

$mail = popen($default->path_to_sendmail." -i -f$from -- 
$recipients", 'w');                                                       

This should fix this. If it doesnt please reopen with a smaller reproducing script and full system info. Also try the latest CVS to see if that fixes it.
                
 [2002-12-14 03:49 UTC] wez@php.net
Note that if you --enable-sigchild this will cause popen and proc_open (and anything using waitpid or wait4 syscalls) to return -1 as the status code for the child process.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 21:01:30 2024 UTC