Skip to content

Commit 116099e

Browse files
Hu Yadil0kod
authored andcommitted
selftests/landlock: Fix net_test build with old libc
One issue comes up while building selftest/landlock/net_test on my side (gcc 7.3/glibc-2.28/kernel-4.19). net_test.c: In function ‘set_service’: net_test.c:91:45: warning: implicit declaration of function ‘gettid’; [-Wimplicit-function-declaration] "_selftests-landlock-net-tid%d-index%d", gettid(), ^~~~~~ getgid net_test.c:(.text+0x4e0): undefined reference to `gettid' Signed-off-by: Hu Yadi <hu.yadi@h3c.com> Suggested-by: Jiao <jiaoxupo@h3c.com> Reviewed-by: Berlin <berlin@h3c.com> Fixes: a549d05 ("selftests/landlock: Add network tests") Link: https://lore.kernel.org/r/20240123062621.25082-1-hu.yadi@h3c.com [mic: Cosmetic fixes] Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 6613476 commit 116099e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

tools/testing/selftests/landlock/net_test.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string.h>
1818
#include <sys/prctl.h>
1919
#include <sys/socket.h>
20+
#include <sys/syscall.h>
2021
#include <sys/un.h>
2122

2223
#include "common.h"
@@ -54,6 +55,11 @@ struct service_fixture {
5455
};
5556
};
5657

58+
static pid_t sys_gettid(void)
59+
{
60+
return syscall(__NR_gettid);
61+
}
62+
5763
static int set_service(struct service_fixture *const srv,
5864
const struct protocol_variant prot,
5965
const unsigned short index)
@@ -88,7 +94,7 @@ static int set_service(struct service_fixture *const srv,
8894
case AF_UNIX:
8995
srv->unix_addr.sun_family = prot.domain;
9096
sprintf(srv->unix_addr.sun_path,
91-
"_selftests-landlock-net-tid%d-index%d", gettid(),
97+
"_selftests-landlock-net-tid%d-index%d", sys_gettid(),
9298
index);
9399
srv->unix_addr_len = SUN_LEN(&srv->unix_addr);
94100
srv->unix_addr.sun_path[0] = '\0';

0 commit comments

Comments
 (0)