Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/code-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
-Dopenssl=false \
-Ddbus=false \
-Dandroid-log=true \
-Dlandlock-monitor=true \
--cross-file aarch64-android-api30.txt

meson compile -C build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
sudo apt-get install -y -qq build-essential pipx python3-venv pkg-config cmake docbook2x \
python3-pip pipx jq
sudo npm install -g conventional-changelog-cli
conventional-changelog -i CHANGELOG.md -s
conventional-changelog -o CHANGELOG.md -r 2
pipx ensurepath
pipx install meson==0.61
pipx install ninja
Expand Down Expand Up @@ -74,6 +74,7 @@ jobs:
-Dopenssl=true \
-Ddbus=false \
-Dandroid-log=true \
-Dlandlock-monitor=true \
--cross-file aarch64-android-api30.txt

meson compile -C build
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@

# Release tarballs.
lxc-*.tar.gz*
/.github/workflows
3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ if have
endif
endif

## NDK doesn't implement thread_setcancelstate functions, and is only used as a placeholder here
have = cc.has_function('pthread_kill', prefix: '#include <pthread.h>')
have = cc.has_function('pthread_setcancelstate', prefix: '#include <pthread.h>')
srcconf.set10('HAVE_PTHREAD_SETCANCELSTATE', have)

have = cc.has_function('rand_r')
Expand Down
20 changes: 3 additions & 17 deletions src/include/getgrgid_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,9 @@

#define FIX(x) (gr->gr_##x = gr->gr_##x - line + buf)

#define SIG_CANCEL_SIGNAL SIGUSR1
#define PTHREAD_CANCEL_ENABLE 1
#define PTHREAD_CANCEL_DISABLE 0

static int pthread_setcancelstate(int state, int *oldstate) {
sigset_t new, old;
int ret;
sigemptyset (&new);
sigaddset (&new, SIG_CANCEL_SIGNAL);

ret = pthread_sigmask(state == PTHREAD_CANCEL_ENABLE ? SIG_BLOCK : SIG_UNBLOCK, &new , &old);
if(oldstate != NULL)
{
*oldstate =sigismember(&old,SIG_CANCEL_SIGNAL) == 0 ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE;
}
return ret;
}
#if !HAVE_PTHREAD_SETCANCELSTATE
#include <pthread_ext.h>
#endif

static unsigned atou(char **s)
{
Expand Down
6 changes: 6 additions & 0 deletions src/include/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ if srcconf.get('HAVE_HASMNTOPT') == 0
'hasmntopt.c',
'hasmntopt.h')
endif

if srcconf.get('HAVE_PTHREAD_SETCANCELSTATE') == 0
include_sources += files(
'pthread_setcancelstate.c',
'pthread_ext.h')
endif
18 changes: 18 additions & 0 deletions src/include/pthread_ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* liblxcapi
*
* SPDX-License-Identifier: LGPL-2.1+ *
*
*/

#ifndef _PTHREAD_EXT_H
#define _PTHREAD_EXT_H

#include "../lxc/compiler.h"

#ifndef PTHREAD_CANCELED
#define PTHREAD_CANCELED ((void *)-1)
#endif

__hidden extern int pthread_setcancelstate(int, int *);

#endif
29 changes: 29 additions & 0 deletions src/include/pthread_setcancelstate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* liblxcapi
*
* SPDX-License-Identifier: LGPL-2.1+ *
*
* This is not a standard implementation.
* It only protects getgrgid_r().
*/

#include <pthread.h>
#include "pthread_ext.h"

static const int signals[] = {
SIGINT,
SIGTERM,
SIGQUIT,
};

int pthread_setcancelstate(int state, int *oldstate)
{
sigset_t signal_set;
sigset_t old_mask;
sigemptyset(&signal_set);

for (size_t i = 0; i < sizeof(signals)/sizeof(signals[0]); i++)
sigaddset(&signal_set, signals[i]);

int operation = (state == 1) ? SIG_UNBLOCK : SIG_BLOCK;
return pthread_sigmask(operation, &signal_set, &old_mask);
}
9 changes: 8 additions & 1 deletion src/lxc/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
#include "strlcpy.h"
#endif

#if IS_BIONIC
#include <pthread_ext.h>
#endif

#if HAVE_LANDLOCK_MONITOR
#ifndef landlock_create_ruleset
static inline int
Expand Down Expand Up @@ -729,10 +733,13 @@ int lxc_handler_mainloop(struct lxc_async_descr *descr, struct lxc_handler *hand
pthread_t thread;

/* Skip protection if a seccomp proxy is setup. */
#if HAVE_DECL_SECCOMP_NOTIFY_FD
if (!handler || !handler->conf || handler->conf->seccomp.notifier.proxy_fd > 0) {
/* Landlock not supported when seccomp notify is in use. */
SYSERROR("Skipping Landlock due to seccomp notify");

#else
if (!handler || !handler->conf) {
#endif
/* We don't need to use thread then */
return lxc_mainloop(descr, -1);
}
Expand Down