Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor: update to the latest systemd_ctypes #19927

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
2 changes: 2 additions & 0 deletions containers/flatpak/test/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extend = "../../../pyproject.toml"

[lint]
ignore = [
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`
]
2 changes: 2 additions & 0 deletions pkg/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extend = "../pyproject.toml"

[lint]
ignore = [
"E501", # https://github.com/charliermarsh/ruff/issues/3206#issuecomment-1562681390

Expand Down
20 changes: 11 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ disable = [
]

[tool.ruff]
exclude = [
".git/",
"modules/",
"node_modules/",
]
line-length = 118
src = []

[tool.ruff.lint]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
Expand All @@ -52,11 +61,6 @@ select = [
"W", # warnings (mostly whitespace)
"YTT", # flake8-2020
]
exclude = [
".git/",
"modules/",
"node_modules/",
]
ignore = [
"A003", # Class attribute is shadowing a python builtin
"B011", # Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
Expand All @@ -66,14 +70,12 @@ ignore = [
"TCH001", # Move application import into a type-checking block
"TCH002", # Move third-party import `..packages.Packages` into a type-checking block
]
line-length = 118
src = []

[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["cockpit"]

[tool.pytest.ini_options]
Expand Down
3 changes: 2 additions & 1 deletion src/cockpit/channels/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from cockpit._vendor.systemd_ctypes import Handle, PathWatch
from cockpit._vendor.systemd_ctypes.inotify import Event as InotifyEvent
from cockpit._vendor.systemd_ctypes.pathwatch import Listener as PathWatchListener

from ..channel import Channel, ChannelError, GeneratorChannel
from ..jsonutil import (
Expand Down Expand Up @@ -298,7 +299,7 @@ class Follow(enum.Enum):
YES = True


class FsInfoChannel(Channel):
class FsInfoChannel(Channel, PathWatchListener):
payload = 'fsinfo'

# Options (all get set in `do_open()`)
Expand Down
32 changes: 17 additions & 15 deletions src/common/cockpitwebresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ cockpit_web_response_new (GIOStream *io,
const gchar *original_path,
const gchar *path,
GHashTable *in_headers,
const gchar *method,
const gchar *protocol)
{
CockpitWebResponse *self;
Expand Down Expand Up @@ -233,6 +234,7 @@ cockpit_web_response_new (GIOStream *io,
self->url_root = NULL;
self->full_path = g_strdup (path);
self->path = self->full_path;
cockpit_web_response_set_method (self, method);

if (path && original_path)
{
Expand Down Expand Up @@ -267,6 +269,7 @@ cockpit_web_response_set_method (CockpitWebResponse *response,
const gchar *method)
{
g_return_if_fail (g_strcmp0 (method, "GET") == 0 || g_strcmp0 (method, "HEAD") == 0);
g_free (response->method);
response->method = g_strdup (method);
}

Expand Down Expand Up @@ -1089,10 +1092,9 @@ cockpit_web_response_error (CockpitWebResponse *self,
...)
{
va_list var_args;
gchar *reason = NULL;
gchar *escaped = NULL;
g_autofree gchar *reason = NULL;
g_autofree gchar *escaped = NULL;
const gchar *message;
GList *output, *l;

g_return_if_fail (COCKPIT_IS_WEB_RESPONSE (self));

Expand Down Expand Up @@ -1147,10 +1149,6 @@ cockpit_web_response_error (CockpitWebResponse *self,

g_debug ("%s: returning error: %u %s", self->logname, code, message);

extern const char *cockpit_webresponse_fail_html_text;
g_autoptr(GBytes) input = g_bytes_new_static (cockpit_webresponse_fail_html_text, strlen (cockpit_webresponse_fail_html_text));
output = cockpit_template_expand (input, "@@", "@@", substitute_message, (gpointer) message);

/* If sending arbitrary messages, make sure they're escaped */
if (reason)
{
Expand All @@ -1170,17 +1168,21 @@ cockpit_web_response_error (CockpitWebResponse *self,
cockpit_web_response_headers (self, code, message, -1, "Content-Type", "text/html; charset=utf8", NULL);
}

for (l = output; l != NULL; l = g_list_next (l))
if (g_str_equal (self->method, "GET"))
{
if (!cockpit_web_response_queue (self, l->data))
break;
extern const char *cockpit_webresponse_fail_html_text;
g_autoptr(GBytes) input = g_bytes_new_static (cockpit_webresponse_fail_html_text, strlen (cockpit_webresponse_fail_html_text));
g_autolist(GBytes) output = cockpit_template_expand (input, "@@", "@@", substitute_message, (gpointer) message);

for (GList *l = output; l != NULL; l = g_list_next (l))
{
if (!cockpit_web_response_queue (self, l->data))
/* error: early exit */
return;
}
}
if (l == NULL)
cockpit_web_response_complete (self);
g_list_free_full (output, (GDestroyNotify)g_bytes_unref);

g_free (reason);
g_free (escaped);
cockpit_web_response_complete (self);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/common/cockpitwebresponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CockpitWebResponse * cockpit_web_response_new (GIOStream *io,
const gchar *original_path,
const gchar *path,
GHashTable *in_headers,
const gchar *method,
const gchar *protocol);
void cockpit_web_response_set_method (CockpitWebResponse *response,
const gchar *method);
Expand Down
5 changes: 3 additions & 2 deletions src/common/cockpitwebserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ cockpit_web_request_process (CockpitWebRequest *self,
}
}

self->method = method;

if (self->delayed_reply)
{
cockpit_web_request_process_delayed_reply (self, path, headers);
Expand All @@ -844,7 +846,6 @@ cockpit_web_request_process (CockpitWebRequest *self,

self->original_path = path_copy;
self->path = path_copy + self->web_server->url_root->len;
self->method = method;
self->headers = headers;
self->host = host;

Expand Down Expand Up @@ -1288,7 +1289,7 @@ CockpitWebResponse *
cockpit_web_request_respond (CockpitWebRequest *self)
{
return cockpit_web_response_new (self->io, self->original_path, self->path, self->headers,
cockpit_web_request_get_protocol (self));
self->method, cockpit_web_request_get_protocol (self));
}

const gchar *
Expand Down
20 changes: 10 additions & 10 deletions src/common/test-webresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ setup (TestCase *tc,
g_hash_table_insert (headers, g_strdup (fixture->header), g_strdup (fixture->value));
}

tc->response = cockpit_web_response_new (io, path, path, headers,
tc->response = cockpit_web_response_new (io, path, path, headers, "GET",
(fixture && fixture->for_tls_proxy) ? "https" : "http");

if (headers)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ test_pop_path (TestPlain *tc,
gchar *part;
const gchar *start = "/cockpit/@localhost/another/test.html";

response = cockpit_web_response_new (tc->io, start, start, tc->headers, NULL);
response = cockpit_web_response_new (tc->io, start, start, tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, start);
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, NULL);

Expand Down Expand Up @@ -1142,7 +1142,7 @@ test_pop_path_root (TestPlain *tc,
CockpitWebResponse *response;
gchar *part;

response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/");

part = cockpit_web_response_pop_path (response);
Expand All @@ -1161,7 +1161,7 @@ test_skip_path (TestPlain *tc,
CockpitWebResponse *response;
const gchar *start = "/cockpit/@localhost/another/test.html";

response = cockpit_web_response_new (tc->io, start, start, tc->headers, NULL);
response = cockpit_web_response_new (tc->io, start, start, tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/cockpit/@localhost/another/test.html");

g_assert (cockpit_web_response_skip_path (response) == TRUE);
Expand Down Expand Up @@ -1189,7 +1189,7 @@ test_skip_path_root (TestPlain *tc,
{
CockpitWebResponse *response;

response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/");

g_assert (cockpit_web_response_skip_path (response) == FALSE);
Expand All @@ -1205,31 +1205,31 @@ test_removed_prefix (TestPlain *tc,
{
CockpitWebResponse *response;

response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/", "/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/");
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, NULL);
cockpit_web_response_abort (response);
g_clear_object (&response);

response = cockpit_web_response_new (tc->io, "/path/", "/path/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/path/", "/path/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/path/");
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, NULL);
cockpit_web_response_abort (response);
g_clear_object (&response);

response = cockpit_web_response_new (tc->io, "/path/path2/", "/path2/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/path/path2/", "/path2/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/path2/");
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, "/path");
cockpit_web_response_abort (response);
g_clear_object (&response);

response = cockpit_web_response_new (tc->io, "/mis/", "/match/", tc->headers, NULL);
response = cockpit_web_response_new (tc->io, "/mis/", "/match/", tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, "/match/");
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, NULL);
cockpit_web_response_abort (response);
g_clear_object (&response);

response = cockpit_web_response_new (tc->io, NULL, NULL, tc->headers, NULL);
response = cockpit_web_response_new (tc->io, NULL, NULL, tc->headers, "GET", NULL);
g_assert_cmpstr (cockpit_web_response_get_path (response), ==, NULL);
g_assert_cmpstr (cockpit_web_response_get_url_root (response), ==, NULL);
cockpit_web_response_abort (response);
Expand Down
4 changes: 2 additions & 2 deletions src/tls/test-socket-activation-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trap "kill $HELPER_PID; rm -r '$SOCKET_DIR'" EXIT INT QUIT PIPE

# wait until it is ready
for timeout in `seq 50`; do
curl --silent --head --unix "$SOCKET_DIR/http.sock" http://dummy/cockpit/login >/dev/null && break
curl --silent --head --unix-socket "$SOCKET_DIR/http.sock" http://dummy/cockpit/login >/dev/null && break
sleep 0.2
done

Expand All @@ -26,7 +26,7 @@ REDIRECT="HTTP/1.1 301"

# args: <socketname> <expected output>
expect_curl() {
OUT=$(curl --silent --show-error --head --unix "$SOCKET_DIR/$1" http://dummy/cockpit/login)
OUT=$(curl --silent --show-error --head --unix-socket "$SOCKET_DIR/$1" http://dummy/cockpit/login)
if ! echo "$OUT" | grep -q "$2"; then
echo "FAIL: output does not contain $2" >&2
echo "$OUT" >&2
Expand Down
Loading
Loading