Using g_get_tmp_dir to build the console socket name

Signed-off-by: Lorenzo Fontana <lo@linux.com>
This commit is contained in:
Lorenzo Fontana 2017-08-06 17:26:14 +02:00
parent dc3b6f4d78
commit e9e40c9df2
No known key found for this signature in database
GPG key ID: 0D48B0B074C3DC15

View file

@ -884,7 +884,8 @@ static void write_sync_fd(int sync_pipe_fd, int res, const char *message)
static char *setup_console_socket(void) static char *setup_console_socket(void)
{ {
struct sockaddr_un addr = {0}; struct sockaddr_un addr = {0};
char csname[PATH_MAX] = "/tmp/conmon-term.XXXXXXXX"; _cleanup_free_ const char *tmpdir = g_get_tmp_dir();
_cleanup_free_ char *csname = g_build_filename(tmpdir, "conmon-term.XXXXXX", NULL);
/* /*
* Generate a temporary name. Is this unsafe? Probably, but we can * Generate a temporary name. Is this unsafe? Probably, but we can
* replace it with a rename(2) setup if necessary. * replace it with a rename(2) setup if necessary.
@ -908,7 +909,7 @@ static char *setup_console_socket(void)
pexit("Failed to change console-socket permissions"); pexit("Failed to change console-socket permissions");
/* XXX: This should be handled with a rename(2). */ /* XXX: This should be handled with a rename(2). */
if (unlink(csname) < 0) if (unlink(csname) < 0)
pexit("Failed to unlink temporary ranom path"); pexit("Failed to unlink temporary random path");
if (bind(console_socket_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) if (bind(console_socket_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
pexit("Failed to bind to console-socket"); pexit("Failed to bind to console-socket");
if (listen(console_socket_fd, 128) < 0) if (listen(console_socket_fd, 128) < 0)
@ -1116,7 +1117,7 @@ int main(int argc, char *argv[])
the parent is waiting for the stdout to end when the intermediate the parent is waiting for the stdout to end when the intermediate
child dies */ child dies */
if (dup2(dev_null_r, STDIN_FILENO) < 0) if (dup2(dev_null_r, STDIN_FILENO) < 0)
pexit("Failed to dup over stdout"); pexit("Failed to dup over stdin");
if (dup2(dev_null_w, STDOUT_FILENO) < 0) if (dup2(dev_null_w, STDOUT_FILENO) < 0)
pexit("Failed to dup over stdout"); pexit("Failed to dup over stdout");
if (dup2(dev_null_w, STDERR_FILENO) < 0) if (dup2(dev_null_w, STDERR_FILENO) < 0)