Checks in edg_wll_InitContext(), SB #47776.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 23 Dec 2010 16:11:31 +0000 (16:11 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 23 Dec 2010 16:11:31 +0000 (16:11 +0000)
Fix default parameter settings.
Check return codes of egd_wll_InitContext() calls.

17 files changed:
org.glite.lb.client/src/logevent.c.T
org.glite.lb.client/src/notify.c
org.glite.lb.client/src/register_sandbox.c
org.glite.lb.common/src/context.c
org.glite.lb.common/src/lb_perftest.c
org.glite.lb.common/src/param.c
org.glite.lb.common/test/parse.cpp.T
org.glite.lb.harvester/src/harvester.c
org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/lcas_lb.c
org.glite.lb.server/src/mon-db.c
org.glite.lb.utils/src/dump.c
org.glite.lb.utils/src/dump_exporter.c
org.glite.lb.utils/src/load.c
org.glite.lb.utils/src/purge.c
org.glite.lb.utils/src/state_history.c

index c5dbe41..ba16d90 100644 (file)
@@ -155,7 +155,10 @@ int main(int argc, char *argv[])
                          "[-s source_id] -e event [key=value ...]");
 
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context\n");
+               exit(1);
+       }
 
        /* log the event - priority/normal/proxy */
        logev = (pri) ? edg_wll_LogEventSync : edg_wll_LogEvent;
index 8013dcc..fb41afa 100644 (file)
@@ -107,7 +107,10 @@ int main(int argc,char **argv)
 //     sleep(20);
 
        me = argv[0];
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
 
        if ( argc < 2 ) {
                usage(NULL); goto cleanup;
index c674dbe..348ce03 100644 (file)
@@ -96,7 +96,10 @@ int main(int argc,char **argv)
                default:        usage(argv[0]); exit(1);
        }
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
 
        if (!jobid_s || type == EDG_WLL_SANDBOX_SANDBOX_TYPE_UNDEFINED
                        || !from || !to)
index fb638b8..d905525 100644 (file)
@@ -38,8 +38,13 @@ static void free_voms_groups(edg_wll_VomsGroups *);
 
 int edg_wll_InitContext(edg_wll_Context *ctx)
 {
-       int i;
+       int i, ret;
        edg_wll_Context out     = (edg_wll_Context) malloc(sizeof(*out));
+       union {
+               int i;
+               char *s;
+               struct timeval *tv;
+       } null;
 
        if (!out) return ENOMEM;
        memset(out,0,sizeof(*out));
@@ -48,16 +53,23 @@ int edg_wll_InitContext(edg_wll_Context *ctx)
        out->allowAnonymous = 1;
        out->notifSock  = -1;
 
-       /* XXX */
-       for (i=0; i<EDG_WLL_PARAM__LAST; i++) edg_wll_SetParam(out,i,NULL);
+       memset(&null, 0, sizeof null);
+       for (i=0; i<EDG_WLL_PARAM__LAST; i++) {
+               if ((ret = edg_wll_SetParam(out,i,null)) != 0) {
+                       edg_wll_FreeParams(out);
+                       free(out);
+                       return ret;
+               }
+       }
 
        out->p_tmp_timeout.tv_sec = out->p_log_timeout.tv_sec;
        out->p_tmp_timeout.tv_usec = out->p_log_timeout.tv_usec;
 
-        out->connections = edg_wll_initConnections();
        out->connNotif = (edg_wll_Connections *) calloc(1, sizeof(edg_wll_Connections));
-       edg_wll_initConnNotif(out->connNotif);
        out->connProxy = (edg_wll_ConnProxy *) calloc(1, sizeof(edg_wll_ConnProxy));
+       if (!out->connNotif || !out->connProxy) goto enomem;
+       out->connections = edg_wll_initConnections();
+       edg_wll_initConnNotif(out->connNotif);
        out->connProxy->conn.sock = -1;
 //     out->connToUse = -1;
 
@@ -75,6 +87,12 @@ int edg_wll_InitContext(edg_wll_Context *ctx)
 #endif
 
        return 0;
+enomem:
+       edg_wll_FreeParams(out);
+       free(out->connNotif);
+       free(out->connProxy);
+       free(out);
+       return ENOMEM;
 }
 
 void edg_wll_FreeContext(edg_wll_Context ctx)
index cf4cc7a..3dfc575 100644 (file)
@@ -282,7 +282,10 @@ glite_wll_perftest_init(const char *host,
 {
        edg_wll_Context ctx;
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "edg_wll_InitContext() failed\n");
+               return(-1);
+       }
 
        if(trio_asprintf(&termination_string, EDG_WLL_FORMAT_USERTAG,
                    PERFTEST_END_TAG_NAME, PERFTEST_END_TAG_VALUE) < 0)
index 7a0a0d8..4b6ab39 100644 (file)
@@ -243,14 +243,16 @@ int edg_wll_SetParamInt(edg_wll_Context ctx,edg_wll_ContextParam param,int val)
                                ctx->p_query_results = val;
                        }
                        else {
-                               char    *s = extract_split(param,'/',0);
-                               if (s) {
-                                       val = edg_wll_StringToQResult(s);
-                                       if (!val) return edg_wll_SetError(ctx,EINVAL,"can't parse query result parameter name");
-                                       ctx->p_query_results = val;
-                                       free(s);
-                               }
-                               return edg_wll_SetError(ctx,EINVAL,"can't parse query result parameter name");
+                               if (mygetenv(param)) {
+                                       char    *s = extract_split(param,'/',0);
+                                       if (s) {
+                                               val = edg_wll_StringToQResult(s);
+                                               if (!val) return edg_wll_SetError(ctx,EINVAL,"can't parse query result parameter name");
+                                               ctx->p_query_results = val;
+                                               free(s);
+                                       } else
+                                               return edg_wll_SetError(ctx,EINVAL,"can't parse query result parameter name");
+                               } // else default EDG_WLL_QUERYRES_UNDEF
                        }
                        break;
                case EDG_WLL_PARAM_CONNPOOL_SIZE:
@@ -269,14 +271,16 @@ int edg_wll_SetParamInt(edg_wll_Context ctx,edg_wll_ContextParam param,int val)
                                ctx->p_source = val;
                        }
                        else {
-                               char    *s = extract_split(param,'/',0);
-                               if (s) {
-                                       val = edg_wll_StringToSource(s);
-                                       if (!val) return edg_wll_SetError(ctx,EINVAL,"can't parse source name");
-                                       ctx->p_source = val;
-                                       free(s);
-                               }
-                               return edg_wll_SetError(ctx,EINVAL,"can't parse source name");
+                               if (mygetenv(param)) {
+                                       char    *s = extract_split(param,'/',0);
+                                       if (s) {
+                                               val = edg_wll_StringToSource(s);
+                                               if (!val) return edg_wll_SetError(ctx,EINVAL,"can't parse source name");
+                                               ctx->p_source = val;
+                                               free(s);
+                                       } else
+                                               return edg_wll_SetError(ctx,EINVAL,"can't parse source name");
+                               } // else default EDG_WLL_SOURCE_NONE
                        }
                        break;
                default:
index fa67b01..aa3636e 100644 (file)
@@ -73,7 +73,10 @@ void EventParseTest::$l()
        edg_wll_Event   *e1,*e2;
        char    *line,*et,*ed;
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               std::cerr << std::string("edg_wll_InitContext() failed") << std::endl;
+               exit(1);
+       }
        e1 = edg_wll_InitEvent(EDG_WLL_EVENT_$u);
 
        gettimeofday(&e1->any.timestamp,NULL);
index d7acc7e..7ce879d 100644 (file)
@@ -2705,7 +2705,10 @@ int main(int argn, char *argv[]) {
                }
        }
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               lprintf(NULL, ERR, "can't init LB context");
+               goto quit;
+       }
        if (config.cert) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_CERT, config.cert);
        if (config.key) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_KEY, config.key);
        last_summary = 0;
index e0d302b..cc8c064 100644 (file)
@@ -110,7 +110,10 @@ int main(int argc,char **argv)
                else fname = argv[optind];
        }
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.");
+               exit(1);
+       }
        if (!dbstring) dbstring = DEFAULTCS;
        if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
        if ((ctx->dbcaps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1) do_exit(ctx, EX_SOFTWARE);
index f0a2e87..8360096 100644 (file)
@@ -429,7 +429,10 @@ int main(int argc, char *argv[])
        purge_timeout[EDG_WLL_JOB_CLEARED] = 60*60*24*3;
        purge_timeout[EDG_WLL_JOB_ABORTED] = 60*60*24*7;
        purge_timeout[EDG_WLL_JOB_CANCELLED] = 60*60*24*7;
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context, exiting.\n");
+               exit(1);
+       }
 
        while ((opt = getopt_long(argc,argv,get_opt_string,opts,NULL)) != EOF) switch (opt) {
                case 'A': enable_lcas = 1; break;
index 57e9b34..16e63da 100644 (file)
@@ -59,7 +59,11 @@ plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred)
    lcas_log_debug(1,"\t%s-plugin: checking LB access policy\n",
                  modname);
 
-   edg_wll_InitContext(&ctx);
+   if (edg_wll_InitContext(&ctx) != 0) {
+     lcas_log(0, "Couldn't create L&B context\n");
+     ret = LCAS_MOD_FAIL;
+     goto end;
+   }
 
    if ((action = find_authz_action(request)) == ACTION_UNDEF) {
       lcas_log(0, "lcas.mod-lb() error: unsupported action\n");
index c1ccf62..e157075 100644 (file)
@@ -78,7 +78,10 @@ int main(int argc,char **argv)
                case '?': usage(); exit(EX_USAGE);
        }
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
        for (i = 1; i<EDG_WLL_NUMBER_OF_STATCODES; i++) jobs[i] = 0;
        if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
        if ((caps = glite_lbu_DBQueryCaps(ctx->dbctx)) < 0 || !(caps & GLITE_LBU_DB_CAP_INDEX)) do_exit(ctx,EX_SOFTWARE);
index 0bba745..57d34ad 100644 (file)
@@ -128,7 +128,10 @@ int main(int argc,char *argv[])
        }
 
        /* initialize context */
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
        if ( server )
        {
                char *p = strrchr(server, ':');
index 45a8c92..81d21f4 100644 (file)
@@ -150,7 +150,10 @@ int main(int argc, char **argv)
 
        ret = 0;
        memset(&buf, 0, sizeof(buf));
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
        while ( 1 ) {
                int             rl_ret,
                                written,
index db2cd16..a277038 100644 (file)
@@ -101,7 +101,10 @@ int main(int argc,char *argv[])
        }
 
        /* initialize context */
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
        if ( server )
        {
                char *p = strrchr(server, ':');
index 4c7ac92..f8884b8 100644 (file)
@@ -130,7 +130,10 @@ int main(int argc,char *argv[])
        if (me) me++; else me=argv[0];
 
        /* initialize context */
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
 
        /* get arguments */
        while ((opt = getopt_long(argc,argv,"a:c:n:e:o:j:m:rlsidhvxX:t:b:",opts,NULL)) != EOF) {
index 17cb8ea..4653351 100644 (file)
@@ -61,7 +61,10 @@ int main (int argc, char ** argv)
        }
 
 
-       edg_wll_InitContext(&ctx);
+       if (edg_wll_InitContext(&ctx) != 0) {
+               fprintf(stderr, "Couldn't create L&B context.\n");
+               exit(1);
+       }
        jc[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
        jc[0].op = EDG_WLL_QUERY_OP_EQUAL;