summaryrefslogtreecommitdiff
path: root/attach.c
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2014-08-04 12:51:15 -0700
committerNed T. Crigler <crigler@users.sourceforge.net>2014-08-04 13:00:24 -0700
commitb7d5154c18cb57dd5680114315fbc4175cf1ea26 (patch)
treedf8d256ff73078eef12bc045a70ea25c27c200ce /attach.c
parenta51207bf473193016e38814ceea27335f517cb16 (diff)
Try to use chdir to get around the sun_path length limit.
If a socket's path name would overflow sun_path, try to make it fit by temporarily changing to the directory the socket is in and using the path's basename in sun_path. This should help for the case where the basename of the socket does fit in sun_path, even if the rest of the path doesn't.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/attach.c b/attach.c
index a4ae626..45788e2 100644
--- a/attach.c
+++ b/attach.c
@@ -156,6 +156,28 @@ attach_main(int noerror)
/* Attempt to open the socket. Don't display an error if noerror is
** set. */
s = connect_socket(sockname);
+ if (s < 0 && errno == ENAMETOOLONG)
+ {
+ char *slash = strrchr(sockname, '/');
+
+ /* Try to shorten the socket's path name by using chdir. */
+ if (slash)
+ {
+ int dirfd = open(".", O_RDONLY);
+
+ if (dirfd >= 0)
+ {
+ *slash = '\0';
+ if (chdir(sockname) >= 0)
+ {
+ s = connect_socket(slash + 1);
+ fchdir(dirfd);
+ }
+ *slash = '/';
+ close(dirfd);
+ }
+ }
+ }
if (s < 0)
{
if (!noerror)