mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 10:46:33 +08:00
Mixer load: don't upload empty mixers from non-existing files
This commit is contained in:
@@ -52,7 +52,8 @@ int load_mixer_file(const char *fname, char *buf, unsigned maxlen)
|
|||||||
/* open the mixer definition file */
|
/* open the mixer definition file */
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return 1;
|
warnx("file not found");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read valid lines from the file into a buffer */
|
/* read valid lines from the file into a buffer */
|
||||||
@@ -88,7 +89,8 @@ int load_mixer_file(const char *fname, char *buf, unsigned maxlen)
|
|||||||
|
|
||||||
/* if the line is too long to fit in the buffer, bail */
|
/* if the line is too long to fit in the buffer, bail */
|
||||||
if ((strlen(line) + strlen(buf) + 1) >= maxlen) {
|
if ((strlen(line) + strlen(buf) + 1) >= maxlen) {
|
||||||
return 1;
|
warnx("line too long");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the line to the buffer */
|
/* add the line to the buffer */
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ load(const char *devname, const char *fname)
|
|||||||
if (ioctl(dev, MIXERIOCRESET, 0))
|
if (ioctl(dev, MIXERIOCRESET, 0))
|
||||||
err(1, "can't reset mixers on %s", devname);
|
err(1, "can't reset mixers on %s", devname);
|
||||||
|
|
||||||
load_mixer_file(fname, &buf[0], sizeof(buf));
|
if (load_mixer_file(fname, &buf[0], sizeof(buf)) < 0)
|
||||||
|
err(1, "can't load mixer: %s", fname);
|
||||||
|
|
||||||
/* XXX pass the buffer to the device */
|
/* XXX pass the buffer to the device */
|
||||||
int ret = ioctl(dev, MIXERIOCLOADBUF, (unsigned long)buf);
|
int ret = ioctl(dev, MIXERIOCLOADBUF, (unsigned long)buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user