Skip to content

Commit 4977106

Browse files
authored
Merge pull request #33 from ssahani/tiny_cleanup
Introduce github CI and cleanups
2 parents 0b8ed18 + daeb2a9 commit 4977106

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: systemd-netlogd CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: update
17+
run: sudo apt-get update
18+
- name: install python
19+
run: sudo apt-get install python3 python3-pip python3-dev python3-setuptools build-essential meson ninja-build sphinx-doc sphinx-common python-configparser
20+
- name: install build essentials
21+
run: sudo apt-get install -y ninja-build glib-2.0-dev libudev-dev libyaml-dev libsystemd-dev clang gperf libcap-dev build-essential
22+
- name: build
23+
run: make

.lgtm.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/netlog/netlog-manager.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ int manager_new(Manager **ret, const char *state_file, const char *cursor) {
484484
if (r < 0)
485485
return r;
486486

487-
*ret = m;
488-
m = NULL;
489-
487+
*ret = TAKE_PTR(m);
490488
return 0;
491489
}

src/netlog/netlog-network.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ int manager_open_network_socket(Manager *m) {
207207
if (SYSLOG_TRANSMISSION_PROTOCOL_TCP == m->protocol) {
208208
union sockaddr_union sa;
209209
socklen_t salen;
210+
210211
switch (m->address.sockaddr.sa.sa_family) {
211212
case AF_INET:
212213
sa = (union sockaddr_union) {
@@ -228,6 +229,7 @@ int manager_open_network_socket(Manager *m) {
228229
r = -EAFNOSUPPORT;
229230
goto fail;
230231
}
232+
231233
r = connect(m->socket, &m->address.sockaddr.sa, salen);
232234
if (r < 0 && errno != EINPROGRESS) {
233235
r = -errno;
@@ -239,7 +241,7 @@ int manager_open_network_socket(Manager *m) {
239241
return r;
240242
}
241243

242-
r = fd_nonblock(m->socket, 1);
244+
r = fd_nonblock(m->socket, true);
243245
if (r < 0)
244246
goto fail;
245247

src/share/macro.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,15 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
399399
} \
400400
struct __useless_struct_to_allow_trailing_semicolon__
401401

402+
/* Takes inspiration from Rust's Option::take() method: reads and returns a pointer, but at the same time
403+
* resets it to NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */
404+
#define TAKE_PTR(ptr) \
405+
({ \
406+
typeof(ptr) *_pptr_ = &(ptr); \
407+
typeof(ptr) _ptr_ = *_pptr_; \
408+
*_pptr_ = NULL; \
409+
_ptr_; \
410+
})
411+
412+
402413
#include "log.h"

0 commit comments

Comments
 (0)