mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
errno: don’t use ‘_errno’ as a variable name; _ are reserved for use as identifiers
This commit is contained in:
parent
0bda60aacc
commit
555f751f94
4 changed files with 29 additions and 28 deletions
6
config.c
6
config.c
|
|
@ -148,13 +148,13 @@ static_assert(ALEN(url_binding_action_map) == BIND_ACTION_URL_COUNT,
|
||||||
|
|
||||||
#define LOG_AND_NOTIFY_ERRNO(...) \
|
#define LOG_AND_NOTIFY_ERRNO(...) \
|
||||||
do { \
|
do { \
|
||||||
int _errno = errno; \
|
int errno_copy = errno; \
|
||||||
LOG_ERRNO(__VA_ARGS__); \
|
LOG_ERRNO(__VA_ARGS__); \
|
||||||
int len = snprintf(NULL, 0, __VA_ARGS__); \
|
int len = snprintf(NULL, 0, __VA_ARGS__); \
|
||||||
int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \
|
int errno_len = snprintf(NULL, 0, ": %s", strerror(errno_copy)); \
|
||||||
char *text = xmalloc(len + errno_len + 1); \
|
char *text = xmalloc(len + errno_len + 1); \
|
||||||
snprintf(text, len + errno_len + 1, __VA_ARGS__); \
|
snprintf(text, len + errno_len + 1, __VA_ARGS__); \
|
||||||
snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \
|
snprintf(&text[len], errno_len + 1, ": %s", strerror(errno_copy)); \
|
||||||
struct user_notification notif = { \
|
struct user_notification notif = { \
|
||||||
.kind = USER_NOTIFICATION_ERROR, \
|
.kind = USER_NOTIFICATION_ERROR, \
|
||||||
.text = text, \
|
.text = text, \
|
||||||
|
|
|
||||||
6
log.c
6
log.c
|
|
@ -149,14 +149,14 @@ void log_errno(enum log_class log_class, const char *module,
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_errno_provided(enum log_class log_class, const char *module,
|
void log_errno_provided(enum log_class log_class, const char *module,
|
||||||
const char *file, int lineno, int _errno,
|
const char *file, int lineno, int errno_copy,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap1, ap2;
|
va_list ap1, ap2;
|
||||||
va_start(ap1, fmt);
|
va_start(ap1, fmt);
|
||||||
va_copy(ap2, ap1);
|
va_copy(ap2, ap1);
|
||||||
_log(log_class, module, file, lineno, fmt, _errno, ap1);
|
_log(log_class, module, file, lineno, fmt, errno_copy, ap1);
|
||||||
_sys_log(log_class, module, file, lineno, fmt, _errno, ap2);
|
_sys_log(log_class, module, file, lineno, fmt, errno_copy, ap2);
|
||||||
va_end(ap1);
|
va_end(ap1);
|
||||||
va_end(ap2);
|
va_end(ap2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
slave.c
22
slave.c
|
|
@ -268,20 +268,20 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
|
||||||
close(fork_pipe[0]); /* Close read end */
|
close(fork_pipe[0]); /* Close read end */
|
||||||
|
|
||||||
if (chdir(cwd) < 0) {
|
if (chdir(cwd) < 0) {
|
||||||
const int _errno = errno;
|
const int errno_copy = errno;
|
||||||
LOG_ERRNO("failed to change working directory");
|
LOG_ERRNO("failed to change working directory");
|
||||||
(void)!write(fork_pipe[1], &_errno, sizeof(_errno));
|
(void)!write(fork_pipe[1], &errno_copy, sizeof(errno_copy));
|
||||||
_exit(_errno);
|
_exit(errno_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore signal mask */
|
/* Restore signal mask */
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigemptyset(&mask);
|
sigemptyset(&mask);
|
||||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
|
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
|
||||||
const int _errno = errno;
|
const int errno_copy = errno;
|
||||||
LOG_ERRNO_P(errno, "failed to restore signals");
|
LOG_ERRNO_P(errno, "failed to restore signals");
|
||||||
(void)!write(fork_pipe[1], &_errno, sizeof(_errno));
|
(void)!write(fork_pipe[1], &errno_copy, sizeof(errno_copy));
|
||||||
_exit(_errno);
|
_exit(errno_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
setenv("TERM", term_env, 1);
|
setenv("TERM", term_env, 1);
|
||||||
|
|
@ -319,18 +319,18 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
|
||||||
close(fork_pipe[1]); /* Close write end */
|
close(fork_pipe[1]); /* Close write end */
|
||||||
LOG_DBG("slave has PID %d", pid);
|
LOG_DBG("slave has PID %d", pid);
|
||||||
|
|
||||||
int _errno;
|
int errno_copy;
|
||||||
static_assert(sizeof(errno) == sizeof(_errno), "errno size mismatch");
|
static_assert(sizeof(errno) == sizeof(errno_copy), "errno size mismatch");
|
||||||
|
|
||||||
ssize_t ret = read(fork_pipe[0], &_errno, sizeof(_errno));
|
ssize_t ret = read(fork_pipe[0], &errno_copy, sizeof(errno_copy));
|
||||||
close(fork_pipe[0]);
|
close(fork_pipe[0]);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERRNO("failed to read from pipe");
|
LOG_ERRNO("failed to read from pipe");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (ret == sizeof(_errno)) {
|
} else if (ret == sizeof(errno_copy)) {
|
||||||
LOG_ERRNO_P(
|
LOG_ERRNO_P(
|
||||||
_errno, "%s: failed to execute",
|
errno_copy, "%s: failed to execute",
|
||||||
argc == 0 ? conf_shell : argv[0]);
|
argc == 0 ? conf_shell : argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
23
spawn.c
23
spawn.c
|
|
@ -39,10 +39,10 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigemptyset(&mask);
|
sigemptyset(&mask);
|
||||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
|
if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0) {
|
||||||
const int _errno = errno;
|
const int errno_copy = errno;
|
||||||
LOG_ERRNO_P(errno, "failed to restore signals");
|
LOG_ERRNO("failed to restore signals");
|
||||||
(void)!write(pipe_fds[1], &_errno, sizeof(_errno));
|
(void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
|
||||||
_exit(_errno);
|
_exit(errno_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stdin_fd >= 0 && (dup2(stdin_fd, STDIN_FILENO) < 0 || close(stdin_fd) < 0)) ||
|
if ((stdin_fd >= 0 && (dup2(stdin_fd, STDIN_FILENO) < 0 || close(stdin_fd) < 0)) ||
|
||||||
|
|
@ -51,8 +51,9 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
||||||
(cwd != NULL && chdir(cwd) < 0) ||
|
(cwd != NULL && chdir(cwd) < 0) ||
|
||||||
execvp(argv[0], argv) < 0)
|
execvp(argv[0], argv) < 0)
|
||||||
{
|
{
|
||||||
(void)!write(pipe_fds[1], &errno, sizeof(errno));
|
const int errno_copy = errno;
|
||||||
_exit(errno);
|
(void)!write(pipe_fds[1], &errno_copy, sizeof(errno_copy));
|
||||||
|
_exit(errno_copy);
|
||||||
}
|
}
|
||||||
xassert(false);
|
xassert(false);
|
||||||
_exit(errno);
|
_exit(errno);
|
||||||
|
|
@ -61,10 +62,10 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
||||||
/* Parent */
|
/* Parent */
|
||||||
close(pipe_fds[1]);
|
close(pipe_fds[1]);
|
||||||
|
|
||||||
int _errno;
|
int errno_copy;
|
||||||
static_assert(sizeof(_errno) == sizeof(errno), "errno size mismatch");
|
static_assert(sizeof(errno_copy) == sizeof(errno), "errno size mismatch");
|
||||||
|
|
||||||
ssize_t ret = read(pipe_fds[0], &_errno, sizeof(_errno));
|
ssize_t ret = read(pipe_fds[0], &errno_copy, sizeof(errno_copy));
|
||||||
close(pipe_fds[0]);
|
close(pipe_fds[0]);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
|
@ -74,8 +75,8 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
||||||
LOG_ERRNO("failed to read from pipe");
|
LOG_ERRNO("failed to read from pipe");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
LOG_ERRNO_P(_errno, "%s: failed to spawn", argv[0]);
|
LOG_ERRNO_P(errno_copy, "%s: failed to spawn", argv[0]);
|
||||||
errno = _errno;
|
errno = errno_copy;
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue