From d6adde0e32376554e461098dcd7cfdb824fabd1e Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Mon, 13 Dec 2021 14:40:56 +0100
Subject: [PATCH 1/4] ucm: top-level path - set directory from symlink
It is useful to read the top-level symlink and set the configuration
directory according this symlink for the relative paths.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/ucm/parser.c | 55 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 45 insertions(+), 10 deletions(-)
diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index 48790057..7bdaa8fe 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -31,6 +31,7 @@
*/
#include "ucm_local.h"
+#include <sys/stat.h>
#include <stdbool.h>
#include <dirent.h>
#include <limits.h>
@@ -2186,6 +2187,7 @@ static int parse_toplevel_path(snd_use_case_mgr_t *uc_mgr,
snd_config_t *n, *n2;
const char *id;
char *dir = NULL, *file = NULL, fn[PATH_MAX];
+ struct stat st;
long version;
int err;
@@ -2260,23 +2262,51 @@ static int parse_toplevel_path(snd_use_case_mgr_t *uc_mgr,
}
ucm_filename(fn, sizeof(fn), version, dir, file);
- if (access(fn, R_OK) == 0) {
- if (replace_string(&uc_mgr->conf_dir_name, dir) == NULL) {
- err = -ENOMEM;
- goto __error;
- }
- if (replace_string(&uc_mgr->conf_file_name, file) == NULL) {
- err = -ENOMEM;
- goto __error;
+ if (access(fn, R_OK) == 0 && lstat(fn, &st) == 0) {
+ if (st.st_mode & S_IFLNK) {
+ ssize_t r;
+ char *link, *dir2, *p;
+
+ link = malloc(PATH_MAX);
+ if (link == NULL)
+ goto __enomem;
+ r = readlink(fn, link, PATH_MAX - 1);
+ if (r <= 0) {
+ free(link);
+ goto __next;
+ }
+ link[r] = '\0';
+ p = strrchr(link, '/');
+ if (p) {
+ *p = '\0';
+ dir2 = malloc(PATH_MAX);
+ if (dir2 == NULL) {
+ free(link);
+ goto __enomem;
+ }
+ strncpy(dir2, dir, PATH_MAX - 1);
+ strncat(dir2, "/", PATH_MAX - 1);
+ strncat(dir2, link, PATH_MAX - 1);
+ fn[PATH_MAX - 1] = '\0';
+ free(dir);
+ dir = dir2;
+ }
+ free(link);
}
+ if (replace_string(&uc_mgr->conf_dir_name, dir) == NULL)
+ goto __enomem;
+ if (replace_string(&uc_mgr->conf_file_name, file) == NULL)
+ goto __enomem;
strncpy(filename, fn, PATH_MAX);
+ filename[PATH_MAX - 1] = '\0';
uc_mgr->conf_format = version;
goto __ok;
}
__next:
free(file);
- free(dir);
+ if (dir != fn)
+ free(dir);
dir = NULL;
file = NULL;
}
@@ -2284,11 +2314,16 @@ __next:
err = -ENOENT;
goto __error;
+__enomem:
+ err = -ENOMEM;
+ goto __error;
+
__ok:
err = 0;
__error:
free(file);
- free(dir);
+ if (dir != fn)
+ free(dir);
return err;
}
--
2.34.1
From 47252054b4a2d5c8382cb1342f5d4eb89dabf95f Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Date: Sat, 1 Jan 2022 17:20:47 +0100
Subject: [PATCH 2/4] src/topology/parser.c: drop duplicate safe_strtol_base
The safe_strtol_base() function is defined twice since
f547b2e3 ("conf: introduce safe_strtol_base()") and
5fab157a ("topology: do not call strtol directly")
resulting in the following build failure when alsa-utils is built
statically because safe_strtol_base is defined twice.
Fixes: http://autobuild.buildroot.org/results/08d028004090b2a8292f03910cb9bf80a73ac804
Fixes: https://github.com/alsa-project/alsa-lib/pull/207
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/topology/parser.c | 19 -------------------
1 file changed, 19 deletions(-)
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 01c95afa..e70173f6 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -21,25 +21,6 @@
#include "list.h"
#include "tplg_local.h"
-/*
- * Safe strtol call
- */
-int safe_strtol_base(const char *str, long *val, int base)
-{
- char *end;
- long v;
- if (!*str)
- return -EINVAL;
- errno = 0;
- v = strtol(str, &end, base);
- if (errno)
- return -errno;
- if (*end)
- return -EINVAL;
- *val = v;
- return 0;
-}
-
/*
* Get integer value
*/
--
2.34.1
From c687c482107f746332dd18f7407f6c6efbffccb2 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sat, 1 Jan 2022 19:18:25 +0100
Subject: [PATCH 3/4] conf: fix the export of safe_strto* functions from
libasound
Only one library should define the safe_strto function. Export it
correctly and add _snd_ prefix to avoid possible clashes with the other
application code.
Fixes: 47252054 ("src/topology/parser.c: drop duplicate safe_strtol_base")
Fixes: https://github.com/alsa-project/alsa-lib/pull/208
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
include/local.h | 8 ++++++--
src/Versions.in | 6 ++++++
src/conf.c | 6 +++---
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/include/local.h b/include/local.h
index ebc9350c..f64fe9d8 100644
--- a/include/local.h
+++ b/include/local.h
@@ -232,10 +232,14 @@ size_t page_align(size_t size);
size_t page_size(void);
size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
-int safe_strtoll_base(const char *str, long long *val, int base);
+#define safe_strtoll_base _snd_safe_strtoll_base
+int _snd_safe_strtoll_base(const char *str, long long *val, int base);
static inline int safe_strtoll(const char *str, long long *val) { return safe_strtoll_base(str, val, 0); }
-int safe_strtol_base(const char *str, long *val, int base);
+#define safe_strtol_base _snd_safe_strtol_base
+int _snd_safe_strtol_base(const char *str, long *val, int base);
static inline int safe_strtol(const char *str, long *val) { return safe_strtol_base(str, val, 0); }
+#define safe_strtod _snd_safe_strtod
+int _snd_safe_strtod(const char *str, double *val);
int snd_send_fd(int sock, void *data, size_t len, int fd);
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
diff --git a/src/Versions.in b/src/Versions.in
index 5daccbd4..85031b38 100644
--- a/src/Versions.in
+++ b/src/Versions.in
@@ -134,3 +134,9 @@ ALSA_1.1.6 {
@SYMBOL_PREFIX@snd_dlopen;
} ALSA_0.9.7;
+
+ALSA_1.2.6 {
+ global:
+
+ @SYMBOL_PREFIX@_snd_safe_strto*;
+} ALSA_1.1.6;
diff --git a/src/conf.c b/src/conf.c
index d3597cbc..098ebd63 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -663,7 +663,7 @@ static int input_stdio_open(snd_input_t **inputp, const char *file,
return err;
}
-int safe_strtoll_base(const char *str, long long *val, int base)
+int _snd_safe_strtoll_base(const char *str, long long *val, int base)
{
char *end;
long v;
@@ -679,7 +679,7 @@ int safe_strtoll_base(const char *str, long long *val, int base)
return 0;
}
-int safe_strtol_base(const char *str, long *val, int base)
+int _snd_safe_strtol_base(const char *str, long *val, int base)
{
char *end;
long v;
@@ -695,7 +695,7 @@ int safe_strtol_base(const char *str, long *val, int base)
return 0;
}
-static int safe_strtod(const char *str, double *val)
+int _snd_safe_strtod(const char *str, double *val)
{
char *end;
double v;
--
2.34.1
From 3dbe072d8deba7c11f6e766ef80c0e50a69447d0 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Thu, 27 Jan 2022 18:25:00 +0100
Subject: [PATCH 4/4] conf: snd_config_merge - fix comment (overwrite /
override)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/conf.c b/src/conf.c
index 098ebd63..70f0e773 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -2276,7 +2276,7 @@ static int _snd_config_array_merge(snd_config_t *dst, snd_config_t *src, int ind
*
* \par Errors:
* <dl>
- * <dt>-EEXIST<dd>identifier already exists (!overwrite)
+ * <dt>-EEXIST<dd>identifier already exists (!override)
* <dt>-ENOMEM<dd>not enough memory
* </dl>
*/
--
2.34.1