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

Fix a couple of compilation warnings when building with clang #520

Merged
merged 5 commits into from
Nov 6, 2024
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
21 changes: 11 additions & 10 deletions .github/workflows/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ set -eux
set -o pipefail

# TODO
# - enable --werror
# - currently there's a lot of warnings which need to be taken care of first
# - re-enable test-polkitbackendjsauthority
# - mocklibc overrides LD_PRELOAD, causing ASan to report false positives
# (with asan_verify_no_link=0)
# - re-enable unit tests built with ASan + sanitizers
# - currently polkit fails to build with clang >= 17 completely, and
# with older clang it needs to be built with -shared-libasan, which
# requires another set of tweaks to the environment
# - drop -Wno-deprecated-declarations

PHASE="${1:?}"
COMMON_BUILD_OPTS=(
Expand Down Expand Up @@ -40,9 +32,17 @@ case "$PHASE" in
)

for opt in "${BUILD_TEST_FLAGS[@]}"; do
COMPILER_FLAGS=(-Wno-deprecated-declarations)

if [[ "$opt" != --optimization=0 ]]; then
COMPILER_FLAGS+=(-D_FORTIFY_SOURCE=2)
fi

meson setup build \
-Dman=true \
-Dcpp_args="-D_FORTIFY_SOURCE=2" \
--werror \
-Dc_args="${COMPILER_FLAGS[*]}" \
-Dcpp_args="${COMPILER_FLAGS[*]}" \
"${COMMON_BUILD_OPTS[@]}" \
"$opt"
meson compile -C build -v
Expand All @@ -55,6 +55,7 @@ case "$PHASE" in

meson setup build \
-Dman=true \
-Dc_args="-D_FORTIFY_SOURCE=2" \
-Dcpp_args="-D_FORTIFY_SOURCE=2" \
"${COMMON_BUILD_OPTS[@]}"

Expand Down
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ compiler_c_flags += cc.get_supported_arguments([
'-Wno-declaration-after-statement',
])

if cc.get_id() == 'gcc'
compiler_c_flags += cc.get_supported_arguments([
# -Wunused-result can't be suppressed by using (void) in gcc, so let's disable it for now
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
'-Wno-unused-result',
])
endif

glib_req_version = '>= 2.30.0'

gio_dep = dependency('gio-2.0', version: glib_req_version)
Expand Down
62 changes: 31 additions & 31 deletions src/polkitbackend/polkitbackendactionpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,44 +260,44 @@ polkit_backend_action_pool_set_property (GObject *object,
switch (prop_id)
{
case PROP_DIRECTORIES:

const gchar **dir_names = (const gchar**) g_value_get_boxed (value);

for (int n = 0; dir_names[n] != NULL; n++)
{
GFile *file;
GFileMonitor *monitor;
GError *error = NULL;
const gchar **dir_names = (const gchar**) g_value_get_boxed (value);

const gchar *dir_name = dir_names[n];
for (int n = 0; dir_names[n] != NULL; n++)
{
GFile *file;
GFileMonitor *monitor;
GError *error = NULL;

file = g_file_new_for_path (dir_name);
priv->directories = g_list_prepend (priv->directories, file);
const gchar *dir_name = dir_names[n];

monitor = g_file_monitor_directory (file,
G_FILE_MONITOR_NONE,
NULL,
&error);
if (monitor == NULL)
{
g_warning ("Error monitoring actions directory: %s", error->message);
g_error_free (error);
}
else
{
g_signal_connect (monitor,
"changed",
(GCallback) dir_monitor_changed,
pool);
priv->dir_monitors = g_list_prepend (priv->dir_monitors, monitor);
}
}
file = g_file_new_for_path (dir_name);
priv->directories = g_list_prepend (priv->directories, file);

priv->directories = g_list_reverse(priv->directories);
priv->dir_monitors = g_list_reverse(priv->dir_monitors);
monitor = g_file_monitor_directory (file,
G_FILE_MONITOR_NONE,
NULL,
&error);
if (monitor == NULL)
{
g_warning ("Error monitoring actions directory: %s", error->message);
g_error_free (error);
}
else
{
g_signal_connect (monitor,
"changed",
(GCallback) dir_monitor_changed,
pool);
priv->dir_monitors = g_list_prepend (priv->dir_monitors, monitor);
}
}

break;
priv->directories = g_list_reverse(priv->directories);
priv->dir_monitors = g_list_reverse(priv->dir_monitors);

break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down
1 change: 1 addition & 0 deletions src/polkitbackend/polkitbackendauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ _color_get (_Color color)

/* ---------------------------------------------------------------------------------------------------- */

G_GNUC_PRINTF(3, 4)
void
polkit_backend_authority_log (PolkitBackendAuthority *authority,
const guint message_log_level,
Expand Down
4 changes: 2 additions & 2 deletions src/polkitbackend/polkitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ become_user (const gchar *user,
goto out;
}

setregid (pw->pw_gid, pw->pw_gid);
setreuid (pw->pw_uid, pw->pw_uid);
(void) setregid (pw->pw_gid, pw->pw_gid);
(void) setreuid (pw->pw_uid, pw->pw_uid);
if ((geteuid () != pw->pw_uid) || (getuid () != pw->pw_uid) ||
(getegid () != pw->pw_gid) || (getgid () != pw->pw_gid))
{
Expand Down
7 changes: 4 additions & 3 deletions src/programs/pkexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ usage (int argc, char *argv[])

/* ---------------------------------------------------------------------------------------------------- */

G_GNUC_PRINTF(3, 4)
static void
log_message (gint level,
gboolean print_to_stderr,
Expand Down Expand Up @@ -967,7 +968,7 @@ main (int argc, char *argv[])
/* if not changing to uid 0, become uid 0 before changing to the user */
if (pw->pw_uid != 0)
{
setreuid (0, 0);
(void) setreuid (0, 0);
if ((geteuid () != 0) || (getuid () != 0))
{
g_printerr ("Error becoming uid 0: %s\n", g_strerror (errno));
Expand Down Expand Up @@ -1020,8 +1021,8 @@ main (int argc, char *argv[])
g_printerr ("Error initializing groups for %s: %s\n", pw->pw_name, g_strerror (errno));
goto out;
}
setregid (pw->pw_gid, pw->pw_gid);
setreuid (pw->pw_uid, pw->pw_uid);
(void) setregid (pw->pw_gid, pw->pw_gid);
(void) setreuid (pw->pw_uid, pw->pw_uid);
if ((geteuid () != pw->pw_uid) || (getuid () != pw->pw_uid) ||
(getegid () != pw->pw_gid) || (getgid () != pw->pw_gid))
{
Expand Down