141 lines
3.7 KiB
Plaintext
141 lines
3.7 KiB
Plaintext
$OpenBSD: patch-src_tracker-control_tracker-control-general_c,v 1.5 2011/12/16 17:36:55 ajacoutot Exp $
|
|
--- src/tracker-control/tracker-control-general.c.orig Fri Dec 16 16:38:16 2011
|
|
+++ src/tracker-control/tracker-control-general.c Fri Dec 16 18:02:12 2011
|
|
@@ -21,6 +21,16 @@
|
|
|
|
#include <errno.h>
|
|
|
|
+#ifdef __OpenBSD__
|
|
+#include <stdio.h>
|
|
+#include <fcntl.h>
|
|
+#include <limits.h>
|
|
+#include <kvm.h>
|
|
+#include <sys/param.h>
|
|
+#include <sys/sysctl.h>
|
|
+#include <sys/proc.h>
|
|
+#endif
|
|
+
|
|
#include <glib.h>
|
|
#include <glib/gi18n.h>
|
|
|
|
@@ -117,6 +127,7 @@ tracker_control_general_options_enabled (void)
|
|
return GENERAL_OPTIONS_ENABLED ();
|
|
}
|
|
|
|
+#ifndef __OpenBSD__
|
|
static GSList *
|
|
get_pids (void)
|
|
{
|
|
@@ -153,6 +164,7 @@ get_pids (void)
|
|
|
|
return g_slist_reverse (pids);
|
|
}
|
|
+#endif
|
|
|
|
static void
|
|
log_handler (const gchar *domain,
|
|
@@ -643,66 +655,37 @@ tracker_control_general_run (void)
|
|
if (kill_option != TERM_NONE ||
|
|
terminate_option != TERM_NONE ||
|
|
list_processes) {
|
|
- guint32 own_pid;
|
|
- guint32 own_uid;
|
|
- gchar *own_pid_str;
|
|
-
|
|
- pids = get_pids ();
|
|
- str = g_strdup_printf (g_dngettext (NULL,
|
|
- "Found %d PID…",
|
|
- "Found %d PIDs…",
|
|
- g_slist_length (pids)),
|
|
- g_slist_length (pids));
|
|
- g_print ("%s\n", str);
|
|
- g_free (str);
|
|
-
|
|
- /* Establish own uid/pid */
|
|
- own_pid = (guint32) getpid ();
|
|
- own_pid_str = g_strdup_printf ("%d", own_pid);
|
|
- own_uid = get_uid_for_pid (own_pid_str, NULL);
|
|
- g_free (own_pid_str);
|
|
-
|
|
- for (l = pids; l; l = l->next) {
|
|
- GError *error = NULL;
|
|
- gchar *filename;
|
|
- gchar *contents = NULL;
|
|
- gchar **strv;
|
|
- guint uid;
|
|
-
|
|
- uid = get_uid_for_pid (l->data, &filename);
|
|
-
|
|
- /* Stat the file and make sure current user == file owner */
|
|
- if (uid != own_uid) {
|
|
+ gchar *basename, **strv;
|
|
+ int i, nproc;
|
|
+ struct kinfo_proc *plist, *kp;
|
|
+ char buf[_POSIX2_LINE_MAX];
|
|
+ kvm_t *kd;
|
|
+
|
|
+ if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, buf)) == NULL) {
|
|
+ printf("%s\n", buf);
|
|
+ return EXIT_FAILURE;
|
|
+ }
|
|
+
|
|
+ plist = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(*plist), &nproc);
|
|
+ if (plist == NULL)
|
|
+ return EXIT_FAILURE;
|
|
+
|
|
+ for (i = 0, kp = plist; i < nproc; i++, kp++) {
|
|
+ if ((kp->p_flag & P_SYSTEM) != 0)
|
|
continue;
|
|
- }
|
|
|
|
- /* Get contents to determine basename */
|
|
- if (!g_file_get_contents (filename, &contents, NULL, &error)) {
|
|
- str = g_strdup_printf (_("Could not open '%s'"), filename);
|
|
- g_printerr ("%s, %s\n",
|
|
- str,
|
|
- error ? error->message : _("no error given"));
|
|
- g_free (str);
|
|
- g_clear_error (&error);
|
|
- g_free (contents);
|
|
- g_free (filename);
|
|
+ if ((strv = kvm_getargv(kd, kp, 0)) == NULL)
|
|
+ continue;
|
|
+
|
|
+ basename = g_path_get_basename(strv[0]);
|
|
|
|
- continue;
|
|
- }
|
|
-
|
|
- strv = g_strsplit (contents, "^@", 2);
|
|
- if (strv && strv[0]) {
|
|
- gchar *basename;
|
|
-
|
|
- basename = g_path_get_basename (strv[0]);
|
|
-
|
|
if ((g_str_has_prefix (basename, "tracker") == TRUE ||
|
|
g_str_has_prefix (basename, "lt-tracker") == TRUE) &&
|
|
g_str_has_suffix (basename, "-control") == FALSE &&
|
|
g_str_has_suffix (basename, "-status-icon") == FALSE) {
|
|
pid_t pid;
|
|
|
|
- pid = atoi (l->data);
|
|
+ pid = kp->p_pid;
|
|
str = g_strdup_printf (_("Found process ID %d for '%s'"), pid, basename);
|
|
g_print ("%s\n", str);
|
|
g_free (str);
|
|
@@ -754,14 +737,6 @@ tracker_control_general_run (void)
|
|
|
|
g_free (basename);
|
|
}
|
|
-
|
|
- g_strfreev (strv);
|
|
- g_free (contents);
|
|
- g_free (filename);
|
|
- }
|
|
-
|
|
- g_slist_foreach (pids, (GFunc) g_free, NULL);
|
|
- g_slist_free (pids);
|
|
|
|
/* If we just wanted to list processes, all done */
|
|
if (list_processes &&
|