aboutsummaryrefslogtreecommitdiff
path: root/tmux.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-11-12 15:12:08 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-11-12 15:12:08 +0000
commit4309d65475d2b5ad4e00a9c590a2e97c1c90ca16 (patch)
tree29f1cf14959e783e68373dae70ff1e0f9170530b /tmux.c
parente4a6cdefda66dbc7b4cab944975e5d9053e3f862 (diff)
downloadrtmux-4309d65475d2b5ad4e00a9c590a2e97c1c90ca16.tar.gz
rtmux-4309d65475d2b5ad4e00a9c590a2e97c1c90ca16.tar.bz2
rtmux-4309d65475d2b5ad4e00a9c590a2e97c1c90ca16.zip
realpath the socket path; also sprinkle some const.
Diffstat (limited to 'tmux.c')
-rw-r--r--tmux.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/tmux.c b/tmux.c
index a8d69338..b6ba1533 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.39 2007-11-09 11:03:35 nicm Exp $ */
+/* $Id: tmux.c,v 1.40 2007-11-12 15:12:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -19,7 +19,6 @@
#include <sys/types.h>
#include <sys/wait.h>
-#include <err.h>
#include <errno.h>
#include <paths.h>
#include <poll.h>
@@ -174,7 +173,7 @@ main(int argc, char **argv)
struct hdr hdr;
const char *shell;
struct passwd *pw;
- char *path, *cause, *name;
+ char *path, rpath[MAXPATHLEN], *cause, *name;
int n, opt;
path = name = NULL;
@@ -209,6 +208,16 @@ main(int argc, char **argv)
bell_action = BELL_ANY;
+ if (path == NULL) {
+ xasprintf(&path,
+ "%s/%s-%lu", _PATH_TMP, __progname, (u_long) getuid());
+ }
+ if (realpath(path, rpath) == NULL) {
+ log_warn("%s", path);
+ exit(1);
+ }
+ xfree(path);
+
shell = getenv("SHELL");
if (shell == NULL || *shell == '\0') {
pw = getpwuid(getuid());
@@ -231,7 +240,7 @@ main(int argc, char **argv)
if (!(cmd->entry->flags & CMD_NOSESSION) ||
(cmd->entry->flags & CMD_CANTNEST))
client_fill_session(&data);
- if (client_init(path, &cctx, cmd->entry->flags & CMD_STARTSERVER) != 0)
+ if (client_init(rpath, &cctx, cmd->entry->flags & CMD_STARTSERVER) != 0)
exit(1);
b = buffer_create(BUFSIZ);
cmd_send_string(b, name);
@@ -242,8 +251,6 @@ main(int argc, char **argv)
MSG_COMMAND, &data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b));
buffer_destroy(b);
- if (path != NULL)
- xfree(path);
if (name != NULL)
xfree(name);