Skip to content

Commit 1bd0f98

Browse files
stonemasterAndré Stein
authored andcommitted
Add new flag --disable-compression/-D that allows writing ZIP file
uncompressed. Also rewrite coredump piping code to use io::copy which prevents core dump corruption in large core dumps. Signed-off-by: André Stein <[email protected]>
1 parent f6b44a4 commit 1bd0f98

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

core-dump-composer/src/config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct CoreConfig {
2626
pub os_hostname: String,
2727
pub filename_template: String,
2828
pub params: CoreParams,
29+
pub disable_compression: bool,
2930
}
3031

3132
#[derive(Serialize)]
@@ -62,6 +63,7 @@ impl CoreConfig {
6263
.unwrap_or("120")
6364
.parse::<u64>()
6465
.unwrap();
66+
let disable_compression = matches.contains_id("disable-compression");
6567

6668
let uuid = Uuid::new_v4();
6769

@@ -144,6 +146,7 @@ impl CoreConfig {
144146
filename_template,
145147
log_length,
146148
params,
149+
disable_compression,
147150
})
148151
}
149152

@@ -208,11 +211,11 @@ impl CoreConfig {
208211
format!("{}-ps-info.json", self.get_templated_name())
209212
}
210213

211-
pub fn get_image_filename(&self, counter: u32) -> String {
214+
pub fn get_image_filename(&self, counter: usize) -> String {
212215
format!("{}-{}-image-info.json", self.get_templated_name(), counter)
213216
}
214217

215-
pub fn get_log_filename(&self, counter: u32) -> String {
218+
pub fn get_log_filename(&self, counter: usize) -> String {
216219
format!("{}-{}.log", self.get_templated_name(), counter)
217220
}
218221
pub fn get_zip_full_path(&self) -> String {
@@ -315,6 +318,13 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
315318
.takes_value(true)
316319
.help("test-threads mapped to support the test scenarios"),
317320
)
321+
.arg(
322+
Arg::new("disable-compression")
323+
.short('D')
324+
.long("disable-compression")
325+
.takes_value(false)
326+
.help("Disables deflate compression in resulting zip file and stores data uncompressed."),
327+
)
318328
.try_get_matches()
319329
}
320330

core-dump-composer/src/main.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
111111
cc.set_podname(podname.to_string());
112112

113113
// Create the base zip file that we are going to put everything into
114+
let compression_method = if cc.disable_compression {
115+
zip::CompressionMethod::Stored
116+
} else {
117+
zip::CompressionMethod::Deflated
118+
};
114119
let options = FileOptions::default()
115-
.compression_method(zip::CompressionMethod::Deflated)
120+
.compression_method(compression_method)
116121
.unix_permissions(0o444)
117122
.large_file(true);
118123

@@ -159,20 +164,14 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
159164

160165
let stdin = io::stdin();
161166
let mut stdin = stdin.lock();
162-
let mut data = [0u8; 8192];
163167

164-
while let Ok(n) = stdin.read(&mut data) {
165-
if n == 0 {
166-
break;
168+
match io::copy(&mut stdin, &mut zip) {
169+
Ok(v) => v,
170+
Err(e) => {
171+
error!("Error writing core file \n{}", e);
172+
process::exit(1);
167173
}
168-
match zip.write_all(&data) {
169-
Ok(v) => v,
170-
Err(e) => {
171-
error!("Error writing core file \n{}", e);
172-
process::exit(1);
173-
}
174-
};
175-
}
174+
};
176175
zip.flush()?;
177176

178177
if cc.ignore_crio {

0 commit comments

Comments
 (0)