diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-05-12 22:18:42 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-05-12 22:18:42 +0200 |
commit | ef1fcbd1830778e9ba8065fc764105f0b67bff27 (patch) | |
tree | 1b134297fa5090441a7537440a7e1111bce81346 /src/plugins/relay/relay-config.c | |
parent | 585eb337e8eb72698eaaf04cc1bd5069bd246ea3 (diff) | |
download | weechat-ef1fcbd1830778e9ba8065fc764105f0b67bff27.zip |
relay: do not overwrite a file if it's not a socket, display an error when the socket can not be created
Diffstat (limited to 'src/plugins/relay/relay-config.c')
-rw-r--r-- | src/plugins/relay/relay-config.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index 904537216..4c0771387 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -19,11 +19,15 @@ * along with WeeChat. If not, see <https://www.gnu.org/licenses/>. */ +#include <unistd.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <regex.h> #include <sys/un.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> #include "../weechat-plugin.h" #include "relay.h" @@ -546,6 +550,40 @@ relay_config_check_path_length (const char *path) } /* + * Checks if a UNIX path is available: it is available if not existing, or + * if a file of type socket already exists. + * + * Returns: + * 0: path is available + * -1: path already exists and is not a socket + * -2: invalid path + */ + +int +relay_config_check_path_available (const char *path) +{ + struct stat buf; + int rc; + + rc = stat (path, &buf); + + /* OK if an existing file is a socket */ + if ((rc == 0) && S_ISSOCK(buf.st_mode)) + return 0; + + /* error if an existing file is NOT a socket */ + if (rc == 0) + return -1; + + /* OK if the file does not exist */ + if (errno == ENOENT) + return 0; + + /* on any other error, the path it considered as not available */ + return -2; +} + +/* * Checks if a path is valid. * * Returns: |