diff options
Diffstat (limited to 'libmount/src')
| -rw-r--r-- | libmount/src/context.c | 20 | ||||
| -rw-r--r-- | libmount/src/context_mount.c | 5 | ||||
| -rw-r--r-- | libmount/src/mountP.h | 1 |
3 files changed, 26 insertions, 0 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c index 7cf4ef79ed..332e456e66 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -41,6 +41,7 @@ #include "namespace.h" #include "match.h" +#include <stdarg.h> #include <sys/wait.h> /** @@ -2666,6 +2667,25 @@ int mnt_context_append_errmsg(struct libmnt_context *cxt, const char *msg) return strappend(&cxt->errmsg, msg); } +int mnt_context_sprintf_errmsg(struct libmnt_context *cxt, const char *msg, ...) +{ + int rc; + va_list ap; + char *p = NULL; + + va_start(ap, msg); + rc = vasprintf(&p, msg, ap); + va_end(ap); + + if (rc < 0 || !p) + return rc; + + free(cxt->errmsg); + cxt->errmsg = p; + + return 0; +} + /** * mnt_context_strerror * @cxt: context diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 783244a61c..53918c3fca 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -1433,6 +1433,11 @@ int mnt_context_get_mount_excode( mnt_context_get_user_mflags(cxt, &uflags); /* userspace flags */ if (!mnt_context_syscall_called(cxt)) { + if (buf && cxt->errmsg) { + xstrncpy(buf, cxt->errmsg, bufsz); + return MNT_EX_USAGE; + } + /* * libmount errors (extra library checks) */ diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index db58e9f749..d3232bf1c4 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -628,6 +628,7 @@ extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg extern int mnt_context_set_errmsg(struct libmnt_context *cxt, const char *msg); extern int mnt_context_append_errmsg(struct libmnt_context *cxt, const char *msg); +extern int mnt_context_sprintf_errmsg(struct libmnt_context *cxt, const char *msg, ...); extern int mnt_context_propagation_only(struct libmnt_context *cxt) __attribute__((nonnull)); |
