[BACK]Return to osdep-netbsd.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / bsd / tmux / dist

File: [cvs.NetBSD.org] / src / external / bsd / tmux / dist / osdep-netbsd.c (download)

Revision 1.1.1.9 (vendor branch), Mon Jan 6 20:40:37 2020 UTC (4 years, 2 months ago) by christos
Branch: TMUX, MAIN
CVS Tags: tmux-3-1c, tmux-3-0a, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, is-mlppp-base, is-mlppp
Changes since 1.1.1.8: +16 -1 lines

CHANGES FROM 3.0 to 3.0a

* Do not require REG_STARTEND.

* Respawn panes or windows correctly if default-command is set.

* Add missing option for after-kill-pane hook.

* Fix for crash with a format variable that doesn't exist.

* Do not truncate list-keys output on some platforms.

* Do not crash when restoring a layout with only one pane.

CHANGES FROM 2.9 to 3.0

* Workaround invalid layout strings generated by older tmux versions and add
  some additional sanity checks

* xterm 348 now disables margins when resized, so send DECLRMM again after
  resize.

* Add support for the SD (scroll down) escape sequence.

* Expand arguments to C and s format modifiers to match the m modifier.

* Add support for underscore colours (Setulc capability must be added with
  terminal-overrides as described in tmux(1)).

* Add a "fill" style attribute for the fill colour of the drawing area (where
  appropriate).

* New -H flag to send-keys to send literal keys.

* Format variables for pane mouse modes (mouse_utf8_flag and mouse_sgr_flag)
  and for origin mode (origin_flag).

* Add -F to refresh-client for flags for control mode clients, only one flag
  (no-output) supported at the moment.

* Add a few vi(1) keys for menus.

* Add pane options, set with set-option -p and displayed with show-options -p.
  Pane options inherit from window options (so every pane option is also
  a window option). The pane style is now configured by setting window-style
  and window-active-style in the pane options; select-pane -P and -g now change
  the option but are no longer documented.

* Do not document set-window-option and show-window-options. set-option -w and
  show-options -w should be used instead.

* Add a -A flag to show-options to show parent options as well (they are marked
  with a *).

* Resize panes lazily - do not resize unless they are in an attached, active
  window.

* Add regular expression support for the format search, match and substitute
  modifiers and make them able to ignore case. find-window now accepts -r to
  use regular expressions.

* Do not use $TMUX to find the session because for windows in multiple sessions
  it is wrong as often as it is right, and for windows in one session it is
  pointless. Instead use TMUX_PANE if it is present.

* Do not always resize the window back to its original size after applying a
  layout, keep it at the layout size until it must be resized (for example when
  attached and window-size is not manual).

* Add new-session -X and attach-session -x to send SIGHUP to parent when
  detaching (like detach-client -P).

* Support for octal escapes in strings (such as \007) and improve list-keys
  output so it parses correctly if copied into a configuration file.

* INCOMPATIBLE: Add a new {} syntax to the configuration file. This is a string
  similar to single quotes but also includes newlines and allows commands that
  take other commands as string arguments to be expressed more clearly and
  without additional escaping.

  A literal { and } or a string containing { or } must now be escaped or
  quoted, for example '{' and '}' instead of { or }, or 'X#{foo}' instead of
  X#{foo}.

* New <, >, <= and >= comparison operators for formats.

* Improve escaping of special characters in list-keys output.

* INCOMPATIBLE: tmux's configuration parsing has changed to use yacc(1). There
  is one incompatible change: a \ on its own must be escaped or quoted as
  either \\ or '\' (the latter works on older tmux versions).

  Entirely the same parser is now used for parsing the configuration file
  and for string commands. This means that constructs previously only
  available in .tmux.conf, such as %if, can now be used in string commands
  (for example, those given to if-shell - not commands invoked from the
  shell, they are still parsed by the shell itself).

* Add support for the overline attribute (SGR 53). The Smol capability is
  needed in terminal-overrides.

* Add the ability to create simple menus. Introduces new command
  display-menu. Default menus are bound to MouseDown3 on the status line;
  MouseDown3 or M-MouseDown3 on panes; MouseDown3 in tree, client and
  buffer modes; and C-b C-m and C-b M-m.

* Allow panes to be empty (no command). They can be created either by piping to
  split-window -I, or by passing an empty command ('') to split-window. Output
  can be sent to an existing empty window with display-message -I.

* Add keys to jump between matching brackets (emacs C-M-f and C-M-b, vi %).

* Add a -e flag to new-window, split-window, respawn-window, respawn-pane to
  pass environment variables into the newly created process.

* Hooks are now stored in the options tree as array options, allowing them to
  have multiple separate commands. set-hook and show-hooks remain but
  set-option and show-options can now also be used (show-options will only show
  hooks if given the -H flag). Hooks with multiple commands are run in index
  order.

* Automatically scroll if dragging to create a selection with the mouse and the
  cursor reaches the top or bottom line.

* Add -no-clear variants of copy-selection and copy-pipe which do not clear the
  selection after copying. Make copy-pipe clear the selection by default to be
  consistent with copy-selection.

* Add an argument to copy commands to set the prefix for the buffer name, this
  (for example) allows buffers for different sessions to be named separately.

* Update session activity on focus event.

* Pass target from source-file into the config file parser so formats in %if
  and %endif have access to more useful variables.

* Add the ability to infer an option type (server, session, window) from its
  name to show-options (it was already present in set-option).

/* $OpenBSD$ */

/*
 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/sysctl.h>

#include <errno.h>
#include <event.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "tmux.h"

#define is_runnable(p) \
	((p)->p_stat == LSRUN || (p)->p_stat == SIDL)
#define is_stopped(p) \
	((p)->p_stat == SSTOP || (p)->p_stat == SZOMB)

struct kinfo_proc2	*cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *);
char			*osdep_get_name(int, char *);
char			*osdep_get_cwd(int);
struct event_base	*osdep_event_init(void);

struct kinfo_proc2 *
cmp_procs(struct kinfo_proc2 *p1, struct kinfo_proc2 *p2)
{
	if (is_runnable(p1) && !is_runnable(p2))
		return (p1);
	if (!is_runnable(p1) && is_runnable(p2))
		return (p2);

	if (is_stopped(p1) && !is_stopped(p2))
		return (p1);
	if (!is_stopped(p1) && is_stopped(p2))
		return (p2);

	if (p1->p_estcpu > p2->p_estcpu)
		return (p1);
	if (p1->p_estcpu < p2->p_estcpu)
		return (p2);

	if (p1->p_slptime < p2->p_slptime)
		return (p1);
	if (p1->p_slptime > p2->p_slptime)
		return (p2);

	if (p1->p_pid > p2->p_pid)
		return (p1);
	return (p2);
}

char *
osdep_get_name(int fd, __unused char *tty)
{
	int		 mib[6];
	struct stat	 sb;
	size_t		 len, i;
	struct kinfo_proc2 *buf, *newbuf, *bestp;
	char		*name;

	if (stat(tty, &sb) == -1)
		return (NULL);
	if ((mib[3] = tcgetpgrp(fd)) == -1)
		return (NULL);

	buf = NULL;
	len = sizeof bestp;

	mib[0] = CTL_KERN;
	mib[1] = KERN_PROC2;
	mib[2] = KERN_PROC_PGRP;
	mib[4] = sizeof *buf;

retry:
	mib[5] = 0;

	if (sysctl(mib, __arraycount(mib), NULL, &len, NULL, 0) == -1)
		return (NULL);

	if ((newbuf = realloc(buf, len)) == NULL)
		goto error;
	buf = newbuf;

	mib[5] = len / (sizeof *buf);
	if (sysctl(mib, __arraycount(mib), buf, &len, NULL, 0) == -1) {
		if (errno == ENOMEM)
			goto retry;
		goto error;
	}

	bestp = NULL;
	for (i = 0; i < len / (sizeof *buf); i++) {
		if (buf[i].p_tdev != sb.st_rdev)
			continue;
		if (bestp == NULL)
			bestp = &buf[i];
		else
			bestp = cmp_procs(&buf[i], bestp);
	}

	name = NULL;
	if (bestp != NULL)
		name = strdup(bestp->p_comm);

	free(buf);
	return (name);

error:
	free(buf);
	return (NULL);
}

char *
osdep_get_cwd(int fd)
{
	static char	target[PATH_MAX + 1];
	pid_t		pgrp;
#ifdef KERN_PROC_CWD
	int		mib[4];
	size_t		len;
#else
	char		*path;
	ssize_t		n;
#endif

	if ((pgrp = tcgetpgrp(fd)) == -1)
		return (NULL);

#ifdef KERN_PROC_CWD
	mib[0] = CTL_KERN;
	mib[1] = KERN_PROC_ARGS;
	mib[2] = pgrp;
	mib[3] = KERN_PROC_CWD;
	len = sizeof(target);
	if (sysctl(mib, __arraycount(mib), target, &len, NULL, 0) == 0)
		return (target);
#else
	xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
	n = readlink(path, target, sizeof(target) - 1);
	free(path);
	if (n > 0) {
		target[n] = '\0';
		return (target);
	}
#endif

	return (NULL);
}

struct event_base *
osdep_event_init(void)
{
	return (event_init());
}