Skip to content

Commit

Permalink
snmptrapd: Let configure check for mysql_options()
Browse files Browse the repository at this point in the history
Let configure check for mysql_options() instead of using mysql_options()
depending on the MySQL version. Only call load_defaults() or
my_load_defaults() if mysql_options() is not available. Parse not_argv[]
only if mysql_options() is not available. This last change fixes
Coverity ID 266336 ("logically dead code").
  • Loading branch information
bvanassche committed Jun 25, 2019
1 parent 6972080 commit 011342d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
17 changes: 12 additions & 5 deletions apps/snmptrapd_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ netsnmp_mysql_connect(void)
int
netsnmp_mysql_init(void)
{
int not_argc = 0, i;
char *not_args[] = { NULL };
char **not_argv = not_args;
netsnmp_trapd_handler *traph;

DEBUGMSGTL(("sql:init","called\n"));
Expand All @@ -450,14 +447,22 @@ netsnmp_mysql_init(void)
my_init();
#endif

#if !defined(HAVE_MYSQL_OPTIONS)
{
int not_argc = 0, i;
char *not_args[] = { NULL };
char **not_argv = not_args;

/** load .my.cnf values */
#if HAVE_MY_LOAD_DEFAULTS
my_load_defaults ("my", _sql.groups, &not_argc, &not_argv, 0);
#elif defined(HAVE_LOAD_DEFAULTS)
load_defaults ("my", _sql.groups, &not_argc, &not_argv);
#else
#error Neither load_defaults() nor mysql_options() are available.
#endif

for(i=0; i < not_argc; ++i) {
for (i = 0; i < not_argc; ++i) {
if (NULL == not_argv[i])
continue;
if (strncmp(not_argv[i],"--password=",11) == 0)
Expand All @@ -475,6 +480,8 @@ netsnmp_mysql_init(void)
else
snmp_log(LOG_WARNING, "unknown argument[%d] %s\n", i, not_argv[i]);
}
}
#endif /* !defined(HAVE_MYSQL_OPTIONS) */

/** init bind structures */
memset(_tbind, 0x0, sizeof(_tbind));
Expand Down Expand Up @@ -554,7 +561,7 @@ netsnmp_mysql_init(void)
return -1;
}

#if MYSQL_VERSION_ID >= 100000
#if HAVE_MYSQL_OPTIONS
mysql_options(_sql.conn, MYSQL_READ_DEFAULT_GROUP, "snmptrapd");
#endif

Expand Down
20 changes: 9 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -24969,19 +24969,17 @@ $as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
ac_fn_c_check_func "$LINENO" "mysql_init" "ac_cv_func_mysql_init"
if test "x$ac_cv_func_mysql_init" = xyes; then :

$as_echo "#define HAVE_MYSQL_INIT 1" >>confdefs.h

fi

ac_fn_c_check_func "$LINENO" "load_defaults" "ac_cv_func_load_defaults"
if test "x$ac_cv_func_load_defaults" = xyes; then :

$as_echo "#define HAVE_LOAD_DEFAULTS 1" >>confdefs.h
for ac_func in load_defaults mysql_init mysql_options
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done

CPPFLAGS="${_cppflags}"
LIBS="${_libs}"
Expand Down
9 changes: 1 addition & 8 deletions configure.d/config_os_libs2
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,7 @@ if test "x$with_mysql" = "xyes" ; then
AC_DEFINE([HAVE_MY_LOAD_DEFAULTS], 1,
[Define if having my_load_defaults()])],
[AC_MSG_RESULT(no)])
AC_CHECK_FUNC(
[mysql_init],
AC_DEFINE([HAVE_MYSQL_INIT], 1,
[Define if mysql_init() is available in libmysqlclient]))
AC_CHECK_FUNC(
[load_defaults],
AC_DEFINE([HAVE_LOAD_DEFAULTS], 1,
[Define if load_defaults() is available in libmysqlclient]))
AC_CHECK_FUNCS([load_defaults mysql_init mysql_options])
CPPFLAGS="${_cppflags}"
LIBS="${_libs}"
AC_MSG_CACHE_ADD(MYSQL Trap Logging: enabled)
Expand Down
7 changes: 5 additions & 2 deletions include/net-snmp/net-snmp-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
/* Define to 1 if you have the <linux/tasks.h> header file. */
#undef HAVE_LINUX_TASKS_H

/* Define if load_defaults() is available in libmysqlclient */
/* Define to 1 if you have the `load_defaults' function. */
#undef HAVE_LOAD_DEFAULTS

/* Define to 1 if you have the <locale.h> header file. */
Expand Down Expand Up @@ -521,9 +521,12 @@
/* Define to 1 if you have the <mtab.h> header file. */
#undef HAVE_MTAB_H

/* Define if mysql_init() is available in libmysqlclient */
/* Define to 1 if you have the `mysql_init' function. */
#undef HAVE_MYSQL_INIT

/* Define to 1 if you have the `mysql_options' function. */
#undef HAVE_MYSQL_OPTIONS

/* Define to 1 if you have the <my_global.h> header file. */
#undef HAVE_MY_GLOBAL_H

Expand Down

0 comments on commit 011342d

Please sign in to comment.