Commit 2c718667 authored by Niels Möller's avatar Niels Möller
Browse files

(werror_vformat): Added %e specifier. Updated all

errno printing functions to use it.
(werror_format): New function.
(fatal): Compile time flag to display pid and hang, instead of
aborting. Useful for debugging.

Rev: src/adns.c:1.3
Rev: src/client.c:1.141
Rev: src/daemon.c:1.8
Rev: src/io.c:1.174
Rev: src/lock_file.c:1.6
Rev: src/lsh-decode-key.c:1.17
Rev: src/lsh-export-key.c:1.15
Rev: src/lsh-make-seed.c:1.9
Rev: src/lsh-writekey.c:1.26
Rev: src/lsh.c:1.166
Rev: src/lshd.c:1.144
Rev: src/reaper.c:1.24
Rev: src/server.c:1.70
Rev: src/server_pty.c:1.23
Rev: src/server_session.c:1.94
Rev: src/server_x11.c:1.9
Rev: src/ssh1_fallback.c:1.13
Rev: src/suspend.c:1.2
Rev: src/unix_interact.c:1.16
Rev: src/unix_process.c:1.11
Rev: src/unix_random.c:1.11
Rev: src/unix_user.c:1.54
Rev: src/werror.c:1.67
parent e776fecd
...@@ -104,7 +104,7 @@ make_resolver(void) ...@@ -104,7 +104,7 @@ make_resolver(void)
if ( (res = adns_init(&self->adns, flags, NULL)) ) if ( (res = adns_init(&self->adns, flags, NULL)) )
{ {
werror("adns_init failed (errno = %i): %z", res, strerror(res)); werror("adns_init failed %e\n", res);
KILL(self); KILL(self);
return NULL; return NULL;
} }
......
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
#include "werror.h" #include "werror.h"
#include "xalloc.h" #include "xalloc.h"
#include <string.h>
#include <assert.h> #include <assert.h>
#include <string.h>
#include <signal.h> #include <signal.h>
...@@ -865,8 +865,7 @@ DEFINE_COMMAND(background_process) ...@@ -865,8 +865,7 @@ DEFINE_COMMAND(background_process)
break; break;
case -1: case -1:
/* Error */ /* Error */
werror("background_process: fork failed (errno = %i): %z\n", werror("background_process: fork failed %e\n", errno);
errno, STRERROR(errno));
COMMAND_RETURN(c, a); COMMAND_RETURN(c, a);
break; break;
default: default:
...@@ -909,8 +908,7 @@ make_client_session(struct client_options *options) ...@@ -909,8 +908,7 @@ make_client_session(struct client_options *options)
if (in < 0) if (in < 0)
{ {
werror("lsh: Can't dup/open stdin (errno = %i): %z!\n", werror("lsh: Can't dup/open stdin %e\n", errno);
errno, strerror(errno));
return NULL; return NULL;
} }
...@@ -952,8 +950,7 @@ make_client_session(struct client_options *options) ...@@ -952,8 +950,7 @@ make_client_session(struct client_options *options)
if (out < 0) if (out < 0)
{ {
werror("lsh: Can't dup/open stdout (errno = %i): %z!\n", werror("lsh: Can't dup/open stdout %e\n", errno);
errno, strerror(errno));
close(in); close(in);
return NULL; return NULL;
} }
......
...@@ -88,8 +88,8 @@ int daemon_pidfile(const char *name) ...@@ -88,8 +88,8 @@ int daemon_pidfile(const char *name)
{ {
if (errno != EEXIST) if (errno != EEXIST)
{ {
werror("Failed to open pid file '%z' (errno = %i): %z\n", werror("Failed to open pid file '%z' %e\n",
name, errno, STRERROR(errno)); name, errno);
return 0; return 0;
} }
...@@ -118,8 +118,8 @@ int daemon_pidfile(const char *name) ...@@ -118,8 +118,8 @@ int daemon_pidfile(const char *name)
fd = open(name, O_RDONLY); fd = open(name, O_RDONLY);
if (fd < 0) if (fd < 0)
{ {
werror("Pid file '%z' already exists, and is unreadable (errno = %i): %z\n", werror("Pid file '%z' already exists, and is unreadable %e\n",
name, errno, STRERROR(errno)); name, errno);
return 0; return 0;
} }
{ {
...@@ -132,14 +132,14 @@ int daemon_pidfile(const char *name) ...@@ -132,14 +132,14 @@ int daemon_pidfile(const char *name)
if (length < 0) if (length < 0)
{ {
werror("Pid file '%z' already exists, but read failed (errno = %i): %z\n", werror("Pid file '%z' already exists, but read failed %e\n",
name, errno, STRERROR(errno)); name, errno);
return 0; return 0;
} }
if ( !length|| !buffer[0] || (length == BUF_SIZE) ) if ( !length|| !buffer[0] || (length == BUF_SIZE) )
{ {
werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n", werror("Pid file '%z' already exists, but contents is garbled.\n",
name, errno, STRERROR(errno)); name);
return 0; return 0;
} }
...@@ -157,8 +157,8 @@ int daemon_pidfile(const char *name) ...@@ -157,8 +157,8 @@ int daemon_pidfile(const char *name)
if ( (errno == ERANGE) || (end != buffer + length) if ( (errno == ERANGE) || (end != buffer + length)
|| (other <= 0) || (other != (pid_t) other)) || (other <= 0) || (other != (pid_t) other))
{ {
werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n", werror("Pid file '%z' already exists, but contents is garbled.\n",
name, errno, STRERROR(errno)); name);
return 0; return 0;
} }
...@@ -191,13 +191,12 @@ int daemon_pidfile(const char *name) ...@@ -191,13 +191,12 @@ int daemon_pidfile(const char *name)
lsh_string_free(pid); lsh_string_free(pid);
return 1; return 1;
} }
werror("Writing pid file '%z' failed (errno = %i): %z", werror("Writing pid file '%z' failed %e\n", name, errno);
name, errno, STRERROR(errno));
/* Attempt unlinking file */ /* Attempt unlinking file */
if (unlink(name) < 0) if (unlink(name) < 0)
werror("Unlinking pid file '%z' failed (errno = %i): %z", werror("Unlinking pid file '%z' failed %e\n",
name, errno, STRERROR(errno)); name, errno);
lsh_string_free(pid); lsh_string_free(pid);
...@@ -475,8 +474,8 @@ int daemon_close(const char *name) ...@@ -475,8 +474,8 @@ int daemon_close(const char *name)
{ {
if (unlink(name) < 0) if (unlink(name) < 0)
{ {
werror("daemon_close: Unlink of pid file '%z' failed (errno = %i): %z\n", werror("daemon_close: Unlink of pid file '%z' failed %e\n",
name, errno, STRERROR(errno)); name, errno);
return 0; return 0;
} }
return 1; return 1;
......
...@@ -333,8 +333,7 @@ io_run(void) ...@@ -333,8 +333,7 @@ io_run(void)
/* We need liboop-0.8, OOP_ERROR is not defined in liboop-0.7. */ /* We need liboop-0.8, OOP_ERROR is not defined in liboop-0.7. */
if (res == OOP_ERROR) if (res == OOP_ERROR)
werror("oop_sys_run (errno = %i): %z\n", werror("oop_sys_run %e\n", errno);
errno, STRERROR(errno));
trace("io_run: Exiting\n"); trace("io_run: Exiting\n");
} }
...@@ -660,7 +659,7 @@ do_write_callback(struct io_callback *s UNUSED, ...@@ -660,7 +659,7 @@ do_write_callback(struct io_callback *s UNUSED,
&& (fd->write_buffer->length == 1) ) && (fd->write_buffer->length == 1) )
debug("io.c: ignoring write error, on the final ^D character\n"); debug("io.c: ignoring write error, on the final ^D character\n");
#endif #endif
werror("io.c: write failed, %z\n", STRERROR(errno)); werror("io.c: write failed %e\n", errno);
EXCEPTION_RAISE(fd->e, EXCEPTION_RAISE(fd->e,
make_io_exception(EXC_IO_WRITE, make_io_exception(EXC_IO_WRITE,
fd, errno, NULL)); fd, errno, NULL));
...@@ -722,7 +721,7 @@ do_listen_callback(struct io_callback *s, ...@@ -722,7 +721,7 @@ do_listen_callback(struct io_callback *s,
(struct sockaddr *) &peer, &addr_len); (struct sockaddr *) &peer, &addr_len);
if (conn < 0) if (conn < 0)
{ {
werror("io.c: accept failed, %z", STRERROR(errno)); werror("io.c: accept failed %e", errno);
return; return;
} }
...@@ -1104,11 +1103,10 @@ fd2info(struct lsh_fd *fd, int side) ...@@ -1104,11 +1103,10 @@ fd2info(struct lsh_fd *fd, int side)
get = getsockname( fd->fd, (struct sockaddr *) &sock, &s_len ); get = getsockname( fd->fd, (struct sockaddr *) &sock, &s_len );
else else
get = getpeername( fd->fd, (struct sockaddr *) &sock, &s_len ); get = getpeername( fd->fd, (struct sockaddr *) &sock, &s_len );
if (get < 0) if (get < 0)
{ {
werror("io.c: getXXXXname failed, %z", STRERROR(errno)); werror("io.c: getXXXXname failed %e", errno);
return NULL; return NULL;
} }
...@@ -1280,10 +1278,10 @@ void io_set_nonblocking(int fd) ...@@ -1280,10 +1278,10 @@ void io_set_nonblocking(int fd)
int old = fcntl(fd, F_GETFL); int old = fcntl(fd, F_GETFL);
if (old < 0) if (old < 0)
fatal("io_set_nonblocking: fcntl(F_GETFL) failed, %z", STRERROR(errno)); fatal("io_set_nonblocking: fcntl(F_GETFL) failed %e", errno);
if (fcntl(fd, F_SETFL, old | O_NONBLOCK) < 0) if (fcntl(fd, F_SETFL, old | O_NONBLOCK) < 0)
fatal("io_set_nonblocking: fcntl(F_SETFL) failed, %z", STRERROR(errno)); fatal("io_set_nonblocking: fcntl(F_SETFL) failed %e", errno);
} }
void io_set_blocking(int fd) void io_set_blocking(int fd)
...@@ -1291,10 +1289,10 @@ void io_set_blocking(int fd) ...@@ -1291,10 +1289,10 @@ void io_set_blocking(int fd)
int old = fcntl(fd, F_GETFL); int old = fcntl(fd, F_GETFL);
if (old < 0) if (old < 0)
fatal("io_set_blocking: fcntl(F_GETFL) failed, %z", STRERROR(errno)); fatal("io_set_blocking: fcntl(F_GETFL) failed %e", errno);
if (fcntl(fd, F_SETFL, old & ~O_NONBLOCK) < 0) if (fcntl(fd, F_SETFL, old & ~O_NONBLOCK) < 0)
fatal("io_set_blocking: fcntl(F_SETFL) failed, %z", STRERROR(errno)); fatal("io_set_blocking: fcntl(F_SETFL) failed %e", errno);
} }
void io_set_close_on_exec(int fd) void io_set_close_on_exec(int fd)
...@@ -1305,11 +1303,10 @@ void io_set_close_on_exec(int fd) ...@@ -1305,11 +1303,10 @@ void io_set_close_on_exec(int fd)
int old = fcntl(fd, F_GETFD); int old = fcntl(fd, F_GETFD);
if (old < 0) if (old < 0)
fatal("io_set_nonblocking: fcntl(F_GETFD) failed, %z", STRERROR(errno)); fatal("io_set_nonblocking: fcntl(F_GETFD) failed %e", errno);
if (fcntl(fd, F_SETFD, old | 1) < 0) if (fcntl(fd, F_SETFD, old | 1) < 0)
fatal("Can't set close-on-exec flag for fd %i: %z\n", fatal("Can't set close-on-exec flag for fd %i %e\n", fd, errno);
fd, STRERROR(errno));
} }
...@@ -1429,8 +1426,7 @@ io_bind_sockaddr(struct sockaddr *local, ...@@ -1429,8 +1426,7 @@ io_bind_sockaddr(struct sockaddr *local,
if (bind(s, (struct sockaddr *)local, length) < 0) if (bind(s, (struct sockaddr *)local, length) < 0)
{ {
trace("io.c: bind failed: (errno = %d) %z\n", trace("io.c: bind failed %e\n", errno);
errno, STRERROR(errno));
close(s); close(s);
return NULL; return NULL;
} }
...@@ -1490,8 +1486,8 @@ lsh_popd(int old_cd, const char *directory) ...@@ -1490,8 +1486,8 @@ lsh_popd(int old_cd, const char *directory)
{ {
while (fchdir(old_cd) < 0) while (fchdir(old_cd) < 0)
if (errno != EINTR) if (errno != EINTR)
fatal("io.c: Failed to cd back from %z (errno = %i): %z\n", fatal("io.c: Failed to cd back from %z %e\n",
directory, errno, STRERROR(errno)); directory, errno);
close(old_cd); close(old_cd);
} }
...@@ -1514,8 +1510,7 @@ lsh_pushd_fd(int dir) ...@@ -1514,8 +1510,7 @@ lsh_pushd_fd(int dir)
while (fchdir(old_cd) < 0) while (fchdir(old_cd) < 0)
if (errno != EINTR) if (errno != EINTR)
{ {
werror("io.c: fchdir(`.') failed (errno = %i): %z\n", werror("io.c: fchdir(`.') failed %e\n", errno);
errno, strerror(errno));
close(old_cd); close(old_cd);
return -1; return -1;
} }
...@@ -1555,7 +1550,7 @@ lsh_pushd(const char *directory, ...@@ -1555,7 +1550,7 @@ lsh_pushd(const char *directory,
&& (errno != EEXIST) ) && (errno != EEXIST) )
{ {
werror("io.c: Creating directory %z failed " werror("io.c: Creating directory %z failed "
"(errno = %i): %z\n", directory, errno, STRERROR(errno)); "%e\n", directory, errno);
} }
} }
...@@ -1566,7 +1561,7 @@ lsh_pushd(const char *directory, ...@@ -1566,7 +1561,7 @@ lsh_pushd(const char *directory,
if (fstat(fd, &sbuf) < 0) if (fstat(fd, &sbuf) < 0)
{ {
werror("io.c: Failed to stat `%z'.\n" werror("io.c: Failed to stat `%z'.\n"
" (errno = %i): %z\n", directory, errno, STRERROR(errno)); " %e\n", directory, errno);
return -1; return -1;
} }
...@@ -1610,8 +1605,7 @@ lsh_pushd(const char *directory, ...@@ -1610,8 +1605,7 @@ lsh_pushd(const char *directory,
/* Test if we are allowed to cd to our current working directory. */ /* Test if we are allowed to cd to our current working directory. */
while (fchdir(old_cd) < 0) while (fchdir(old_cd) < 0)
{ {
werror("io.c: fchdir(\".\") failed (errno = %i): %z\n", werror("io.c: fchdir(\".\") failed %e\n", errno);
errno, strerror(errno));
close(fd); close(fd);
close(old_cd); close(old_cd);
return -1; return -1;
...@@ -1679,8 +1673,8 @@ io_bind_local(struct local_info *info, ...@@ -1679,8 +1673,8 @@ io_bind_local(struct local_info *info,
if ( (unlink(cname) < 0) if ( (unlink(cname) < 0)
&& (errno != ENOENT)) && (errno != ENOENT))
{ {
werror("io.c: unlink '%S'/'%S' failed (errno = %i): %z\n", werror("io.c: unlink '%S'/'%S' failed %e\n",
info->directory, info->name, errno, STRERROR(errno)); info->directory, info->name, errno);
lsh_popd(old_cd, cdir); lsh_popd(old_cd, cdir);
return NULL; return NULL;
} }
...@@ -1855,8 +1849,7 @@ close_fd(struct lsh_fd *fd) ...@@ -1855,8 +1849,7 @@ close_fd(struct lsh_fd *fd)
if (close(fd->fd) < 0) if (close(fd->fd) < 0)
{ {
werror("io.c: close failed, (errno = %i): %z\n", werror("io.c: close failed %e\n", errno);
errno, STRERROR(errno));
EXCEPTION_RAISE(fd->e, EXCEPTION_RAISE(fd->e,
make_io_exception(EXC_IO_CLOSE, fd, make_io_exception(EXC_IO_CLOSE, fd,
errno, NULL)); errno, NULL));
...@@ -1938,8 +1931,7 @@ close_fd_write(struct lsh_fd *fd) ...@@ -1938,8 +1931,7 @@ close_fd_write(struct lsh_fd *fd)
/* Try calling shutdown */ /* Try calling shutdown */
if ( (shutdown (fd->fd, SHUT_WR) < 0) if ( (shutdown (fd->fd, SHUT_WR) < 0)
&& errno != ENOTSOCK) && errno != ENOTSOCK)
werror("close_fd_write, shutdown failed, (errno = %i): %z\n", werror("close_fd_write, shutdown failed, %e\n", errno);
errno, STRERROR(errno));
} }
} }
} }
...@@ -2032,19 +2024,19 @@ lsh_make_pipe(int *fds) ...@@ -2032,19 +2024,19 @@ lsh_make_pipe(int *fds)
{ {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
{ {
werror("socketpair failed: %z\n", STRERROR(errno)); werror("socketpair failed %e\n", errno);
return 0; return 0;
} }
trace("Created socket pair. Using fd:s %i <-- %i\n", fds[0], fds[1]); trace("Created socket pair. Using fd:s %i <-- %i\n", fds[0], fds[1]);
if (SHUTDOWN_UNIX(fds[0], SHUT_WR_UNIX) < 0) if (SHUTDOWN_UNIX(fds[0], SHUT_WR_UNIX) < 0)
{ {
werror("shutdown(%i, SHUT_WR) failed: %z\n", fds[0], STRERROR(errno)); werror("shutdown(%i, SHUT_WR) failed %e\n", fds[0], errno);
goto fail; goto fail;
} }
if (SHUTDOWN_UNIX(fds[1], SHUT_RD_UNIX) < 0) if (SHUTDOWN_UNIX(fds[1], SHUT_RD_UNIX) < 0)
{ {
werror("shutdown(%i, SHUT_RD_UNIX) failed: %z\n", fds[0], STRERROR(errno)); werror("shutdown(%i, SHUT_RD_UNIX) failed %e\n", fds[0], errno);
fail: fail:
{ {
int saved_errno = errno; int saved_errno = errno;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "xalloc.h" #include "xalloc.h"
#include <errno.h> #include <errno.h>
#include <string.h> /* #include <string.h> */
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -94,8 +94,8 @@ do_lsh_file_lock(struct lsh_file_lock_info *self, unsigned retries) ...@@ -94,8 +94,8 @@ do_lsh_file_lock(struct lsh_file_lock_info *self, unsigned retries)
if (fd < 0) if (fd < 0)
{ {
if (errno != EEXIST) if (errno != EEXIST)
werror("Could not create lock file `%S' (errno = %i): %z\n", werror("Could not create lock file `%S' %e\n",
self->lockname, errno, STRERROR(errno)); self->lockname, errno);
return NULL; return NULL;
} }
else else
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "werror.h" #include "werror.h"
#include "xalloc.h" #include "xalloc.h"
#include <string.h> /* #include <string.h> */
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -187,8 +187,8 @@ int main(int argc, char **argv) ...@@ -187,8 +187,8 @@ int main(int argc, char **argv)
O_WRONLY | O_CREAT, 0666); O_WRONLY | O_CREAT, 0666);
if (out < 0) if (out < 0)
{ {
werror("Failed to open file `%S' for writing: %z\n", werror("Failed to open file `%S' for writing %e\n",
options->file, STRERROR(errno)); options->file, errno);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
...@@ -196,8 +196,7 @@ int main(int argc, char **argv) ...@@ -196,8 +196,7 @@ int main(int argc, char **argv)
input = io_read_file_raw(STDIN_FILENO, 3000); input = io_read_file_raw(STDIN_FILENO, 3000);
if (!input) if (!input)
{ {
werror("Failed to read stdin: %z\n", werror("Failed to read stdin %e\n", errno);
STRERROR(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
...@@ -60,7 +60,7 @@ B2CTISEmV3KYx5NJpyKC3IBw/ckP6Q== ...@@ -60,7 +60,7 @@ B2CTISEmV3KYx5NJpyKC3IBw/ckP6Q==
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> /* #include <string.h> */
#include <unistd.h> #include <unistd.h>
#include "lsh-export-key.c.x" #include "lsh-export-key.c.x"
...@@ -241,8 +241,8 @@ int main(int argc, char **argv) ...@@ -241,8 +241,8 @@ int main(int argc, char **argv)
in = open(options->infile, O_RDONLY); in = open(options->infile, O_RDONLY);
if (in < 0) if (in < 0)
{ {
werror("Failed to open '%z' for reading: %z\n", werror("Failed to open '%z' for reading %e\n",
options->infile, STRERROR(errno)); options->infile, errno);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
...@@ -253,8 +253,8 @@ int main(int argc, char **argv) ...@@ -253,8 +253,8 @@ int main(int argc, char **argv)
O_WRONLY | O_CREAT, 0666); O_WRONLY | O_CREAT, 0666);
if (out < 0) if (out < 0)
{ {
werror("Failed to open '%z' for writing: %z\n", werror("Failed to open '%z' for writing %e\n",
options->outfile, STRERROR(errno)); options->outfile, errno);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
...@@ -264,8 +264,8 @@ int main(int argc, char **argv) ...@@ -264,8 +264,8 @@ int main(int argc, char **argv)
if (!input) if (!input)
{ {
werror("Failed to read '%z': %z\n", werror("Failed to read '%z' %e\n",
options->infile, STRERROR(errno)); options->infile, errno);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
...@@ -297,8 +297,8 @@ get_dev_random(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -297,8 +297,8 @@ get_dev_random(struct yarrow256_ctx *ctx, enum source_type source)
while ( (res < 0) && (errno == EINTR)); while ( (res < 0) && (errno == EINTR));
if (res < 0) if (res < 0)
werror("Reading from %z failed (errno = %i): %z\n", werror("Reading from %z failed %e\n",
names[i], errno, STRERROR(errno)); names[i], errno);
else if (res > 0) else if (res > 0)
{ {
...@@ -374,8 +374,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -374,8 +374,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source)
if (fd < 0) if (fd < 0)
{ {
if (!getuid() || (errno != EACCES)) if (!getuid() || (errno != EACCES))
werror("Couldn't open /dev/mem (errno = %i): %z\n", werror("Couldn't open /dev/mem %e\n", errno);
errno, STRERROR(errno));
} }
else else
{ {
...@@ -410,8 +409,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -410,8 +409,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source)
break; break;
if (res < 0) if (res < 0)
{ {
werror("Reading /dev/mem failed (errno = %i): %z\n", werror("Reading /dev/mem failed %e\n", errno);
errno, STRERROR(errno));
break; break;