Fixed socket usage to work with AFS home folders.

On corporate/university environments it is not uncommon for the home
folder of each user to be hosted on OpenAFS (so you can work from any
terminal and IT services can backup everything at will).

However it is not possible to create sockets in AFS, hence when awesome
attempts to create a socket at ~/.awesome-ctl it fails. To fix this
awesome now uses /tmp/.awesome-ctl as a fallback before giving up.

Signed-off-by: Alex Cornejo <acornejo@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Alex Cornejo 2009-03-17 18:41:52 -04:00 committed by Julien Danjou
parent 691b732f1a
commit 96cf05f002
4 changed files with 19 additions and 10 deletions

View File

@ -56,11 +56,16 @@ sockets_init(void)
if((csfd = socket_getclient()) < 0) if((csfd = socket_getclient()) < 0)
return false; return false;
if(!(addr = socket_getaddr(display))) if(!(addr = socket_getaddr(getenv("HOME"), display)))
return false; return false;
if(connect(csfd, addr, sizeof(struct sockaddr_un)) == -1) if(connect(csfd, addr, sizeof(struct sockaddr_un)) == -1)
{
if(!(addr = socket_getaddr("/tmp", display)))
return false; return false;
if(connect(csfd, addr, sizeof(struct sockaddr_un)) == -1)
return false;
}
return true; return true;
} }

View File

@ -34,19 +34,19 @@
/** Get a sockaddr_un struct with information feeded for opening a /** Get a sockaddr_un struct with information feeded for opening a
* communication to the awesome socket for given display * communication to the awesome socket for given display
* \param directory Where socket is created.
* \param display the display number * \param display the display number
* \return sockaddr_un struct ready to be used or NULL if a problem occured * \return sockaddr_un struct ready to be used or NULL if a problem occured
*/ */
struct sockaddr_un * struct sockaddr_un *
socket_getaddr(const char *display) socket_getaddr(const char *directory, const char *display)
{ {
char *homedir, *host = NULL; char *host = NULL;
int screenp = 0, displayp = 0; int screenp = 0, displayp = 0;
ssize_t path_len, len; ssize_t path_len, len;
struct sockaddr_un *addr; struct sockaddr_un *addr;
addr = p_new(struct sockaddr_un, 1); addr = p_new(struct sockaddr_un, 1);
homedir = getenv("HOME");
xcb_parse_display(NULL, &host, &displayp, &screenp); xcb_parse_display(NULL, &host, &displayp, &screenp);
@ -55,7 +55,7 @@ socket_getaddr(const char *display)
/* + 2 for / and . and \0 */ /* + 2 for / and . and \0 */
path_len = snprintf(addr->sun_path, sizeof(addr->sun_path), path_len = snprintf(addr->sun_path, sizeof(addr->sun_path),
"%s/" CONTROL_UNIX_SOCKET_PATH "%s%s%d", "%s/" CONTROL_UNIX_SOCKET_PATH "%s%s%d",
homedir, len ? host : "", len ? "." : "", directory, len ? host : "", len ? "." : "",
displayp); displayp);
p_delete(&host); p_delete(&host);

View File

@ -22,7 +22,7 @@
#ifndef AWESOME_COMMON_SOCKET_H #ifndef AWESOME_COMMON_SOCKET_H
#define AWESOME_COMMON_SOCKET_H #define AWESOME_COMMON_SOCKET_H
struct sockaddr_un * socket_getaddr(const char *); struct sockaddr_un * socket_getaddr(const char *, const char *);
int socket_getclient(void); int socket_getclient(void);
#endif #endif

6
luaa.c
View File

@ -1115,7 +1115,7 @@ luaA_cs_init(void)
if (csfd < 0 || fcntl(csfd, F_SETFD, FD_CLOEXEC) == -1) if (csfd < 0 || fcntl(csfd, F_SETFD, FD_CLOEXEC) == -1)
return; return;
addr = socket_getaddr(getenv("DISPLAY")); addr = socket_getaddr(getenv("HOME"), getenv("DISPLAY"));
/* Needed for some OSes like Solaris */ /* Needed for some OSes like Solaris */
#ifndef SUN_LEN #ifndef SUN_LEN
@ -1132,8 +1132,12 @@ luaA_cs_init(void)
return warn("error binding UNIX domain socket: %s", strerror(errno)); return warn("error binding UNIX domain socket: %s", strerror(errno));
} }
else else
{
addr = socket_getaddr("/tmp", getenv("DISPLAY"));
if (bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr)))
return warn("error binding UNIX domain socket: %s", strerror(errno)); return warn("error binding UNIX domain socket: %s", strerror(errno));
} }
}
listen(csfd, 10); listen(csfd, 10);
ev_io_init(&csio, &luaA_conn_cb, csfd, EV_READ); ev_io_init(&csio, &luaA_conn_cb, csfd, EV_READ);