Hi!
Here is updated patch. Changes:
* exit codes are in y2/exitcodes.h header now
* `abort and `cancel are handled as client errors, returning 16
Let me know if something is still missing.
Stano
Index: liby2/src/include/y2/exitcodes.h
===================================================================
--- liby2/src/include/y2/exitcodes.h (revision 0)
+++ liby2/src/include/y2/exitcodes.h (revision 0)
@@ -0,0 +1,31 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: exitcodes.h
+
+ Author: Stanislav Visnovsky <[EMAIL PROTECTED]>
+ Maintainer: Stanislav Visnovsky <[EMAIL PROTECTED]>
+
+/-*/
+// -*- c++ -*-
+
+#ifndef exitcodes_h
+#define exitcodes_h
+
+enum error_codes {
+ YAST_OK = 0, // process finished without errors
+ YAST_FEWARGUMENTS = 1, // too few arguments for the commandline
+ YAST_OPTIONERROR = 5, // error in provided arguments
+ YAST_CLIENTRESULT = 16 // client (YCP) returned special result, this is used as offset (or as generic error)
+};
+
+#endif // exitcodes_h
Index: liby2/src/genericfrontend.cc
===================================================================
--- liby2/src/genericfrontend.cc (revision 51559)
+++ liby2/src/genericfrontend.cc (working copy)
@@ -14,6 +14,7 @@
Authors: Mathias Kettner <[EMAIL PROTECTED]>
Arvin Schnell <[EMAIL PROTECTED]>
+ Stanislav Visnovsky <[EMAIL PROTECTED]>
Maintainer: Arvin Schnell <[EMAIL PROTECTED]>
/-*/
@@ -44,12 +45,17 @@
#include <YCP.h>
#include <ycp/Parser.h>
#include <ycp/pathsearch.h>
+#include "exitcodes.h"
+#define MAX_YCP_ERROR_EXIT_SYMBOLS 2
+const char* ycp_error_exit_symbols[MAX_YCP_ERROR_EXIT_SYMBOLS] = {
+ "abort",
+ "cancel"
+};
+
using std::string;
ExecutionEnvironment ee;
-static const int YCP_ERROR = 16;
-
static const char *progname = "genericfrontend";
static void print_usage ();
@@ -262,7 +268,7 @@
if (!argv[arg]) {
print_usage ();
- exit (1);
+ exit (YAST_FEWARGUMENTS);
}
client_name = argv[arg];
@@ -299,13 +305,13 @@
if (option.isNull())
{
print_error ("Client option -s: Couldn't parse valid YCP value from stdin");
- exit (5);
+ exit (YAST_OPTIONERROR);
}
if (!option->isList())
{
print_error ("Client option -s: Parsed YCP value is NOT a YCPList");
- exit (5);
+ exit (YAST_OPTIONERROR);
}
arglist = option->asList(); // the option read _IS_ arglist
@@ -387,13 +393,13 @@
{
fprintf(stderr, "No server module given\n");
print_usage ();
- exit (5);
+ exit (YAST_OPTIONERROR);
}
// now create server
if (!argv[arg]) {
print_usage ();
- exit (1);
+ exit (YAST_FEWARGUMENTS);
}
server_name = argv[arg];
@@ -477,7 +483,7 @@
if (!argv[0])
{
fprintf (stderr, "Missing argv[0]. It is a NULL pointer.");
- exit (5);
+ exit (YAST_OPTIONERROR);
}
progname = basename (argv[0]); // get program name
@@ -501,12 +507,12 @@
if (argc < 2) {
fprintf (stderr, "\nToo few arguments");
print_usage();
- exit (1);
+ exit (YAST_FEWARGUMENTS);
}
if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) {
print_help ();
- exit (0);
+ exit (YAST_OK);
}
// client _AND_ server must be given
@@ -591,7 +597,7 @@
if (pos == NULL)
{
print_error ("Option %s argument must be in format namespace=component", argv[arg-1]);
- exit (5);
+ exit (YAST_OPTIONERROR);
}
*pos = 0;
Y2ComponentBroker::registerNamespaceException (argv[arg], pos+1);
@@ -689,12 +695,12 @@
fprintf (stderr, " %s\n", i->c_str());
print_usage ();
- exit (5);
+ exit (YAST_OPTIONERROR);
}
if (dynamic_cast<Y2ErrorComponent *>(client))
{
print_error ("Error while creating client module %s", client_name);
- exit (5);
+ exit (YAST_OPTIONERROR);
}
@@ -729,10 +735,30 @@
// might be useful in tracking segmentation faults
y2milestone ("Finished YaST2 component '%s'", progname);
- if( !result.isNull () && result->isBoolean() )
- exit( result->asBoolean()->value() ? 0 : YCP_ERROR );
+ if( result.isNull () )
+ exit (YAST_OK);
- exit (EXIT_SUCCESS);
+ y2milestone( "Exiting with client return value '%s'", result->toString ().c_str ());
+
+ if( result->isBoolean () )
+ {
+ exit( result->asBoolean()->value() ? YAST_OK : YAST_CLIENTRESULT );
+ }
+
+ if( result->isInteger () )
+ exit( YAST_CLIENTRESULT + result->asInteger ()->value () );
+
+ // if it is one of error symbols, return it as error
+ if( result->isSymbol () )
+ {
+ string symbol = result->asSymbol()->symbol();
+ for( int i = 0 ; i < MAX_YCP_ERROR_EXIT_SYMBOLS; i++ )
+ if( symbol == ycp_error_exit_symbols[i] )
+ exit( YAST_CLIENTRESULT );
+ }
+
+ // all other values
+ exit (YAST_OK);
}