Use XDG_RUNTIME_DIR when available
XDG_RUNTIME_DIR is the volatile runtime data dir provided by modern session manager such as systemd
This commit is contained in:
parent
3721bcb868
commit
8a40dc0011
12
src/main.c
12
src/main.c
@ -260,12 +260,13 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.ipc_socket_path == NULL)
|
if (config.ipc_socket_path == NULL) {
|
||||||
config.ipc_socket_path = getenv("I3SOCK");
|
|
||||||
|
|
||||||
/* Fall back to a file name in /tmp/ based on the PID */
|
/* Fall back to a file name in /tmp/ based on the PID */
|
||||||
if (config.ipc_socket_path == NULL)
|
if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL)
|
||||||
config.ipc_socket_path = get_process_filename("i3-ipc-socket");
|
config.ipc_socket_path = get_process_filename("ipc-socket");
|
||||||
|
else
|
||||||
|
config.ipc_socket_path = sstrdup(config.ipc_socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t mask = XCB_CW_EVENT_MASK;
|
uint32_t mask = XCB_CW_EVENT_MASK;
|
||||||
uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
|
uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
|
||||||
@ -389,6 +390,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if (ipc_socket == -1) {
|
if (ipc_socket == -1) {
|
||||||
ELOG("Could not create the IPC socket, IPC disabled\n");
|
ELOG("Could not create the IPC socket, IPC disabled\n");
|
||||||
} else {
|
} else {
|
||||||
|
free(config.ipc_socket_path);
|
||||||
struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
|
struct ev_io *ipc_io = scalloc(sizeof(struct ev_io));
|
||||||
ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
|
ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
|
||||||
ev_io_start(loop, ipc_io);
|
ev_io_start(loop, ipc_io);
|
||||||
|
28
src/util.c
28
src/util.c
@ -244,15 +244,35 @@ static char **append_argument(char **original, char *argument) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char *get_process_filename(const char *prefix) {
|
char *get_process_filename(const char *prefix) {
|
||||||
|
char *dir = getenv("XDG_RUNTIME_DIR");
|
||||||
|
if (dir == NULL) {
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
const char *username = pw ? pw->pw_name : "unknown";
|
const char *username = pw ? pw->pw_name : "unknown";
|
||||||
char *filename;
|
if (asprintf(&dir, "/tmp/i3-%s", username) == -1) {
|
||||||
int res = asprintf(&filename, "/tmp/%s-%s.%d", prefix, username, getpid());
|
|
||||||
if (res == -1) {
|
|
||||||
perror("asprintf()");
|
perror("asprintf()");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
char *tmp;
|
||||||
|
if (asprintf(&tmp, "%s/i3", dir) == -1) {
|
||||||
|
perror("asprintf()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
dir = tmp;
|
||||||
|
}
|
||||||
|
if (!path_exists(dir)) {
|
||||||
|
if (mkdir(dir, 0700) == -1) {
|
||||||
|
perror("mkdir()");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char *filename;
|
||||||
|
if (asprintf(&filename, "%s/%s.%d", dir, prefix, getpid()) == -1) {
|
||||||
|
perror("asprintf()");
|
||||||
|
filename = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(dir);
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +295,7 @@ char *store_restart_layout() {
|
|||||||
* resolve the tildes in the specified path */
|
* resolve the tildes in the specified path */
|
||||||
char *filename;
|
char *filename;
|
||||||
if (config.restart_state_path == NULL) {
|
if (config.restart_state_path == NULL) {
|
||||||
filename = get_process_filename("i3-restart-state");
|
filename = get_process_filename("restart-state");
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user