From: Michael Stapelberg Date: Sun, 1 May 2011 10:50:18 +0000 (+0200) Subject: wizard: check if the config file does not already exist and if we can create it X-Git-Tag: tree-pr3~60 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9101f4cce2d23847a498733b2ea0792ab24cb27f;p=i3%2Fi3 wizard: check if the config file does not already exist and if we can create it --- diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index d50669ed..b546f607 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -45,6 +47,7 @@ while (0) enum { STEP_WELCOME, STEP_GENERATE } current_step = STEP_WELCOME; enum { MOD_ALT, MOD_SUPER } modifier = MOD_SUPER; +static char *config_path = "/tmp/wizout/i3.config"; static xcb_connection_t *conn; static uint32_t font_id; static uint32_t font_bold_id; @@ -271,6 +274,22 @@ int main(int argc, char *argv[]) { } } + /* Check if the destination config file does not exist but the path is + * writable. If not, exit now, this program is not useful in that case. */ + struct stat stbuf; + if (stat(config_path, &stbuf) == 0) { + printf("The config file \"%s\" already exists. Exiting.\n", config_path); + return 0; + } + + int fd; + if ((fd = open(config_path, O_CREAT | O_RDWR, 0644)) == -1) { + printf("Cannot open file \"%s\" for writing: %s. Exiting.\n", config_path, strerror(errno)); + return 0; + } + close(fd); + unlink(config_path); + if (socket_path == NULL) socket_path = socket_path_from_x11();