summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas James Alexander Thurman <tthurman@src.gnome.org>2009-03-06 22:51:02 +0000
committerThomas James Alexander Thurman <tthurman@src.gnome.org>2009-03-06 22:51:02 +0000
commitab6aa5463ffdd5cfaf729eb1f5407be749ba1090 (patch)
tree6919745dae59f7a7a0bfcaae5e51be4241fa77ee /src
parent42387bff6ffab4e741cdc69b46cdf8308a690a22 (diff)
downloadmetacity-ab6aa5463ffdd5cfaf729eb1f5407be749ba1090.tar.gz
metacity-ab6aa5463ffdd5cfaf729eb1f5407be749ba1090.tar.bz2
add optional dependency on gtop. Include "(as username)" in the titlebar
* configure.in: add optional dependency on gtop. * src/core/window-props.c: Include "(as username)" in the titlebar if a window is running as another user. * src/core/window.c: check for PID before name, since the rendering of the name can now depend on the PID. Closes #549389. svn path=/trunk/; revision=4181
Diffstat (limited to 'src')
-rw-r--r--src/core/window-props.c99
-rw-r--r--src/core/window.c2
2 files changed, 99 insertions, 2 deletions
diff --git a/src/core/window-props.c b/src/core/window-props.c
index 2ef3597..02b8845 100644
--- a/src/core/window-props.c
+++ b/src/core/window-props.c
@@ -47,6 +47,16 @@
#include <X11/Xatom.h>
#include <unistd.h>
#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <pwd.h>
+
+#ifdef HAVE_GTOP
+#include <glibtop/procuid.h>
+#include <errno.h>
+#include <pwd.h>
+#endif /* HAVE_GTOP */
+
#ifndef HOST_NAME_MAX
/* Solaris headers apparently don't define this so do so manually; #326745 */
#define HOST_NAME_MAX 255
@@ -337,6 +347,32 @@ reload_net_wm_user_time_window (MetaWindow *window,
}
}
+/**
+ * Finds who owns a particular process, if we can.
+ *
+ * \param process The process's ID.
+ * \result Set to the ID of the user, if we returned true.
+ *
+ * \result True if we could tell.
+ */
+static gboolean
+owner_of_process (pid_t process, uid_t *result)
+{
+#ifdef HAVE_GTOP
+ glibtop_proc_uid process_details;
+
+ glibtop_get_proc_uid (&process_details, process);
+
+ *result = process_details.uid;
+ return TRUE;
+#else
+ /* I don't know, maybe we could do something hairy like see whether
+ * /proc/$PID exists and who owns it, in case they have procfs.
+ */
+ return FALSE;
+#endif /* HAVE_GTOP */
+}
+
#define MAX_TITLE_LENGTH 512
/**
@@ -369,15 +405,76 @@ set_title_text (MetaWindow *window,
modified = TRUE;
}
/* if WM_CLIENT_MACHINE indicates this machine is on a remote host
- * lets place that hostname in the title */
+ * let's place that hostname in the title */
else if (window->wm_client_machine &&
!gethostname (hostname, HOST_NAME_MAX + 1) &&
strcmp (hostname, window->wm_client_machine))
{
+ /* Translators: the title of a window from another machine */
*target = g_strdup_printf (_("%s (on %s)"),
title, window->wm_client_machine);
modified = TRUE;
}
+ else if (window->net_wm_pid != -1)
+ {
+ /* We know the process which owns this window; perhaps we can
+ * find out the name of its owner (if it's not us).
+ */
+
+ char *found_name = NULL;
+
+ uid_t window_owner = 0;
+ gboolean window_owner_known =
+ owner_of_process (window->net_wm_pid, &window_owner);
+
+ /* Assume a window with unknown ownership is ours (call it usufruct!) */
+ gboolean window_owner_is_us =
+ !window_owner_known || window_owner==getuid ();
+
+ if (window_owner_is_us)
+ {
+ /* we own it, so fall back to the simple case */
+ *target = g_strdup (title);
+ }
+ else
+ {
+ /* it belongs to window_owner. So what's their name? */
+
+ if (window_owner==0)
+ {
+ /* Simple case-- don't bother to look it up. It's root. */
+ *target = g_strdup_printf (_("%s (as superuser)"),
+ title);
+ }
+ else
+ {
+ /* Okay, let's look up the name. */
+ struct passwd *pwd;
+
+ errno = 0;
+ pwd = getpwuid (window_owner);
+ if (errno==0 || pwd==NULL)
+ {
+ found_name = pwd->pw_name;
+ }
+
+ if (found_name)
+ /* Translators: the title of a window owned by another user
+ * on this machine */
+ *target = g_strdup_printf (_("%s (as %s)"),
+ title,
+ found_name);
+ else
+ /* Translators: the title of a window owned by another user
+ * on this machine, whose name we don't know */
+ *target = g_strdup_printf (_("%s (as another user)"),
+ title);
+ }
+ /* either way we changed it */
+ modified = TRUE;
+
+ }
+ }
else
*target = g_strdup (title);
diff --git a/src/core/window.c b/src/core/window.c
index c9bc037..6de86ee 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -572,9 +572,9 @@ meta_window_new_with_attrs (MetaDisplay *display,
*/
i = 0;
initial_props[i++] = display->atom_WM_CLIENT_MACHINE;
+ initial_props[i++] = display->atom__NET_WM_PID;
initial_props[i++] = display->atom__NET_WM_NAME;
initial_props[i++] = XA_WM_CLASS;
- initial_props[i++] = display->atom__NET_WM_PID;
initial_props[i++] = XA_WM_NAME;
initial_props[i++] = display->atom__NET_WM_ICON_NAME;
initial_props[i++] = XA_WM_ICON_NAME;