8000 move error messages to hooksets by karelzak · Pull Request #2314 · util-linux/util-linux · GitHub
[go: up one dir, main page]

Skip to content

move error messages to hooksets #2314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/strutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ static inline void strrem(char *s, int rem)
*p = '\0';
}

extern int errsnprint(char *buf, size_t bufsz, int errnum, const char *fmt, ...);

extern char *strnconcat(const char *s, const char *suffix, size_t b);
extern char *strconcat(const char *s, const char *suffix);
extern char *strfconcat(const char *s, const char *format, ...)
Expand Down
21 changes: 21 additions & 0 deletions lib/strutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,27 @@ int ul_optstr_next(char **optstr, char **name, size_t *namesz,
return 1; /* end of optstr */
}

int errsnprint(char *buf, size_t bufsz, int errnum, const char *fmt, ...)
Copy link
Member
@t-8ch t-8ch Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird.

The advantage of "%m" is that it saves a "%s", strerror(errno).
It is non-standard and of limited advantage.

Instead of introducing a custom helper to do the same with arbitrary errnum the user could just specify "%s", strerror(errnum).

(Also it should probably be called errsnprintf)

{
int errsv, re;
va_list ap;

if (!buf || !bufsz)
return 0;

va_start(ap, fmt);

errsv = errno;
errno = errnum;

re = vsnprintf(buf, bufsz, fmt, ap);

va_end(ap);
errno = errsv;

return re;
}

#ifdef TEST_PROGRAM_STRUTILS

#include "cctype.h"
Expand Down
13 changes: 6 additions & 7 deletions libmount/src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct libmnt_context *mnt_new_context(void)
ruid = getuid();
euid = geteuid();

mnt_context_reset_status(cxt);
mnt_context_reset_failure(cxt);

cxt->ns_orig.fd = -1;
cxt->ns_tgt.fd = -1;
Expand Down Expand Up @@ -170,7 +170,7 @@ int mnt_reset_context(struct libmnt_context *cxt)
cxt->map_linux = mnt_get_builtin_optmap(MNT_LINUX_MAP);
cxt->map_userspace = mnt_get_builtin_optmap(MNT_USERSPACE_MAP);

mnt_context_reset_status(cxt);
mnt_context_reset_failure(cxt);
mnt_context_deinit_hooksets(cxt);

if (cxt->table_fltrcb)
Expand Down Expand Up @@ -283,7 +283,7 @@ struct libmnt_context *mnt_copy_context(struct libmnt_context *o)
n->map_linux = o->map_linux;
n->map_userspace = o->map_userspace;

mnt_context_reset_status(n);
mnt_context_reset_failure(n);

n->table_fltrcb = o->table_fltrcb;
n->table_fltrcb_data = o->table_fltrcb_data;
Expand Down Expand Up @@ -314,9 +314,7 @@ int mnt_context_reset_status(struct libmnt_context *cxt)
if (!cxt)
return -EINVAL;

cxt->syscall_status = 1; /* means not called yet */
cxt->helper_exec_status = 1;
cxt->helper_status = 0;
mnt_context_reset_failure(cxt);
return 0;
}

Expand Down Expand Up @@ -2570,6 +2568,8 @@ int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status)
if (!cxt)
return -EINVAL;

mnt_context_reset_failure(cxt);

DBG(CXT, ul_debugobj(cxt, "syscall status set to: %d", status));
cxt->syscall_status = status;
return 0;
Expand All @@ -2589,7 +2589,6 @@ int mnt_context_strerror(struct libmnt_context *cxt __attribute__((__unused__)),
char *buf __attribute__((__unused__)),
size_t bufsiz __attribute__((__unused__)))
{
/* TODO: based on cxt->syscall_errno or cxt->helper_status */
return 0;
}

Expand Down
Loading
0