~starbuggers/sakila-server/mysql-5.1-wl820

« back to all changes in this revision

Viewing changes to mysys/my_getopt.c

  • Committer: Alexey Botchkov
  • Date: 2008-10-27 09:57:59 UTC
  • mto: (2661.128.4 51mrg)
  • mto: This revision was merged to the branch mainline in revision 2791.
  • Revision ID: holyfoot@mysql.com-20081027095759-6bkwkuv2i99hgzjy
Bug#39289 libmysqld.a calls exit() upon error 

Several functions (mostly in mysqld.cc) directly call
exit() function in case of errors, which is not a desired
behaviour expecially in the embedded-server library.

Fixed by making these functions return error sign instead
of exiting.

per-file comments:
  include/my_getopt.h
Bug#39289 libmysqld.a calls exit() upon error 
  added 'error' retvalue for my_getopt_register_get_addr

  libmysqld/lib_sql.cc
Bug#39289 libmysqld.a calls exit() upon error 
  unireg_clear() function implemented

  mysys/default.c
Bug#39289 libmysqld.a calls exit() upon error 
  error returned instead of exit() call

  mysys/mf_tempdir.c
Bug#39289 libmysqld.a calls exit() upon error 
  free_tmpdir() - fixed so it's not produce crash on uninitialized
    tmpdir structure

  mysys/my_getopt.c
Bug#39289 libmysqld.a calls exit() upon error 
  error returned instead of exit() call

  sql/mysql_priv.h
Bug#39289 libmysqld.a calls exit() upon error 
  unireg_abort definition fixed for the embedded server

  sql/mysqld.cc
Bug#39289 libmysqld.a calls exit() upon error 
  various functions fixed
  error returned instead of exit() call

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
  one. Call function 'get_one_option()' once for each option.
101
101
*/
102
102
 
103
 
static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *);
 
103
static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *);
104
104
 
105
105
void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint,
106
 
                                                    const struct my_option *))
 
106
                                                    const struct my_option *, int *))
107
107
{
108
108
  getopt_get_addr= func_addr;
109
109
}
362
362
                                     my_progname, optp->name);
363
363
          return EXIT_NO_ARGUMENT_ALLOWED;
364
364
        }
 
365
        error= 0;
365
366
        value= optp->var_type & GET_ASK_ADDR ?
366
 
          (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value;
 
367
          (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp, &error) :
 
368
          optp->value;
 
369
        if (error)
 
370
          return error;
367
371
  
368
372
        if (optp->arg_type == NO_ARG)
369
373
        {
397
401
                                       my_progname, optp->name, optend);
398
402
              continue;
399
403
            }
400
 
            get_one_option(optp->id, optp,
401
 
                           *((my_bool*) value) ?
402
 
                           (char*) "1" : disabled_my_option);
 
404
            if (get_one_option(optp->id, optp,
 
405
                               *((my_bool*) value) ?
 
406
                               (char*) "1" : disabled_my_option))
 
407
              return EXIT_UNSPECIFIED_ERROR;
403
408
            continue;
404
409
          }
405
410
          argument= optend;
457
462
                  optp->arg_type == NO_ARG)
458
463
              {
459
464
                *((my_bool*) optp->value)= (my_bool) 1;
460
 
                get_one_option(optp->id, optp, argument);
 
465
                if (get_one_option(optp->id, optp, argument))
 
466
                  return EXIT_UNSPECIFIED_ERROR;
461
467
                continue;
462
468
              }
463
469
              else if (optp->arg_type == REQUIRED_ARG ||
476
482
                  {
477
483
                    if (optp->var_type == GET_BOOL)
478
484
                      *((my_bool*) optp->value)= (my_bool) 1;
479
 
                    get_one_option(optp->id, optp, argument);
 
485
                    if (get_one_option(optp->id, optp, argument))
 
486
                      return EXIT_UNSPECIFIED_ERROR;
480
487
                    continue;
481
488
                  }
482
489
                  /* Check if there are more arguments after this one */
501
508
                                         my_progname, argument, optp->name);
502
509
                return error;
503
510
              }
504
 
              get_one_option(optp->id, optp, argument);
 
511
              if (get_one_option(optp->id, optp, argument))
 
512
                return EXIT_UNSPECIFIED_ERROR;
505
513
              break;
506
514
            }
507
515
          }
524
532
                                 my_progname, argument, optp->name);
525
533
        return error;
526
534
      }
527
 
      get_one_option(optp->id, optp, argument);
 
535
      if (get_one_option(optp->id, optp, argument))
 
536
        return EXIT_UNSPECIFIED_ERROR;
528
537
 
529
538
      (*argc)--; /* option handled (short or long), decrease argument count */
530
539
    }
1085
1094
    if (options->value)
1086
1095
      init_one_value(options, options->value, options->def_value);
1087
1096
    if (options->var_type & GET_ASK_ADDR &&
1088
 
        (variable= (*getopt_get_addr)("", 0, options)))
 
1097
        (variable= (*getopt_get_addr)("", 0, options, 0)))
1089
1098
      init_one_value(options, variable, options->def_value);
1090
1099
  }
1091
1100
  DBUG_VOID_RETURN;
1189
1198
  for (optp= options; optp->id; optp++)
1190
1199
  {
1191
1200
    uchar* *value= (optp->var_type & GET_ASK_ADDR ?
1192
 
                  (*getopt_get_addr)("", 0, optp) : optp->value);
 
1201
                  (*getopt_get_addr)("", 0, optp, 0) : optp->value);
1193
1202
    if (value)
1194
1203
    {
1195
1204
      printf("%s ", optp->name);