changeset 168:4dee3368df63

merged with upstream
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 16 Apr 2010 19:08:58 +0900
parents 3d4df1fe4166 (current diff) b307e3749e80 (diff)
children 1c4558d1a449
files
diffstat 1 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/recorder.php	Thu Apr 08 04:22:20 2010 +0900
+++ b/recorder.php	Fri Apr 16 19:08:58 2010 +0900
@@ -8,9 +8,11 @@
 include_once( INSTALL_PATH . "/recLog.inc.php" );
 include_once( INSTALL_PATH . "/reclib.php" );
 
+define("DEBUG", true );
+
 // 後方互換性
 
-if( ! defined( RECORDER_CMD ) ) {
+if( ! defined( "RECORDER_CMD" ) ) {
 	define( "RECORDER_CMD", INSTALL_PATH . "/recorder.php" );
 }
 
@@ -19,6 +21,7 @@
 $msgh_r = null;		// 受信用メッセージハンドラ
 $msgh_w = null;		// 送信用メッセージハンドラ
 
+$logfile = INSTALL_PATH."/settings/recorder_".$reserve_id.".log";
 
 // ノンブロッキングメッセージ受信
 
@@ -68,7 +71,7 @@
 			2 => array( 'file','/dev/null','w' ),
 	);
 	
-	$ps = proc_open( "/bin/ps -o pid,ppid -ax" , $d, $pipes );
+	$ps = proc_open( "/bin/ps -o pid,ppid ax" , $d, $pipes );
 	do {
 		$st = proc_get_status( $ps );
 	}while( $st['running'] );
@@ -92,24 +95,48 @@
 
 function epgrec_termproc( $p )
 {
+	if( DEBUG ) {
+		global $logfile;
+		system( "ps ax >>".$logfile );
+		system( "echo ------- >>".$logfile );
+	}
+	
 	$cpids = epgrec_childproc( $p );
 	
+	if( DEBUG ) {
+		 global $logfile;
+		 
+		 foreach( $cpids as $cpid ) {
+			system( "echo ".$cpid." >>".$logfile );
+		}
+		system( "echo ------- >>".$logfile );
+	}
+	
 	@proc_terminate( $p );
 	sleep(1);
 	@proc_terminate( $p );	// 2度送る
 	
 	foreach( $cpids as $cpid ) {
-		@posix_kill( $cpid, SIGTERM );	// sigterm
-		usleep(100);
-		@posix_kill( $cpid, SIGKILL );	// sigkill
+		$ret = posix_kill( $cpid, SIGTERM );	// sigterm
+		usleep(100*1000);
+		if( ! $ret ) posix_kill( $cpid, SIGKILL );	// sigkill
 	}
 	
+	if( DEBUG ) {
+		global $logfile;
+		system( "ps ax >>".$logfile );
+		system( "echo ------- >>".$logfile );
+	}
+	
+	foreach( $cpids as $cpid ) {
+		$ret = posix_kill( $cpid, SIGTERM );	// sigterm
+		if( $ret ) return false;	// 恐らくプロセスが存在するのでエラー
+	}
 	return true;	// 保証できない
 }
 
 ////// ここから本編
 
-
 // メッセージハンドラを得る
 $ipc_key = ftok( RECORDER_CMD, "R" );
 $msgh_r = msg_get_queue( $ipc_key );