Merge pull request #1816 from tcreech/tcreech-for-illumos

Changes for compiling i3 on Illumos
next
Michael Stapelberg 2015-08-04 00:10:06 -07:00
commit 419b73be9e
6 changed files with 26 additions and 15 deletions

View File

@ -178,6 +178,10 @@ else ifneq ($(UNAME),OpenBSD)
LIBS += -lrt
endif
ifeq ($(UNAME),SunOS)
LIBS += -lsocket -liconv -lgen
endif
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
I3_CPPFLAGS += -D_GNU_SOURCE
endif

View File

@ -799,7 +799,7 @@ int main(int argc, char *argv[]) {
struct stat stbuf;
sasprintf(&config_dir, "%s/i3", xdg_config_home);
if (stat(config_dir, &stbuf) != 0)
if (!mkdirp(config_dir))
if (mkdirp(config_dir, DEFAULT_DIR_MODE) != 0)
err(EXIT_FAILURE, "mkdirp(%s) failed", config_dir);
free(config_dir);
free(xdg_config_home);

View File

@ -21,6 +21,8 @@
#include <pango/pango.h>
#endif
#define DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
/**
* Opaque data structure for storing strings.
*
@ -471,8 +473,10 @@ char *resolve_tilde(const char *path);
*/
char *get_config_path(const char *override_configpath, bool use_system_paths);
#if !defined(__sun)
/**
* Emulates mkdir -p (creates any missing folders)
*
*/
bool mkdirp(const char *path);
int mkdirp(const char *path, mode_t mode);
#endif

View File

@ -8,24 +8,26 @@
* Emulates mkdir -p (creates any missing folders)
*
*/
bool mkdirp(const char *path) {
if (mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
return true;
#if !defined(__sun)
int mkdirp(const char *path, mode_t mode) {
if (mkdir(path, mode) == 0)
return 0;
if (errno == EEXIST) {
struct stat st;
/* Check that the named file actually is a directory. */
if (stat(path, &st)) {
ELOG("stat(%s) failed: %s\n", path, strerror(errno));
return false;
return -1;
}
if (!S_ISDIR(st.st_mode)) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(ENOTDIR));
return false;
return -1;
}
return true;
return 0;
} else if (errno != ENOENT) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
return false;
return -1;
}
char *copy = sstrdup(path);
/* strip trailing slashes, if any */
@ -38,13 +40,14 @@ bool mkdirp(const char *path) {
free(copy);
copy = NULL;
}
return false;
return -1;
}
*sep = '\0';
bool result = false;
if (mkdirp(copy))
result = mkdirp(path);
int result = -1;
if (mkdirp(copy, mode) == 0)
result = mkdirp(path, mode);
free(copy);
return result;
}
#endif

View File

@ -1087,7 +1087,7 @@ int ipc_create_socket(const char *filename) {
char *copy = sstrdup(resolved);
const char *dir = dirname(copy);
if (!path_exists(dir))
mkdirp(dir);
mkdirp(dir, DEFAULT_DIR_MODE);
free(copy);
/* Unlink the unix domain socket before */

View File

@ -222,7 +222,7 @@ char *store_restart_layout(void) {
char *filenamecopy = sstrdup(filename);
char *base = dirname(filenamecopy);
DLOG("Creating \"%s\" for storing the restart layout\n", base);
if (!mkdirp(base))
if (mkdirp(base, DEFAULT_DIR_MODE) != 0)
ELOG("Could not create \"%s\" for storing the restart layout, layout will be lost.\n", base);
free(filenamecopy);