elinks dies with weird message if ~/.elinks not writeable

Mikel Ward <[email protected]>
Newsgroups gmane.comp.web.elinks.user
Message-ID <[email protected]>
Hi

In elinks 0.11 and 0.12, I get this error message on startup:
  ERROR at interlink.c:329: The call to connect() failed: 13 (Permission denied)

Which doesn't give me enough information to understand the cause.

Running it inside strace shows that it couldn't create a Unix domain
socket in ~/.elinks because that directory wasn't writeable by me.

The attached patch makes it print this instead:
  ERROR at interlink.c:343: connect() failed on /home/mward/.elinks/socket0: 13 (Permission denied)

I hope you can use it or implement something like it.

Thanks

Mike

_______________________________________________
elinks-users mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-users
elinks.socketerror.patch (text/x-patch, 2.5 KB)
diff -Naur elinks-0.12-20081014/src/main/interlink.c elinks-0.12-20081014.socketerror/src/main/interlink.c
--- elinks-0.12-20081014/src/main/interlink.c	2008-10-14 09:40:03.000000000 +1100
+++ elinks-0.12-20081014.socketerror/src/main/interlink.c	2008-10-14 13:21:22.000000000 +1100
@@ -324,10 +324,24 @@
 #define CONNECT_TRIES_DELAY		50000
 
 static void
-report_af_unix_error(unsigned char *function, int error)
+report_af_unix_error(unsigned char *function, int error, struct socket_info *info)
 {
-	ERROR(gettext("The call to %s failed: %d (%s)"),
-	      function, error, (unsigned char *) strerror(error));
+	struct sockaddr_un *addr = NULL;
+	const char *path = NULL;
+	
+	if (info != NULL) {
+		addr = (struct sockaddr_un *)info->addr;
+		if (addr != NULL) {
+			path = addr->sun_path;
+		}
+	}
+
+	if (path == NULL) {
+		path = "(null)";
+	}
+
+	ERROR(gettext("%s failed on %s: %d (%s)"),
+	      function, path, error, (unsigned char *) strerror(error));
 }
 
 /* Called when we receive a connection on listening socket. */
@@ -345,7 +359,7 @@
 	memset(info->addr, 0, l);
 	ns = accept(info->fd, info->addr, &l);
 	if (ns < 0) {
-		report_af_unix_error("accept()", errno);
+		report_af_unix_error("accept()", errno, info);
 		return;
 	}
 
@@ -384,7 +398,7 @@
 	while (1) {
 		s_info_listen.fd = socket(pf, SOCK_STREAM, 0);
 		if (s_info_listen.fd == -1) {
-			report_af_unix_error("socket()", errno);
+			report_af_unix_error("socket()", errno, &s_info_listen);
 			goto free_and_error;
 		}
 
@@ -392,9 +406,10 @@
 
 		if (bind(s_info_listen.fd, s_info_listen.addr, s_info_listen.size) >= 0)
 			break;
-
-		if (errno != EADDRINUSE)
-			report_af_unix_error("bind()", errno);
+ 
+		if (errno != EADDRINUSE) {
+			report_af_unix_error("bind()", errno, &s_info_listen);
+		}
 
 		++attempts;
 
@@ -415,7 +430,7 @@
 	s_info_accept.fd = s_info_listen.fd;
 
 	if (listen(s_info_listen.fd, LISTEN_BACKLOG)) {
-		report_af_unix_error("listen()", errno);
+		report_af_unix_error("listen()", errno, &s_info_listen);
 		goto free_and_error;
 	}
 
@@ -446,7 +461,7 @@
 
 		s_info_connect.fd = socket(pf, SOCK_STREAM, 0);
 		if (s_info_connect.fd == -1) {
-			report_af_unix_error("socket()", errno);
+			report_af_unix_error("socket()", errno, &s_info_connect);
 			break;
 		}
 
@@ -458,7 +473,7 @@
 		close(s_info_connect.fd);
 
 		if (saved_errno != ECONNREFUSED && saved_errno != ENOENT) {
-			report_af_unix_error("connect()", errno);
+			report_af_unix_error("connect()", errno, &s_info_connect);
 			break;
 		}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.