Skip to content

Conversation

@Wandalen
Copy link
Contributor

No description provided.

@Wandalen Wandalen marked this pull request as draft August 16, 2024 18:08
@Wandalen Wandalen changed the title [fuser] basic implementation [fuser] full implementation Sep 4, 2024
@Wandalen Wandalen marked this pull request as ready for review September 4, 2024 15:29
@Wandalen
Copy link
Contributor Author

Wandalen commented Sep 4, 2024

Mac version is ready too

@jgarzik jgarzik added the enhancement New feature or request label Sep 6, 2024
@jgarzik
Copy link
Contributor

jgarzik commented Sep 10, 2024

Please fix the large number of build warnings on macos. fuser must build without warnings or errors on both macos and linux.

warning: unused variable: `unix_socket_list`
   --> process/./fuser.rs:472:13
    |
472 |         mut unix_socket_list,
    |             ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unix_socket_list`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `mount_list`
   --> process/./fuser.rs:473:13
    |
473 |         mut mount_list,
    |             ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mount_list`

warning: unused variable: `device_list`
   --> process/./fuser.rs:474:13
    |
474 |         mut device_list,
    |             ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_device_list`

warning: unused variable: `inode_list`
   --> process/./fuser.rs:475:13
    |
475 |         mut inode_list,
    |             ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_inode_list`

warning: unused variable: `need_check_map`
   --> process/./fuser.rs:476:13
    |
476 |         mut need_check_map,
    |             ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_need_check_map`

warning: variable does not need to be mutable
   --> process/./fuser.rs:472:9
    |
472 |         mut unix_socket_list,
    |         ----^^^^^^^^^^^^^^^^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
   --> process/./fuser.rs:473:9
    |
473 |         mut mount_list,
    |         ----^^^^^^^^^^
    |         |
    |         help: remove this `mut`

warning: variable does not need to be mutable
   --> process/./fuser.rs:474:9
    |
474 |         mut device_list,
    |         ----^^^^^^^^^^^
    |         |
    |         help: remove this `mut`

warning: variable does not need to be mutable
   --> process/./fuser.rs:475:9
    |
475 |         mut inode_list,
    |         ----^^^^^^^^^^
    |         |
    |         help: remove this `mut`

warning: variable does not need to be mutable
   --> process/./fuser.rs:476:9
    |
476 |         mut need_check_map,
    |         ----^^^^^^^^^^^^^^
    |         |
    |         help: remove this `mut`

warning: constant `PROC_PATH` is never used
  --> process/./fuser.rs:33:7
   |
33 | const PROC_PATH: &'static str = "/proc";
   |       ^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: constant `PROC_MOUNTS` is never used
  --> process/./fuser.rs:34:7
   |
34 | const PROC_MOUNTS: &'static str = "/proc/mounts";
   |       ^^^^^^^^^^^

warning: function `listpids` is never used
  --> process/./fuser.rs:72:15
   |
72 | pub(crate) fn listpids(proc_type: u32) -> io::Result<Vec<u32>> {
   |               ^^^^^^^^

warning: variants `Mount`, `Knfsd`, and `Swap` are never constructed
   --> process/./fuser.rs:141:5
    |
138 | enum ProcType {
    |      -------- variants in this enum
...
141 |     Mount = 1,
    |     ^^^^^
142 |     Knfsd = 2,
    |     ^^^^^
143 |     Swap = 3,
    |     ^^^^
    |
    = note: `ProcType` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

warning: variants `Tcp` and `Udp` are never constructed
   --> process/./fuser.rs:150:5
    |
147 | enum NameSpace {
    |      --------- variants in this enum
...
150 |     Tcp = 1,
    |     ^^^
151 |     Udp = 2,
    |     ^^^
    |
    = note: `NameSpace` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

warning: variants `Exe`, `Root`, `Mmap`, and `Filewr` are never constructed
   --> process/./fuser.rs:157:5
    |
155 | enum Access {
    |      ------ variants in this enum
156 |     Cwd = 1,
157 |     Exe = 2,
    |     ^^^
...
160 |     Root = 8,
    |     ^^^^
161 |     Mmap = 16,
    |     ^^^^
162 |     Filewr = 32,
    |     ^^^^^^
    |
    = note: `Access` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

warning: fields `names`, `lcl_port`, `rmt_port`, `rmt_addr`, and `next` are never read
   --> process/./fuser.rs:167:5
    |
166 | struct IpConnections {
    |        ------------- fields in this struct
167 |     names: Names,
    |     ^^^^^
168 |     lcl_port: u64,
    |     ^^^^^^^^
169 |     rmt_port: u64,
    |     ^^^^^^^^
170 |     rmt_addr: IpAddr,
    |     ^^^^^^^^
171 |     next: Option<Box<IpConnections>>,
    |     ^^^^
    |
    = note: `IpConnections` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis

warning: associated items `new` and `iter` are never used
   --> process/./fuser.rs:187:8
    |
186 | impl IpConnections {
    | ------------------ associated items in this implementation
187 |     fn new(names: Names, lcl_port: u64, rmt_port: u64, rmt_addr: IpAddr...
    |        ^^^
...
197 |     fn iter(&self) -> IpConnectionsIterator {
    |        ^^^^

warning: struct `IpConnectionsIterator` is never constructed
   --> process/./fuser.rs:204:8
    |
204 | struct IpConnectionsIterator<'a> {
    |        ^^^^^^^^^^^^^^^^^^^^^

warning: fields `username` and `command` are never read
   --> process/./fuser.rs:225:5
    |
220 | struct Procs {
    |        ----- fields in this struct
...
225 |     username: Option<i8>,
    |     ^^^^^^^^
226 |     command: String,
    |     ^^^^^^^
    |
    = note: `Procs` has derived impls for the traits `Default` and `Clone`, but these are intentionally ignored during dead code analysis

warning: fields `name`, `device_id`, `inode`, `net_inode`, and `next` are never read
   --> process/./fuser.rs:244:5
    |
243 | struct UnixSocketList {
    |        -------------- fields in this struct
244 |     name: String,
    |     ^^^^
245 |     device_id: DeviceId,
    |     ^^^^^^^^^
246 |     inode: u64,
    |     ^^^^^
247 |     net_inode: u64,
    |     ^^^^^^^^^
248 |     next: Option<Box<UnixSocketList>>,
    |     ^^^^
    |
    = note: `UnixSocketList` has derived impls for the traits `Default` and `Clone`, but these are intentionally ignored during dead code analysis

warning: associated items `new`, `add_socket`, and `iter` are never used
   --> process/./fuser.rs:252:8
    |
251 | impl UnixSocketList {
    | ------------------- associated items in this implementation
252 |     fn new(name: String, device_id: DeviceId, inode: u64, net_inode: u6...
    |        ^^^
...
262 |     fn add_socket(&mut self, name: String, device_id: DeviceId, inode: ...
    |        ^^^^^^^^^^
...
274 |     fn iter(&self) -> UnixSocketListIterator {
    |        ^^^^

warning: struct `UnixSocketListIterator` is never constructed
   --> process/./fuser.rs:281:8
    |
281 | struct UnixSocketListIterator<'a> {
    |        ^^^^^^^^^^^^^^^^^^^^^^

warning: fields `name`, `device_id`, `inode`, and `next` are never read
   --> process/./fuser.rs:298:5
    |
297 | struct InodeList {
    |        --------- fields in this struct
298 |     name: Names,
    |     ^^^^
299 |     device_id: DeviceId,
    |     ^^^^^^^^^
300 |     inode: u64,
    |     ^^^^^
301 |     next: Option<Box<InodeList>>,
    |     ^^^^
    |
    = note: `InodeList` has a derived impl for the trait `Default`, but this is intentionally ignored during dead code analysis

warning: associated items `new` and `iter` are never used
   --> process/./fuser.rs:305:8
    |
304 | impl InodeList {
    | -------------- associated items in this implementation
305 |     fn new(name: Names, device_id: DeviceId, inode: u64) -> Self {
    |        ^^^
...
314 |     fn iter(&self) -> InodeListIterator {
    |        ^^^^

warning: struct `InodeListIterator` is never constructed
   --> process/./fuser.rs:321:8
    |
321 | struct InodeListIterator<'a> {
    |        ^^^^^^^^^^^^^^^^^

warning: field `mountpoints` is never read
   --> process/./fuser.rs:338:5
    |
337 | struct MountList {
    |        --------- field in this struct
338 |     mountpoints: Vec<PathBuf>,
    |     ^^^^^^^^^^^
    |
    = note: `MountList` has derived impls for the traits `Default` and `Clone`, but these are intentionally ignored during dead code analysis

warning: fields `name_space` and `st` are never read
   --> process/./fuser.rs:362:5
    |
360 | struct Names {
    |        ----- fields in this struct
361 |     filename: PathBuf,
362 |     name_space: NameSpace,
    |     ^^^^^^^^^^
363 |     matched_procs: Vec<Procs>,
364 |     st: LibcStat,
    |     ^^
    |
    = note: `Names` has derived impls for the traits `Default` and `Clone`, but these are intentionally ignored during dead code analysis

warning: fields `name`, `device_id`, and `next` are never read
   --> process/./fuser.rs:396:5
    |
395 | struct DeviceList {
    |        ---------- fields in this struct
396 |     name: Names,
    |     ^^^^
397 |     device_id: DeviceId,
    |     ^^^^^^^^^
398 |     next: Option<Box<DeviceList>>,
    |     ^^^^
    |
    = note: `DeviceList` has a derived impl for the trait `Default`, but this is intentionally ignored during dead code analysis

warning: associated items `new` and `iter` are never used
   --> process/./fuser.rs:402:8
    |
401 | impl DeviceList {
    | --------------- associated items in this implementation
402 |     fn new(name: Names, device_id: DeviceId) -> Self {
    |        ^^^
...
409 |     fn iter(&self) -> DeviceListIterator {
    |        ^^^^

warning: struct `DeviceListIterator` is never constructed
   --> process/./fuser.rs:416:8
    |
416 | struct DeviceListIterator<'a> {
    |        ^^^^^^^^^^^^^^^^^^

warning: function `determine_namespace` is never used
   --> process/./fuser.rs:637:4
    |
637 | fn determine_namespace(filename: &Path) -> NameSpace {
    |    ^^^^^^^^^^^^^^^^^^^

warning: function `handle_file_namespace` is never used
   --> process/./fuser.rs:672:4
    |
672 | fn handle_file_namespace(
    |    ^^^^^^^^^^^^^^^^^^^^^

warning: function `handle_tcp_namespace` is never used
   --> process/./fuser.rs:710:4
    |
710 | fn handle_tcp_namespace(
    |    ^^^^^^^^^^^^^^^^^^^^

warning: function `handle_udp_namespace` is never used
   --> process/./fuser.rs:736:4
    |
736 | fn handle_udp_namespace(
    |    ^^^^^^^^^^^^^^^^^^^^

warning: function `scan_procs` is never used
   --> process/./fuser.rs:839:4
    |
839 | fn scan_procs(
    |    ^^^^^^^^^^

warning: function `check_root_access` is never used
   --> process/./fuser.rs:923:4
    |
923 | fn check_root_access(
    |    ^^^^^^^^^^^^^^^^^

warning: function `check_cwd_access` is never used
   --> process/./fuser.rs:967:4
    |
967 | fn check_cwd_access(
    |    ^^^^^^^^^^^^^^^^

warning: function `check_exe_access` is never used
    --> process/./fuser.rs:1011:4
     |
1011 | fn check_exe_access(
     |    ^^^^^^^^^^^^^^^^

warning: function `check_dir` is never used
    --> process/./fuser.rs:1072:4
     |
1072 | fn check_dir(
     |    ^^^^^^^^^

warning: function `check_map` is never used
    --> process/./fuser.rs:1139:4
     |
1139 | fn check_map(
     |    ^^^^^^^^^

warning: function `get_pid_stat` is never used
    --> process/./fuser.rs:1189:4
     |
1189 | fn get_pid_stat(pid: i32, filename: &str) -> Result<libc::stat, io::Er...
     |    ^^^^^^^^^^^^

warning: function `fill_unix_cache` is never used
    --> process/./fuser.rs:1207:4
     |
1207 | fn fill_unix_cache(unix_socket_list: &mut UnixSocketList) -> Result<()...
     |    ^^^^^^^^^^^^^^^

warning: function `read_proc_mounts` is never used
    --> process/./fuser.rs:1247:4
     |
1247 | fn read_proc_mounts(mount_list: &mut MountList) -> io::Result<&mut Mou...
     |    ^^^^^^^^^^^^^^^^

warning: function `normalize_path` is never used
    --> process/./fuser.rs:1262:4
     |
1262 | fn normalize_path(scanned_path: &str) -> String {
     |    ^^^^^^^^^^^^^^

warning: function `parse_inet` is never used
    --> process/./fuser.rs:1285:4
     |
1285 | fn parse_inet(names: &mut Names) -> Result<IpConnections, io::Error> {
     |    ^^^^^^^^^^

warning: function `find_net_dev` is never used
    --> process/./fuser.rs:1345:4
     |
1345 | fn find_net_dev() -> Result<DeviceId, io::Error> {
     |    ^^^^^^^^^^^^

warning: function `find_net_sockets` is never used
    --> process/./fuser.rs:1379:4
     |
1379 | fn find_net_sockets(
     |    ^^^^^^^^^^^^^^^^

warning: function `parse_ipv4_addr` is never used
    --> process/./fuser.rs:1433:4
     |
1433 | fn parse_ipv4_addr(addr: &str) -> Option<Ipv4Addr> {
     |    ^^^^^^^^^^^^^^^

warning: `posixutils-process` (bin "fuser") generated 49 warnings (run `cargo fix --bin "fuser"` to apply 5 suggestions)

@Wandalen
Copy link
Contributor Author

Fixed. Please, check

@jgarzik
Copy link
Contributor

jgarzik commented Sep 17, 2024

Testing results:

  1. cargo test warning:
   Compiling posixutils-process v0.2.0 (/Users/jgarzik/repo/posixutils-rs/process)
warning: unused imports: `TcpListener`, `UdpSocket`, and `UnixListener`
  --> process/tests/fuser/mod.rs:13:18
   |
13 | use tokio::net::{TcpListener, UdpSocket, UnixListener};
   |                  ^^^^^^^^^^^  ^^^^^^^^^  ^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

  1. test failure on macos:
test fuser::test_fuser_basic ... ok
test fuser::test_fuser_with_user ... ok
test fuser::test_fuser_with_many_files ... FAILED
test fuser::test_fuser_large_directory ... ok

failures:

---- fuser::test_fuser_with_many_files stdout ----
thread 'fuser::test_fuser_with_many_files' panicked at process/tests/fuser/mod.rs:168:13:
PID 98779 not found in the output.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    fuser::test_fuser_with_many_files

test result: FAILED. 10 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.14s

@jgarzik
Copy link
Contributor

jgarzik commented Sep 17, 2024

Also: is it possible to test without tokio/mio? That is a large dependency added to the build, just for testing.

@jgarzik jgarzik merged commit d2b4ea4 into rustcoreutils:main Sep 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants