fix: drop stdio of game process output when the log file exceeds its size limit

This commit is contained in:
Nikita Podvirnyi 2024-07-21 06:10:21 +02:00
parent 4589c81c27
commit d78221002a
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3
6 changed files with 142 additions and 18 deletions

View file

@ -314,8 +314,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -331,11 +329,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -348,19 +351,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -267,8 +267,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -284,11 +282,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -301,17 +304,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -257,8 +257,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -274,11 +272,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -291,17 +294,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -268,8 +268,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -285,11 +283,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -302,17 +305,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -248,8 +248,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -265,11 +263,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -282,17 +285,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));

View file

@ -266,8 +266,6 @@ pub fn run() -> anyhow::Result<()> {
// Log process output while it's running
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
if written < *consts::GAME_LOG_FILE_LIMIT {
// Redirect stdout to the game.log file
@ -283,11 +281,16 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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 {
let mut buf = Vec::new();
@ -300,17 +303,35 @@ pub fn run() -> anyhow::Result<()> {
game_output.write_all(b"\n")?;
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")]
if let Some(rpc) = &rpc {
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?)
loop {
std::thread::sleep(std::time::Duration::from_secs(3));