socket_shutdown($msgsock);
        socket_close($msgsock);
        continue;
    }
    @fclose($fifo_handle);
    /* read output now */
    @($fp = fopen($fifo_reply_file, "r"));
    if (!$fp) {
        @unlink($fifo_reply_file);
        $msg = "sorry -- reply fifo opening error";
        socket_write($msgsock, $msg, strlen($msg));
        socket_shutdown($msgsock);
        socket_close($msgsock);
        continue;
    }
    $status = fgetS($fp, 256);
    if (!$status) {
        @unlink($fifo_reply_file);
        $msg = "sorry -- reply fifo reading error";
        socket_write($msgsock, $msg, strlen($msg));
        socket_shutdown($msgsock);
        socket_close($msgsock);
        continue;
    }
    socket_write($msgsock, $status, strlen($status));
    $rest = fread($fp, 8192);
    @unlink($fifo_reply_file);
    socket_write($msgsock, $rest, strlen($rest));
    socket_close($msgsock);
} while (true);
socket_close($sock);
Exemplo n.º 2
0
function write2fifo($fifo_cmd, &$errors, &$status){
	global $config;

	/* open fifo now */
	$fifo_handle=fopen( $config->fifo_server, "w" );
	if (!$fifo_handle) {
		$errors[]="sorry -- cannot open write fifo"; return;
	}

	/* create fifo for replies */
	@system("mkfifo -m 666 ".$config->reply_fifo_path );


	/* add command separator */
	$fifo_cmd=$fifo_cmd."\n";

	/* write fifo command */
	if (fwrite( $fifo_handle, $fifo_cmd)==-1) {
	    @unlink($config->reply_fifo_path);
	    @fclose($fifo_handle);
		$errors[]="sorry -- fifo writing error"; return;
	}
	@fclose($fifo_handle);

	/* read output now */
	@$fp = fopen( $config->reply_fifo_path, "r");
	if (!$fp) {
	    @unlink($config->reply_fifo_path);
		$errors[]="sorry -- reply fifo opening error"; return;
	}

	$status=fgetS($fp,256);
	if (!$status) {
	    @unlink($config->reply_fifo_path);
		$errors[]="sorry -- reply fifo reading error"; return;
	}
	
	$rd=fread($fp,8192);
	@unlink($config->reply_fifo_path);
	
	return $rd;
}