summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-10-23 08:34:02 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-10-23 08:34:02 +0000
commit436e188d636566b43d727d0356572ecdff1c87d9 (patch)
tree230ce9c9b07c6de1b46b3576a9dc398288f9d778
parent496b6cc1a81073b990d5aab40895b939234183c4 (diff)
Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).
-rw-r--r--usr.bin/tmux/cmd-load-buffer.c18
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c19
-rw-r--r--usr.bin/tmux/tmux.c18
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 52 insertions, 6 deletions
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c
index 349fb771d25..cfa4fbbc285 100644
--- a/usr.bin/tmux/cmd-load-buffer.c
+++ b/usr.bin/tmux/cmd-load-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-load-buffer.c,v 1.18 2011/10/23 00:49:25 nicm Exp $ */
+/* $OpenBSD: cmd-load-buffer.c,v 1.19 2011/10/23 08:34:01 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -48,8 +48,9 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c = ctx->cmdclient;
+ struct session *s;
FILE *f;
- const char *path;
+ const char *path, *newpath, *wd;
char *pdata, *new_pdata, *cause;
size_t psize;
u_int limit;
@@ -93,6 +94,19 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
return (1);
}
+ if (c != NULL)
+ wd = c->cwd;
+ else if ((s = cmd_current_session(ctx, 0)) != NULL) {
+ wd = options_get_string(&s->options, "default-path");
+ if (*wd == '\0')
+ wd = s->cwd;
+ } else
+ wd = NULL;
+ if (wd != NULL && *wd != '\0') {
+ newpath = get_full_path(wd, path);
+ if (newpath != NULL)
+ path = newpath;
+ }
if ((f = fopen(path, "rb")) == NULL) {
ctx->error(ctx, "%s: %s", path, strerror(errno));
return (-1);
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index 33c736a922c..3bd24058de9 100644
--- a/usr.bin/tmux/cmd-save-buffer.c
+++ b/usr.bin/tmux/cmd-save-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-save-buffer.c,v 1.11 2011/10/23 00:49:25 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.12 2011/10/23 08:34:01 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -45,8 +45,9 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c = ctx->cmdclient;
+ struct session *s;
struct paste_buffer *pb;
- const char *path;
+ const char *path, *newpath, *wd;
char *cause;
int buffer;
mode_t mask;
@@ -80,6 +81,20 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
}
bufferevent_write(c->stdout_event, pb->data, pb->size);
} else {
+ if (c != NULL)
+ wd = c->cwd;
+ else if ((s = cmd_current_session(ctx, 0)) != NULL) {
+ wd = options_get_string(&s->options, "default-path");
+ if (*wd == '\0')
+ wd = s->cwd;
+ } else
+ wd = NULL;
+ if (wd != NULL && *wd != '\0') {
+ newpath = get_full_path(wd, path);
+ if (newpath != NULL)
+ path = newpath;
+ }
+
mask = umask(S_IRWXG | S_IRWXO);
if (args_has(self->args, 'a'))
f = fopen(path, "ab");
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 9b0f197e6ed..ebb3b91a3cd 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.106 2011/10/23 08:03:27 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.107 2011/10/23 08:34:01 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -124,6 +124,22 @@ areshell(const char *shell)
return (0);
}
+const char*
+get_full_path(const char *wd, const char *path)
+{
+ static char newpath[MAXPATHLEN];
+ char oldpath[MAXPATHLEN];
+
+ if (getcwd(oldpath, sizeof oldpath) == NULL)
+ return (NULL);
+ if (chdir(wd) != 0)
+ return (NULL);
+ if (realpath(path, newpath) != 0)
+ return (NULL);
+ chdir(oldpath);
+ return (newpath);
+}
+
void
parseenvironment(void)
{
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index e5495c939e9..092ec0c8e69 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.295 2011/10/23 01:12:46 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.296 2011/10/23 08:34:01 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1345,6 +1345,7 @@ void logfile(const char *);
const char *getshell(void);
int checkshell(const char *);
int areshell(const char *);
+const char* get_full_path(const char *, const char *);
void setblocking(int, int);
__dead void shell_exec(const char *, const char *);