Skip to content
Snippets Groups Projects
  1. May 21, 2016
  2. May 20, 2016
  3. May 18, 2016
    • bors's avatar
      Auto merge of #289 - fnichol:fix-musl-ioctl-constants, r=alexcrichton · fb5008c0
      bors authored
      Fix ioctl constants for musl target envs.
      
      Heya!
      
      I ran across this issue today while trying to build a portable static binary using the `x86_64-unknown-linux-musl` target. Took a bit of digging to make sure I understood what was going on, and while I may still be off the mark, I believe this is a fix to my issue.
      
      Thanks!!
      
      ----
      
      According to musl's source, the `ioctl` [function signature][musl-ioctl-h] takes an `int` as the request argument (i.e. an `i32`) which is reflected in this crate's [ioctl binding][musl-ioctl-rs]. It looks like when the ioctl constants were added that [glibc's default][glibc-ioctl-h] of a `c_ulong` type was used for the musl values as well, rather than a `c_int` type. This change updates these constants to a `c_int` so that they match the expected function call type.
      
      Here is a minimal reproduction of the issue. Given this Rust program:
      
      ```rust
      extern crate libc;
      
      use libc::{ioctl, winsize, STDOUT_FILENO, TIOCGWINSZ};
      
      fn main() {
          let mut wsize = winsize {
              ws_row: 0,
              ws_col: 0,
              ws_xpixel: 0,
              ws_ypixel: 0,
          };
          unsafe {
              ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut wsize);
          }
          println!("Sizes: {{ rows: {}, cols: {}, xpixel: {}, ypixel: {} }}",
                   wsize.ws_row,
                   wsize.ws_col,
                   wsize.ws_xpixel,
                   wsize.ws_ypixel);
      }
      ```
      
      When run against the `x86_64-unknwon-linux-gnu` and
      `x86_64-unknown-linux-musl` targets, we see the difference in behavior:
      
      ```
      > cargo clean
      
      > cargo run --target=x86_64-unknown-linux-gnu
         Compiling libc v0.2.11
         Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl)
           Running `target/x86_64-unknown-linux-gnu/debug/libc-musl-ioctl`
      Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 }
      
      > cargo clean
      
      > cargo run --target=x86_64-unknown-linux-musl
         Compiling libc v0.2.11
         Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl)
      src/main.rs:13:30: 13:40 error: mismatched types:
       expected `i32`,
          found `u64` [E0308]
      src/main.rs:13         ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut wsize);
                                                  ^~~~~~~~~~
      src/main.rs:13:30: 13:40 help: run `rustc --explain E0308` to see a detailed explanation
      error: aborting due to previous error
      Could not compile `libc-musl-ioctl`.
      
      To learn more, run the command again with --verbose.
      ```
      
      Working against this fix:
      
      ```
      > cargo clean
      
      > cargo run --target=x86_64-unknown-linux-gnu
          Updating git repository `https://github.com/fnichol/rust-lang-libc.git`
         Compiling libc v0.2.11 (https://github.com/fnichol/rust-lang-libc.git?branch=fix-musl-ioctl-constants#3285f387)
         Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl)
           Running `target/x86_64-unknown-linux-gnu/debug/libc-musl-ioctl`
      Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 }
      
      > cargo clean
      
      > cargo run --target=x86_64-unknown-linux-musl
         Compiling libc v0.2.11 (https://github.com/fnichol/rust-lang-libc.git?branch=fix-musl-ioctl-constants#3285f387)
         Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl)
           Running `target/x86_64-unknown-linux-musl/debug/libc-musl-ioctl`
      Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 }
      ```
      
      [musl-ioctl-rs]:
      https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc/fn.ioctl.html
      
      [musl-ioctl-h]:
      https://git.musl-libc.org/cgit/musl/tree/include/sys/ioctl.h
      
      [glibc-ioctl-h]:
      http://bazaar.launchpad.net/~vcs-imports/glibc/master/view/head:/include/sys/ioctl.h
      fb5008c0
  4. May 16, 2016
  5. May 15, 2016
  6. May 14, 2016
    • bors's avatar
      Auto merge of #285 - lemonrock:sysctl, r=alexcrichton · 72519bf4
      bors authored
      Added extensive constants to make use of the BSD's sysctl function.
      
      sysctl usage does differ significantly across the BSDs, and, whilst
      some constants overlap, many do not. It is easier to maintain them
      in separate modules, rather than trying to tease out common definitions.
      72519bf4
  7. May 13, 2016
  8. May 12, 2016
  9. May 11, 2016
  10. May 10, 2016
    • bors's avatar
      Auto merge of #281 - lemonrock:getprogname, r=alexcrichton · 19fd5047
      bors authored
      Getprogname
      
      Added `getprogname()` and `setprogname()` for all BSDs and Solaris (including Mac OS X).
      
      Added `program_invocation_short_name` global, for Linux (glibc and Musl) which is effectively the same thing, and is what compatibility libraries like `libbsd` use to implement `getprogname()`.
      
      Added `__progname` global for Android, which, whilst not quite the same as `getprogname` or `program_invocation_short_name`, is better than using argv[0], as it (a) avoids a common bug with no arguments (b) avoids a common bug with a NULL string in argv[0] and (c) incorporates Android's chosen name for an unknown process.
      19fd5047
    • Raphael Cohn's avatar
      Adding getprogname and setprogname for all BSDs and Solaris. · 893d4d84
      Raphael Cohn authored
      Adding program_invocation_short_name for Linux (Musl and glibc).
      
      Adding __progname for Android. This is a little different, but
      is a safer alternative to using argv[0], which may not exist, and
      includes Android's default application name (currently '<unknown>').
      
      Adding these functions and externs means it is possible for all
      but Windows applications to safely discover their
      name, rather than rely on argv[0] parsing, /proc/self/exe, etc.
      893d4d84
  11. May 08, 2016
  12. May 07, 2016
  13. May 06, 2016
  14. May 05, 2016
    • Kamal Marhubi's avatar
      unix: Add PIPE_BUF for bsd and notbsd · ce0dc736
      Kamal Marhubi authored
      This is the maximum size of guaranteed-atomic writes to a pipe.
      ce0dc736
    • bors's avatar
      Auto merge of #278 - lemonrock:syslog, r=alexcrichton · 4fc03fe9
      bors authored
      Adding syslog functions, constants and structs
      
      This commit adds the functions:-
      - syslog
      - openlog
      - closelog
      - setlogmask
      
      It adds LOG_* constants.
      
      It adds the `CODE` struct used by the `#define` definitions `prioritynames` and `facilitynames`.
      
      It does not add:-
      - the function `vsyslog`; this is an extension to POSIX and uses va_list macros;
      - the `#define`s `prioritynames` and `facilitynames`, as usage is not common
      - rust functions mirroring the macros:-
        - LOG_PRI
        - LOG_MAKEPRI
        - LOG_MASK
        - LOG_UPTO
        - LOG_FAC
      * `CODE` is included in case a third-party unsafe C function returns or takes it.
      4fc03fe9
    • Raphael Cohn's avatar
      Added LOG_CRON back for Solaris · 828766fd
      Raphael Cohn authored
      828766fd
    • Raphael Cohn's avatar
      Added support for LOG_NTP, LOG_SECURITY and LOG_CONSOLE to FreeBSD. · 25df1e4c
      Raphael Cohn authored
      Did this by moving these definitions up from DragonFlyBSD.
      25df1e4c
    • Raphael Cohn's avatar
    • Raphael Cohn's avatar
      Moved `LOG_NFEATURES` from notbsd to Linux · 1c6c0ca7
      Raphael Cohn authored
      This is because Android bionic doesn't support `LOG_NFEATURES`.
      1c6c0ca7
    • Raphael Cohn's avatar
      Merge branch 'master' into syslog · 3045cb2e
      Raphael Cohn authored
      3045cb2e
    • Raphael Cohn's avatar
      Substantial changes to better support Solaris and BSD variants. · 7fc09699
      Raphael Cohn authored
      Removed CODE, as its definition and name varies too wildy and I
      have no current code using it to test permutations with.
      
      Moved LOG_NFACILITIES down, as Mac OS X defines this value
      differently.
      
      Added Mac OS X specific LOG_* facilities.
      
      Added FreeBSD / DragonFly BSD specific LOG_* facilities.
      
      Moved LOG_PERROR down, as all platforms bar Solaris define this.
      
      Moved LOG_CRON down, as Solaris defines this with a different value.
      
      Moved LOG_AUTHPRIV and LOG_FTP down, as all platforms bar Solaris
      define these.
      
      Looks like Solaris is suffering from the bit rot of commercial Unix...
      7fc09699
    • bors's avatar
      Auto merge of #277 - lemonrock:strnlen, r=alexcrichton · ac752505
      bors authored
      Added strnlen function to all platforms.
      
      strnlen is used to find the length of a C string that may be
      lacking a terminal NUL character. Whilst it is possible to
      implement the equivalent functionality in rust code, it is
      cleaner, simpler and removes the need for duplication of tricky
      functionality to get right. It also makes it easier to port
      C code snippets to rust. In my case, it's needed for dealing with
      the result of `gethostname`.
      
      Note that strnlen is not part of POSIX or C99, but is present on all major platforms.
      ac752505
  15. May 04, 2016
    • bors's avatar
      Auto merge of #276 - lemonrock:SC_HOSTNAME_MAX_OpenBsd, r=alexcrichton · 39f03eaa
      bors authored
      Definition of _SC_HOST_NAME_MAX for OpenBSD and FreeBSD
      39f03eaa
    • Raphael Cohn's avatar
      Added strnlen function to all platforms. · 29b1ceab
      Raphael Cohn authored
      strnlen is used to find the length of a C string that may be
      lacking a terminal NUL character. Whilst it is possible to
      implement the equivalent functionality in rust code, it is
      cleaner, simpler and removes the need for duplication of tricky
      functionality to get right. It also makes it easier to port
      C code snippets to rust.
      
      Note that strnlen is not part of POSIX or C99.
      29b1ceab
    • bors's avatar
      Auto merge of #275 - lemonrock:SC_HOSTNAME_MAX, r=alexcrichton · fc9a7dee
      bors authored
      Added _SC_HOST_NAME_MAX for FreeBSD, DragonFly, BitRig and Linux (glibc and musl)
      
      I'd have liked to also add NetBSD and OpenBSD, but I can't find where _SC_HOST_NAME_MAX is defined.
      fc9a7dee
    • Raphael Cohn's avatar
      Adding syslog functions, constants and structs · 7e0dbc32
      Raphael Cohn authored
      This commit adds the functions:-
      - syslog
      - openlog
      - closelog
      - setlogmask
      
      It adds LOG_* constants.
      
      It adds the CODE struct used by the #define definitions prioritynames and facilitynames.
      
      It does not add:-
      - the function vsyslog; this is an extension to POSIX and uses va_list macros;
      - the #defines prioritynames and facilitynames, as usage is not common
      - rust functions mirroring the macros:-
        - LOG_PRI
        - LOG_MAKEPRI
        - LOG_MASK
        - LOG_UPTO
        - LOG_FAC
      * CODE is included in case a third-party unsafe C function returns or takes it.
      7e0dbc32
    • Raphael Cohn's avatar
Loading