diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..546e12e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: systemd-netlogd CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: update + run: sudo apt-get update + - name: install python + run: sudo apt-get install python3 python3-pip python3-dev python3-setuptools build-essential meson ninja-build sphinx-doc sphinx-common python-configparser + - name: install build essentials + run: sudo apt-get install -y ninja-build glib-2.0-dev libudev-dev libyaml-dev libsystemd-dev clang gperf libcap-dev build-essential + - name: build + run: make diff --git a/.lgtm.yml b/.lgtm.yml deleted file mode 100644 index 049e7ff..0000000 --- a/.lgtm.yml +++ /dev/null @@ -1,9 +0,0 @@ -extraction: - cpp: - prepare: - packages: - - python-sphinx - - python3-sphinx - configure: - command: meson build - command: ninja -C build diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6145657..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -os: linux -dist: bionic -language: c - -services: - - docker - -before_install: - - sudo apt-get update - - sudo apt-get install python3.7 python3-pip python3-dev python3-setuptools build-essential python3-sphinx python-sphinx python-configparser - - sudo apt-get install -y ninja-build glib-2.0-dev libudev-dev libyaml-dev libsystemd-dev clang gperf libcap-dev - - sudo pip3 install -U meson pytest - -script: - - meson build - - ninja -C build - - sudo ninja -C build install diff --git a/src/netlog/netlog-manager.c b/src/netlog/netlog-manager.c index f3b541f..422ca5b 100644 --- a/src/netlog/netlog-manager.c +++ b/src/netlog/netlog-manager.c @@ -484,8 +484,6 @@ int manager_new(Manager **ret, const char *state_file, const char *cursor) { if (r < 0) return r; - *ret = m; - m = NULL; - + *ret = TAKE_PTR(m); return 0; } diff --git a/src/netlog/netlog-network.c b/src/netlog/netlog-network.c index 670382b..59cdcec 100644 --- a/src/netlog/netlog-network.c +++ b/src/netlog/netlog-network.c @@ -207,6 +207,7 @@ int manager_open_network_socket(Manager *m) { if (SYSLOG_TRANSMISSION_PROTOCOL_TCP == m->protocol) { union sockaddr_union sa; socklen_t salen; + switch (m->address.sockaddr.sa.sa_family) { case AF_INET: sa = (union sockaddr_union) { @@ -228,6 +229,7 @@ int manager_open_network_socket(Manager *m) { r = -EAFNOSUPPORT; goto fail; } + r = connect(m->socket, &m->address.sockaddr.sa, salen); if (r < 0 && errno != EINPROGRESS) { r = -errno; @@ -239,7 +241,7 @@ int manager_open_network_socket(Manager *m) { return r; } - r = fd_nonblock(m->socket, 1); + r = fd_nonblock(m->socket, true); if (r < 0) goto fail; diff --git a/src/share/macro.h b/src/share/macro.h index 0423390..b475020 100644 --- a/src/share/macro.h +++ b/src/share/macro.h @@ -399,4 +399,15 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { } \ struct __useless_struct_to_allow_trailing_semicolon__ +/* Takes inspiration from Rust's Option::take() method: reads and returns a pointer, but at the same time + * resets it to NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */ +#define TAKE_PTR(ptr) \ + ({ \ + typeof(ptr) *_pptr_ = &(ptr); \ + typeof(ptr) _ptr_ = *_pptr_; \ + *_pptr_ = NULL; \ + _ptr_; \ + }) + + #include "log.h"