http://qs1969.pair.com?node_id=792672

hesco has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a REST application which interacts with an Asterisk server. When I write a test script and run it as sudo root, unlink works fine. However, when I use WWW::Mechanize to run my code across port 80, presumably as www-data, it is able to write a call file to my queue directory with permissions:

drwxrwsr-x 2 www-data www-data 48 2009-09-01 03:18 queue
and then to move that call file to the outbound spool:

drwxrwxr-x 2 root dialer 48 2009-09-01 10:24 outgoing
(www-data is a member of the dialer group.)

That call file is picked up from the spool and used by asterisk (running as root, according to `ps`) to initiate an outbound call and connect it to an extension in my dialplan. The dialplan includes an AGI() call to a script (again running as root if my debug statements for $< and $> are to be believed), which initiates additional calls, staged in the pending queue, and successfully moved to the spool.

The issue arises when one of those calls is successfully connected and bridged to the first. At that point, any still pending call files are supposed to be moved aside before they also get moved to the outbound spool. I've tried unlink "$queue/$call_file" and rename "$queue/$call_file", "$queue/pending/$call_file", and neither seems to work as advertised. Neither seems to be able to successfully remove or move aside those pending call files and the calls keep coming.

Based on speculation last night in a cb conversation, I experimented unsuccessfully with adding the --no-lock option to File::Util->write_file() call used to write the call file originally, hoping that releasing it in that way might free it up for the next process to remove the file. But that did not work either.

Does anyone have any idea what might be missing here? I was at this issue for an hour or more last night without being able to move it forward.

-- Hugh

UPDATE:

Thank you folks. I had been using a foreach to loop over the files returned by a call to File::Utils->list_dir(). The ->list_dir() was looking in the wrong directory, an issue pointed to by an empty debug log when I started looking for the $! output. Thank you kindly.

if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }