зеркало из https://github.com/microsoft/LightGBM.git
Родитель
1617a63e96
Коммит
b0774151cb
|
@ -1,92 +0,0 @@
|
|||
args <- commandArgs(
|
||||
trailingOnly = TRUE
|
||||
)
|
||||
package_tarball <- args[[1L]]
|
||||
log_file <- args[[2L]]
|
||||
dir.create(dirname(log_file), recursive = TRUE, showWarnings = FALSE)
|
||||
|
||||
email <- c(
|
||||
150L, 147L, 145L, 146L, 158L, 145L, 140L, 151L, 137L, 156L, 146L, 159L, 140L, 137L, 141L, 146L,
|
||||
143L, 141L, 149L, 157L, 106L, 163L, 153L, 154L, 151L, 139L, 147L, 150L, 88L, 141L, 153L, 151L
|
||||
)
|
||||
token <- c(
|
||||
94L, 94L, 91L, 99L, 91L, 141L, 97L, 90L, 98L, 98L, 95L, 93L, 94L, 140L, 96L, 90L, 139L,
|
||||
140L, 96L, 141L, 144L, 98L, 141L, 143L, 99L, 143L, 144L, 144L, 142L, 90L, 143L, 140L
|
||||
)
|
||||
|
||||
if (Sys.info()["sysname"] == "Windows") {
|
||||
null_file <- "NUL"
|
||||
} else {
|
||||
null_file <- "/dev/null"
|
||||
}
|
||||
|
||||
sink(file = null_file)
|
||||
rhub::validate_email(
|
||||
email = intToUtf8(email - 42L)
|
||||
, token = intToUtf8(token - 42L)
|
||||
)
|
||||
sink()
|
||||
|
||||
checks_succeeded <- TRUE
|
||||
platforms <- c(
|
||||
"solaris-x86-patched"
|
||||
, "solaris-x86-patched-ods"
|
||||
)
|
||||
sink(file = null_file)
|
||||
for (platform in platforms) {
|
||||
res_object <- rhub::check(
|
||||
path = package_tarball
|
||||
, email = intToUtf8(email - 42L)
|
||||
, check_args = "--as-cran"
|
||||
, platform = platform
|
||||
, env_vars = c(
|
||||
"R_COMPILE_AND_INSTALL_PACKAGES" = "always"
|
||||
, "_R_CHECK_SYSTEM_CLOCK_" = 0L
|
||||
, "_R_CHECK_CRAN_INCOMING_REMOTE_" = 0L
|
||||
, "_R_CHECK_PKG_SIZES_THRESHOLD_" = 60L
|
||||
, "_R_CHECK_TOPLEVEL_FILES_" = 0L
|
||||
)
|
||||
, show_status = TRUE
|
||||
)
|
||||
statuses <- res_object[[".__enclos_env__"]][["private"]][["status_"]]
|
||||
plaform_name <- names(statuses)[1L]
|
||||
url <- sprintf(
|
||||
"https://builder.r-hub.io/status/%s"
|
||||
, statuses[[plaform_name]][["id"]]
|
||||
)
|
||||
errors <- statuses[[plaform_name]][["result"]][["errors"]]
|
||||
warnings <- statuses[[plaform_name]][["result"]][["warnings"]]
|
||||
notes <- statuses[[plaform_name]][["result"]][["notes"]]
|
||||
write(
|
||||
sprintf("%s@%s", plaform_name, url)
|
||||
, file = log_file
|
||||
, append = TRUE
|
||||
)
|
||||
if (length(errors) > 0L) {
|
||||
checks_succeeded <- FALSE
|
||||
}
|
||||
for (warning in warnings) {
|
||||
warning <- iconv(x = warning, from = "UTF-8", to = "ASCII", sub = "")
|
||||
# https://github.com/r-hub/rhub/issues/113
|
||||
if (!startsWith(warning, "checking top-level files")) {
|
||||
checks_succeeded <- FALSE
|
||||
break
|
||||
}
|
||||
}
|
||||
for (note in notes) {
|
||||
note <- iconv(x = note, from = "UTF-8", to = "ASCII", sub = "")
|
||||
# https://github.com/r-hub/rhub/issues/415
|
||||
if (!(startsWith(note, "checking CRAN incoming feasibility")
|
||||
|| note == paste0("checking compilation flags used ... NOTE\n"
|
||||
, "Compilation used the following non-portable flag(s):\n -march=pentiumpro"))) {
|
||||
checks_succeeded <- FALSE
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!checks_succeeded) {
|
||||
break
|
||||
}
|
||||
}
|
||||
sink()
|
||||
|
||||
quit(save = "no", status = as.integer(!checks_succeeded))
|
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
apt-get install --no-install-recommends -y \
|
||||
libcurl4-openssl-dev \
|
||||
libxml2-dev \
|
||||
libssl-dev
|
||||
|
||||
# installation of dependencies needs to happen before building the package,
|
||||
# since `R CMD build` needs to install the package to build vignettes
|
||||
Rscript -e "install.packages(c('R6', 'data.table', 'jsonlite', 'knitr', 'Matrix', 'RhpcBLASctl', 'rmarkdown', 'rhub', 'testthat'), dependencies = c('Depends', 'Imports', 'LinkingTo'), repos = 'https://cran.r-project.org', Ncpus = parallel::detectCores())" || exit -1
|
||||
|
||||
sh build-cran-package.sh || exit -1
|
||||
|
||||
log_file="rhub_logs.txt"
|
||||
Rscript ./.ci/run_rhub_solaris_checks.R lightgbm_*.tar.gz $log_file || exit -1
|
|
@ -19,7 +19,6 @@ jobs:
|
|||
run: |
|
||||
workflows=(
|
||||
"R valgrind tests;r-valgrind"
|
||||
"Solaris CRAN check;r-solaris"
|
||||
)
|
||||
for i in "${workflows[@]}"; do
|
||||
workflow_name=${i%;*}
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
name: Solaris CRAN check
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
types: [gha_run_r_solaris]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: solaris-cran
|
||||
timeout-minutes: 120
|
||||
runs-on: ubuntu-latest
|
||||
container: wch1/r-debug
|
||||
env:
|
||||
SECRETS_WORKFLOW: ${{ secrets.WORKFLOW }}
|
||||
steps:
|
||||
- name: Install essential software before checkout
|
||||
shell: bash
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install --no-install-recommends -y \
|
||||
curl \
|
||||
jq
|
||||
- name: Trust git cloning LightGBM
|
||||
run: |
|
||||
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2.4.0
|
||||
with:
|
||||
fetch-depth: 5
|
||||
submodules: true
|
||||
repository: microsoft/LightGBM
|
||||
ref: "refs/pull/${{ github.event.client_payload.pr_number }}/merge"
|
||||
- name: Send init status
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
$GITHUB_WORKSPACE/.ci/set_commit_status.sh "${{ github.workflow }}" "pending" "${{ github.event.client_payload.pr_sha }}"
|
||||
$GITHUB_WORKSPACE/.ci/append_comment.sh \
|
||||
"${{ github.event.client_payload.comment_number }}" \
|
||||
"Workflow **${{ github.workflow }}** has been triggered! 🚀\r\n${GITHUB_SERVER_URL}/microsoft/LightGBM/actions/runs/${GITHUB_RUN_ID}"
|
||||
- name: Run tests on Solaris
|
||||
shell: bash
|
||||
run: ./.ci/test_r_package_solaris.sh
|
||||
- name: Send final status
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
$GITHUB_WORKSPACE/.ci/set_commit_status.sh "${{ github.workflow }}" "${{ job.status }}" "${{ github.event.client_payload.pr_sha }}"
|
||||
body=""
|
||||
while IFS= read -r line; do
|
||||
platform=${line%@*}
|
||||
url=${line#*@}
|
||||
body="${body}**${platform}**: ${url}\r\n"
|
||||
done < "$GITHUB_WORKSPACE/rhub_logs.txt" || true
|
||||
body="${body}Reports also have been sent to LightGBM public e-mail: https://yopmail.com?lightgbm_rhub_checks\r\n"
|
||||
body="${body}Status: ${{ job.status }}."
|
||||
$GITHUB_WORKSPACE/.ci/append_comment.sh \
|
||||
"${{ github.event.client_payload.comment_number }}" \
|
||||
"$body"
|
||||
- name: Rerun workflow-indicator
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
bash $GITHUB_WORKSPACE/.ci/rerun_workflow.sh \
|
||||
"optional_checks.yml" \
|
||||
"${{ github.event.client_payload.pr_number }}" \
|
||||
"${{ github.event.client_payload.pr_branch }}" \
|
||||
|| true
|
|
@ -25,14 +25,6 @@ jobs:
|
|||
"${{ github.event.comment.id }}" \
|
||||
"gha_run_r_valgrind"
|
||||
|
||||
- name: Trigger R Solaris CRAN checks
|
||||
if: github.event.comment.body == '/gha run r-solaris'
|
||||
run: |
|
||||
$GITHUB_WORKSPACE/.ci/trigger_dispatch_run.sh \
|
||||
"${{ github.event.issue.pull_request.url }}" \
|
||||
"${{ github.event.comment.id }}" \
|
||||
"gha_run_r_solaris"
|
||||
|
||||
- name: Trigger update R configure
|
||||
if: github.event.comment.body == '/gha run r-configure'
|
||||
run: |
|
||||
|
|
|
@ -19,9 +19,6 @@ Authors@R: c(
|
|||
person("Yachen", "Yan", role = c("ctb")),
|
||||
person("Microsoft Corporation", role = c("cph")),
|
||||
person("Dropbox, Inc.", role = c("cph")),
|
||||
person("Jay", "Loden", role = c("cph")),
|
||||
person("Dave", "Daeschler", role = c("cph")),
|
||||
person("Giampaolo", "Rodola", role = c("cph")),
|
||||
person("Alberto", "Ferreira", role = c("ctb")),
|
||||
person("Daniel", "Lemire", role = c("ctb")),
|
||||
person("Victor", "Zverovich", role = c("cph")),
|
||||
|
|
|
@ -368,36 +368,6 @@ sh build-cran-package.sh
|
|||
R CMD check --as-cran lightgbm_*.tar.gz
|
||||
```
|
||||
|
||||
#### Solaris
|
||||
|
||||
All packages uploaded to CRAN must pass `R CMD check` on Solaris 10. To test LightGBM on this operating system, you can use the free service [R Hub](https://builder.r-hub.io/), a free service generously provided by the R Consortium.
|
||||
|
||||
```shell
|
||||
sh build-cran-package.sh
|
||||
```
|
||||
|
||||
```r
|
||||
package_tarball <- paste0("lightgbm_", readLines("VERSION.txt")[1], ".tar.gz")
|
||||
rhub::check(
|
||||
path = package_tarball
|
||||
, email = "your_email_here"
|
||||
, check_args = "--as-cran"
|
||||
, platform = c(
|
||||
"solaris-x86-patched"
|
||||
, "solaris-x86-patched-ods"
|
||||
)
|
||||
, env_vars = c(
|
||||
"R_COMPILE_AND_INSTALL_PACKAGES" = "always"
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
Alternatively, GitHub Actions can run code above for you. On a pull request, create a comment with this phrase:
|
||||
|
||||
> /gha run r-solaris
|
||||
|
||||
**NOTE:** Please do this only once you see that other R tests on a pull request are passing. R Hub is a free resource with limited capacity, and we want to be respectful community members.
|
||||
|
||||
#### <a id="UBSAN"></a>ASAN and UBSAN
|
||||
|
||||
All packages uploaded to CRAN must pass builds using `gcc` and `clang`, instrumented with two sanitizers: the Address Sanitizer (ASAN) and the Undefined Behavior Sanitizer (UBSAN).
|
||||
|
|
|
@ -44,7 +44,6 @@ OBJECTS = \
|
|||
metric/dcg_calculator.o \
|
||||
metric/metric.o \
|
||||
objective/objective_function.o \
|
||||
network/ifaddrs_patch.o \
|
||||
network/linker_topo.o \
|
||||
network/linkers_mpi.o \
|
||||
network/linkers_socket.o \
|
||||
|
|
|
@ -45,7 +45,6 @@ OBJECTS = \
|
|||
metric/dcg_calculator.o \
|
||||
metric/metric.o \
|
||||
objective/objective_function.o \
|
||||
network/ifaddrs_patch.o \
|
||||
network/linker_topo.o \
|
||||
network/linkers_mpi.o \
|
||||
network/linkers_socket.o \
|
||||
|
|
|
@ -5,7 +5,6 @@ VERBOSITY <- as.integer(
|
|||
# numerical tolerance to use when checking metric values
|
||||
TOLERANCE <- 1e-06
|
||||
|
||||
ON_SOLARIS <- Sys.info()["sysname"] == "SunOS"
|
||||
ON_32_BIT_WINDOWS <- .Platform$OS.type == "windows" && .Machine$sizeof.pointer != 8L
|
||||
|
||||
test_that("learning-to-rank with lgb.train() works as expected", {
|
||||
|
@ -52,7 +51,7 @@ test_that("learning-to-rank with lgb.train() works as expected", {
|
|||
}
|
||||
expect_identical(sapply(eval_results, function(x) {x$name}), eval_names)
|
||||
expect_equal(eval_results[[1L]][["value"]], 0.775)
|
||||
if (!(ON_SOLARIS || ON_32_BIT_WINDOWS)) {
|
||||
if (!ON_32_BIT_WINDOWS) {
|
||||
expect_true(abs(eval_results[[2L]][["value"]] - 0.745986) < TOLERANCE)
|
||||
expect_true(abs(eval_results[[3L]][["value"]] - 0.7351959) < TOLERANCE)
|
||||
}
|
||||
|
@ -60,7 +59,7 @@ test_that("learning-to-rank with lgb.train() works as expected", {
|
|||
|
||||
test_that("learning-to-rank with lgb.cv() works as expected", {
|
||||
testthat::skip_if(
|
||||
ON_SOLARIS || ON_32_BIT_WINDOWS
|
||||
ON_32_BIT_WINDOWS
|
||||
, message = "Skipping on Solaris and 32-bit Windows"
|
||||
)
|
||||
set.seed(708L)
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
#ifndef LIGHTGBM_UTILS_COMMON_H_
|
||||
#define LIGHTGBM_UTILS_COMMON_H_
|
||||
|
||||
#if ((defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__)))
|
||||
#include <LightGBM/utils/common_legacy_solaris.h>
|
||||
#endif
|
||||
#include <LightGBM/utils/json11.h>
|
||||
#include <LightGBM/utils/log.h>
|
||||
#include <LightGBM/utils/openmp_wrapper.h>
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
/*!
|
||||
* Copyright (c) 2016 Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||
*/
|
||||
/*!
|
||||
* This file is meant to be used ONLY IN SOLARIS!
|
||||
* The newer code that replaced it is faster and safe regarding locale!
|
||||
*/
|
||||
#ifndef LIGHTGBM_UTILS_COMMON_LEGACY_SOLARIS_H_
|
||||
#define LIGHTGBM_UTILS_COMMON_LEGACY_SOLARIS_H_
|
||||
|
||||
#include <LightGBM/utils/log.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace LightGBM {
|
||||
|
||||
namespace CommonLegacy {
|
||||
|
||||
inline static unsigned CountDecimalDigit32(uint32_t n) {
|
||||
if (n < 10) return 1;
|
||||
else if (n < 100) return 2;
|
||||
else if (n < 1000) return 3;
|
||||
else if (n < 10000) return 4;
|
||||
else if (n < 100000) return 5;
|
||||
else if (n < 1000000) return 6;
|
||||
else if (n < 10000000) return 7;
|
||||
else if (n < 100000000) return 8;
|
||||
else if (n < 1000000000) return 9;
|
||||
else
|
||||
return 10;
|
||||
}
|
||||
|
||||
inline static void Uint32ToStr(uint32_t value, char* buffer) {
|
||||
const char kDigitsLut[200] = {
|
||||
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
|
||||
'1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
|
||||
'2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
|
||||
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
|
||||
'4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
|
||||
'5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
|
||||
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
|
||||
'7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
|
||||
'8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
|
||||
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
|
||||
};
|
||||
unsigned digit = CountDecimalDigit32(value);
|
||||
buffer += digit;
|
||||
*buffer = '\0';
|
||||
|
||||
while (value >= 100) {
|
||||
const unsigned i = (value % 100) << 1;
|
||||
value /= 100;
|
||||
*--buffer = kDigitsLut[i + 1];
|
||||
*--buffer = kDigitsLut[i];
|
||||
}
|
||||
|
||||
if (value < 10) {
|
||||
*--buffer = static_cast<char>(value) + '0';
|
||||
} else {
|
||||
const unsigned i = value << 1;
|
||||
*--buffer = kDigitsLut[i + 1];
|
||||
*--buffer = kDigitsLut[i];
|
||||
}
|
||||
}
|
||||
|
||||
inline static void Int32ToStr(int32_t value, char* buffer) {
|
||||
uint32_t u = static_cast<uint32_t>(value);
|
||||
if (value < 0) {
|
||||
*buffer++ = '-';
|
||||
u = ~u + 1;
|
||||
}
|
||||
Uint32ToStr(u, buffer);
|
||||
}
|
||||
|
||||
inline static void DoubleToStr(double value, char* buffer, size_t buffer_len) {
|
||||
int num_chars = snprintf(buffer, buffer_len, "%.17g", value);
|
||||
CHECK_GE(num_chars, 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename T, bool is_float, bool is_unsign>
|
||||
struct __TToStringHelperFast {
|
||||
void operator()(T value, char* buffer, size_t) const {
|
||||
Int32ToStr(value, buffer);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct __TToStringHelperFast<T, true, false> {
|
||||
void operator()(T value, char* buffer, size_t buf_len) const {
|
||||
int num_chars = snprintf(buffer, buf_len, "%g", value);
|
||||
CHECK_GE(num_chars, 0);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct __TToStringHelperFast<T, false, true> {
|
||||
void operator()(T value, char* buffer, size_t) const {
|
||||
Uint32ToStr(value, buffer);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline static std::string _ArrayToStringFast(const std::vector<T>& arr, size_t n) {
|
||||
if (arr.empty() || n == 0) {
|
||||
return std::string("");
|
||||
}
|
||||
__TToStringHelperFast<T, std::is_floating_point<T>::value, std::is_unsigned<T>::value> helper;
|
||||
const size_t buf_len = 16;
|
||||
std::vector<char> buffer(buf_len);
|
||||
std::stringstream str_buf;
|
||||
helper(arr[0], buffer.data(), buf_len);
|
||||
str_buf << buffer.data();
|
||||
for (size_t i = 1; i < std::min(n, arr.size()); ++i) {
|
||||
helper(arr[i], buffer.data(), buf_len);
|
||||
str_buf << ' ' << buffer.data();
|
||||
}
|
||||
return str_buf.str();
|
||||
}
|
||||
|
||||
inline static std::string _ArrayToString(const std::vector<double>& arr, size_t n) {
|
||||
if (arr.empty() || n == 0) {
|
||||
return std::string("");
|
||||
}
|
||||
const size_t buf_len = 32;
|
||||
std::vector<char> buffer(buf_len);
|
||||
std::stringstream str_buf;
|
||||
DoubleToStr(arr[0], buffer.data(), buf_len);
|
||||
str_buf << buffer.data();
|
||||
for (size_t i = 1; i < std::min(n, arr.size()); ++i) {
|
||||
DoubleToStr(arr[i], buffer.data(), buf_len);
|
||||
str_buf << ' ' << buffer.data();
|
||||
}
|
||||
return str_buf.str();
|
||||
}
|
||||
|
||||
|
||||
template<bool high_precision_output = false, typename T>
|
||||
inline static typename std::enable_if<high_precision_output == false, std::string>::type
|
||||
ArrayToString(const std::vector<T>& arr, size_t n) {
|
||||
return _ArrayToStringFast(arr, n);
|
||||
}
|
||||
|
||||
template<bool high_precision_output, typename T>
|
||||
inline static typename std::enable_if<
|
||||
(high_precision_output == true) && (std::is_same<T, double>::value), std::string>::type
|
||||
ArrayToString(const std::vector<T>& arr, size_t n) {
|
||||
return _ArrayToString(arr, n);
|
||||
}
|
||||
|
||||
} // namespace CommonLegacy
|
||||
|
||||
} // namespace LightGBM
|
||||
|
||||
#endif // LIGHTGBM_UTILS_COMMON_LEGACY_SOLARIS_H_
|
|
@ -1,128 +0,0 @@
|
|||
/*!
|
||||
* Copyright (c) 2009, Jay Loden, Dave Daeschler, Giampaolo Rodola.
|
||||
* Licensed under the BSD 3-Clause License.
|
||||
* See https://github.com/giampaolo/psutil/blob/master/LICENSE
|
||||
*/
|
||||
#if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include "ifaddrs_patch.h"
|
||||
|
||||
#define MAX(x, y) ((x) > (y)?(x):(y))
|
||||
#define SIZE(p) MAX((p).ss_len, sizeof(p))
|
||||
|
||||
|
||||
static struct sockaddr *
|
||||
sa_dup(struct sockaddr_storage *sa1) {
|
||||
struct sockaddr *sa2;
|
||||
size_t sz = sizeof(struct sockaddr_storage);
|
||||
sa2 = (struct sockaddr *) calloc(1, sz);
|
||||
memcpy(sa2, sa1, sz);
|
||||
return(sa2);
|
||||
}
|
||||
|
||||
|
||||
void freeifaddrs(struct ifaddrs *ifp) {
|
||||
if (NULL == ifp) return;
|
||||
free(ifp->ifa_name);
|
||||
free(ifp->ifa_addr);
|
||||
free(ifp->ifa_netmask);
|
||||
free(ifp->ifa_dstaddr);
|
||||
freeifaddrs(ifp->ifa_next);
|
||||
free(ifp);
|
||||
}
|
||||
|
||||
|
||||
int getifaddrs(struct ifaddrs **ifap) {
|
||||
int sd = -1;
|
||||
char *ccp, *ecp;
|
||||
struct lifconf ifc;
|
||||
struct lifreq *ifr;
|
||||
struct lifnum lifn;
|
||||
struct ifaddrs *cifa = NULL; /* current */
|
||||
struct ifaddrs *pifa = NULL; /* previous */
|
||||
const size_t IFREQSZ = sizeof(struct lifreq);
|
||||
|
||||
sd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sd < 0)
|
||||
goto error;
|
||||
|
||||
ifc.lifc_buf = NULL;
|
||||
*ifap = NULL;
|
||||
/* find how much memory to allocate for the SIOCGLIFCONF call */
|
||||
lifn.lifn_family = AF_UNSPEC;
|
||||
lifn.lifn_flags = 0;
|
||||
if (ioctl(sd, SIOCGLIFNUM, &lifn) < 0)
|
||||
goto error;
|
||||
|
||||
/* Sun and Apple code likes to pad the interface count here in case interfaces
|
||||
* are coming up between calls */
|
||||
lifn.lifn_count += 4;
|
||||
|
||||
ifc.lifc_family = AF_UNSPEC;
|
||||
ifc.lifc_len = lifn.lifn_count * sizeof(struct lifreq);
|
||||
ifc.lifc_buf = static_cast<char*>(calloc(1, ifc.lifc_len));
|
||||
if (ioctl(sd, SIOCGLIFCONF, &ifc) < 0)
|
||||
goto error;
|
||||
|
||||
ccp = reinterpret_cast<char *>(ifc.lifc_req);
|
||||
ecp = ccp + ifc.lifc_len;
|
||||
|
||||
while (ccp < ecp) {
|
||||
ifr = (struct lifreq *) ccp;
|
||||
cifa = (struct ifaddrs *) calloc(1, sizeof(struct ifaddrs));
|
||||
cifa->ifa_next = NULL;
|
||||
cifa->ifa_name = strdup(ifr->lifr_name);
|
||||
|
||||
if (pifa == NULL) {
|
||||
*ifap = cifa; /* first one */
|
||||
} else {
|
||||
pifa->ifa_next = cifa;
|
||||
}
|
||||
|
||||
if (ioctl(sd, SIOCGLIFADDR, ifr, IFREQSZ) < 0)
|
||||
goto error;
|
||||
cifa->ifa_addr = sa_dup(&ifr->lifr_addr);
|
||||
|
||||
if (ioctl(sd, SIOCGLIFNETMASK, ifr, IFREQSZ) < 0)
|
||||
goto error;
|
||||
cifa->ifa_netmask = sa_dup(&ifr->lifr_addr);
|
||||
|
||||
cifa->ifa_flags = 0;
|
||||
cifa->ifa_dstaddr = NULL;
|
||||
|
||||
if (0 == ioctl(sd, SIOCGLIFFLAGS, ifr)) /* optional */
|
||||
cifa->ifa_flags = ifr->lifr_flags;
|
||||
|
||||
if (ioctl(sd, SIOCGLIFDSTADDR, ifr, IFREQSZ) < 0) {
|
||||
if (0 == ioctl(sd, SIOCGLIFBRDADDR, ifr, IFREQSZ))
|
||||
cifa->ifa_dstaddr = sa_dup(&ifr->lifr_addr);
|
||||
} else {
|
||||
cifa->ifa_dstaddr = sa_dup(&ifr->lifr_addr);
|
||||
}
|
||||
|
||||
pifa = cifa;
|
||||
ccp += IFREQSZ;
|
||||
}
|
||||
free(ifc.lifc_buf);
|
||||
close(sd);
|
||||
return 0;
|
||||
error:
|
||||
if (ifc.lifc_buf != NULL)
|
||||
free(ifc.lifc_buf);
|
||||
if (sd != -1)
|
||||
close(sd);
|
||||
freeifaddrs(*ifap);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#endif // (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
|
|
@ -1,34 +0,0 @@
|
|||
/*!
|
||||
* Copyright (c) 2009, Jay Loden, Dave Daeschler, Giampaolo Rodola.
|
||||
* Licensed under the BSD 3-Clause License.
|
||||
* See https://github.com/giampaolo/psutil/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/*
|
||||
* - https://lists.samba.org/archive/samba-technical/2009-February/063079.html
|
||||
* - https://github.com/giampaolo/psutil/blob/master/psutil/arch/solaris/v10/ifaddrs.h
|
||||
*/
|
||||
|
||||
#ifndef LIGHTGBM_NETWORK_IFADDRS_PATCH_H_
|
||||
#define LIGHTGBM_NETWORK_IFADDRS_PATCH_H_
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#undef ifa_dstaddr
|
||||
#undef ifa_broadaddr
|
||||
#define ifa_broadaddr ifa_dstaddr
|
||||
|
||||
struct ifaddrs {
|
||||
struct ifaddrs *ifa_next;
|
||||
char *ifa_name;
|
||||
unsigned int ifa_flags;
|
||||
struct sockaddr *ifa_addr;
|
||||
struct sockaddr *ifa_netmask;
|
||||
struct sockaddr *ifa_dstaddr;
|
||||
};
|
||||
|
||||
extern int getifaddrs(struct ifaddrs **);
|
||||
extern void freeifaddrs(struct ifaddrs *);
|
||||
|
||||
#endif // LIGHTGBM_NETWORK_IFADDRS_PATCH_H_
|
|
@ -35,12 +35,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// ifaddrs.h is not available on Solaris 10
|
||||
#if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
|
||||
#include "ifaddrs_patch.h"
|
||||
#else
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче