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)
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);
return NULL;
}
......
......@@ -39,8 +39,8 @@
#include "werror.h"
#include "xalloc.h"
#include <string.h>
#include <assert.h>
#include <string.h>
#include <signal.h>
......@@ -865,8 +865,7 @@ DEFINE_COMMAND(background_process)
break;
case -1:
/* Error */
werror("background_process: fork failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("background_process: fork failed %e\n", errno);
COMMAND_RETURN(c, a);
break;
default:
......@@ -909,8 +908,7 @@ make_client_session(struct client_options *options)
if (in < 0)
{
werror("lsh: Can't dup/open stdin (errno = %i): %z!\n",
errno, strerror(errno));
werror("lsh: Can't dup/open stdin %e\n", errno);
return NULL;
}
......@@ -952,8 +950,7 @@ make_client_session(struct client_options *options)
if (out < 0)
{
werror("lsh: Can't dup/open stdout (errno = %i): %z!\n",
errno, strerror(errno));
werror("lsh: Can't dup/open stdout %e\n", errno);
close(in);
return NULL;
}
......
......@@ -88,8 +88,8 @@ int daemon_pidfile(const char *name)
{
if (errno != EEXIST)
{
werror("Failed to open pid file '%z' (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("Failed to open pid file '%z' %e\n",
name, errno);
return 0;
}
......@@ -118,8 +118,8 @@ int daemon_pidfile(const char *name)
fd = open(name, O_RDONLY);
if (fd < 0)
{
werror("Pid file '%z' already exists, and is unreadable (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("Pid file '%z' already exists, and is unreadable %e\n",
name, errno);
return 0;
}
{
......@@ -132,14 +132,14 @@ int daemon_pidfile(const char *name)
if (length < 0)
{
werror("Pid file '%z' already exists, but read failed (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("Pid file '%z' already exists, but read failed %e\n",
name, errno);
return 0;
}
if ( !length|| !buffer[0] || (length == BUF_SIZE) )
{
werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("Pid file '%z' already exists, but contents is garbled.\n",
name);
return 0;
}
......@@ -157,8 +157,8 @@ int daemon_pidfile(const char *name)
if ( (errno == ERANGE) || (end != buffer + length)
|| (other <= 0) || (other != (pid_t) other))
{
werror("Pid file '%z' already exists, but contents is garbled (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("Pid file '%z' already exists, but contents is garbled.\n",
name);
return 0;
}
......@@ -191,13 +191,12 @@ int daemon_pidfile(const char *name)
lsh_string_free(pid);
return 1;
}
werror("Writing pid file '%z' failed (errno = %i): %z",
name, errno, STRERROR(errno));
werror("Writing pid file '%z' failed %e\n", name, errno);
/* Attempt unlinking file */
if (unlink(name) < 0)
werror("Unlinking pid file '%z' failed (errno = %i): %z",
name, errno, STRERROR(errno));
werror("Unlinking pid file '%z' failed %e\n",
name, errno);
lsh_string_free(pid);
......@@ -475,8 +474,8 @@ int daemon_close(const char *name)
{
if (unlink(name) < 0)
{
werror("daemon_close: Unlink of pid file '%z' failed (errno = %i): %z\n",
name, errno, STRERROR(errno));
werror("daemon_close: Unlink of pid file '%z' failed %e\n",
name, errno);
return 0;
}
return 1;
......
......@@ -333,8 +333,7 @@ io_run(void)
/* We need liboop-0.8, OOP_ERROR is not defined in liboop-0.7. */
if (res == OOP_ERROR)
werror("oop_sys_run (errno = %i): %z\n",
errno, STRERROR(errno));
werror("oop_sys_run %e\n", errno);
trace("io_run: Exiting\n");
}
......@@ -660,7 +659,7 @@ do_write_callback(struct io_callback *s UNUSED,
&& (fd->write_buffer->length == 1) )
debug("io.c: ignoring write error, on the final ^D character\n");
#endif
werror("io.c: write failed, %z\n", STRERROR(errno));
werror("io.c: write failed %e\n", errno);
EXCEPTION_RAISE(fd->e,
make_io_exception(EXC_IO_WRITE,
fd, errno, NULL));
......@@ -722,7 +721,7 @@ do_listen_callback(struct io_callback *s,
(struct sockaddr *) &peer, &addr_len);
if (conn < 0)
{
werror("io.c: accept failed, %z", STRERROR(errno));
werror("io.c: accept failed %e", errno);
return;
}
......@@ -1105,10 +1104,9 @@ fd2info(struct lsh_fd *fd, int side)
else
get = getpeername( fd->fd, (struct sockaddr *) &sock, &s_len );
if (get < 0)
{
werror("io.c: getXXXXname failed, %z", STRERROR(errno));
werror("io.c: getXXXXname failed %e", errno);
return NULL;
}
......@@ -1280,10 +1278,10 @@ void io_set_nonblocking(int fd)
int old = fcntl(fd, F_GETFL);
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)
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)
......@@ -1291,10 +1289,10 @@ void io_set_blocking(int fd)
int old = fcntl(fd, F_GETFL);
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)
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)
......@@ -1305,11 +1303,10 @@ void io_set_close_on_exec(int fd)
int old = fcntl(fd, F_GETFD);
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)
fatal("Can't set close-on-exec flag for fd %i: %z\n",
fd, STRERROR(errno));
fatal("Can't set close-on-exec flag for fd %i %e\n", fd, errno);
}
......@@ -1429,8 +1426,7 @@ io_bind_sockaddr(struct sockaddr *local,
if (bind(s, (struct sockaddr *)local, length) < 0)
{
trace("io.c: bind failed: (errno = %d) %z\n",
errno, STRERROR(errno));
trace("io.c: bind failed %e\n", errno);
close(s);
return NULL;
}
......@@ -1490,8 +1486,8 @@ lsh_popd(int old_cd, const char *directory)
{
while (fchdir(old_cd) < 0)
if (errno != EINTR)
fatal("io.c: Failed to cd back from %z (errno = %i): %z\n",
directory, errno, STRERROR(errno));
fatal("io.c: Failed to cd back from %z %e\n",
directory, errno);
close(old_cd);
}
......@@ -1514,8 +1510,7 @@ lsh_pushd_fd(int dir)
while (fchdir(old_cd) < 0)
if (errno != EINTR)
{
werror("io.c: fchdir(`.') failed (errno = %i): %z\n",
errno, strerror(errno));
werror("io.c: fchdir(`.') failed %e\n", errno);
close(old_cd);
return -1;
}
......@@ -1555,7 +1550,7 @@ lsh_pushd(const char *directory,
&& (errno != EEXIST) )
{
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,
if (fstat(fd, &sbuf) < 0)
{
werror("io.c: Failed to stat `%z'.\n"
" (errno = %i): %z\n", directory, errno, STRERROR(errno));
" %e\n", directory, errno);
return -1;
}
......@@ -1610,8 +1605,7 @@ lsh_pushd(const char *directory,
/* Test if we are allowed to cd to our current working directory. */
while (fchdir(old_cd) < 0)
{
werror("io.c: fchdir(\".\") failed (errno = %i): %z\n",
errno, strerror(errno));
werror("io.c: fchdir(\".\") failed %e\n", errno);
close(fd);
close(old_cd);
return -1;
......@@ -1679,8 +1673,8 @@ io_bind_local(struct local_info *info,
if ( (unlink(cname) < 0)
&& (errno != ENOENT))
{
werror("io.c: unlink '%S'/'%S' failed (errno = %i): %z\n",
info->directory, info->name, errno, STRERROR(errno));
werror("io.c: unlink '%S'/'%S' failed %e\n",
info->directory, info->name, errno);
lsh_popd(old_cd, cdir);
return NULL;
}
......@@ -1855,8 +1849,7 @@ close_fd(struct lsh_fd *fd)
if (close(fd->fd) < 0)
{
werror("io.c: close failed, (errno = %i): %z\n",
errno, STRERROR(errno));
werror("io.c: close failed %e\n", errno);
EXCEPTION_RAISE(fd->e,
make_io_exception(EXC_IO_CLOSE, fd,
errno, NULL));
......@@ -1938,8 +1931,7 @@ close_fd_write(struct lsh_fd *fd)
/* Try calling shutdown */
if ( (shutdown (fd->fd, SHUT_WR) < 0)
&& errno != ENOTSOCK)
werror("close_fd_write, shutdown failed, (errno = %i): %z\n",
errno, STRERROR(errno));
werror("close_fd_write, shutdown failed, %e\n", errno);
}
}
}
......@@ -2032,19 +2024,19 @@ lsh_make_pipe(int *fds)
{
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
{
werror("socketpair failed: %z\n", STRERROR(errno));
werror("socketpair failed %e\n", errno);
return 0;
}
trace("Created socket pair. Using fd:s %i <-- %i\n", fds[0], fds[1]);
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;
}
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:
{
int saved_errno = errno;
......
......@@ -32,7 +32,7 @@
#include "xalloc.h"
#include <errno.h>
#include <string.h>
/* #include <string.h> */
#if HAVE_UNISTD_H
#include <unistd.h>
......@@ -94,8 +94,8 @@ do_lsh_file_lock(struct lsh_file_lock_info *self, unsigned retries)
if (fd < 0)
{
if (errno != EEXIST)
werror("Could not create lock file `%S' (errno = %i): %z\n",
self->lockname, errno, STRERROR(errno));
werror("Could not create lock file `%S' %e\n",
self->lockname, errno);
return NULL;
}
else
......
......@@ -18,7 +18,7 @@
#include "werror.h"
#include "xalloc.h"
#include <string.h>
/* #include <string.h> */
#include <unistd.h>
#include <fcntl.h>
......@@ -187,8 +187,8 @@ int main(int argc, char **argv)
O_WRONLY | O_CREAT, 0666);
if (out < 0)
{
werror("Failed to open file `%S' for writing: %z\n",
options->file, STRERROR(errno));
werror("Failed to open file `%S' for writing %e\n",
options->file, errno);
return EXIT_FAILURE;
}
}
......@@ -196,8 +196,7 @@ int main(int argc, char **argv)
input = io_read_file_raw(STDIN_FILENO, 3000);
if (!input)
{
werror("Failed to read stdin: %z\n",
STRERROR(errno));
werror("Failed to read stdin %e\n", errno);
return EXIT_FAILURE;
}
......
......@@ -60,7 +60,7 @@ B2CTISEmV3KYx5NJpyKC3IBw/ckP6Q==
#include <assert.h>
#include <fcntl.h>
#include <string.h>
/* #include <string.h> */
#include <unistd.h>
#include "lsh-export-key.c.x"
......@@ -241,8 +241,8 @@ int main(int argc, char **argv)
in = open(options->infile, O_RDONLY);
if (in < 0)
{
werror("Failed to open '%z' for reading: %z\n",
options->infile, STRERROR(errno));
werror("Failed to open '%z' for reading %e\n",
options->infile, errno);
return EXIT_FAILURE;
}
}
......@@ -253,8 +253,8 @@ int main(int argc, char **argv)
O_WRONLY | O_CREAT, 0666);
if (out < 0)
{
werror("Failed to open '%z' for writing: %z\n",
options->outfile, STRERROR(errno));
werror("Failed to open '%z' for writing %e\n",
options->outfile, errno);
return EXIT_FAILURE;
}
}
......@@ -264,8 +264,8 @@ int main(int argc, char **argv)
if (!input)
{
werror("Failed to read '%z': %z\n",
options->infile, STRERROR(errno));
werror("Failed to read '%z' %e\n",
options->infile, errno);
return EXIT_FAILURE;
}
......
......@@ -297,8 +297,8 @@ get_dev_random(struct yarrow256_ctx *ctx, enum source_type source)
while ( (res < 0) && (errno == EINTR));
if (res < 0)
werror("Reading from %z failed (errno = %i): %z\n",
names[i], errno, STRERROR(errno));
werror("Reading from %z failed %e\n",
names[i], errno);
else if (res > 0)
{
......@@ -374,8 +374,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source)
if (fd < 0)
{
if (!getuid() || (errno != EACCES))
werror("Couldn't open /dev/mem (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Couldn't open /dev/mem %e\n", errno);
}
else
{
......@@ -410,8 +409,7 @@ get_dev_mem(struct yarrow256_ctx *ctx, enum source_type source)
break;
if (res < 0)
{
werror("Reading /dev/mem failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Reading /dev/mem failed %e\n", errno);
break;
}
......@@ -652,8 +650,8 @@ spawn_source_process(unsigned *index,
{
if (access(system_sources[i].path, X_OK) < 0)
{
debug("unix_random.c: spawn_source_process: Skipping '%z'; not executable: %z\n",
system_sources[i].path, STRERROR(errno));
debug("unix_random.c: spawn_source_process: Skipping '%z'; not executable %e\n",
system_sources[i].path, errno);
i++;
}
else
......@@ -668,8 +666,7 @@ spawn_source_process(unsigned *index,
if (!lsh_make_pipe(output))
{
werror("spawn_source_process: Can't create pipe (errno = %i): %z\n",
errno, STRERROR(errno));
werror("spawn_source_process: Can't create pipe %e\n", errno);
return 0;
}
......@@ -717,38 +714,32 @@ spawn_source_process(unsigned *index,
{
if (setgroups(0, NULL) < 0)
{
werror("Failed to clear supplimentary groups list "
"(errno = %i): %z\n",
errno, STRERROR(errno));
werror("Failed to clear supplimentary groups list %e\n", errno);
_exit(EXIT_FAILURE);
}
if (setgid(gid) < 0)
{
werror("Failed to change gid (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Failed to change gid %e\n", errno);
_exit(EXIT_FAILURE);
}
if (setuid(uid) < 0)
{
werror("Failed to change uid (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Failed to change uid %e\n", errno);
_exit(EXIT_FAILURE);
}
}
if (dup2(output[1], STDOUT_FILENO) < 0)
{
werror("spawn_source_process: dup2 for stdout failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("spawn_source_process: dup2 for stdout failed %e\n", errno);
_exit(EXIT_FAILURE);
}
/* Ignore stderr. */
if (dup2(dev_null, STDERR_FILENO) < 0)
{
werror("spawn_source_process: dup2 for stderr failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("spawn_source_process: dup2 for stderr failed %e\n", errno);
_exit(EXIT_FAILURE);
}
......@@ -759,8 +750,8 @@ spawn_source_process(unsigned *index,
execl(state->source->path, state->source->path,
state->source->arg, NULL);
werror("spawn_source_process: execl '%z' failed (errno = %i): %z\n",
state->source->path, errno, STRERROR(errno));
werror("spawn_source_process: execl '%z' failed %e\n",
state->source->path, errno);
_exit(EXIT_FAILURE);
}
......@@ -860,8 +851,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
if (dev_null < 0)
{
werror("Failed to open /dev/null (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Failed to open /dev/null %e\n", errno);
return;
}
......@@ -869,8 +859,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
unique.pid = getpid();
if (gettimeofday(&unique.now, NULL) < 0)
{
werror("getimeofday failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("getimeofday failed %e\n", errno);
return;
}
......@@ -907,8 +896,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
trace("get_system: calling poll, nfds = %i\n", nfds);
if (poll(fds, nfds, -1) < 0)
{
werror("get_system: poll failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("get_system: poll failed %e\n", errno);
break;
}
......@@ -946,9 +934,8 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
{
if (errno != EINTR)
{
werror("get_system: background_poll read failed "
"(errno = %i): %z\n",
errno, STRERROR(errno));
werror("get_system: background_poll read failed %e\n",
errno);
return;
}
}
......@@ -995,8 +982,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
if (waitpid(state[j].pid, &status, 0) < 0)
{
werror("waitpid failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("waitpid failed %e\n", errno);
return;
}
if (WIFEXITED(status))
......@@ -1038,8 +1024,8 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
while ( (res < 0) && (errno = EINTR) );
if (res < 0)
werror("Reading %z failed (errno = %i): %z\n",
linux_proc_sources[i].name, errno, STRERROR(errno));
werror("Reading %z failed %e\n",
linux_proc_sources[i].name, errno);
else
{
unsigned entropy = 0;
......@@ -1076,16 +1062,14 @@ get_time_accuracy(void)
if (gettimeofday(&start, NULL))
{
werror("gettimeofday failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("gettimeofday failed %e\n", errno);
return 0;
}
do
if (gettimeofday(&next, NULL))
{
werror("gettimeofday failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("gettimeofday failed %e\n", errno);
return 0;
}
......@@ -1163,8 +1147,7 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source)
event.c = getchar();
if (gettimeofday(&event.now, NULL) < 0)
{
werror("gettimeofday failed (errno = %i): %z\n",
errno, STRERROR(errno));
werror("gettimeofday failed %e\n", errno);
return;
}
......@@ -1244,8 +1227,8 @@ main(int argc, char **argv)
&& (mkdir(lsh_get_cstring(options->directory), 0755) < 0)
&& (errno != EEXIST) )
{
werror("Creating `%S' failed (errno = %i): %z.\n",
options->directory, errno, STRERROR(errno));
werror("Creating `%S' failed %e.\n",
options->directory, errno);
return EXIT_FAILURE;
}
......@@ -1325,8 +1308,8 @@ main(int argc, char **argv)
if (fd < 0)
{
werror("Failed to open file `%S' (errno = %i): %z\n",
options->filename, errno, STRERROR(errno));
werror("Failed to open file `%S' %e\n",
options->filename, errno);
KILL_RESOURCE(lock);
return EXIT_FAILURE;
......@@ -1340,8 +1323,8 @@ main(int argc, char **argv)
struct stat sbuf;
if (fstat(fd, &sbuf) < 0)
{
werror("Failed to stat file `%S' (errno = %i): %z\n",
options->filename, errno, STRERROR(errno));
werror("Failed to stat file `%S' %e\n",
options->filename, errno);
close(fd);
KILL_RESOURCE(lock);
......@@ -1363,8 +1346,7 @@ main(int argc, char **argv)
options->filename);
if (fchmod(fd, sbuf.st_mode & ~(S_IRWXG | S_IRWXO)) < 0)
{
werror("Failed to change permissions (errno = %i): %z\n",
errno, STRERROR(errno));
werror("Failed to change permissions %e\n", errno);
close(fd);
KILL_RESOURCE(lock);
return EXIT_FAILURE;
......@@ -1373,8 +1355,8 @@ main(int argc, char **argv)