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.
This commit is contained in:
parent
a51207bf47
commit
b7d5154c18
22
attach.c
22
attach.c
|
|
@ -156,6 +156,28 @@ attach_main(int noerror)
|
||||||
/* Attempt to open the socket. Don't display an error if noerror is
|
/* Attempt to open the socket. Don't display an error if noerror is
|
||||||
** set. */
|
** set. */
|
||||||
s = connect_socket(sockname);
|
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 (s < 0)
|
||||||
{
|
{
|
||||||
if (!noerror)
|
if (!noerror)
|
||||||
|
|
|
||||||
22
master.c
22
master.c
|
|
@ -561,6 +561,28 @@ master_main(char **argv, int waitattach, int dontfork)
|
||||||
|
|
||||||
/* Create the unix domain socket. */
|
/* Create the unix domain socket. */
|
||||||
s = create_socket(sockname);
|
s = create_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 = create_socket(slash + 1);
|
||||||
|
fchdir(dirfd);
|
||||||
|
}
|
||||||
|
*slash = '/';
|
||||||
|
close(dirfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
{
|
{
|
||||||
printf("%s: %s: %s\n", progname, sockname, strerror(errno));
|
printf("%s: %s: %s\n", progname, sockname, strerror(errno));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue