diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-20 22:17:53 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-01-20 22:17:53 +0000 |
commit | 8c259f562be24570a19fd94b223034ae8c6e4277 (patch) | |
tree | 1b6506a2ce27e4ca9ce743f8f00f14c3114d523d | |
parent | caa93f0e02bfeedff48bb1fe19460732b08e39d1 (diff) | |
download | rtmux-8c259f562be24570a19fd94b223034ae8c6e4277.tar.gz rtmux-8c259f562be24570a19fd94b223034ae8c6e4277.tar.bz2 rtmux-8c259f562be24570a19fd94b223034ae8c6e4277.zip |
Darwin support for automatic-rename, from joshe.
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | GNUmakefile | 5 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | osdep-darwin.c | 50 | ||||
-rw-r--r-- | osdep-freebsd.c | 4 | ||||
-rw-r--r-- | osdep-openbsd.c | 4 | ||||
-rw-r--r-- | osdep-unknown.c | 5 |
7 files changed, 67 insertions, 11 deletions
@@ -1,5 +1,8 @@ 20 January 2009 +* Darwin support for automatic-rename from joshe; Darwin doesn't seem to have + a sane method of getting argv[0] and searching for the precise insane way + is too frustrating, so this just uses the executable name. * Try to change the window title to match the command running it in. This is done by reading argv[0] from the process group leader of the group that owns the tty (tcgetpgrp()). This can't be done portably so some OS-dependent code @@ -983,7 +986,7 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.225 2009-01-20 19:35:03 nicm Exp $ +$Id: CHANGES,v 1.226 2009-01-20 22:17:53 nicm Exp $ LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms diff --git a/GNUmakefile b/GNUmakefile index cbcb6d3b..a313fc9a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.64 2009-01-20 20:00:39 nicm Exp $ +# $Id: GNUmakefile,v 1.65 2009-01-20 22:17:53 nicm Exp $ .PHONY: clean @@ -41,7 +41,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ window-choose.c \ options.c options-cmd.c paste.c colour.c utf8.c clock.c \ tty.c tty-term.c tty-keys.c tty-write.c util.c names.c \ - osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c + osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c \ + osdep-darwin.c CC?= gcc INCDIRS+= -I. -I- @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.103 2009-01-20 19:35:03 nicm Exp $ +# $Id: Makefile,v 1.104 2009-01-20 22:17:53 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean update-index.html upload-index.html @@ -45,7 +45,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ window-choose.c \ options.c options-cmd.c paste.c colour.c utf8.c clock.c \ tty.c tty-term.c tty-keys.c tty-write.c util.c names.c \ - osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c + osdep-unknown.c osdep-openbsd.c osdep-freebsd.c osdep-linux.c \ + osdep-darwin.c CC?= cc INCDIRS+= -I. -I- -I/usr/local/include diff --git a/osdep-darwin.c b/osdep-darwin.c new file mode 100644 index 00000000..653b52fe --- /dev/null +++ b/osdep-darwin.c @@ -0,0 +1,50 @@ +/* $Id: osdep-darwin.c,v 1.1 2009-01-20 22:17:53 nicm Exp $ */ + +/* + * Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org> + * + * 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. + */ + +#ifdef __APPLE__ + +#include <sys/types.h> +#include <sys/sysctl.h> + +#include <stdlib.h> + +char *get_argv0(pid_t); + +/* + * XXX This actually returns the executable path, not the process's argv[0]. + * Anyone who wishes to complain about this is welcome to grab a copy of + * Apple's 'ps' source and start digging. + */ + +char * +get_argv0(pid_t pgrp) +{ + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; + size_t size; + struct kinfo_proc kp; + + mib[3] = pgrp; + size = sizeof kp; + if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1 || + kp.kp_proc.p_comm[0] == '\0') + return (NULL); + + return (strdup(kp.kp_proc.p_comm)); +} + +#endif diff --git a/osdep-freebsd.c b/osdep-freebsd.c index e22e28ac..0e04a4c0 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -1,4 +1,4 @@ -/* $Id: osdep-freebsd.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */ +/* $Id: osdep-freebsd.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -45,7 +45,7 @@ get_argv0(pid_t pgrp) size = 128; while (size < SIZE_MAX / 2) { size *= 2; - if ((args2 = realloc(args, 2 * size)) == NULL) + if ((args2 = realloc(args, size)) == NULL) break; args = args2; if (sysctl(mib, 4, args, &size, NULL, 0) == -1) { diff --git a/osdep-openbsd.c b/osdep-openbsd.c index 2a6a7d1d..6c39416d 100644 --- a/osdep-openbsd.c +++ b/osdep-openbsd.c @@ -1,4 +1,4 @@ -/* $Id: osdep-openbsd.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */ +/* $Id: osdep-openbsd.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -44,7 +44,7 @@ get_argv0(pid_t pgrp) size = 128; while (size < SIZE_MAX / 2) { size *= 2; - if ((args2 = realloc(args, 2 * size)) == NULL) + if ((args2 = realloc(args, size)) == NULL) break; args = args2; if (sysctl(mib, 4, args, &size, NULL, 0) == -1) { diff --git a/osdep-unknown.c b/osdep-unknown.c index cbfac3a0..1b5f4516 100644 --- a/osdep-unknown.c +++ b/osdep-unknown.c @@ -1,4 +1,4 @@ -/* $Id: osdep-unknown.c,v 1.1 2009-01-20 19:35:03 nicm Exp $ */ +/* $Id: osdep-unknown.c,v 1.2 2009-01-20 22:17:53 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -16,7 +16,8 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__) +#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && \ + !defined(__APPLE__) #include <sys/types.h> |