errno = saved_errno;
perror("");
+ /* perror writes a newline. */
+ } else {
+ fprintf(stderr, "\n");
}
funlockfile(stderr);
static const char *get_socket_path(void) {
const char *path = getenv("SOCKET2UNIX_PATH");
if (!path) {
- ERROR("SOCKET2UNIX_PATH environment variable not defined\n");
+ ERROR("SOCKET2UNIX_PATH environment variable not defined");
}
if (path[0] != '/') {
- ERROR("SOCKET2UNIX_PATH '%s' must be an absolute path\n", path);
+ ERROR("SOCKET2UNIX_PATH '%s' must be an absolute path", path);
}
return path;
}
char option[length + 1];
strncpy(option, pos, length);
option[length] = '\0';
- ERROR("unknown option '%s' in SOCKET2UNIX_OPTIONS\n",
- option);
+ ERROR("unknown option '%s' in SOCKET2UNIX_OPTIONS", option);
}
}
if ((options & OPTION_CLIENT_ONLY) && (options & OPTION_SERVER_ONLY)) {
ERROR("conflicting options 'client_only', 'server_only' "
- "in SOCKET2UNIX_OPTIONS\n");
+ "in SOCKET2UNIX_OPTIONS");
}
return options;
&& addrlen < sizeof(struct sockaddr_in))
|| (addr->sa_family == AF_INET6
&& addrlen < sizeof(struct sockaddr_in6))) {
- WARN("invalid addrlen from program\n");
+ WARN("invalid addrlen from program");
return -1;
}
} else {
af = "unknown";
port = 0;
- WARN("unknown sa_family '%s' (%d)\n",
+ WARN("unknown sa_family '%s' (%d)",
af_to_name(addr->sa_family), addr->sa_family);
}
return sockfd;
}
- DBG("socket(%s, %s, %d)\n",
+ DBG("socket(%s, %s, %d)",
af_to_name(domain), sock_to_name(type), protocol);
struct list *entry = xmalloc(sizeof(*entry));
struct list *entry = remove_sockfd(fd);
if (entry == NULL) {
- DBG("close(%d): sockfd not found\n", fd);
+ DBG("close(%d): sockfd not found", fd);
return real_close(fd);
}
assert(fd == entry->orig_sockfd);
- DBG("close(%d)\n", fd);
+ DBG("close(%d)", fd);
free(entry->orig_addr);
free(entry);
struct list *entry = find_sockfd(sockfd);
if (!entry) {
- DBG("bind(%d, ..): sockfd not found\n", sockfd);
+ DBG("bind(%d, ..): sockfd not found", sockfd);
return real_bind(sockfd, addr, addrlen);
}
assert(sockfd == entry->orig_sockfd);
- DBG("bind(%d, ..): %s %s\n",
+ DBG("bind(%d, ..): %s %s",
sockfd,
af_to_name(entry->orig_domain), sock_to_name(entry->orig_type));
}
if (global_options & OPTION_CLIENT_ONLY) {
- DBG("listen(%d, %d): server hooking disabled\n", sockfd, backlog);
+ DBG("listen(%d, %d): server hooking disabled", sockfd, backlog);
return real_listen(sockfd, backlog);
}
struct list *entry = find_sockfd(sockfd);
if (!entry) {
- DBG("listen(%d, %d): sockfd not found\n", sockfd, backlog);
+ DBG("listen(%d, %d): sockfd not found", sockfd, backlog);
return real_listen(sockfd, backlog);
}
assert(sockfd == entry->orig_sockfd);
- DBG("listen(%d, %d): %s %s\n",
+ DBG("listen(%d, %d): %s %s",
sockfd, backlog,
af_to_name(entry->orig_domain), sock_to_name(entry->orig_type));
struct sockaddr_un sockaddr;
if (set_sockaddr_un(&sockaddr, entry->orig_addr,
entry->orig_addrlen) != 0) {
- ERROR("listen(%d, ..) failed\n", sockfd);
+ ERROR("listen(%d, ..) failed", sockfd);
}
- DBG("listen(%d, ..): using path '%s'\n", sockfd, sockaddr.sun_path);
+ DBG("listen(%d, ..): using path '%s'", sockfd, sockaddr.sun_path);
int attempts = 0;
while (attempts < 10) {
}
if (!S_ISSOCK(buf.st_mode)) {
- ERROR("listen(%d, ..): path '%s' exits and is no socket\n",
+ ERROR("listen(%d, ..): path '%s' exits and is no socket",
sockfd, sockaddr.sun_path);
}
- WARN("listen(%d, ..): unlinking '%s'\n", sockfd, sockaddr.sun_path);
+ WARN("listen(%d, ..): unlinking '%s'", sockfd, sockaddr.sun_path);
if (unlink(sockaddr.sun_path) != 0) {
DIE("listen(%d, ..): unlink '%s' failed",
sockfd, sockaddr.sun_path);
}
if (attempts == 10) {
- ERROR("listen(%d, ..): failed to create UNIX socket file\n", sockfd);
+ ERROR("listen(%d, ..): failed to create UNIX socket file", sockfd);
}
/* Replace the original socket of the program with our socket. */
}
if (global_options & OPTION_CLIENT_ONLY) {
- DBG("accept(%d, ..): server hooking disabled\n", sockfd);
+ DBG("accept(%d, ..): server hooking disabled", sockfd);
return real_accept(sockfd, addr, addrlen);
}
struct list *entry = find_sockfd(sockfd);
if (!entry) {
- DBG("accept(%d, ..): sockfd not found\n", sockfd);
+ DBG("accept(%d, ..): sockfd not found", sockfd);
return real_accept(sockfd, addr, addrlen);
}
assert(sockfd == entry->orig_sockfd);
- DBG("accept(%d, ..): %s %s\n",
+ DBG("accept(%d, ..): %s %s",
sockfd,
af_to_name(entry->orig_domain), sock_to_name(entry->orig_type));
if (addr == NULL || addrlen == NULL) {
return sock;
}
- DBG("accept(%d, ..): caller requested sockaddr\n", sockfd);
+ DBG("accept(%d, ..): caller requested sockaddr", sockfd);
if (*addrlen < size) {
WARN("accept(%d, ..): invalid addrlen from program", sockfd);
}
if (global_options & OPTION_SERVER_ONLY) {
- DBG("connect(%d, ..): client hooking disabled\n", sockfd);
+ DBG("connect(%d, ..): client hooking disabled", sockfd);
return real_connect(sockfd, addr, addrlen);
}
struct list *entry = find_sockfd(sockfd);
if (!entry) {
- DBG("connect(%d, ..): sockfd not found\n", sockfd);
+ DBG("connect(%d, ..): sockfd not found", sockfd);
return real_connect(sockfd, addr, addrlen);
}
assert(sockfd == entry->orig_sockfd);
- DBG("connect(%d, ..): %s %s\n",
+ DBG("connect(%d, ..): %s %s",
sockfd,
af_to_name(entry->orig_domain), sock_to_name(entry->orig_type));
struct sockaddr_un sockaddr;
if (set_sockaddr_un(&sockaddr, addr, addrlen) != 0) {
- ERROR("connect(%d, ..) failed\n", sockfd);
+ ERROR("connect(%d, ..) failed", sockfd);
}
- DBG("connect(%d, ..): using path '%s'\n", sockfd, sockaddr.sun_path);
+ DBG("connect(%d, ..): using path '%s'", sockfd, sockaddr.sun_path);
if (real_connect(entry->orig_sockfd, (struct sockaddr *)&sockaddr,
sizeof(sockaddr)) != 0) {
static int (*real_getsockname)(int, struct sockaddr *, socklen_t *);
LOAD_FUNCTION(real_getsockname, "getsockname");
- DBG("getsockname(%d, ..)\n", sockfd);
+ DBG("getsockname(%d, ..)", sockfd);
return real_getsockname(sockfd, addr, addrlen);
}
static int (*real_getpeername)(int, struct sockaddr *, socklen_t *);
LOAD_FUNCTION(real_getpeername, "getpeername");
- DBG("getpeername(%d, ..)\n", sockfd);
+ DBG("getpeername(%d, ..)", sockfd);
return real_getpeername(sockfd, addr, addrlen);
}
static int (*real_getsockopt)(int, int, int, void *, socklen_t *);
LOAD_FUNCTION(real_getsockopt, "getsockopt");
- DBG("getsockopt(%d, %d %s, %d, ..)\n",
+ DBG("getsockopt(%d, %d %s, %d, ..)",
sockfd, level, level_to_name(level), optname);
return real_getsockopt(sockfd, level, optname, optval, optlen);
static int (*real_setsockopt)(int, int, int, const void *, socklen_t);
LOAD_FUNCTION(real_setsockopt, "setsockopt");
- DBG("setsockopt(%d, %d %s, %d, ..)\n",
+ DBG("setsockopt(%d, %d %s, %d, ..)",
sockfd, level, level_to_name(level), optname);
return real_setsockopt(sockfd, level, optname, optval, optlen);