From: David Zeuthen Date: Tue, 6 Jan 2009 19:14:12 +0000 (-0500) Subject: slightly rework commandline tool X-Git-Tag: 0.91~48^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82714f2713afd6d8351645e1f79e5c67ace68744;p=platform%2Fupstream%2Fpolkit.git slightly rework commandline tool --- diff --git a/src/programs/Makefile.am b/src/programs/Makefile.am index b6a83cb..30aae64 100644 --- a/src/programs/Makefile.am +++ b/src/programs/Makefile.am @@ -15,18 +15,16 @@ INCLUDES = \ -D_REENTRANT \ $(NULL) -bin_PROGRAMS = polkit-verify-claim-1 +bin_PROGRAMS = polkit-1 -polkit_verify_claim_1_SOURCES = polkit-verify-claim.c +polkit_1_SOURCES = polkit.c -polkit_verify_claim_1_CFLAGS = \ +polkit_1_CFLAGS = \ $(GLIB_CFLAGS) \ - $(EGG_DBUS_CFLAGS) \ $(NULL) -polkit_verify_claim_1_LDADD = \ +polkit_1_LDADD = \ $(GLIB_LDADD) \ - $(EGG_DBUS_LDADD) \ $(top_builddir)/src/polkit/libpolkit-gobject-1.la \ $(NULL) diff --git a/src/programs/polkit-verify-claim.c b/src/programs/polkit.c similarity index 72% rename from src/programs/polkit-verify-claim.c rename to src/programs/polkit.c index fb22b6a..7b53497 100644 --- a/src/programs/polkit-verify-claim.c +++ b/src/programs/polkit.c @@ -23,16 +23,76 @@ static PolkitAuthority *authority; -static void +static gboolean opt_list_actions = FALSE; + +static GOptionEntry option_entries[] = { + {"list-actions", 'l', 0, G_OPTION_ARG_NONE, &opt_list_actions, "List registered actions", NULL }, + {NULL, }, +}; + +static gboolean list_actions (void); + +int +main (int argc, char *argv[]) +{ + gboolean ret; + GError *error; + GOptionContext *option_ctx; + + ret = FALSE; + + g_type_init (); + + option_ctx = g_option_context_new ("polkit-1"); + g_option_context_add_main_entries (option_ctx, option_entries, NULL); + g_option_context_set_summary (option_ctx, "PolicyKit commandline tool"); + error = NULL; + if (!g_option_context_parse (option_ctx, &argc, &argv, &error)) + { + g_printerr ("Error parsing options: %s\n", error->message); + g_error_free (error); + goto out; + } + + authority = polkit_authority_get (); + + if (opt_list_actions) + { + ret = list_actions (); + } + else + { + gchar *s; + + /* print usage */ + s = g_option_context_get_help (option_ctx, TRUE, NULL); + g_print ("%s", s); + g_free (s); + ret = 0; + goto out; + } + + g_object_unref (authority); + + g_option_context_free (option_ctx); + + out: + return ret ? 0 : 1; +} + +static gboolean list_actions (void) { + gboolean ret; GError *error; GList *actions; GList *l; + ret = FALSE; + error = NULL; actions = polkit_authority_enumerate_actions_sync (authority, - "", + NULL, NULL, &error); if (error != NULL) @@ -52,22 +112,10 @@ list_actions (void) g_list_foreach (actions, (GFunc) g_object_unref, NULL); g_list_free (actions); - out: - ; -} + ret = TRUE; -int -main (int argc, char *argv[]) -{ - g_type_init (); - - authority = polkit_authority_get (); - - list_actions (); - - g_object_unref (authority); - - return 0; + out: + return ret; }