Mercurial > epgrec.yaz
comparison recorder.php @ 166:68f6b36e7c01
mod: ?????????
| author | Sushi-k <epgrec@park.mda.or.jp> |
|---|---|
| date | Fri, 16 Apr 2010 17:31:18 +0900 |
| parents | b3095425e613 |
| children | b307e3749e80 |
comparison
equal
deleted
inserted
replaced
| 164:254d8a21bf36 | 166:68f6b36e7c01 |
|---|---|
| 6 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | 6 include_once( INSTALL_PATH . "/DBRecord.class.php" ); |
| 7 include_once( INSTALL_PATH . "/Settings.class.php" ); | 7 include_once( INSTALL_PATH . "/Settings.class.php" ); |
| 8 include_once( INSTALL_PATH . "/recLog.inc.php" ); | 8 include_once( INSTALL_PATH . "/recLog.inc.php" ); |
| 9 include_once( INSTALL_PATH . "/reclib.php" ); | 9 include_once( INSTALL_PATH . "/reclib.php" ); |
| 10 | 10 |
| 11 define("DEBUG", true ); | |
| 12 | |
| 11 // 後方互換性 | 13 // 後方互換性 |
| 12 | 14 |
| 13 if( ! defined( RECORDER_CMD ) ) { | 15 if( ! defined( RECORDER_CMD ) ) { |
| 14 define( "RECORDER_CMD", INSTALL_PATH . "/recorder.php" ); | 16 define( "RECORDER_CMD", INSTALL_PATH . "/recorder.php" ); |
| 15 } | 17 } |
| 17 $settings = Settings::factory(); | 19 $settings = Settings::factory(); |
| 18 $reserve_id = $argv[1]; | 20 $reserve_id = $argv[1]; |
| 19 $msgh_r = null; // 受信用メッセージハンドラ | 21 $msgh_r = null; // 受信用メッセージハンドラ |
| 20 $msgh_w = null; // 送信用メッセージハンドラ | 22 $msgh_w = null; // 送信用メッセージハンドラ |
| 21 | 23 |
| 24 $logfile = INSTALL_PATH."/settings/recorder_".$reserve_id.".log"; | |
| 22 | 25 |
| 23 // ノンブロッキングメッセージ受信 | 26 // ノンブロッキングメッセージ受信 |
| 24 | 27 |
| 25 function epgrec_get_message() { | 28 function epgrec_get_message() { |
| 26 global $msgh_r, $reserve_id; | 29 global $msgh_r, $reserve_id; |
| 66 0 => array( 'file','/dev/null','r' ), | 69 0 => array( 'file','/dev/null','r' ), |
| 67 1 => array( 'pipe','w' ), | 70 1 => array( 'pipe','w' ), |
| 68 2 => array( 'file','/dev/null','w' ), | 71 2 => array( 'file','/dev/null','w' ), |
| 69 ); | 72 ); |
| 70 | 73 |
| 71 $ps = proc_open( "/bin/ps -o pid,ppid -ax" , $d, $pipes ); | 74 $ps = proc_open( "/bin/ps -o pid,ppid ax" , $d, $pipes ); |
| 72 do { | 75 do { |
| 73 $st = proc_get_status( $ps ); | 76 $st = proc_get_status( $ps ); |
| 74 }while( $st['running'] ); | 77 }while( $st['running'] ); |
| 75 | 78 |
| 76 // 標準出力を読む | 79 // 標準出力を読む |
| 90 | 93 |
| 91 // 指定したプロセスハンドルを子プロセスを含め終了させる | 94 // 指定したプロセスハンドルを子プロセスを含め終了させる |
| 92 | 95 |
| 93 function epgrec_termproc( $p ) | 96 function epgrec_termproc( $p ) |
| 94 { | 97 { |
| 98 if( DEBUG ) { | |
| 99 global $logfile; | |
| 100 system( "ps ax >>".$logfile ); | |
| 101 system( "echo ------- >>".$logfile ); | |
| 102 } | |
| 103 | |
| 95 $cpids = epgrec_childproc( $p ); | 104 $cpids = epgrec_childproc( $p ); |
| 105 | |
| 106 if( DEBUG ) { | |
| 107 global $logfile; | |
| 108 | |
| 109 foreach( $cpids as $cpid ) { | |
| 110 system( "echo ".$cpid." >>".$logfile ); | |
| 111 } | |
| 112 system( "echo ------- >>".$logfile ); | |
| 113 } | |
| 96 | 114 |
| 97 @proc_terminate( $p ); | 115 @proc_terminate( $p ); |
| 98 sleep(1); | 116 sleep(1); |
| 99 @proc_terminate( $p ); // 2度送る | 117 @proc_terminate( $p ); // 2度送る |
| 100 | 118 |
| 101 foreach( $cpids as $cpid ) { | 119 foreach( $cpids as $cpid ) { |
| 102 @posix_kill( $cpid, SIGTERM ); // sigterm | 120 $ret = posix_kill( $cpid, SIGTERM ); // sigterm |
| 103 usleep(100); | 121 usleep(100*1000); |
| 104 @posix_kill( $cpid, SIGKILL ); // sigkill | 122 if( ! $ret ) posix_kill( $cpid, SIGKILL ); // sigkill |
| 105 } | 123 } |
| 106 | 124 |
| 125 if( DEBUG ) { | |
| 126 global $logfile; | |
| 127 system( "ps ax >>".$logfile ); | |
| 128 system( "echo ------- >>".$logfile ); | |
| 129 } | |
| 130 | |
| 131 foreach( $cpids as $cpid ) { | |
| 132 $ret = posix_kill( $cpid, SIGTERM ); // sigterm | |
| 133 if( $ret ) return false; // 恐らくプロセスが存在するのでエラー | |
| 134 } | |
| 107 return true; // 保証できない | 135 return true; // 保証できない |
| 108 } | 136 } |
| 109 | 137 |
| 110 ////// ここから本編 | 138 ////// ここから本編 |
| 111 | |
| 112 | 139 |
| 113 // メッセージハンドラを得る | 140 // メッセージハンドラを得る |
| 114 $ipc_key = ftok( RECORDER_CMD, "R" ); | 141 $ipc_key = ftok( RECORDER_CMD, "R" ); |
| 115 $msgh_r = msg_get_queue( $ipc_key ); | 142 $msgh_r = msg_get_queue( $ipc_key ); |
| 116 | 143 |
