Skip to content

Commit

Permalink
Fix various compiler warnings (#488)
Browse files Browse the repository at this point in the history
* Build with -Wno-format-y2k

As suggested in strftime() manpage

* Replace deprecated g_get_current_time()

* Fix unused-label warning

* Fix unused-variable warning

* Disable declaration-after-statement compiler warnings

We build with -std=c99 but for some reason these c90 warnings
still appear, ignore them

* Fix strict-prototypes compiler warning

* Fix function annotation

polkitimplicitauthorization.h:61: Warning: Polkit: out annotation takes at most one option, 2 given

* Cast away 'volatile' when passing variable to g_once_init_enter()

warning: argument 2 of ‘__atomic_load’ discards ‘volatile’ qualifier

* Return after warning with NULL callback

Fixes #478
  • Loading branch information
bluca authored Oct 9, 2024
1 parent 5a6cad0 commit 94e2b54
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 25 deletions.
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ if get_option('buildtype').contains('debug')
])
endif

compiler_c_flags += cc.get_supported_arguments([
'-Wno-format-y2k',
'-Wno-declaration-after-statement',
])

glib_req_version = '>= 2.30.0'

gio_dep = dependency('gio-2.0', version: glib_req_version)
Expand Down
2 changes: 1 addition & 1 deletion src/polkit/polkitenumtypes.c.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GType
{
static volatile gsize g_define_type_id__volatile = 0;

if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
{
static const G@Type@Value values[] = {
/*** END value-header ***/
Expand Down
2 changes: 1 addition & 1 deletion src/polkit/polkitidentity.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ polkit_identity_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;

if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
{
static const GTypeInfo info =
{
Expand Down
2 changes: 1 addition & 1 deletion src/polkit/polkitimplicitauthorization.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const gchar *polkit_implicit_authorization_to_string (PolkitIm
/**
* polkit_implicit_authorization_from_string:
* @string: A string
* @out_implicit_authorization: (out caller-allocates optional): The location of the resulting deserialization
* @out_implicit_authorization: (out caller-allocates): The location of the resulting deserialization
*/
gboolean polkit_implicit_authorization_from_string (const gchar *string,
PolkitImplicitAuthorization *out_implicit_authorization);
Expand Down
4 changes: 2 additions & 2 deletions src/polkit/polkitpermission.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum
static void process_result (PolkitPermission *permission,
PolkitAuthorizationResult *result);

static char *get_session_state();
static char *get_session_state(void);

static void on_authority_changed (PolkitAuthority *authority,
gpointer user_data);
Expand Down Expand Up @@ -490,7 +490,7 @@ changed_check_cb (GObject *source_object,
g_object_unref (permission);
}

static char *get_session_state()
static char *get_session_state(void)
{
#ifdef HAVE_LIBSYSTEMD
char *session = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/polkit/polkitsubject.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ polkit_subject_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;

if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
{
static const GTypeInfo info =
{
Expand Down
2 changes: 1 addition & 1 deletion src/polkitagent/polkitagentenumtypes.c.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GType
{
static volatile gsize g_define_type_id__volatile = 0;

if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
{
static const G@Type@Value values[] = {
/*** END value-header ***/
Expand Down
2 changes: 1 addition & 1 deletion src/polkitagent/polkitagenthelperprivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ send_dbus_message (const char *cookie, const char *user)
}

void
flush_and_wait ()
flush_and_wait (void)
{
fflush (stdout);
fflush (stderr);
Expand Down
2 changes: 1 addition & 1 deletion src/polkitagent/polkitagenthelperprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ char *read_cookie (int argc, char **argv);

gboolean send_dbus_message (const char *cookie, const char *user);

void flush_and_wait ();
void flush_and_wait (void);

#endif /* __POLKIT_AGENT_HELPER_PRIVATE_H */
2 changes: 1 addition & 1 deletion src/polkitagent/polkitagentsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _show_debug (void)
static volatile gsize has_show_debug = 0;
static gboolean show_debug_value = FALSE;

if (g_once_init_enter (&has_show_debug))
if (g_once_init_enter ((gsize*) &has_show_debug))
{
show_debug_value = (g_getenv ("POLKIT_DEBUG") != NULL);
g_once_init_leave (&has_show_debug, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/polkitbackend/polkitbackendactionlookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ polkit_backend_action_lookup_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;

if (g_once_init_enter (&g_define_type_id__volatile))
if (g_once_init_enter ((gsize*) &g_define_type_id__volatile))
{
static const GTypeInfo info =
{
Expand Down
8 changes: 4 additions & 4 deletions src/polkitbackend/polkitbackendauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ polkit_backend_authority_log (PolkitBackendAuthority *authority,
const gchar *format,
...)
{
GTimeVal now;
guint64 now;
time_t now_time;
struct tm *now_tm;
gchar time_buf[128];
Expand All @@ -1693,13 +1693,13 @@ polkit_backend_authority_log (PolkitBackendAuthority *authority,

syslog (message_log_level, "%s", message);

g_get_current_time (&now);
now_time = (time_t) now.tv_sec;
now = g_get_real_time ();
now_time = (time_t) now / G_TIME_SPAN_SECOND;
now_tm = localtime (&now_time);
strftime (time_buf, sizeof time_buf, "%H:%M:%S", now_tm);
g_print ("%s%s%s.%03d%s: %s\n",
_color_get (_COLOR_BOLD_ON), _color_get (_COLOR_FG_YELLOW),
time_buf, (gint) now.tv_usec / 1000,
time_buf, (gint) (now % G_TIME_SPAN_SECOND / G_TIME_SPAN_MILLISECOND),
_color_get (_COLOR_RESET),
message);

Expand Down
4 changes: 2 additions & 2 deletions src/polkitbackend/polkitbackendduktapeauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,9 @@ runaway_killer_common(PolkitBackendJsAuthority *authority, RunawayKillerCtx *ctx
{
int pthread_err;
gboolean cancel = FALSE;
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_t attr;
#endif
struct timespec abs_time;

#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
Expand Down Expand Up @@ -860,9 +862,7 @@ runaway_killer_common(PolkitBackendJsAuthority *authority, RunawayKillerCtx *ctx
err_clean_cond:
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
pthread_cond_destroy(&ctx->cond);
#endif
err_clean_condattr:
#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_destroy(&attr);
#endif
return FALSE;
Expand Down
8 changes: 4 additions & 4 deletions src/polkitbackend/polkitbackendinteractiveauthority.c
Original file line number Diff line number Diff line change
Expand Up @@ -3392,7 +3392,7 @@ polkit_backend_interactive_authority_enumerate_temporary_authorizations (PolkitB
GList *ret;
GList *l;
gint64 monotonic_now;
GTimeVal real_now;
gint64 real_now;

interactive_authority = POLKIT_BACKEND_INTERACTIVE_AUTHORITY (authority);
priv = polkit_backend_interactive_authority_get_instance_private (interactive_authority);
Expand Down Expand Up @@ -3431,7 +3431,7 @@ polkit_backend_interactive_authority_enumerate_temporary_authorizations (PolkitB
}

monotonic_now = g_get_monotonic_time ();
g_get_current_time (&real_now);
real_now = g_get_real_time () / G_TIME_SPAN_SECOND;

for (l = priv->temporary_authorization_store->authorizations; l != NULL; l = l->next)
{
Expand All @@ -3443,8 +3443,8 @@ polkit_backend_interactive_authority_enumerate_temporary_authorizations (PolkitB
if (!polkit_subject_equal (ta->scope, subject))
continue;

real_granted = (ta->time_granted - monotonic_now) / G_USEC_PER_SEC + real_now.tv_sec;
real_expires = (ta->time_expires - monotonic_now) / G_USEC_PER_SEC + real_now.tv_sec;
real_granted = (ta->time_granted - monotonic_now) / G_USEC_PER_SEC + real_now;
real_expires = (ta->time_expires - monotonic_now) / G_USEC_PER_SEC + real_now;

tmp_authz = polkit_temporary_authorization_new (ta->id,
ta->action_id,
Expand Down
3 changes: 3 additions & 0 deletions src/polkitbackend/polkitbackendsessionmonitor-systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ sd_source_dispatch (GSource *source,

g_warn_if_fail (callback != NULL);

if (callback == NULL)
return G_SOURCE_CONTINUE;

ret = (*callback) (user_data);

sd_login_monitor_flush (sd_source->monitor);
Expand Down
8 changes: 4 additions & 4 deletions src/programs/pkcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ do_list_or_revoke_temp_authz (gboolean revoke)
gchar *subject_cmdline;
time_t obtained;
time_t expires;
GTimeVal now;
gint64 now;
gchar *subject_str;
gchar obtained_str[64];
gchar expires_str[64];
Expand All @@ -283,15 +283,15 @@ do_list_or_revoke_temp_authz (gboolean revoke)
obtained = polkit_temporary_authorization_get_time_obtained (a);
expires = polkit_temporary_authorization_get_time_expires (a);

g_get_current_time (&now);
now = g_get_real_time () / G_TIME_SPAN_SECOND;

broken_down = localtime (&obtained);
strftime (obtained_str, sizeof (obtained_str), "%c", broken_down);
broken_down = localtime (&expires);
strftime (expires_str, sizeof (expires_str), "%c", broken_down);

obtained_rel_str = format_reltime (obtained - now.tv_sec);
expires_rel_str = format_reltime (expires - now.tv_sec);
obtained_rel_str = format_reltime (obtained - now);
expires_rel_str = format_reltime (expires - now);

g_print ("authorization id: %s\n"
"action: %s\n"
Expand Down

0 comments on commit 94e2b54

Please sign in to comment.