8954f27882
from and ok robert@
125 lines
3.2 KiB
Plaintext
125 lines
3.2 KiB
Plaintext
$OpenBSD: patch-src_tracker-control_tracker-control_c,v 1.1 2011/01/15 19:51:08 ajacoutot Exp $
|
|
|
|
We don't use procfs in OpenBSD.
|
|
|
|
--- src/tracker-control/tracker-control.c.orig Thu Sep 2 14:51:00 2010
|
|
+++ src/tracker-control/tracker-control.c Sat Jan 15 20:39:04 2011
|
|
@@ -27,6 +27,16 @@
|
|
#include <sys/types.h>
|
|
#include <signal.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>
|
|
#include <glib/gprintf.h>
|
|
@@ -101,6 +111,7 @@ static GOptionEntry entries[] = {
|
|
{ NULL }
|
|
};
|
|
|
|
+#ifndef __OpenBSD__
|
|
static GSList *
|
|
get_pids (void)
|
|
{
|
|
@@ -137,6 +148,7 @@ get_pids (void)
|
|
|
|
return g_slist_reverse (pids);
|
|
}
|
|
+#endif
|
|
|
|
static void
|
|
log_handler (const gchar *domain,
|
|
@@ -298,46 +310,37 @@ main (int argc, char **argv)
|
|
if (kill_option != TERM_NONE ||
|
|
terminate_option != TERM_NONE ||
|
|
(!start && !remove_config)) {
|
|
- 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);
|
|
|
|
- for (l = pids; l; l = l->next) {
|
|
- gchar *filename;
|
|
- gchar *contents = NULL;
|
|
- gchar **strv;
|
|
+ gchar *basename, **strv;
|
|
+ int i, nproc;
|
|
+ struct kinfo_proc2 *plist, *kp;
|
|
+ char buf[_POSIX2_LINE_MAX];
|
|
+ kvm_t *kd;
|
|
|
|
- filename = g_build_filename ("/proc", l->data, "cmdline", NULL);
|
|
- 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 ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, buf)) == NULL) {
|
|
+ printf("%s\n", buf);
|
|
+ return EXIT_FAILURE;
|
|
+ }
|
|
|
|
- continue;
|
|
- }
|
|
+ plist = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(*plist), &nproc);
|
|
+ if (plist == NULL)
|
|
+ return EXIT_FAILURE;
|
|
|
|
- strv = g_strsplit (contents, "^@", 2);
|
|
- if (strv && strv[0]) {
|
|
- gchar *basename;
|
|
+ for (i = 0, kp = plist; i < nproc; i++, kp++) {
|
|
+ if ((kp->p_flag & P_SYSTEM) != 0)
|
|
+ continue;
|
|
|
|
- basename = g_path_get_basename (strv[0]);
|
|
+ if ((strv = kvm_getargv2(kd, kp, 0)) == NULL)
|
|
+ continue;
|
|
|
|
+ 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) {
|
|
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);
|
|
@@ -386,17 +389,8 @@ main (int argc, char **argv)
|
|
}
|
|
}
|
|
}
|
|
-
|
|
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 (hard_reset || soft_reset) {
|