Skip to content

Commit

Permalink
[#96] Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jan 26, 2024
1 parent 61738de commit 812c93d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
68 changes: 35 additions & 33 deletions iceoryx2-bb/posix/src/process_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! ```
//! use iceoryx2_bb_posix::process_state::*;
//!
//! let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
//! let process_state_path = FilePath::new(b"process_state_file").unwrap();
//!
//! // remove potentially uncleaned process state file that can remain when this process crashed
//! // before
Expand All @@ -44,7 +44,7 @@
//! ```
//! use iceoryx2_bb_posix::process_state::*;
//!
//! let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
//! let process_state_path = FilePath::new(b"process_state_file").unwrap();
//!
//! let mut monitor = ProcessMonitor::new(&process_state_path).expect("");
//!
Expand Down Expand Up @@ -142,7 +142,7 @@ enum_gen! {
/// ```
/// use iceoryx2_bb_posix::process_state::*;
///
/// let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
/// let process_state_path = FilePath::new(b"process_state_file").unwrap();
///
/// // remove potentially uncleaned process state file that can remain when this process crashed
/// // before
Expand Down Expand Up @@ -197,7 +197,7 @@ impl ProcessGuard {
/// ```
/// use iceoryx2_bb_posix::process_state::*;
///
/// let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
/// let process_state_path = FilePath::new(b"process_state_file").unwrap();
///
/// // start monitoring from this point on
/// let guard = ProcessGuard::new(&process_state_path).expect("");
Expand All @@ -216,44 +216,46 @@ impl ProcessGuard {
| Permission::OTHERS_EXEC;

let dir_path = path.path();
match Directory::does_exist(&dir_path) {
Ok(true) => (),
Ok(false) => match Directory::create(&dir_path, default_directory_permissions) {
Ok(_) | Err(DirectoryCreateError::DirectoryAlreadyExists) => (),
Err(DirectoryCreateError::InsufficientPermissions) => {
fail!(from origin, with ProcessGuardCreateError::InsufficientPermissions,
if !dir_path.is_empty() {
match Directory::does_exist(&dir_path) {
Ok(true) => (),
Ok(false) => match Directory::create(&dir_path, default_directory_permissions) {
Ok(_) | Err(DirectoryCreateError::DirectoryAlreadyExists) => (),
Err(DirectoryCreateError::InsufficientPermissions) => {
fail!(from origin, with ProcessGuardCreateError::InsufficientPermissions,
"{} since the directory {} could not be created due to insufficient permissions.",
msg, dir_path);
}
Err(DirectoryCreateError::ReadOnlyFilesystem) => {
fail!(from origin, with ProcessGuardCreateError::ReadOnlyFilesystem,
}
Err(DirectoryCreateError::ReadOnlyFilesystem) => {
fail!(from origin, with ProcessGuardCreateError::ReadOnlyFilesystem,
"{} since the directory {} could not be created since it is located on an read-only file system.",
msg, dir_path);
}
Err(DirectoryCreateError::NoSpaceLeft) => {
fail!(from origin, with ProcessGuardCreateError::NoSpaceLeft,
}
Err(DirectoryCreateError::NoSpaceLeft) => {
fail!(from origin, with ProcessGuardCreateError::NoSpaceLeft,
"{} since the directory {} could not be created since there is no space left.",
msg, dir_path);
}
Err(v) => {
fail!(from origin, with ProcessGuardCreateError::NoSpaceLeft,
}
Err(v) => {
fail!(from origin, with ProcessGuardCreateError::NoSpaceLeft,
"{} since the directory {} could not be created due to an unknown failure ({:?}).",
msg, dir_path, v);
}
},
Err(DirectoryAccessError::InsufficientPermissions) => {
fail!(from origin, with ProcessGuardCreateError::InsufficientPermissions,
}
},
Err(DirectoryAccessError::InsufficientPermissions) => {
fail!(from origin, with ProcessGuardCreateError::InsufficientPermissions,
"{} since the directory {} could not be accessed due to insufficient permissions.",
msg, dir_path);
}
Err(DirectoryAccessError::PathPrefixIsNotADirectory) => {
fail!(from origin, with ProcessGuardCreateError::InvalidDirectory,
}
Err(DirectoryAccessError::PathPrefixIsNotADirectory) => {
fail!(from origin, with ProcessGuardCreateError::InvalidDirectory,
"{} since the directory {} is actually not a valid directory.", msg, dir_path);
}
Err(v) => {
fail!(from origin, with ProcessGuardCreateError::UnknownError(0),
}
Err(v) => {
fail!(from origin, with ProcessGuardCreateError::UnknownError(0),
"{} since an unknown failure occurred ({:?}) while checking if directory {} exists.",
msg, v, dir_path);
}
}
}

Expand Down Expand Up @@ -381,7 +383,7 @@ impl ProcessGuard {
/// ```
/// use iceoryx2_bb_posix::process_state::*;
///
/// let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
/// let process_state_path = FilePath::new(b"process_state_file").unwrap();
///
/// let mut monitor = ProcessMonitor::new(&process_state_path).expect("");
///
Expand Down Expand Up @@ -428,7 +430,7 @@ impl ProcessMonitor {
/// ```
/// use iceoryx2_bb_posix::process_state::*;
///
/// let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
/// let process_state_path = FilePath::new(b"process_state_file").unwrap();
///
/// let mut monitor = ProcessMonitor::new(&process_state_path).expect("");
/// ```
Expand All @@ -449,12 +451,12 @@ impl ProcessMonitor {

/// Returns the current state of the process that is monitored.
///
/// # Exampel
/// # Example
///
/// ```
/// use iceoryx2_bb_posix::process_state::*;
///
/// let process_state_path = FilePath::new(b"/tmp/process_state_file").unwrap();
/// let process_state_path = FilePath::new(b"process_state_file").unwrap();
///
/// let mut monitor = ProcessMonitor::new(&process_state_path).expect("");
///
Expand Down
4 changes: 3 additions & 1 deletion iceoryx2-bb/posix/tests/process_state_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use iceoryx2_bb_container::semantic_string::SemanticString;
use iceoryx2_bb_posix::config::*;
use iceoryx2_bb_posix::file::{File, FileBuilder};
use iceoryx2_bb_posix::file_descriptor::FileDescriptorManagement;
use iceoryx2_bb_posix::shared_memory::Permission;
use iceoryx2_bb_posix::unix_datagram_socket::CreationMode;
use iceoryx2_bb_posix::{process_state::*, unique_system_id::UniqueSystemId};
Expand Down Expand Up @@ -165,14 +166,15 @@ pub fn process_state_watcher_transitions_work_starting_from_existing_process() {
pub fn process_state_watcher_detects_initialized_state() {
let path = generate_file_path();

let file = FileBuilder::new(&path)
let mut file = FileBuilder::new(&path)
.creation_mode(CreationMode::PurgeAndCreate)
.permission(Permission::OWNER_WRITE)
.create()
.unwrap();

let mut watcher = ProcessMonitor::new(&path).unwrap();
assert_that!(watcher.state().unwrap(), eq ProcessState::InInitialization);
file.set_permission(Permission::OWNER_ALL).unwrap();
file.remove_self().unwrap();
assert_that!(watcher.state().unwrap(), eq ProcessState::DoesNotExist);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use crate::posix::{types::*, S_IRUSR, S_IWUSR, S_IXUSR};
const SID_LENGTH: usize = 255;
const GENERIC_PERM_ALL: &[u8] = b"GA";
const GENERIC_PERM_READ: &[u8] = b"GR";
const GENERIC_PERM_WRITE: &[u8] = b"GWSD";
const GENERIC_PERM_WRITE: &[u8] = b"GW";
const GENERIC_PERM_EXECUTE: &[u8] = b"GX";
const FILE_PERM_ALL: &[u8] = b"FA";
const FILE_PERM_READ: &[u8] = b"FR";
Expand Down

0 comments on commit 812c93d

Please sign in to comment.