It is too easy to create things in the same second; use a timespec instead.

This commit is contained in:
Nicholas Marriott 2008-06-03 18:13:54 +00:00
parent 743956edf8
commit 73c9b25d2d
8 changed files with 26 additions and 28 deletions

8
TODO
View File

@ -39,10 +39,6 @@
buffer manip: clear, view etc (clear-buffer, show-buffer)
- function groups, bind-key ^W { select-window 0; send-key ^W } etc ***
- allow fnmatch for -c, so that you can, eg, detach all clients
- session specification is all over the place. some things use -s before cmd,
some -s after, some no -s, there are various uses of -n. the differences are
sort of logical, but confusing. needs rethought
- XXX should -i for win idx be before cmd too??
- bind non prefix keys
- stuff like rename would be nice to be able to do in-client like screen, if
it could be implemented in a non-icky way
@ -67,8 +63,8 @@
- tobiasu says it is borken on Linux with aterm + TERM=rxvt
- poll(2) is broken on OS X/Darwin, a workaround for this would be nice
- different screen model? layers perhaps? hmm
- cfg file improvements: * comments to EOL
- select-window can become windowonly...
- cfg file improvements
- select-window can become windowonly (what about default?)
---
[18:20] *priteau* i found something in tmux that could be tweaked to be better

View File

@ -1,4 +1,4 @@
/* $Id: cmd-kill-server.c,v 1.2 2008-06-03 05:35:50 nicm Exp $ */
/* $Id: cmd-kill-server.c,v 1.3 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,7 +44,7 @@ const struct cmd_entry cmd_kill_server_entry = {
void
cmd_kill_server_exec(unused void *ptr, struct cmd_ctx *ctx)
{
kill(getpid(), SIGTERM);
sigterm = 1;
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-sessions.c,v 1.12 2008-06-03 05:35:51 nicm Exp $ */
/* $Id: cmd-list-sessions.c,v 1.13 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -56,7 +56,7 @@ cmd_list_sessions_exec(unused void *ptr, struct cmd_ctx *ctx)
n = 0;
RB_FOREACH(wl, winlinks, &s->windows)
n++;
tim = ctime(&s->tim);
tim = ctime(&s->ts.tv_sec);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "%s: %u windows"

View File

@ -1,4 +1,4 @@
/* $Id: cmd-switch-client.c,v 1.5 2008-06-03 05:35:51 nicm Exp $ */
/* $Id: cmd-switch-client.c,v 1.6 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -41,7 +41,7 @@ struct cmd_switch_client_data {
const struct cmd_entry cmd_switch_client_entry = {
"switch-client", "switchc",
"session-name",
"[-c client-tty] session-name",
0,
cmd_switch_client_parse,
cmd_switch_client_exec,

19
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.39 2008-06-03 16:55:09 nicm Exp $ */
/* $Id: cmd.c,v 1.40 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -17,6 +17,7 @@
*/
#include <sys/types.h>
#include <sys/time.h>
#include <fnmatch.h>
#include <getopt.h>
@ -253,18 +254,18 @@ struct session *
cmd_lookup_session(const char *sname)
{
struct session *s, *newest = NULL;
time_t tim;
struct timespec *ts;
u_int i;
tim = 0;
ts = NULL;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i);
if (s == NULL || fnmatch(sname, s->name, 0) != 0)
continue;
if (s->tim > tim) {
if (ts == NULL || timespeccmp(&s->ts, ts, >)) {
newest = s;
tim = s->tim;
ts = &s->ts;
}
}
@ -305,7 +306,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *cname, const char *sname)
struct client *c;
struct msg_command_data *data = ctx->msgdata;
u_int i;
time_t tim;
struct timespec *ts;
if (cname != NULL) {
if ((c = cmd_lookup_client(cname)) == NULL) {
@ -342,12 +343,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *cname, const char *sname)
return (s);
}
tim = 0;
ts = NULL;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i);
if (s != NULL && s->tim > tim) {
if (s != NULL && (ts == NULL || timespeccmp(&s->ts, ts, >))) {
newest = ARRAY_ITEM(&sessions, i);
tim = s->tim;
ts = &s->ts;
}
}
if (newest == NULL)

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.31 2008-06-02 21:08:36 nicm Exp $ */
/* $Id: session.c,v 1.32 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -17,10 +17,10 @@
*/
#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
@ -90,7 +90,8 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
u_int i;
s = xmalloc(sizeof *s);
s->tim = time(NULL);
if (clock_gettime(CLOCK_REALTIME, &s->ts) != 0)
fatal("clock_gettime");
s->curw = s->lastw = NULL;
RB_INIT(&s->windows);
ARRAY_INIT(&s->bells);

4
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.49 2008-06-03 05:35:51 nicm Exp $ */
/* $Id: tmux.c,v 1.50 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -59,7 +59,7 @@ __dead void
usage(void)
{
fprintf(stderr,
"usage: %s [-v] [-f file] [-S socket-path] [command [flags]]",
"usage: %s [-v] [-f file] [-S socket-path] [command [flags]]\n",
__progname);
exit(1);
}

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.123 2008-06-03 16:55:09 nicm Exp $ */
/* $Id: tmux.h,v 1.124 2008-06-03 18:13:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -536,7 +536,7 @@ RB_HEAD(winlinks, winlink);
/* Client session. */
struct session {
char *name;
time_t tim;
struct timespec ts;
u_int sx;
u_int sy;