Skip to content

Commit 484bd15

Browse files
authored
Merge pull request #176 from baranyaib90/master
Yearly modernization
2 parents 8afbba7 + ae93cd1 commit 484bd15

File tree

8 files changed

+45
-35
lines changed

8 files changed

+45
-35
lines changed

.github/workflows/cmake.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
# well on Windows or Mac. You can convert this to a matrix build if you need
99
# cross-platform coverage.
1010
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-24.04
1212

1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
compiler: [gcc-12, clang-15]
16+
compiler: [gcc-13, clang-18]
1717

1818
steps:
1919
- uses: actions/checkout@main
@@ -22,18 +22,18 @@ jobs:
2222
run: sudo apt-get update
2323

2424
- name: Setup Dependencies
25-
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-15 ${{ matrix.compiler }} dnsutils python3-pip valgrind
25+
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy dnsutils python3-pip python3-venv valgrind ${{ matrix.compiler }}
2626

27-
- name: Setup Robot Framework
28-
run: sudo pip3 install robotframework
27+
- name: Setup Python Virtual Environment
28+
run: python3 -m venv ${{github.workspace}}/venv
2929

30-
- name: Set clang-tidy
31-
run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 100
30+
- name: Setup Robot Framework
31+
run: ${{github.workspace}}/venv/bin/pip3 install robotframework
3232

3333
- name: Configure CMake
3434
env:
3535
CC: ${{ matrix.compiler }}
36-
run: cmake -D CMAKE_BUILD_TYPE=Debug -B ${{github.workspace}}/
36+
run: cmake -D CMAKE_BUILD_TYPE=Debug -D PYTHON3_EXE=${{github.workspace}}/venv/bin/python3 -B ${{github.workspace}}/
3737

3838
- name: Build
3939
env:
@@ -44,7 +44,7 @@ jobs:
4444
- name: Test
4545
run: make -C ${{github.workspace}}/ test ARGS="--verbose"
4646

47-
- uses: actions/upload-artifact@v3
47+
- uses: actions/upload-artifact@v4
4848
if: ${{ success() || failure() }}
4949
with:
5050
name: robot-logs-${{ matrix.compiler }}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if(USE_CLANG_TIDY)
9595
message(STATUS "clang-tidy not found.")
9696
else()
9797
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
98-
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix" "-checks=*,-cert-err34-c,-readability-identifier-length,-altera-unroll-loops,-bugprone-easily-swappable-parameters,-concurrency-mt-unsafe,-*magic-numbers,-hicpp-signed-bitwise,-readability-function-cognitive-complexity,-altera-id-dependent-backward-branch,-google-readability-todo")
98+
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix" "-fix-errors" "-checks=*,-cert-err34-c,-readability-identifier-length,-altera-unroll-loops,-bugprone-easily-swappable-parameters,-concurrency-mt-unsafe,-*magic-numbers,-hicpp-signed-bitwise,-readability-function-cognitive-complexity,-altera-id-dependent-backward-branch,-google-readability-todo,-misc-include-cleaner")
9999
endif()
100100
else()
101101
message(STATUS "Not using clang-tidy.")

https_dns_proxy.service.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ After=network.target
77

88
[Service]
99
Type=simple
10+
DynamicUser=yes
1011
Restart=on-failure
1112
ExecStart=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/https_dns_proxy \
12-
-u nobody -g nogroup -v -v ${SERVICE_EXTRA_OPTIONS}
13+
-v -v ${SERVICE_EXTRA_OPTIONS}
1314
TimeoutStopSec=10
1415

1516
[Install]

src/dns_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <ares.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
2-
#include <arpa/inet.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
32
#include <errno.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
43
#include <netdb.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
54
#include <netinet/in.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
5+
#include <stdint.h>
66
#include <string.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
77
#include <sys/socket.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
88
#include <unistd.h> // NOLINT(llvmlibc-restrict-system-libc-headers)

src/https_client.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ev.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
44
#include <math.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
55
#include <netinet/in.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
6+
#include <stdint.h>
67
#include <stdio.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
78
#include <string.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
89
#include <sys/socket.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
@@ -11,6 +12,7 @@
1112
#include "https_client.h"
1213
#include "logging.h"
1314
#include "options.h"
15+
#include "stat.h"
1416

1517
#define DOH_CONTENT_TYPE "application/dns-message"
1618
enum {
@@ -162,7 +164,7 @@ int https_curl_debug(CURL __attribute__((unused)) * handle, curl_infotype type,
162164
char *data, size_t size, void *userp)
163165
{
164166
GET_PTR(struct https_fetch_ctx, ctx, userp);
165-
const char *prefix = "";
167+
const char *prefix = NULL;
166168

167169
switch (type) {
168170
case CURLINFO_TEXT:
@@ -458,11 +460,11 @@ static int https_fetch_ctx_process_response(https_client_t *client,
458460
DLOG_REQ("CURLINFO_HTTP_VERSION: %s", http_version_str(long_resp));
459461
}
460462

461-
res = curl_easy_getinfo(ctx->curl, CURLINFO_PROTOCOL, &long_resp);
463+
res = curl_easy_getinfo(ctx->curl, CURLINFO_SCHEME, &str_resp);
462464
if (res != CURLE_OK) {
463-
ELOG_REQ("CURLINFO_PROTOCOL: %s", curl_easy_strerror(res));
464-
} else if (long_resp != CURLPROTO_HTTPS) {
465-
DLOG_REQ("CURLINFO_PROTOCOL: %d", long_resp);
465+
ELOG_REQ("CURLINFO_SCHEME: %s", curl_easy_strerror(res));
466+
} else if (strcasecmp(str_resp, "https") != 0) {
467+
DLOG_REQ("CURLINFO_SCHEME: %s", str_resp);
466468
}
467469

468470
double namelookup_time = NAN;

src/logging.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/* logs of this severity or higher are flushed immediately after write */
1111
#define LOG_FLUSH_LEVEL LOG_WARNING
1212

13-
static FILE *logf = NULL; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
13+
static FILE *logfile = NULL; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
1414
static int loglevel = LOG_ERROR; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
1515
static ev_timer logging_timer; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
1616

@@ -23,11 +23,11 @@ static const char * const SeverityStr[] = {
2323
"[F]"
2424
};
2525

26-
static void logging_timer_cb(struct ev_loop __attribute__((unused)) *loop,
26+
void logging_timer_cb(struct ev_loop __attribute__((unused)) *loop,
2727
ev_timer __attribute__((unused)) *w,
2828
int __attribute__((unused)) revents) {
29-
if (logf) {
30-
(void)fflush(logf);
29+
if (logfile) {
30+
(void)fflush(logfile);
3131
}
3232
}
3333

@@ -47,18 +47,18 @@ void logging_flush_cleanup(struct ev_loop *loop) {
4747
}
4848

4949
void logging_init(int fd, int level) {
50-
if (logf) {
51-
(void)fclose(logf);
50+
if (logfile) {
51+
(void)fclose(logfile);
5252
}
53-
logf = fdopen(fd, "a");
53+
logfile = fdopen(fd, "a");
5454
loglevel = level;
5555
}
5656

5757
void logging_cleanup(void) {
58-
if (logf) {
59-
(void)fclose(logf);
58+
if (logfile) {
59+
(void)fclose(logfile);
6060
}
61-
logf = NULL;
61+
logfile = NULL;
6262
}
6363

6464
int logging_debug_enabled(void) {
@@ -73,24 +73,28 @@ void _log(const char *file, int line, int severity, const char *fmt, ...) {
7373
if (severity < 0 || severity >= LOG_MAX) {
7474
FLOG("Unknown log severity: %d\n", severity);
7575
}
76-
if (!logf) {
77-
logf = fdopen(STDOUT_FILENO, "w");
76+
if (!logfile) {
77+
logfile = fdopen(STDOUT_FILENO, "w");
7878
}
7979

8080
struct timeval tv;
8181
gettimeofday(&tv, NULL);
82-
(void)fprintf(logf, "%s %8"PRIu64".%06"PRIu64" %s:%d ", SeverityStr[severity],
82+
83+
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
84+
(void)fprintf(logfile, "%s %8"PRIu64".%06"PRIu64" %s:%d ", SeverityStr[severity],
8385
(uint64_t)tv.tv_sec,
8486
(uint64_t)tv.tv_usec, file, line);
8587

8688
va_list args;
8789
va_start(args, fmt);
88-
(void)vfprintf(logf, fmt, args);
90+
(void)vfprintf(logfile, fmt, args);
8991
va_end(args);
90-
(void)fprintf(logf, "\n");
92+
93+
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
94+
(void)fprintf(logfile, "\n");
9195

9296
if (severity >= LOG_FLUSH_LEVEL) {
93-
(void)fflush(logf);
97+
(void)fflush(logfile);
9498
}
9599
if (severity == LOG_FATAL) {
96100
#ifdef DEBUG

src/logging.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef _LOGGING_H_
22
#define _LOGGING_H_
33

4+
#include <stdio.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
45
#include <stdlib.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
5-
#include <ev.h>
6+
#include <ev.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
67

78
#ifdef __cplusplus
89
extern "C" {
910
#endif
11+
1012
// Initializes logging.
1113
// Writes logs to descriptor 'fd' for log levels above or equal to 'level'.
1214
void logging_init(int fd, int level);
@@ -23,6 +25,7 @@ int logging_debug_enabled(void);
2325

2426
// Internal. Don't use.
2527
void _log(const char *file, int line, int severity, const char *fmt, ...);
28+
2629
#ifdef __cplusplus
2730
}
2831
#endif

tests/robot/functional_tests.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Start Dig
6464
[Arguments] ${domain}=google.com
6565
${handle} = Start Process dig +timeout\=${dig_timeout} +retry\=${dig_retry} @127.0.0.1 -p ${PORT} ${domain}
6666
... stderr=STDOUT alias=dig
67-
[Return] ${handle}
67+
RETURN ${handle}
6868

6969
Stop Dig
7070
[Arguments] ${handle}

0 commit comments

Comments
 (0)