Repository: thecoshman/http (language: rust)

Issue:
Build fails on musl host
When compiling https on `x86_64-unknown-linux-musl` build fails due a difference in the function signature of `ioctl`

```
$ rustc --version
rustc 1.43.1 (8d69840ab 2020-05-04)
```

```
$ cargo build
Compiling https v1.9.2 (/home/adrianisuru/http)
error[E0308]: mismatched types
  --> src/util/os/non_windows_non_macos.rs:39:47
   |
39 |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE, &mut block_count as *mut c_ulong) } == 0;
   |                                               ^^^^^^^^^^ expected `i32`, found `u64`
   |
help: you can convert an `u64` to `i32` and panic if the converted value wouldn't fit
   |
39 |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE.try_into().unwrap(), &mut block_count as *mut c_ulong) } == 0;
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
  --> src/util/os/non_windows_non_macos.rs:39:47
   |
39 |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE, &mut block_count as *mut c_ulong) } == 0;
   |                                               ^^^^^^^^^^ expected `i32`, found `u64`
   |
help: you can convert an `u64` to `i32` and panic if the converted value wouldn't fit
   |
39 |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE.try_into().unwrap(), &mut block_count as *mut c_ulong) } == 0;
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0308`.
error: could not compile `https`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: could not compile `https`.
```
On `glibc` systems the `ioctl` function signature is 
```c
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
```
but on `musl` systems the signature is
```c
int ioctl (int, int, ...);
```
so compiling [`src/util/os/non_windows_non_macos.rs`](https://github.com/thecoshman/http/blob/master/src/util/os/non_windows_non_macos.rs) fails because `BLKGETSIZE` is a `c_ulong` not a `c_int`


Discussion / hints:
Update `http` and `httplz` segfault when they get a request. The program opens fine, but when I connect from my browser it segfaults.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 6fb4049..3976745 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,11 +9,12 @@ categories = ["network-programming", "web-programming::http-server"]
 license = "MIT"
 build = "build.rs"
 # Remember to also update in appveyor.yml
-version = "1.9.2"
+version = "1.9.3"
 # Remember to also update in http.md
 authors = ["thecoshman <rust@thecoshman.com>",
            "nabijaczleweli <nabijaczleweli@gmail.com>",
-           "pheki"]
+           "pheki",
+           "Adrian Herath <adrianisuru@gmail.com>"]
 
 [dependencies]
 hyper-native-tls = "0.3"
diff --git a/appveyor.yml b/appveyor.yml
index cc0026b..63d7351 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-version: 1.9.2-{build}
+version: 1.9.3-{build}
 
 skip_tags: false
 
@@ -23,21 +23,21 @@ build: off
 build_script:
   - git submodule update --init --recursive
   - cargo build --verbose --release
-  - cp target\release\http.exe http-v1.9.2.exe
-  - strip --strip-all --remove-section=.comment --remove-section=.note http-v1.9.2.exe
-  - makensis -DHTTP_VERSION=v1.9.2 install.nsi
+  - cp target\release\http.exe http-v1.9.3.exe
+  - strip --strip-all --remove-section=.comment --remove-section=.note http-v1.9.3.exe
+  - makensis -DHTTP_VERSION=v1.9.3 install.nsi
 
 test: off
 test_script:
   - cargo test --verbose --release
 
 artifacts:
-  - path: http-v1.9.2.exe
-  - path: http v1.9.2 installer.exe
+  - path: http-v1.9.3.exe
+  - path: http v1.9.3 installer.exe
 
 deploy:
   provider: GitHub
-  artifact: /http.*v1.9.2.*\.exe/
+  artifact: /http.*v1.9.3.*\.exe/
   auth_token:
     secure: ZTXvCrv9y01s7Hd60w8W7NaouPnPoaw9YJt9WhWQ2Pep8HLvCikt9Exjkz8SGP9P
   on:
diff --git a/build.rs b/build.rs
index 2d72033..c3cc83c 100644
--- a/build.rs
+++ b/build.rs
@@ -15,7 +15,7 @@ use std::fs::{self, File};
 /// The last line of this, after running it through a preprocessor, will expand to the value of `BLKGETSIZE`
 #[cfg(not(any(target_os = "windows", target_os = "macos")))]
 static IOCTL_CHECK_SOURCE: &str = r#"
-#include <linux/fs.h>
+#include <sys/mount.h>
 
 BLKGETSIZE
 "#;
@@ -24,9 +24,15 @@ BLKGETSIZE
 #[cfg(not(any(target_os = "windows", target_os = "macos")))]
 static IOCTL_INCLUDE_SKELETON: &str = r#"
 /// Return `device size / 512` (`long *` arg)
-static BLKGETSIZE: c_ulong = {};
+static BLKGETSIZE: {type} = {expr} as {type};
 "#;
 
+#[cfg(all(not(any(target_os = "windows", target_os = "macos")), not(target_env = "musl")))]
+static IOCTL_REQUEST_TYPE: &str = "libc::c_ulong";
+
+#[cfg(all(not(any(target_os = "windows", target_os = "macos")), target_env = "musl"))]
+static IOCTL_REQUEST_TYPE: &str = "libc::c_int";
+
 
 fn main() {
     embed_resources();
@@ -49,8 +55,11 @@ fn get_ioctl_data() {
     File::create(&ioctl_source).unwrap().write_all(IOCTL_CHECK_SOURCE.as_bytes()).unwrap();
 
     let ioctl_preprocessed = String::from_utf8(cc::Build::new().file(ioctl_source).expand()).unwrap();
-    let blkgetsize_expr = ioctl_preprocessed.lines().next_back().unwrap().replace("U", " as c_ulong");
+    let blkgetsize_expr = ioctl_preprocessed.lines().next_back().unwrap().replace("U", "");
 
     let ioctl_include = ioctl_dir.join("ioctl.rs");
-    File::create(&ioctl_include).unwrap().write_all(IOCTL_INCLUDE_SKELETON.replace("{}", &blkgetsize_expr).as_bytes()).unwrap();
+    File::create(&ioctl_include)
+        .unwrap()
+        .write_all(IOCTL_INCLUDE_SKELETON.replace("{type}", IOCTL_REQUEST_TYPE).replace("{expr}", &blkgetsize_expr).as_bytes())
+        .unwrap();
 }
diff --git a/http.md b/http.md
index dc20ed5..bce35e9 100644
--- a/http.md
+++ b/http.md
@@ -384,7 +384,8 @@ pass parameters like what port to use.
 
 Written by thecoshman &lt;<rust@thecoshman.com>&gt;,
            nabijaczleweli &lt;<nabijaczleweli@gmail.com>&gt;,
-       and pheki.
+           pheki,
+       and Adrian Herath &lt;<adrianisuru@gmail.com>&gt;.
 
 ## REPORTING BUGS
 


Test patch: