I've attached my version of an osdep_get_name() function to get the active
function name on Solaris.

I'm only using it on OpenSolaris snv_124 x86 so far; hopefully it will
work on Solaris 10 as well, given that all of the interfaces it uses are
standard.

tcgetpgrp() returns ENOTTY if it's called on a tty other than the caller's
controlling tty, but issuing the TIOCGPGRP ioctl directly works.

TIOCGPGRP works only on the slave end of a pty pair, but since
tmux provides only the master to osdep_get_name(), and the tty argument is
an empty string (?), I'm calling ptsname() to get the slave and open it.
This should be improved somehow, but I'm not sure how right now. Either
tmux could keep a file descriptor to the slave around, or perhaps there's
some STREAMS trick that would make it work on the master end; I don't know.
/*
 * Copyright (c) 2009 Todd Carson <t...@daybefore.net>
 *
 * 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/types.h>
#include <sys/stat.h>

#include <fcntl.h>
#include <procfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "tmux.h"

char *
osdep_get_name(int fd, unused char *tty)
{
	struct psinfo	 p;
	struct stat	 st;
	char		*path;
	ssize_t		 bytes;
	int		 f;
	pid_t		 pgrp;

	if ((path = ptsname(fd)) == NULL)
		return (NULL);

	if ((f = open(path, O_RDONLY)) < 0)
		return (NULL);

	if ((fstat(f, &st) != 0) ||
	    (ioctl(f, TIOCGPGRP, &pgrp) != 0)) {
		(void) close(f);
		return (NULL);
	}
	(void) close(f);

	xasprintf(&path, "/proc/%hu/psinfo", pgrp);
	f = open(path, O_RDONLY);
	xfree(path);
	if (f < 0)
		return (NULL);

	bytes = read(f, &p, sizeof(p));
	(void) close(f);
	if (bytes != sizeof(p))
		return (NULL);

	if (p.pr_ttydev != st.st_rdev)
		return (NULL);

	return (xstrdup(p.pr_fname));
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to