mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Join oldest session if non specified. Fix errors.
This commit is contained in:
		
							
								
								
									
										19
									
								
								client-cmd.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								client-cmd.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: client-cmd.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
 | 
			
		||||
/* $Id: client-cmd.c,v 1.3 2007-09-26 18:50:49 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -22,13 +22,13 @@
 | 
			
		||||
 | 
			
		||||
int	client_cmd_prefix = META;
 | 
			
		||||
 | 
			
		||||
int	client_cmd_fn_select(int, struct client_ctx *, const char **);
 | 
			
		||||
int	client_cmd_fn_detach(int, struct client_ctx *, const char **);
 | 
			
		||||
int	client_cmd_fn_msg(int, struct client_ctx *, const char **);
 | 
			
		||||
int	client_cmd_fn_select(int, struct client_ctx *, char **);
 | 
			
		||||
int	client_cmd_fn_detach(int, struct client_ctx *, char **);
 | 
			
		||||
int	client_cmd_fn_msg(int, struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
struct cmd {
 | 
			
		||||
	int	key;
 | 
			
		||||
	int	(*fn)(int, struct client_ctx *, const char **);
 | 
			
		||||
	int	(*fn)(int, struct client_ctx *, char **);
 | 
			
		||||
	int	arg;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +63,7 @@ struct cmd client_cmd_table[] = {
 | 
			
		||||
#define NCLIENTCMD (sizeof client_cmd_table / sizeof client_cmd_table[0])
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
client_cmd_dispatch(int key, struct client_ctx *cctx, const char **error)
 | 
			
		||||
client_cmd_dispatch(int key, struct client_ctx *cctx, char **error)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd	*cmd;
 | 
			
		||||
	u_int		 i;
 | 
			
		||||
@@ -78,7 +78,7 @@ client_cmd_dispatch(int key, struct client_ctx *cctx, const char **error)
 | 
			
		||||
 | 
			
		||||
/* Handle generic command. */
 | 
			
		||||
int
 | 
			
		||||
client_cmd_fn_msg(int arg, struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
client_cmd_fn_msg(int arg, struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	client_write_server(cctx, arg, NULL, 0);
 | 
			
		||||
 | 
			
		||||
@@ -87,8 +87,7 @@ client_cmd_fn_msg(int arg, struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
 | 
			
		||||
/* Handle select command. */
 | 
			
		||||
int
 | 
			
		||||
client_cmd_fn_select(
 | 
			
		||||
    int arg, struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
client_cmd_fn_select(int arg, struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	struct select_data	data;
 | 
			
		||||
 | 
			
		||||
@@ -101,7 +100,7 @@ client_cmd_fn_select(
 | 
			
		||||
/* Handle detach command. */
 | 
			
		||||
int
 | 
			
		||||
client_cmd_fn_detach(
 | 
			
		||||
    unused int arg, unused struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
    unused int arg, unused struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	return (-1);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								client-msg.c
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								client-msg.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: client-msg.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
 | 
			
		||||
/* $Id: client-msg.c,v 1.3 2007-09-26 18:50:49 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -24,24 +24,26 @@
 | 
			
		||||
 | 
			
		||||
#include "tmux.h"
 | 
			
		||||
 | 
			
		||||
int	client_msg_fn_output(struct hdr *, struct client_ctx *, const char **);
 | 
			
		||||
int	client_msg_fn_pause(struct hdr *, struct client_ctx *, const char **);
 | 
			
		||||
int	client_msg_fn_exit(struct hdr *, struct client_ctx *, const char **);
 | 
			
		||||
int	client_msg_fn_output(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_pause(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_exit(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_error(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
struct client_msg {
 | 
			
		||||
	enum hdrtype   type;
 | 
			
		||||
	
 | 
			
		||||
	int	       (*fn)(struct hdr *, struct client_ctx *, const char **);
 | 
			
		||||
	int	       (*fn)(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
};
 | 
			
		||||
struct client_msg client_msg_table[] = {
 | 
			
		||||
	{ MSG_OUTPUT, client_msg_fn_output },
 | 
			
		||||
	{ MSG_PAUSE, client_msg_fn_pause },
 | 
			
		||||
	{ MSG_EXIT, client_msg_fn_exit },
 | 
			
		||||
	{ MSG_ERROR, client_msg_fn_error },
 | 
			
		||||
};
 | 
			
		||||
#define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0])
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
client_msg_dispatch(struct client_ctx *cctx, const char **error)
 | 
			
		||||
client_msg_dispatch(struct client_ctx *cctx, char **error)
 | 
			
		||||
{
 | 
			
		||||
	struct hdr		 hdr;
 | 
			
		||||
	struct client_msg	*msg;
 | 
			
		||||
@@ -72,7 +74,7 @@ client_msg_dispatch(struct client_ctx *cctx, const char **error)
 | 
			
		||||
/* Output message from server. */
 | 
			
		||||
int
 | 
			
		||||
client_msg_fn_output(
 | 
			
		||||
    struct hdr *hdr, struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
    struct hdr *hdr, struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	local_output(cctx->srv_in, hdr->size);
 | 
			
		||||
	return (0);
 | 
			
		||||
@@ -81,7 +83,7 @@ client_msg_fn_output(
 | 
			
		||||
/* Pause message from server. */
 | 
			
		||||
int
 | 
			
		||||
client_msg_fn_pause(
 | 
			
		||||
    struct hdr *hdr, unused struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
    struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	if (hdr->size != 0)
 | 
			
		||||
		fatalx("bad MSG_PAUSE size");
 | 
			
		||||
@@ -91,9 +93,23 @@ client_msg_fn_pause(
 | 
			
		||||
/* Exit message from server. */
 | 
			
		||||
int
 | 
			
		||||
client_msg_fn_exit(
 | 
			
		||||
    struct hdr *hdr, unused struct client_ctx *cctx, unused const char **error)
 | 
			
		||||
    struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	if (hdr->size != 0)
 | 
			
		||||
		fatalx("bad MSG_EXIT size");
 | 
			
		||||
	return (-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Error message from server. */
 | 
			
		||||
int
 | 
			
		||||
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
 | 
			
		||||
{
 | 
			
		||||
	if (hdr->size > SIZE_MAX - 1)
 | 
			
		||||
		fatalx("bad MSG_ERROR size");
 | 
			
		||||
 | 
			
		||||
	*error = xmalloc(hdr->size + 1);
 | 
			
		||||
	buffer_read(cctx->srv_in, *error, hdr->size);
 | 
			
		||||
	(*error)[hdr->size] = '\0';
 | 
			
		||||
 | 
			
		||||
	return (-1);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								client.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								client.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: client.c,v 1.3 2007-09-26 18:32:16 nicm Exp $ */
 | 
			
		||||
/* $Id: client.c,v 1.4 2007-09-26 18:50:49 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -33,7 +33,7 @@
 | 
			
		||||
#include "tmux.h"
 | 
			
		||||
 | 
			
		||||
void	client_handle_winch(struct client_ctx *);
 | 
			
		||||
int	client_process_local(struct client_ctx *, const char **);
 | 
			
		||||
int	client_process_local(struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
client_init(char *path, struct client_ctx *cctx, int start_server)
 | 
			
		||||
@@ -126,7 +126,7 @@ int
 | 
			
		||||
client_main(struct client_ctx *cctx)
 | 
			
		||||
{
 | 
			
		||||
	struct pollfd	 pfds[2];
 | 
			
		||||
	const char	*error;
 | 
			
		||||
	char		*error;
 | 
			
		||||
	int		 n;
 | 
			
		||||
 | 
			
		||||
	logfile("client");
 | 
			
		||||
@@ -174,11 +174,13 @@ client_main(struct client_ctx *cctx)
 | 
			
		||||
 | 
			
		||||
	local_done();
 | 
			
		||||
 | 
			
		||||
	if (sigterm) 
 | 
			
		||||
		error = "received SIGTERM";
 | 
			
		||||
	if (error != NULL) {
 | 
			
		||||
		printf("[terminated: %s]\n", error);
 | 
			
		||||
		return (0);
 | 
			
		||||
		printf("[error: %s]\n", error);
 | 
			
		||||
		return (1);
 | 
			
		||||
	}
 | 
			
		||||
	if (sigterm) {
 | 
			
		||||
		printf("[terminated]\n");
 | 
			
		||||
		return (1);
 | 
			
		||||
	}
 | 
			
		||||
	printf("[detached]\n");
 | 
			
		||||
	return (0);
 | 
			
		||||
@@ -223,7 +225,7 @@ client_handle_winch(struct client_ctx *cctx)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
client_process_local(struct client_ctx *cctx, const char **error)
 | 
			
		||||
client_process_local(struct client_ctx *cctx, char **error)
 | 
			
		||||
{
 | 
			
		||||
	struct buffer	*b;
 | 
			
		||||
	size_t		 size;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								server-msg.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								server-msg.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: server-msg.c,v 1.3 2007-09-26 18:09:23 nicm Exp $ */
 | 
			
		||||
/* $Id: server-msg.c,v 1.4 2007-09-26 18:50:49 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -139,6 +139,8 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
 | 
			
		||||
{
 | 
			
		||||
	struct attach_data	 data;
 | 
			
		||||
	char			*msg;
 | 
			
		||||
	struct session		*s;
 | 
			
		||||
	u_int			 i;
 | 
			
		||||
	
 | 
			
		||||
	if (c->session != NULL)
 | 
			
		||||
		return (0);
 | 
			
		||||
@@ -153,10 +155,21 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
 | 
			
		||||
	if (c->sy == 0)
 | 
			
		||||
		c->sy = 25;
 | 
			
		||||
 | 
			
		||||
	if (*data.name != '\0')
 | 
			
		||||
		c->session = session_find(data.name);
 | 
			
		||||
	if (*data.name != '\0') {
 | 
			
		||||
		if ((c->session = session_find(data.name)) == NULL)
 | 
			
		||||
			xasprintf(&msg, "session not found: %s", data.name);
 | 
			
		||||
	} else {
 | 
			
		||||
		/* Find the oldest session. */
 | 
			
		||||
		for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
 | 
			
		||||
			if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
 | 
			
		||||
				continue;
 | 
			
		||||
			if (c->session == NULL || s->tim < c->session->tim)
 | 
			
		||||
				c->session = s;
 | 
			
		||||
		}
 | 
			
		||||
		if (c->session == NULL)
 | 
			
		||||
			xasprintf(&msg, "no sessions found");
 | 
			
		||||
	}
 | 
			
		||||
	if (c->session == NULL) {
 | 
			
		||||
		xasprintf(&msg, "session not found: %s", data.name);
 | 
			
		||||
		server_write_client(c, MSG_ERROR, msg, strlen(msg));
 | 
			
		||||
		xfree(msg);
 | 
			
		||||
		return (0);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: tmux.h,v 1.14 2007-09-26 18:32:17 nicm Exp $ */
 | 
			
		||||
/* $Id: tmux.h,v 1.15 2007-09-26 18:50:49 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -259,24 +259,24 @@ struct buffer {
 | 
			
		||||
 | 
			
		||||
/* Message codes. */
 | 
			
		||||
enum hdrtype {
 | 
			
		||||
	MSG_NEW = 0,
 | 
			
		||||
	MSG_ATTACH,
 | 
			
		||||
	MSG_ERROR,
 | 
			
		||||
	MSG_CREATE,
 | 
			
		||||
	MSG_ERROR,
 | 
			
		||||
	MSG_EXIT,
 | 
			
		||||
	MSG_SIZE,
 | 
			
		||||
	MSG_NEXT,
 | 
			
		||||
	MSG_PREVIOUS,
 | 
			
		||||
	MSG_INPUT,
 | 
			
		||||
	MSG_LAST,
 | 
			
		||||
	MSG_NEW,
 | 
			
		||||
	MSG_NEXT,
 | 
			
		||||
	MSG_OUTPUT,
 | 
			
		||||
	MSG_PAUSE,
 | 
			
		||||
	MSG_PREVIOUS,
 | 
			
		||||
	MSG_REFRESH,
 | 
			
		||||
	MSG_RENAME,
 | 
			
		||||
	MSG_SELECT,
 | 
			
		||||
	MSG_SESSIONS,
 | 
			
		||||
	MSG_SIZE,
 | 
			
		||||
	MSG_WINDOWLIST,
 | 
			
		||||
	MSG_WINDOWS,
 | 
			
		||||
	MSG_PAUSE,
 | 
			
		||||
	MSG_RENAME,
 | 
			
		||||
	MSG_LAST,
 | 
			
		||||
	MSG_WINDOWLIST
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Message header structure. */
 | 
			
		||||
@@ -451,11 +451,11 @@ int	 client_main(struct client_ctx *);
 | 
			
		||||
void	 client_write_server(struct client_ctx *, enum hdrtype, void *, size_t);
 | 
			
		||||
 | 
			
		||||
/* client-msg.c */
 | 
			
		||||
int	 client_msg_dispatch(struct client_ctx *, const char **);
 | 
			
		||||
int	 client_msg_dispatch(struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
/* command.c */
 | 
			
		||||
extern int client_cmd_prefix;
 | 
			
		||||
int	 client_cmd_dispatch(int, struct client_ctx *, const char **);
 | 
			
		||||
int	 client_cmd_dispatch(int, struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
/* server.c */
 | 
			
		||||
extern struct clients clients;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user