Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Robo210 committed Aug 23, 2024
1 parent f218689 commit 6bd84d0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum EtwError {
#[error("Provider group GUID must not be zeroes")]
#[error("Provider group GUID must not be zeros")]
EmptyProviderGroupGuid,
#[error("Provider group names must be lower case ASCII or numeric digits: {0:?}")]
InvalidProviderGroupCharacters(String),
#[error("Linux provider names must be ASCII alphanumeric: {0:?}")]
InvalidProviderNameCharacters(String)
InvalidProviderNameCharacters(String),
#[error("Linux provider name and provider group must less than 234 characters combined. Current length: {0:?}")]
TooManyCharacters(usize)
}
25 changes: 18 additions & 7 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,24 @@ where

fn validate_config(&self) -> Result<(), EtwError> {
#[cfg(target_os = "linux")]
if self
.provider_name
.contains(|f: char| !f.is_ascii_alphanumeric())
{
// The perf command is very particular about the provider names it accepts.
// The Linux kernel itself cares less, and other event consumers should also presumably not need this check.
return Err(EtwError::InvalidProviderNameCharacters(self.provider_name.clone()));
if self
.provider_name
.contains(|f: char| !f.is_ascii_alphanumeric() && f != '_')
{
// The perf command is very particular about the provider names it accepts.
// The Linux kernel itself cares less, and other event consumers should also presumably not need this check.
return Err(EtwError::InvalidProviderNameCharacters(self.provider_name.clone()));
}

let group_name_len = match &self.provider_group {
None => 0,
Some(ref name) => Mode::get_provider_group(&name).as_ref().len()
};

if self.provider_name.len() + group_name_len >= 234 {
return Err(EtwError::TooManyCharacters(self.provider_name.len() + group_name_len));
}
}

match &self.provider_group {
Expand All @@ -150,7 +161,7 @@ where
match self.provider_group {
None => {}
Some(ref name) => {
targets = targets.with_target(Mode::get_provider_group(name), LevelFilter::TRACE);
targets = targets.with_target(Mode::get_provider_group(name).as_ref(), LevelFilter::TRACE);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/native/common_schema/user_events_cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl crate::native::ProviderTypes for CommonSchemaProvider {
}
}

fn get_provider_group(value: &Self::ProviderGroupType) -> impl Into<String> {
fn get_provider_group(value: &Self::ProviderGroupType) -> impl AsRef<str> {
value.clone()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub trait ProviderTypes {
// that it trivially matches a constraint unless we lower the constraint
// checking into the impl, done here through constraint on the return type.
#[cfg(target_os = "linux")]
fn get_provider_group(value: &Self::ProviderGroupType) -> impl Into<String>;
fn get_provider_group(value: &Self::ProviderGroupType) -> impl AsRef<str>;
}

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion src/native/user_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl crate::native::ProviderTypes for Provider {
}
}

fn get_provider_group(value: &Self::ProviderGroupType) -> impl Into<String> {
fn get_provider_group(value: &Self::ProviderGroupType) -> impl AsRef<str> {
value.clone()
}
}
Expand Down

0 comments on commit 6bd84d0

Please sign in to comment.