Extended sockaddr_to_string for use in connect-failed error message in mod_fastcgi

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent 050d0d60d6
commit b033f0c194
  1. 2
      include/lighttpd/utils.h
  2. 8
      src/modules/mod_fastcgi.c
  3. 25
      src/utils.c
  4. 2
      src/worker.c

@ -55,7 +55,7 @@ LI_API guint hash_ipv6(gconstpointer key);
LI_API GString *mimetype_get(vrequest *vr, GString *filename);
/* converts a sock_addr to a human readable string. ipv4 and ipv6 supported. if dest is NULL, a new string will be allocated */
LI_API GString *sockaddr_to_string(sock_addr *saddr, GString *dest);
LI_API GString *sockaddr_to_string(sock_addr *saddr, GString *dest, gboolean showport);
LI_API sockaddr sockaddr_from_string(GString *str, guint tcp_default_port);
LI_API void sockaddr_clear(sockaddr *saddr);

@ -339,7 +339,7 @@ static void fastcgi_env_create(vrequest *vr, environment_dup *envdup, GString* b
}
}
{
sockaddr_to_string(&con->local_addr, tmp);
sockaddr_to_string(&con->local_addr, tmp, FALSE);
fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_ADDR"), GSTR_LEN(tmp));
}
@ -357,7 +357,7 @@ static void fastcgi_env_create(vrequest *vr, environment_dup *envdup, GString* b
}
}
{
sockaddr_to_string(&con->remote_addr, tmp);
sockaddr_to_string(&con->remote_addr, tmp, FALSE);
fastcgi_env_add(buf, envdup, CONST_STR_LEN("REMOTE_ADDR"), GSTR_LEN(tmp));
}
@ -658,7 +658,9 @@ static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon) {
vrequest_backend_overloaded(vr);
return HANDLER_GO_ON;
default:
VR_ERROR(vr, "Couldn't connect: %s", g_strerror(errno));
VR_ERROR(vr, "Couldn't connect to '%s': %s",
sockaddr_to_string(fcon->ctx->socket.addr, vr->con->wrk->tmp_str, TRUE)->str,
g_strerror(errno));
fastcgi_close(vr, p);
vrequest_backend_dead(vr);
return HANDLER_GO_ON;

@ -505,7 +505,7 @@ GString *mimetype_get(vrequest *vr, GString *filename) {
}
GString *sockaddr_to_string(sock_addr *saddr, GString *dest) {
GString *sockaddr_to_string(sock_addr *saddr, GString *dest, gboolean showport) {
gchar *p;
guint8 len = 0;
guint8 tmp;
@ -516,9 +516,9 @@ GString *sockaddr_to_string(sock_addr *saddr, GString *dest) {
case AF_INET:
/* ipv4 */
if (!dest)
dest = g_string_sized_new(16);
dest = g_string_sized_new(16+6);
else
g_string_set_size(dest, 16);
g_string_set_size(dest, 16+6);
p = dest->str;
@ -543,17 +543,32 @@ GString *sockaddr_to_string(sock_addr *saddr, GString *dest) {
dest->str[len-1] = 0;
dest->len = len-1;
if (showport) g_string_append_printf(dest, ":%u", (unsigned int) ntohs(saddr->ipv4.sin_port));
break;
#ifdef HAVE_IPV6
case AF_INET6:
/* ipv6 - not yet implemented with own function */
if (!dest)
dest = g_string_sized_new(INET6_ADDRSTRLEN);
dest = g_string_sized_new(INET6_ADDRSTRLEN+6);
ipv6_tostring(dest, saddr->ipv6.sin6_addr.s6_addr);
if (showport) g_string_append_printf(dest, ":%u", (unsigned int) ntohs(saddr->ipv6.sin6_port));
#endif
#ifdef HAVE_SYS_UN_H
case AF_UNIX:
if (!dest)
dest = g_string_sized_new(0);
else
g_string_truncate(dest, 0);
g_string_append_len(dest, CONST_STR_LEN("unix:"));
g_string_append(dest, saddr->un.sun_path);
break;
#endif
default:
if (dest) g_string_truncate(dest, 0);
if (!dest)
dest = g_string_new_len(CONST_STR_LEN("unknown sockaddr family"));
else
g_string_assign(dest, "unknown sockaddr family");
}
return dest;

@ -210,7 +210,7 @@ void worker_new_con(worker *ctx, worker *wrk, sock_addr *remote_addr, int s) {
ev_io_set(&con->sock_watcher, s, EV_READ);
ev_io_start(wrk->loop, &con->sock_watcher);
con->ts = CUR_TS(con->wrk);
sockaddr_to_string(remote_addr, con->remote_addr_str);
sockaddr_to_string(remote_addr, con->remote_addr_str, FALSE);
waitqueue_push(&wrk->io_timeout_queue, &con->io_timeout_elem);
} else {
worker_new_con_data *d = g_slice_new(worker_new_con_data);

Loading…
Cancel
Save