kopia lustrzana https://github.com/FreeSpacenav/spacenavd
beefed up the error handling and logging around the XAUTHORITY setup, and added the possibility of using the HOME env var as a fallback
git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spacenavd@153 ef983eb1-d774-4af8-acfd-baaf7b16a646pull/1/head
rodzic
a3721ea87d
commit
b2c44718b2
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#ifdef HAVE_ALLOCA_H
|
#ifdef HAVE_ALLOCA_H
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
|
@ -84,8 +85,21 @@ int init_x11(void)
|
||||||
/* ... also there won't be an XAUTHORITY env var, so set one up */
|
/* ... also there won't be an XAUTHORITY env var, so set one up */
|
||||||
if(!getenv("XAUTHORITY")) {
|
if(!getenv("XAUTHORITY")) {
|
||||||
struct passwd *p = getpwuid(getuid());
|
struct passwd *p = getpwuid(getuid());
|
||||||
char *home = p->pw_dir ? p->pw_dir : "/tmp";
|
char *home, *buf;
|
||||||
char *buf = alloca(strlen("XAUTHORITY=") + strlen(home) + strlen("/.Xauthority") + 1);
|
if(!p || !p->pw_dir) {
|
||||||
|
if(!p) {
|
||||||
|
fprintf(stderr, "getpwuid failed: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
fprintf(stderr, "falling back to getting the home directory from the HOME env var...\n");
|
||||||
|
if(!(home = getenv("HOME"))) {
|
||||||
|
fprintf(stderr, "HOME env var not found, using /tmp as a home directory...\n");
|
||||||
|
home = "/tmp";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
home = p->pw_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = alloca(strlen("XAUTHORITY=") + strlen(home) + strlen("/.Xauthority") + 1);
|
||||||
sprintf(buf, "XAUTHORITY=%s/.Xauthority", home);
|
sprintf(buf, "XAUTHORITY=%s/.Xauthority", home);
|
||||||
putenv(buf);
|
putenv(buf);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue