Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unix: Extend UnixStream and UnixDatagram to send and receive file descriptors #69864

Merged
merged 51 commits into from
Dec 2, 2020
Merged

Conversation

LinkTed
Copy link
Contributor

@LinkTed LinkTed commented Mar 9, 2020

Add the functions recv_vectored_fds and send_vectored_fds to UnixDatagram and UnixStream. With this functions UnixDatagram and UnixStream can send and receive file descriptors, by using recvmsg and sendmsg system call.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @shepmaster (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 9, 2020
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-09T17:37:06.7664385Z Prepare build directory.
2020-03-09T17:37:06.7994477Z Set build variables.
2020-03-09T17:37:06.8028943Z Download all required tasks.
2020-03-09T17:37:06.8153165Z Downloading task: Bash (3.163.1)
2020-03-09T17:37:08.2906609Z Checking job knob settings.
2020-03-09T17:37:08.2926713Z Finished checking job knob settings.
2020-03-09T17:37:08.3487589Z ##[section]Finishing: Initialize job
2020-03-09T17:37:08.3832169Z ##[section]Starting: Configure Job Name
2020-03-09T17:37:08.4055139Z ==============================================================================
2020-03-09T17:37:08.4056026Z Task         : Bash
---
2020-03-09T17:37:09.0349046Z ========================== Starting Command Output ===========================
2020-03-09T17:37:09.0351624Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/4ca848a7-f930-456c-8a6c-b9abe94cdec9.sh
2020-03-09T17:37:09.0351893Z 
2020-03-09T17:37:09.0355804Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-09T17:37:09.0375628Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69864/merge to s
2020-03-09T17:37:09.0379425Z Task         : Get sources
2020-03-09T17:37:09.0379748Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-09T17:37:09.0380056Z Version      : 1.0.0
2020-03-09T17:37:09.0380281Z Author       : Microsoft
---
2020-03-09T17:37:10.2767425Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-09T17:37:10.2776033Z ##[command]git config gc.auto 0
2020-03-09T17:37:10.2781679Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-09T17:37:10.2787326Z ##[command]git config --get-all http.proxy
2020-03-09T17:37:10.2796712Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/69864/merge:refs/remotes/pull/69864/merge
---
2020-03-09T18:34:09.8163908Z .................................................................................................... 1700/9754
2020-03-09T18:34:15.0073132Z .................................................................................................... 1800/9754
2020-03-09T18:34:27.2903955Z ...........................................................i........................................ 1900/9754
2020-03-09T18:34:35.2283439Z .................................................................................................... 2000/9754
2020-03-09T18:34:49.1654018Z .................................................iiiii.............................................. 2100/9754
2020-03-09T18:34:59.7721101Z .................................................................................................... 2300/9754
2020-03-09T18:35:02.0775933Z .................................................................................................... 2400/9754
2020-03-09T18:35:05.5692116Z .................................................................................................... 2500/9754
2020-03-09T18:35:27.0489172Z .................................................................................................... 2600/9754
---
2020-03-09T18:38:01.7760315Z ....................i...............i............................................................... 5000/9754
2020-03-09T18:38:11.2944199Z .................................................................................................... 5100/9754
2020-03-09T18:38:16.6865981Z ...............................................................i.................................... 5200/9754
2020-03-09T18:38:22.9982123Z .................................................................................................... 5300/9754
2020-03-09T18:38:31.7759553Z ............................................ii.ii........i...i...................................... 5400/9754
2020-03-09T18:38:39.6083295Z .................................................................................................... 5600/9754
2020-03-09T18:38:48.8375898Z .................................................................................................... 5700/9754
2020-03-09T18:38:55.4054915Z ...................................i................................................................ 5800/9754
2020-03-09T18:39:01.1488073Z .................................................................................................... 5900/9754
2020-03-09T18:39:01.1488073Z .................................................................................................... 5900/9754
2020-03-09T18:39:11.3179866Z .................................................................................................... 6000/9754
2020-03-09T18:39:20.5403273Z ............................ii...i..ii...........i.................................................. 6100/9754
2020-03-09T18:39:37.3430401Z .................................................................................................... 6300/9754
2020-03-09T18:39:42.8749983Z .................................................................................................... 6400/9754
2020-03-09T18:39:49.3530778Z ............................................................i.ii.................................... 6500/9754
2020-03-09T18:40:00.9485489Z .................................................................................................... 6600/9754
---
2020-03-09T18:41:55.8810331Z .................................................................................................... 7700/9754
2020-03-09T18:41:59.6923088Z .................................................................................................... 7800/9754
2020-03-09T18:42:05.3393660Z .................................................................................................... 7900/9754
2020-03-09T18:42:12.0247886Z ..................................i................................................................. 8000/9754
2020-03-09T18:42:20.7399685Z ...................................................................................iiiiiiiiii.i..... 8100/9754
2020-03-09T18:42:36.0584362Z ...........................i......i................................................................. 8300/9754
2020-03-09T18:42:40.6986140Z .................................................................................................... 8400/9754
2020-03-09T18:42:51.6162289Z .................................................................................................... 8500/9754
2020-03-09T18:43:02.8267613Z .................................................................................................... 8600/9754
---
2020-03-09T18:45:19.1489060Z  finished in 6.937
2020-03-09T18:45:19.1679176Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:45:19.3822767Z 
2020-03-09T18:45:19.3823483Z running 179 tests
2020-03-09T18:45:22.1918080Z iiii......i...........ii..iiii....i....i...........i............i..i..................i....i........ 100/179
2020-03-09T18:45:24.4481518Z ....i.i..i..iii..iiiiiiiiiiiiiiii.......................iii............ii......
2020-03-09T18:45:24.4486165Z 
2020-03-09T18:45:24.4493146Z  finished in 5.281
2020-03-09T18:45:24.4686593Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:45:24.6421179Z 
---
2020-03-09T18:45:26.5080982Z  finished in 2.039
2020-03-09T18:45:26.5272909Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:45:26.6975035Z 
2020-03-09T18:45:26.6975403Z running 9 tests
2020-03-09T18:45:26.6976578Z iiiiiiiii
2020-03-09T18:45:26.6977735Z 
2020-03-09T18:45:26.7052136Z  finished in 0.170
2020-03-09T18:45:26.7170153Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:45:26.9100671Z 
---
2020-03-09T18:45:46.0446181Z  finished in 19.327
2020-03-09T18:45:46.0669526Z Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:45:46.2598563Z 
2020-03-09T18:45:46.2598860Z running 115 tests
2020-03-09T18:45:59.1718059Z iiiii..i.....i..i...i..i.i.i..i..i..ii....i.i....ii..........iiii.........i.....i..i.......ii.i.ii.. 100/115
2020-03-09T18:46:00.7200231Z ...iiii.....ii.
2020-03-09T18:46:00.7201917Z 
2020-03-09T18:46:00.7208884Z  finished in 14.654
2020-03-09T18:46:00.7215003Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-09T18:46:00.7215808Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2020-03-09T18:57:57.8430613Z 
2020-03-09T18:57:57.8435984Z    Doc-tests core
2020-03-09T18:58:02.2905061Z 
2020-03-09T18:58:02.2906591Z running 2480 tests
2020-03-09T18:58:10.7679294Z ......iiiii......................................................................................... 100/2480
2020-03-09T18:58:19.2167906Z ....................................................................................ii.............. 200/2480
2020-03-09T18:58:38.7171365Z ...................i................................................................................ 400/2480
2020-03-09T18:58:38.7171365Z ...................i................................................................................ 400/2480
2020-03-09T18:58:47.7868279Z ........................................................................i..i..................iiii.. 500/2480
2020-03-09T18:59:03.1188145Z .................................................................................................... 700/2480
2020-03-09T18:59:11.1719060Z .................................................................................................... 800/2480
2020-03-09T18:59:19.1157613Z .................................................................................................... 900/2480
2020-03-09T18:59:27.0664143Z .................................................................................................... 1000/2480
---
2020-03-09T19:02:42.6825437Z ..thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/rwlock.rs:701:13
2020-03-09T19:02:42.6830898Z .thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/rwlock.rs:629:13
2020-03-09T19:02:42.6838573Z .thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/rwlock.rs:641:13
2020-03-09T19:02:42.6839386Z thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/rwlock.rs:603:13
2020-03-09T19:02:42.6845947Z thread '..<unnamed>' panicked at 'explicit panic', src/libstd/sync/rwlock.rs:616:13
2020-03-09T19:02:44.7410314Z ..........................thread '<unnamed>' panicked at 'What the answer to my lifetimes dilemma is?', src/libstd/sys_common/remutex.rs:229:13
2020-03-09T19:02:44.7520400Z .................................thread '<unnamed>' panicked at 'explicit panic', src/libstd/thread/mod.rs:1573:37
2020-03-09T19:02:45.3599647Z ...........thread '<unnamed>' panicked at 'Box<Any>', src/libstd/thread/mod.rs:1708:13
2020-03-09T19:02:45.3606280Z .thread '<unnamed>' panicked at 'owned string', src/libstd/thread/mod.rs:1692:13
2020-03-09T19:02:45.3613390Z .thread '<unnamed>' panicked at 'static string', src/libstd/thread/mod.rs:1676:13
---
2020-03-09T19:02:51.6344637Z 
2020-03-09T19:02:51.6344983Z running 1014 tests
2020-03-09T19:03:08.0503694Z i................................................................................................... 100/1014
2020-03-09T19:03:18.0777378Z .................................................................................................... 200/1014
2020-03-09T19:03:25.0260664Z ..................iii......i......i...i......i...................................................... 300/1014
2020-03-09T19:03:29.9460602Z .................................................................................................... 400/1014
2020-03-09T19:03:36.5916944Z ............................................i..i......................................ii............ 500/1014
2020-03-09T19:03:48.8782498Z .................................................................................................... 700/1014
2020-03-09T19:03:48.8782498Z .................................................................................................... 700/1014
2020-03-09T19:03:55.4593251Z ....................................iiii............................................................ 800/1014
2020-03-09T19:04:08.5917919Z .................................................................................................... 900/1014
2020-03-09T19:04:15.0124930Z ......................F..F........................F.F.........iiii.................................. 1000/1014
2020-03-09T19:04:15.5845144Z failures:
2020-03-09T19:04:15.5845270Z 
2020-03-09T19:04:15.5845270Z 
2020-03-09T19:04:15.5852323Z ---- sys/unix/ext/net.rs - sys::unix::ext::net::UnixDatagram::recv_vectored_fds (line 1504) stdout ----
2020-03-09T19:04:15.5852830Z error[E0433]: failed to resolve: use of undeclared type or module `IoSliceMut`
2020-03-09T19:04:15.5853386Z   --> sys/unix/ext/net.rs:1513:9
2020-03-09T19:04:15.5853795Z 11 |         IoSliceMut::new(&mut buf1),
2020-03-09T19:04:15.5854135Z    |         ^^^^^^^^^^ use of undeclared type or module `IoSliceMut`
2020-03-09T19:04:15.5854358Z 
2020-03-09T19:04:15.5854656Z error[E0433]: failed to resolve: use of undeclared type or module `IoSliceMut`
---
2020-03-09T19:04:15.5857884Z 
2020-03-09T19:04:15.5858330Z error[E0658]: use of unstable library feature 'unix_socket_fd'
2020-03-09T19:04:15.5858796Z   --> sys/unix/ext/net.rs:1518:40
2020-03-09T19:04:15.5858989Z    |
2020-03-09T19:04:15.5859277Z 16 |     let (size, size_fd, sender) = sock.recv_vectored_fds(bufs, &mut fds[..])?;
2020-03-09T19:04:15.5859885Z    |
2020-03-09T19:04:15.5859885Z    |
2020-03-09T19:04:15.5860172Z    = help: add `#![feature(unix_socket_fd)]` to the crate attributes to enable
2020-03-09T19:04:15.5860604Z error: aborting due to 4 previous errors
2020-03-09T19:04:15.5860782Z 
2020-03-09T19:04:15.5861026Z Some errors have detailed explanations: E0433, E0658.
2020-03-09T19:04:15.5861573Z For more information about an error, try `rustc --explain E0433`.
---
2020-03-09T19:04:15.5868555Z 
2020-03-09T19:04:15.5868985Z error[E0658]: use of unstable library feature 'unix_socket_fd'
2020-03-09T19:04:15.5869619Z   --> sys/unix/ext/net.rs:1617:10
2020-03-09T19:04:15.5869817Z    |
2020-03-09T19:04:15.5870130Z 16 |     sock.send_vectored_fds(bufs, &fds[..], "/some/sock").expect("send_vectored_fds function failed");
2020-03-09T19:04:15.5870682Z    |
2020-03-09T19:04:15.5870682Z    |
2020-03-09T19:04:15.5870953Z    = help: add `#![feature(unix_socket_fd)]` to the crate attributes to enable
2020-03-09T19:04:15.5871448Z error[E0308]: mismatched types
2020-03-09T19:04:15.5871873Z   --> sys/unix/ext/net.rs:1617:34
2020-03-09T19:04:15.5872066Z    |
2020-03-09T19:04:15.5872066Z    |
2020-03-09T19:04:15.5872394Z 16 |     sock.send_vectored_fds(bufs, &fds[..], "/some/sock").expect("send_vectored_fds function failed");
2020-03-09T19:04:15.5872825Z    |                                  ^^^^^^^^ types differ in mutability
2020-03-09T19:04:15.5873308Z    = note: expected mutable reference `&mut [i32]`
2020-03-09T19:04:15.5873308Z    = note: expected mutable reference `&mut [i32]`
2020-03-09T19:04:15.5873614Z                       found reference `&[{integer}]`
2020-03-09T19:04:15.5874017Z error: aborting due to 5 previous errors
2020-03-09T19:04:15.5874191Z 
2020-03-09T19:04:15.5874434Z Some errors have detailed explanations: E0308, E0433, E0658.
2020-03-09T19:04:15.5874998Z For more information about an error, try `rustc --explain E0308`.
2020-03-09T19:04:15.5874998Z For more information about an error, try `rustc --explain E0308`.
2020-03-09T19:04:15.5875455Z Couldn't compile the test.
2020-03-09T19:04:15.5876052Z ---- sys/unix/ext/net.rs - sys::unix::ext::net::UnixStream::recv_vectored_fds (line 643) stdout ----
2020-03-09T19:04:15.5876527Z error[E0433]: failed to resolve: use of undeclared type or module `IoSliceMut`
2020-03-09T19:04:15.5877036Z   --> sys/unix/ext/net.rs:652:9
2020-03-09T19:04:15.5877437Z 11 |         IoSliceMut::new(&mut buf1),
2020-03-09T19:04:15.5877809Z    |         ^^^^^^^^^^ use of undeclared type or module `IoSliceMut`
2020-03-09T19:04:15.5878031Z 
2020-03-09T19:04:15.5878302Z error[E0433]: failed to resolve: use of undeclared type or module `IoSliceMut`
---
2020-03-09T19:04:15.5881512Z 
2020-03-09T19:04:15.5881941Z error[E0658]: use of unstable library feature 'unix_socket_fd'
2020-03-09T19:04:15.5882401Z   --> sys/unix/ext/net.rs:657:34
2020-03-09T19:04:15.5882590Z    |
2020-03-09T19:04:15.5882869Z 16 |     let (size, size_fd) = socket.recv_vectored_fds(bufs, &mut fds[..])?;
2020-03-09T19:04:15.5883441Z    |
2020-03-09T19:04:15.5883441Z    |
2020-03-09T19:04:15.5883725Z    = help: add `#![feature(unix_socket_fd)]` to the crate attributes to enable
2020-03-09T19:04:15.5884158Z error: aborting due to 4 previous errors
2020-03-09T19:04:15.5884332Z 
2020-03-09T19:04:15.5884580Z Some errors have detailed explanations: E0433, E0658.
2020-03-09T19:04:15.5885123Z For more information about an error, try `rustc --explain E0433`.
---
2020-03-09T19:04:15.5892731Z    |
2020-03-09T19:04:15.5892954Z 13 |         IoSliceMut::new(&mut buf3),
2020-03-09T19:04:15.5893276Z    |         ^^^^^^^^^^ use of undeclared type or module `IoSliceMut`
2020-03-09T19:04:15.5893495Z 
2020-03-09T19:04:15.5893723Z error[E0425]: cannot find value `bfs` in this scope
2020-03-09T19:04:15.5894169Z   --> sys/unix/ext/net.rs:710:30
2020-03-09T19:04:15.5894365Z    |
2020-03-09T19:04:15.5894653Z 16 |     socket.send_vectored_fds(bfs, &fds[..]).expect("send_vectored_fds function failed");
2020-03-09T19:04:15.5895158Z    |                              ^^^ help: a local variable with a similar name exists: `bufs`
2020-03-09T19:04:15.5895898Z error[E0658]: use of unstable library feature 'unix_socket_fd'
2020-03-09T19:04:15.5896381Z   --> sys/unix/ext/net.rs:710:12
2020-03-09T19:04:15.5896570Z    |
2020-03-09T19:04:15.5896570Z    |
2020-03-09T19:04:15.5896858Z 16 |     socket.send_vectored_fds(bfs, &fds[..]).expect("send_vectored_fds function failed");
2020-03-09T19:04:15.5897397Z    |
2020-03-09T19:04:15.5897397Z    |
2020-03-09T19:04:15.5897667Z    = help: add `#![feature(unix_socket_fd)]` to the crate attributes to enable
2020-03-09T19:04:15.5898100Z error[E0308]: mismatched types
2020-03-09T19:04:15.5898509Z   --> sys/unix/ext/net.rs:710:35
2020-03-09T19:04:15.5898698Z    |
2020-03-09T19:04:15.5898698Z    |
2020-03-09T19:04:15.5899005Z 16 |     socket.send_vectored_fds(bfs, &fds[..]).expect("send_vectored_fds function failed");
2020-03-09T19:04:15.5899416Z    |                                   ^^^^^^^^ types differ in mutability
2020-03-09T19:04:15.5899903Z    = note: expected mutable reference `&mut [i32]`
2020-03-09T19:04:15.5899903Z    = note: expected mutable reference `&mut [i32]`
2020-03-09T19:04:15.5900212Z                       found reference `&[{integer}]`
2020-03-09T19:04:15.5900612Z error: aborting due to 6 previous errors
2020-03-09T19:04:15.5900787Z 
2020-03-09T19:04:15.5901042Z Some errors have detailed explanations: E0308, E0425, E0433, E0658.
2020-03-09T19:04:15.5901609Z For more information about an error, try `rustc --explain E0308`.
2020-03-09T19:04:15.5901609Z For more information about an error, try `rustc --explain E0308`.
2020-03-09T19:04:15.5902060Z Couldn't compile the test.
2020-03-09T19:04:15.5902208Z 
2020-03-09T19:04:15.5902343Z failures:
2020-03-09T19:04:15.5902879Z     sys/unix/ext/net.rs - sys::unix::ext::net::UnixDatagram::recv_vectored_fds (line 1504)
2020-03-09T19:04:15.5903600Z     sys/unix/ext/net.rs - sys::unix::ext::net::UnixDatagram::send_vectored_fds (line 1603)
2020-03-09T19:04:15.5904292Z     sys/unix/ext/net.rs - sys::unix::ext::net::UnixStream::recv_vectored_fds (line 643)
2020-03-09T19:04:15.5904990Z     sys/unix/ext/net.rs - sys::unix::ext::net::UnixStream::send_vectored_fds (line 696)
2020-03-09T19:04:15.5905541Z test result: FAILED. 990 passed; 4 failed; 20 ignored; 0 measured; 0 filtered out
2020-03-09T19:04:15.5905791Z 
2020-03-09T19:04:15.5937223Z error: test failed, to rerun pass '--doc'
2020-03-09T19:04:15.5985842Z 
---
2020-03-09T19:04:15.6051260Z   local time: Mon Mar  9 19:04:15 UTC 2020
2020-03-09T19:04:15.9025005Z   network time: Mon, 09 Mar 2020 19:04:15 GMT
2020-03-09T19:04:15.9030917Z == end clock drift check ==
2020-03-09T19:04:16.4611648Z 
2020-03-09T19:04:16.4684187Z ##[error]Bash exited with code '1'.
2020-03-09T19:04:16.4699676Z ##[section]Finishing: Run build
2020-03-09T19:04:16.4752563Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69864/merge to s
2020-03-09T19:04:16.4757824Z Task         : Get sources
2020-03-09T19:04:16.4758197Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-09T19:04:16.4758520Z Version      : 1.0.0
2020-03-09T19:04:16.4758750Z Author       : Microsoft
2020-03-09T19:04:16.4758750Z Author       : Microsoft
2020-03-09T19:04:16.4759124Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-09T19:04:16.4759538Z ==============================================================================
2020-03-09T19:04:16.8159906Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-09T19:04:16.8203060Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/69864/merge to s
2020-03-09T19:04:16.8293523Z Cleaning up task key
2020-03-09T19:04:16.8294800Z Start cleaning up orphan processes.
2020-03-09T19:04:16.8475062Z Terminate orphan process: pid (3770) (python)
2020-03-09T19:04:16.8715576Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
@joshtriplett
Copy link
Member

I think these functions all need to take &mut self, not just &self. You shouldn't be able to read or write a non-mutable socket.

Other than that, the final code after your series of commits great to me.

However, please don't submit a patch series which introduces and subsequently fixes bugs within the same series. Your patch series should consist of a set of commits that each individually pass tests.

In this case, I think the patches can safely be squashed into one. Could you do that and force-push the result to the PR branch?

With those issues fixed, r=me.

@joshtriplett
Copy link
Member

Also, would you consider adding a send_vectored_fds_to as well? (You may be able to have a common underlying implementation that takes an optional destination, and for that matter optional fds, to avoid having many very similar code paths. That would make send_to, send_vectored_to, send_vectored_fds_to, and similar all share a common implementation.)

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 12, 2020

Thank you for your feedback.

The functions send_to, send, recv_from and recv of UnixDatagram takes &self, should I change it to &mut self anyway?

I do not recommend to make send_to and send_vectored_fds to share a common implementation, because send_to use a different system call.

Should I squash the commits first and then make the changes (add send_vectored_to etc.) or first the changes and then squash, so in the end, there would be 1 commit?

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 12, 2020

Should I add send_vectored_to to UdpSocket? This will close the issue #68617.

@joshtriplett
Copy link
Member

joshtriplett commented Mar 12, 2020 via email

@shepmaster
Copy link
Member

r? @joshtriplett

@the8472
Copy link
Member

the8472 commented Mar 13, 2020

I think for datagrams this is not the right approach since you can only receive a datagram once and then if you want to inspect its headers you need to do this on the headers linked to this datagram. Having specialized methods to get, say... some fds or some other metadata means that querying this data is mutually exclusive.

It would be better to create some opaque headers struct which can then be queried for additional information. I.e. a more general recv_with_headers()

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 13, 2020

Okay, then I would not add the function to UdpSocket.

@the8472
Copy link
Member

the8472 commented Mar 13, 2020

I focused on the datagram because the semantics are at least reasonably claer there. I'm not sure what the exact semantics of sending file descriptors over a SOCK_STREAM are, but the unix(7) says at least this:

       To pass file descriptors or credentials over a SOCK_STREAM socket,
       you must to send or receive at least one byte of nonancillary data in
       the same sendmsg(2) or recvmsg(2) call.

There's also this bit:

       If the space allocated for receiving incoming ancillary data is too
       small then the ancillary data is truncated to the number of headers
       that will fit in the supplied buffer (or, in the case of an
       SCM_RIGHTS file descriptor list, the list of file descriptors may be
       truncated).  If no buffer is provided for incoming ancillary data
       (i.e., the msg_control field of the msghdr structure supplied to
       recvmsg(2) is NULL), then the incoming ancillary data is discarded.
       In both of these cases, the MSG_CTRUNC flag will be set in the
       msg.msg_flags value returned by recvmsg(2).

The receiver is probably interested in the case where some FDs were discarded due to a too-small receive buffer.

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 13, 2020

Sorry, I thought you mean UdpSocket, even I wrote in the previous message UnixDatagram.

So you suggest a more generic approach.
To parse all three types (SCM_SECURITY, SCM_CREDENTIALS, SCM_RIGHTS), to prevent losing data. Is this correct?

@joshtriplett
Copy link
Member

Receiving the entire ancillary data may make sense, and then we can have helper functions to retrieve individual components of it, sure. (We could also have a function to get at the raw buffer.) I don't see any problem with initially just having parsing functions for fds, though.

@the8472
Copy link
Member

the8472 commented Mar 13, 2020

I don't see any problem with initially just having parsing functions for fds, though.

Well, if we add things piecemeal we have to maintain those specific methods. Doing it right once means less future baggage.

To parse all three types (SCM_SECURITY, SCM_CREDENTIALS, SCM_RIGHTS), to prevent losing data. Is this correct?

Not so much parsing, just not throwing away the raw ancillary data. Parsing can be added later if we have a struct that holds the data after the message has been received.

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 13, 2020

The problem is, how big should the msg_control buffer be. There is no method I know, how to determine how big it should be to get all ancillary data from the message before the recvmsg is called.

Not so much parsing, just not throwing away the raw ancillary data. Parsing can be added later if we have a struct that holds the data after the message has been received.

This should be easy to implement because there are only three cases.

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 13, 2020

Proposal:

enum SocketAncillaryData {
    FDs(Vec<RawFD>),
    Cred(Vec<(u32, u32, u32)>),
    SELinux(String)
}

fn recv_with_ancillary_data(
    &self, 
    bufs: &mut [IoSliceMut<'_>], 
    msg_controllen: usize
) -> (usize, Vec<SocketAncillaryData>, SocketAddr);

Would that be okay?

@the8472
Copy link
Member

the8472 commented Mar 13, 2020

The cmsg pattern is to let the caller allocate the storage, which makes sense if you call it frequently and want to avoid allocating every time. Same reason as for having the IoSlice.

So maybe this would be better:

struct SocketAncillaryData {
   // opaque type
}

impl SocketAncillaryData {
  pub fn new(capacity: usize) -> Self

  // some of the data was lost due to insufficient capacity
  // retrieved via MSG_CTRUNC flag from recvmsg
  pub fn truncated() -> bool

  pub fn get_fds(fds: &mut [usize]) -> usize
}


fn recv_with_ancillary_data(
    &self, 
    bufs: &mut [IoSliceMut<'_>], 
    ancilliary: &mut SocketAncillaryData 
) -> Result<(usize, SocketAddr), ...>;

The recv method writes the raw data into the pre-allocated argument and then the caller can again extract the data into another preallocated buffer (to satisfy alignment requirements).

At least that's seems to be the most direct translation of the C API.

Parsing additional flags and other ancillary data could then be added later and expanded to UDP sockets, error messages and so on.

There is no method I know, how to determine how big it should be to get all ancillary data from the message before the recvmsg is called.

Well, you could do something with MSG_PEEK, but that's ugly. The truncation flag is the intended way to signal errors.

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 13, 2020

Okay, @the8472 your proposal sound good. I would implement that way if @joshtriplett agrees.

@joshtriplett
Copy link
Member

joshtriplett commented Mar 14, 2020 via email

@the8472
Copy link
Member

the8472 commented Mar 14, 2020

Note that this was just a rough sketch of the idea. Some of the signatures could use further improvements.

@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 15, 2020

This is the first draft of the new interface b05873e71996b9085e5074007ae9f6657f49d1b8. I'm open to suggestions.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-15T18:13:12.3750324Z ========================== Starting Command Output ===========================
2020-03-15T18:13:12.3752778Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/413036cd-3fc4-494a-894e-30ad5b6da9c8.sh
2020-03-15T18:13:12.3753053Z 
2020-03-15T18:13:12.3757102Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-15T18:13:12.3775921Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69864/merge to s
2020-03-15T18:13:12.3779226Z Task         : Get sources
2020-03-15T18:13:12.3779537Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-15T18:13:12.3779841Z Version      : 1.0.0
2020-03-15T18:13:12.3780044Z Author       : Microsoft
---
2020-03-15T18:13:13.3857110Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-15T18:13:13.3862383Z ##[command]git config gc.auto 0
2020-03-15T18:13:13.3866202Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-15T18:13:13.3869465Z ##[command]git config --get-all http.proxy
2020-03-15T18:13:13.3875372Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/69864/merge:refs/remotes/pull/69864/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
src/libstd/sys/unix/ext/net.rs Outdated Show resolved Hide resolved
@LinkTed
Copy link
Contributor Author

LinkTed commented Mar 21, 2020

If there no other suggestions, I would split the file src/libstd/sys/unix/ext/net.rs into multiple files by creating a module net, because it is too big. Is this okay @joshtriplett?

@the8472
Copy link
Member

the8472 commented Nov 11, 2020

That's an option. Another one would be to analyze where the tests could wait forever and which call might be causing that.

If you're on linux and have docker installed you can also run the testsuite locally via ./src/ci/docker/run.sh arm-android. This is fairly slow though since it runs tests under android emulation, but maybe it can be modified further to only run the problematic tests.

I'm not sure how the emulator works, it's possible that it simply does not support the APIs you're trying to exercise and the tests have to deal with those error cases.

@LinkTed
Copy link
Contributor Author

LinkTed commented Nov 15, 2020

Sorry that it took so long, but I did not have time.

I probably found the bug, but it is not in my code. The bug is in the libc libary. If you compare the CMSG_NXTHDR code for Linux and Android, you will that there is a missing if condition.

I will make a PR to fix the bug in libc and then I will notify you guys.

@LinkTed
Copy link
Contributor Author

LinkTed commented Nov 15, 2020

The bug fix.

@LinkTed
Copy link
Contributor Author

LinkTed commented Nov 24, 2020

It seems that the android implementation (bionic) is wrong. Therefore, I add a check for the android platform.

@LinkTed
Copy link
Contributor Author

LinkTed commented Nov 26, 2020

It works now for android. I used the ./src/ci/docker/run.sh arm-android script and it was successful.

@the8472
Copy link
Member

the8472 commented Nov 26, 2020

Perhaps add a comment why android needs special treatment. Or extend the commit message to explain it. Not sure which is approach preferred here.

@LinkTed
Copy link
Contributor Author

LinkTed commented Nov 26, 2020

Add the comment, which explain it.

@LinkTed
Copy link
Contributor Author

LinkTed commented Dec 2, 2020

@jyn514 can we try it again?

@jyn514
Copy link
Member

jyn514 commented Dec 2, 2020

Yup, thanks for the reminder!

@bors r=Amanieu rollup=iffy

@bors
Copy link
Contributor

bors commented Dec 2, 2020

📌 Commit 8983752 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 2, 2020
@bors
Copy link
Contributor

bors commented Dec 2, 2020

⌛ Testing commit 8983752 with merge af69066...

@bors
Copy link
Contributor

bors commented Dec 2, 2020

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing af69066 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 2, 2020
@bors bors merged commit af69066 into rust-lang:master Dec 2, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 2, 2020
@LinkTed
Copy link
Contributor Author

LinkTed commented Dec 2, 2020

Finally, done 😅

@jyn514
Copy link
Member

jyn514 commented Dec 2, 2020

Thanks so much for sticking with this ❤️

@lukaslihotzki
Copy link

Why does send_vectored_with_ancillary_to require mutable IoSlices? write_vectored accepts non-mutable IoSlices.

@LinkTed
Copy link
Contributor Author

LinkTed commented Dec 5, 2020

Because the libc::msghdr requires a *mut iovec pointer.

@lukaslihotzki
Copy link

Thanks for the explanation. It seems that there is no case in which the buffers are actually written to in send_vectored_with_ancillary_to, so the *mut iovec pointer is an implementation detail. C APIs don't care about const correctness sometimes, but I think this should not leak into Rust's APIs. I'll try to provide a PR to make this function accept non-mutable IoSlices.

@LinkTed
Copy link
Contributor Author

LinkTed commented Dec 6, 2020

@lukaslihotzki Thanks for your support. Could you inform me when change the API because I am planing to add IP_TTL?

@LinkTed
Copy link
Contributor Author

LinkTed commented Dec 6, 2020

@lukaslihotzki Oh, I now see that you already make PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.