Bug #57953 my_load_defaults return junk argument ----args-separator---- to caller
Submitted: 3 Nov 2010 13:42 Modified: 29 Jan 2011 23:05
Reporter: Magnus Blåudd Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.5.7-rc, 5.6.99 OS:Any
Assigned to: Zhenxing He CPU Architecture:Any
Tags: SEAGULL

[3 Nov 2010 13:42] Magnus Blåudd
Description:
The my_load_defaults() function from mysys in 5.5 returns extra unexpected argument(s) "----args-separator---" in the argv array.

This is an incompatible change.

The source code documentation for my_load_defaults does not say anything about this in 

How to repeat:
#include <stdlib.h>
#include <getopt.h>

#include <mysql.h>
#include <my_sys.h>

int
main(int argc, char** argv)
{
  my_init();
  for (int i = 0; i < argc; i++)
  {
    fprintf(stderr, "argv[%d]: %s\n", i, argv[i]);
  }

  fprintf(stderr, "loading defaults\n");
  const char * mycnf_sections[] = {"mysql", NULL};
  load_defaults("my", mycnf_sections, &argc, &argv);

  for (int i = 0; i < argc; i++)
  {
    fprintf(stderr, "argv[%d]: %s\n", i, argv[i]);
  }
  return EXIT_SUCCESS;
}

Running this program will print:
./a.out  --nodaemon --verbose
argv[0]: ./a.out
argv[1]: --nodaemon
argv[2]: --verbose
loading defaults
argv[0]: ./a.out
argv[1]: ----args-separator----
argv[2]: --nodaemon
argv[3]: --verbose

^ the ---args-separator--- should not be there

Suggested fix:
1) Don't return the "---args-separator---" in argv to caller.

2) If it has to be returned,  make it optional, for example those programs that nedd it can turn on thise "feature" by calling mys_get_opt_set_return_args_separator().

Extra somewhat unrelated note. Don't use a magic variable "extern char* args_separator" variable but instead a function 'my_get_opt_is_args_separator(const char*)' to keep the interface clean.
[3 Nov 2010 13:55] Magnus Blåudd
Would recommend that if the "args_separator" variable is made part of the interface to mysys, it should be prefixed with my_ as all the other variables that (unfortunately) already are ppart of interface.

const char *args_separator= "----args-separator----";
const char *my_defaults_file=0;
const char *my_defaults_group_suffix=0;
char *my_defaults_extra_file=0;
[3 Nov 2010 20:16] Sveta Smirnova
Thank you for the report.

Verified as described.
[10 Nov 2010 10:16] Georgi Kodinov
This is a regression from the fix of bug #25192.
[20 Dec 2010 4:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/127267

3180 He Zhenxing	2010-12-20
      BUG#57953 my_load_defaults return junk argument ----args-separator---- to caller
      
      After fix of bug#25192, load_defaults() will add an args separator
      to distinguish options loaded from configure files from that provided
      in the command line. One problem of this is that the args separator
      would be added no matter the application need it or not.
      
      Fixed the problem by adding an option:
        bool my_getopt_use_args_separator;
      to control whether the separator will be added or not. And also
      added functions:
        bool my_getopt_is_args_separator(const char* arg);
      to check if the argument is the separator or not.
[17 Jan 2011 7:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128889

3256 He Zhenxing	2011-01-17
      BUG#57953 my_load_defaults return junk argument ----args-separator---- to caller
      
      After fix of bug#25192, load_defaults() will add an args separator
      to distinguish options loaded from configure files from that provided
      in the command line. One problem of this is that the args separator
      would be added no matter the application need it or not.
      
      Fixed the problem by adding an option:
        bool my_getopt_use_args_separator;
      to control whether the separator will be added or not. And also
      added functions:
        bool my_getopt_is_args_separator(const char* arg);
      to check if the argument is the separator or not.
[17 Jan 2011 9:59] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:hezx@greatopensource.com-20110117095259-jbpwy1vhb0ggkq9k) (version source revid:hezx@greatopensource.com-20110117095259-jbpwy1vhb0ggkq9k) (merge vers: 5.6.2) (pib:24)
[17 Jan 2011 10:01] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:hezx@greatopensource.com-20110117095918-ibh2zq8x63eqcq4q) (version source revid:hezx@greatopensource.com-20110117074437-v3icyuwsocqj0j6c) (merge vers: 5.5.10) (pib:24)
[18 Jan 2011 20:04] Paul DuBois
Noted in 5.5.10, 5.6.2 changelogs.

The fix for Bug#25192 caused load_defaults() to add an argument
separator to distinguish options loaded from configure files from
those provided on the command line, whether or not the application
needed it.