X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fidentity%2Fgnunet-identity.c;h=0c3f9fead280e0ec3a8d6a9d4460d65ab6398f41;hb=341c1dd692c62a88eeff34fca155ce2377677d4b;hp=23c20d91fdb512803866fb79e44adbebddbf332e;hpb=95f9076a2139f5fb042b944a0658b6cda2fa35db;p=oweals%2Fgnunet.git diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 23c20d91f..0c3f9fead 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c @@ -2,20 +2,18 @@ This file is part of GNUnet. Copyright (C) 2013 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ /** * @file identity/gnunet-identity.c @@ -29,6 +27,12 @@ #include "gnunet_util_lib.h" #include "gnunet_identity_service.h" + +/** + * Return value from main on timeout. + */ +#define TIMEOUT_STATUS_CODE 40 + /** * Handle to IDENTITY service. */ @@ -79,6 +83,11 @@ static struct GNUNET_IDENTITY_Operation *create_op; */ static struct GNUNET_IDENTITY_Operation *delete_op; +/** + * Value to return from #main(). + */ +static int global_ret; + /** * Task run on shutdown. @@ -120,7 +129,11 @@ test_finished () (NULL == set_ego) && (! list) && (! monitor) ) + { + if (TIMEOUT_STATUS_CODE == global_ret) + global_ret = 0; GNUNET_SCHEDULER_shutdown (); + } } @@ -159,9 +172,12 @@ create_finished (void *cls, *op = NULL; if (NULL != emsg) + { fprintf (stderr, _("Failed to create ego: %s\n"), emsg); + global_ret = 1; + } test_finished (); } @@ -178,9 +194,12 @@ set_done (void *cls, { set_op = NULL; if (NULL != emsg) + { fprintf (stderr, _("Failed to set default ego: %s\n"), emsg); + global_ret = 1; + } test_finished (); } @@ -257,17 +276,23 @@ print_ego (void *cls, } if ( (NULL == ego) && (! monitor) ) { - GNUNET_SCHEDULER_shutdown (); + list = 0; + test_finished (); return; } if (! (list | monitor)) return; if (NULL == ego) return; - GNUNET_IDENTITY_ego_get_public_key (ego, &pk); + GNUNET_IDENTITY_ego_get_public_key (ego, + &pk); s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); - if ( (monitor) || (NULL != identifier) ) - fprintf (stdout, "%s - %s\n", identifier, s); + if ( (monitor) || + (NULL != identifier) ) + fprintf (stdout, + "%s - %s\n", + identifier, + s); GNUNET_free (s); } @@ -281,7 +306,9 @@ print_ego (void *cls, * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { if ( (NULL == set_subsystem) ^ @@ -291,7 +318,9 @@ run (void *cls, char *const *args, const char *cfgfile, "Options -e and -s must always be specified together\n"); return; } - sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL); + sh = GNUNET_IDENTITY_connect (cfg, + &print_ego, + NULL); if (NULL != delete_ego) delete_op = GNUNET_IDENTITY_delete (sh, delete_ego, @@ -302,7 +331,8 @@ run (void *cls, char *const *args, const char *cfgfile, create_ego, &create_finished, &create_op); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); test_finished (); } @@ -317,42 +347,60 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *const *argv) { - int res; + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ('C', + "create", + "NAME", + gettext_noop ("create ego NAME"), + &create_ego), + + GNUNET_GETOPT_option_string ('D', + "delete", + "NAME", + gettext_noop ("delete ego NAME "), + &delete_ego), + + GNUNET_GETOPT_option_flag ('d', + "display", + gettext_noop ("display all egos"), + &list), + + GNUNET_GETOPT_option_string ('e', + "ego", + "NAME", + gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -s)"), + &set_ego), + + GNUNET_GETOPT_option_flag ('m', + "monitor", + gettext_noop ("run in monitor mode egos"), + &monitor), + + GNUNET_GETOPT_option_string ('s', + "set", + "SUBSYSTEM", + gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), + &set_subsystem), - static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'C', "create", "NAME", - gettext_noop ("create ego NAME"), - 1, &GNUNET_GETOPT_set_string, &create_ego}, - {'D', "delete", "NAME", - gettext_noop ("delete ego NAME "), - 1, &GNUNET_GETOPT_set_string, &delete_ego}, - {'d', "display", NULL, - gettext_noop ("display all egos"), - 0, &GNUNET_GETOPT_set_one, &list}, - {'e', "ego", "NAME", - gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -s)"), - 1, &GNUNET_GETOPT_set_string, &set_ego}, - {'m', "monitor", NULL, - gettext_noop ("run in monitor mode egos"), - 0, &GNUNET_GETOPT_set_one, &monitor}, - {'s', "set", "SUBSYSYSTEM", - gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), - 1, &GNUNET_GETOPT_set_string, &set_subsystem}, GNUNET_GETOPT_OPTION_END }; + int res; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) - return 2; - - res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity", + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) + return 4; + global_ret = TIMEOUT_STATUS_CODE; /* timeout */ + res = GNUNET_PROGRAM_run (argc, argv, + "gnunet-identity", gettext_noop ("Maintain egos"), options, &run, NULL); GNUNET_free ((void *) argv); if (GNUNET_OK != res) - return 1; - return 0; + return 3; + return global_ret; } /* end of gnunet-identity.c */