}
-/* this function fills a sample with the
- * variable content. Returns 1 if the sample
- * is filled, otherwise it returns 0.
+/* This function fills a sample with the variable content.
+ *
+ * Keep in mind that a sample content is duplicated by using smp_dup()
+ * and it therefore uses a pre-allocated trash chunk as returned by
+ * get_trash_chunk().
+ *
+ * Returns 1 if the sample is filled, otherwise it returns 0.
*/
int vars_get_by_name(const char *name, size_t len, struct sample *smp)
{
return 0;
/* Get the variable entry. */
+ HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
var = var_get(vars, name);
- if (!var)
+ if (!var) {
+ HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
return 0;
+ }
/* Copy sample. */
smp->data = var->data;
- smp->flags = SMP_F_CONST;
+ smp_dup(smp);
+
+ HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
return 1;
}
-/* this function fills a sample with the
- * content of the variable described by <var_desc>. Returns 1
- * if the sample is filled, otherwise it returns 0.
+/* This function fills a sample with the content of the variable described
+ * by <var_desc>.
+ *
+ * Keep in mind that a sample content is duplicated by using smp_dup()
+ * and it therefore uses a pre-allocated trash chunk as returned by
+ * get_trash_chunk().
+ *
+ * Returns 1 if the sample is filled, otherwise it returns 0.
*/
int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp)
{
return 0;
/* Get the variable entry. */
+ HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
var = var_get(vars, var_desc->name);
- if (!var)
+ if (!var) {
+ HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
return 0;
+ }
/* Copy sample. */
smp->data = var->data;
- smp->flags = SMP_F_CONST;
+ smp_dup(smp);
+
+ HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
return 1;
}