From: Simon Ruderich Date: Thu, 12 Dec 2013 22:29:09 +0000 (+0100) Subject: Log functions always write a trailing newline. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;p=socket2unix%2Fsocket2unix.git Log functions always write a trailing newline. --- diff --git a/src/socket2unix.c b/src/socket2unix.c index 693892d..7e761c6 100644 --- a/src/socket2unix.c +++ b/src/socket2unix.c @@ -116,6 +116,9 @@ static void log_helper(int action, const char *file, int line, const char *forma errno = saved_errno; perror(""); + /* perror writes a newline. */ + } else { + fprintf(stderr, "\n"); } funlockfile(stderr); @@ -207,10 +210,10 @@ static struct list *remove_sockfd(int sockfd) { 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; } @@ -257,14 +260,13 @@ static int get_options(void) { 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; @@ -355,7 +357,7 @@ static int set_sockaddr_un(struct sockaddr_un *sockaddr, && 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; } @@ -374,7 +376,7 @@ static int set_sockaddr_un(struct sockaddr_un *sockaddr, } 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); } @@ -425,7 +427,7 @@ int socket(int domain, int type, int protocol) { 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)); @@ -447,12 +449,12 @@ int close(int fd) { 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); @@ -471,11 +473,11 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { 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)); @@ -496,17 +498,17 @@ int listen(int sockfd, int backlog) { } 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)); @@ -518,10 +520,10 @@ int listen(int sockfd, int backlog) { 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) { @@ -546,11 +548,11 @@ int listen(int sockfd, int backlog) { } 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); @@ -560,7 +562,7 @@ int listen(int sockfd, int backlog) { } 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. */ @@ -584,17 +586,17 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { } 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)); @@ -609,7 +611,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { 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); @@ -636,7 +638,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { } 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); } @@ -648,11 +650,11 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t 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)); @@ -668,10 +670,10 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { 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) { @@ -686,7 +688,7 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { 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); } @@ -695,7 +697,7 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *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); } @@ -704,7 +706,7 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl 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); @@ -713,7 +715,7 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t 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);