fix: drop stdio of game process output when the log file exceeds its size limit
This commit is contained in:
parent
4589c81c27
commit
d78221002a
6 changed files with 142 additions and 18 deletions
|
@ -314,8 +314,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -331,11 +329,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -348,19 +351,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
game_output.flush()?;
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -267,8 +267,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -284,11 +282,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -301,17 +304,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -257,8 +257,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -274,11 +272,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -291,17 +294,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -268,8 +268,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -285,11 +283,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -302,17 +305,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -248,8 +248,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -265,11 +263,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -282,17 +285,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
|
@ -266,8 +266,6 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Log process output while it's running
|
// Log process output while it's running
|
||||||
while child.try_wait()?.is_none() {
|
while child.try_wait()?.is_none() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
// Check if we've written less than a limit amount of data
|
// Check if we've written less than a limit amount of data
|
||||||
if written < *consts::GAME_LOG_FILE_LIMIT {
|
if written < *consts::GAME_LOG_FILE_LIMIT {
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stdout to the game.log file
|
||||||
|
@ -283,11 +281,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect stdout to the game.log file
|
// Redirect stderr to the game.log file
|
||||||
if let Some(stderr) = &mut child.stderr {
|
if let Some(stderr) = &mut child.stderr {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
@ -300,17 +303,35 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
game_output.write_all(b"\n")?;
|
game_output.write_all(b"\n")?;
|
||||||
|
|
||||||
written += line.len() + 14;
|
written += line.len() + 14;
|
||||||
|
|
||||||
|
// buf can contain more data than the limit
|
||||||
|
if written > *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop stdio bufs if the limit was reached
|
||||||
|
if written >= *consts::GAME_LOG_FILE_LIMIT {
|
||||||
|
drop(child.stdout.take());
|
||||||
|
drop(child.stderr.take());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord-rpc")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if let Some(rpc) = &rpc {
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Update)?;
|
rpc.update(RpcUpdates::Update)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush and close the game log file
|
||||||
|
game_output.flush()?;
|
||||||
|
|
||||||
|
drop(game_output);
|
||||||
|
|
||||||
// Workaround for fast process closing (is it still a thing?)
|
// Workaround for fast process closing (is it still a thing?)
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
Loading…
Reference in a new issue