Author: mvidner Date: Fri Aug 3 17:32:52 2007 New Revision: 39952 URL: http://svn.opensuse.org/viewcvs/yast?rev=39952&view=rev Log: Create server before client, using the UI namespace exception, so that the client code later finds the UI namespace. Factored out of main: parse_{client,server}_and_options Modified: branches/tmp/mvidner/ui-as-namespace/core/liby2/src/genericfrontend.cc Modified: branches/tmp/mvidner/ui-as-namespace/core/liby2/src/genericfrontend.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mvidner/ui-as-namespace/core/liby2/src/genericfrontend.cc?rev=39952&r1=39951&r2=39952&view=diff ============================================================================== --- branches/tmp/mvidner/ui-as-namespace/core/liby2/src/genericfrontend.cc (original) +++ branches/tmp/mvidner/ui-as-namespace/core/liby2/src/genericfrontend.cc Fri Aug 3 17:32:52 2007 @@ -109,14 +109,12 @@ * @param m the message to be logged */ #if BLOCXX_LIBRARY_VERSION >= 5 - virtual void doProcessLogMessage(const blocxx::String & f, + virtual void doProcessLogMessage(const blocxx::String & /*f*/, const blocxx::LogMessage& m) const - { - (void)f; #else virtual void doProcessLogMessage(const blocxx::LogMessage& m) const - { #endif + { loglevel_t level = LOG_DEBUG; if (m.category == blocxx::Logger::STR_FATAL_CATEGORY || m.category == blocxx::Logger::STR_ERROR_CATEGORY) @@ -165,156 +163,18 @@ }; static logger_initializer initialize_logger; - -int -main (int argc, char **argv) +void +parse_client_and_options (int argc, char ** argv, int& arg, char *& client_name, YCPList& arglist) { - if (!argv[0]) - { - fprintf (stderr, "Missing argv[0]. It is a NULL pointer."); - exit (5); - } - - progname = basename (argv[0]); // get program name - - // Ignore SIGPIPE. No use in signals. Signals can't be assigned to - // components - signal(SIGPIPE, SIG_IGN); - - // Give some output for the SIGSEGV - // and other signals too, #238172 - // Note that USR1 and USR2 are handled by the logger. - signal (SIGHUP, signal_handler); - signal (SIGINT, signal_handler); - signal (SIGQUIT, signal_handler); - signal (SIGILL , signal_handler); - signal (SIGABRT, signal_handler); - signal (SIGFPE, signal_handler); - signal (SIGSEGV, signal_handler); - signal (SIGTERM, signal_handler); - - if (argc < 2) { - fprintf (stderr, "\nToo few arguments"); - print_usage(); - exit (1); - } - - if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) { - print_help (); - exit (0); - } - - // client _AND_ server must be given - if (argc < 3) - { - fprintf (stderr, "\nPlease give client and server as arguments"); - print_usage(); - exit(5); - } - - // Scan all options for -l/--logfile. They must be honored BEFORE - // the logger is used the first time. - for (int arg = 1; arg < argc; arg++) - { - if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) - { - arg++; // switch to filename - - if (arg >= argc) - { - print_error ("Option %s is missing an argument", argv[arg-1]); - exit(5); - } - - set_log_filename( argv[arg] ); // set logfile given in command line - } - if (!strcmp(argv[arg], "-c") || !strcmp(argv[arg], "--logconf")) - { - arg++; // switch to filename - - if (arg >= argc) - { - print_error ("Option %s is missing an argument", argv[arg-1]); - exit(5); - } - - set_log_conf( argv[arg] ); - } - } - - // set a defined umask - umask (0022); - - YCPPathSearch::initialize(); - - ostringstream argdump; - for (int arg = 1; arg < argc; arg++) - { - argdump << " '" << argv[arg] << "'"; - } - - y2milestone ("Launched YaST2 component '%s'%s", progname, argdump.str().c_str()); - - // Now evaluate command line options in sequence - - int arg = 1; - - // The first argument might be the log option or MUST be the client name - if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) - { - // Logfile already done at program start --> ignore here - arg+=2; // skip over logfilename - } - if (!strcmp(argv[arg], "-c") || !strcmp(argv[arg], "--logconf")) - { - // Logfile already done at program start --> ignore here - arg+=2; // skip over logfilename - } - // The first argument might be the log option or MUST be the client name - if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) - { - // Logfile already done at program start --> ignore here - arg+=2; // skip over logfilename - } - - - // Check for namespace exceptions registration - while (!strcmp(argv[arg], "-n")) - { - arg++; - char *pos = index (argv[arg], '='); - if (pos == NULL) - { - print_error ("Option %s argument must be in format namespace=component", argv[arg-1]); - exit (5); - } - *pos = 0; - Y2ComponentBroker::registerNamespaceException (argv[arg], pos+1); - *pos = '='; - arg++; - } - - // now create client - char *client_name = argv[arg]; - if (!client_name) { + if (!argv[arg]) { print_usage (); exit (1); } - Y2Component *client = Y2ComponentBroker::createClient (client_name); - if (!client) - { - print_error ("No such client module %s", client_name); - print_usage (); - exit (5); - } - + client_name = argv[arg]; arg++; // next argument (first client option) // Prepare client options - - YCPList arglist; - while (arg < argc) { if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) @@ -412,7 +272,11 @@ arg++; // switch to next argument } // Parsing client options +} +void +parse_server_and_options (int argc, char ** argv, int& arg, char *& server_name, YCPList& preload) +{ if (arg >= argc) { fprintf(stderr, "No server module given\n"); @@ -421,24 +285,15 @@ } // now create server - char *server_name = argv[arg]; - if (!server_name) { + if (!argv[arg]) { print_usage (); exit (1); } - Y2ComponentBroker::registerNamespaceException ("UI", server_name); - Y2Component *server = Y2ComponentBroker::createServer (server_name); - if (!server) { - print_error ("No such server module %s", server_name); - print_usage(); - exit(5); - } - + server_name = argv[arg]; arg++; // next argument (first server option) // Prepare server and general options - YCPList preload; // prepare preload files from option -p while (arg < argc) { @@ -508,9 +363,159 @@ arg++; // switch to next argument } // parsing server options +} + +int +main (int argc, char **argv) +{ + if (!argv[0]) + { + fprintf (stderr, "Missing argv[0]. It is a NULL pointer."); + exit (5); + } + + progname = basename (argv[0]); // get program name + + // Ignore SIGPIPE. No use in signals. Signals can't be assigned to + // components + signal(SIGPIPE, SIG_IGN); + + // Give some output for the SIGSEGV + // and other signals too, #238172 + // Note that USR1 and USR2 are handled by the logger. + signal (SIGHUP, signal_handler); + signal (SIGINT, signal_handler); + signal (SIGQUIT, signal_handler); + signal (SIGILL , signal_handler); + signal (SIGABRT, signal_handler); + signal (SIGFPE, signal_handler); + signal (SIGSEGV, signal_handler); + signal (SIGTERM, signal_handler); + + if (argc < 2) { + fprintf (stderr, "\nToo few arguments"); + print_usage(); + exit (1); + } + + if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) { + print_help (); + exit (0); + } + + // client _AND_ server must be given + if (argc < 3) + { + fprintf (stderr, "\nPlease give client and server as arguments"); + print_usage(); + exit(5); + } + + // Scan all options for -l/--logfile. They must be honored BEFORE + // the logger is used the first time. + for (int arg = 1; arg < argc; arg++) + { + if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) + { + arg++; // switch to filename + + if (arg >= argc) + { + print_error ("Option %s is missing an argument", argv[arg-1]); + exit(5); + } + + set_log_filename( argv[arg] ); // set logfile given in command line + } + if (!strcmp(argv[arg], "-c") || !strcmp(argv[arg], "--logconf")) + { + arg++; // switch to filename + + if (arg >= argc) + { + print_error ("Option %s is missing an argument", argv[arg-1]); + exit(5); + } + + set_log_conf( argv[arg] ); + } + } + + // set a defined umask + umask (0022); + + YCPPathSearch::initialize(); + + ostringstream argdump; + for (int arg = 1; arg < argc; arg++) + { + argdump << " '" << argv[arg] << "'"; + } + + y2milestone ("Launched YaST2 component '%s'%s", progname, argdump.str().c_str()); + + // Now evaluate command line options in sequence + + int arg = 1; + + // The first argument might be the log option or MUST be the client name + if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) + { + // Logfile already done at program start --> ignore here + arg+=2; // skip over logfilename + } + if (!strcmp(argv[arg], "-c") || !strcmp(argv[arg], "--logconf")) + { + // Logfile already done at program start --> ignore here + arg+=2; // skip over logfilename + } + // The first argument might be the log option or MUST be the client name + if (!strcmp(argv[arg], "-l") || !strcmp(argv[arg], "--logfile")) + { + // Logfile already done at program start --> ignore here + arg+=2; // skip over logfilename + } + + + // Check for namespace exceptions registration + while (!strcmp(argv[arg], "-n")) + { + arg++; + char *pos = index (argv[arg], '='); + if (pos == NULL) + { + print_error ("Option %s argument must be in format namespace=component", argv[arg-1]); + exit (5); + } + *pos = 0; + Y2ComponentBroker::registerNamespaceException (argv[arg], pos+1); + *pos = '='; + arg++; + } + + // "arg" and these two are output params + char * client_name; + YCPList arglist; + parse_client_and_options (argc, argv, arg, client_name, arglist); + + // "arg" and these two are output params + char * server_name; + YCPList preload; // prepare preload files from option -p + parse_server_and_options (argc, argv, arg, server_name, preload); + + // now create server + + Y2ComponentBroker::registerNamespaceException ("UI", server_name); + Y2Component *server = Y2ComponentBroker::getNamespaceComponent ("UI"); + if (!server) { + print_error ("No such server module %s", server_name); + print_usage(); + exit(5); + } + // Put argument into a nice new array and give them to the server char **server_argv = new char *[argc-arg+2]; - server_argv[0] = server_name; + server_argv[0] = strdup (server_name); for (int i = arg; i < argc; i++) server_argv[i-arg+1] = argv[i]; argv[argc] = NULL; @@ -524,6 +529,16 @@ server->evaluate(preload->value(i)); } + // now create client + + Y2Component *client = Y2ComponentBroker::createClient (client_name); + if (!client) + { + print_error ("No such client module %s", client_name); + print_usage (); + exit (5); + } + // The environment variable YAST_IS_RUNNING is checked in rpm // post install scripts. Might be useful for other scripts as // well. -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org