2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
15 #include <sys/types.h>
22 * Returns the name of a temporary file with the specified prefix.
25 char *get_process_filename(const char *prefix) {
26 /* dir stores the directory path for this and all subsequent calls so that
27 * we only create a temporary directory once per i3 instance. */
28 static char *dir = NULL;
30 /* Check if XDG_RUNTIME_DIR is set. If so, we use XDG_RUNTIME_DIR/i3 */
31 if ((dir = getenv("XDG_RUNTIME_DIR"))) {
33 sasprintf(&tmp, "%s/i3", dir);
36 if (stat(dir, &buf) != 0) {
37 if (mkdir(dir, 0700) == -1) {
43 /* If not, we create a (secure) temp directory using the template
44 * /tmp/i3-<user>.XXXXXX */
45 struct passwd *pw = getpwuid(getuid());
46 const char *username = pw ? pw->pw_name : "unknown";
47 sasprintf(&dir, "/tmp/i3-%s.XXXXXX", username);
48 /* mkdtemp modifies dir */
49 if (mkdtemp(dir) == NULL) {
56 sasprintf(&filename, "%s/%s.%d", dir, prefix, getpid());