X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkmountoperation-x11.c;h=fe8beb6949d86652e5c6eb244071f9640cd35dc0;hb=45ad8a06ad511ad95a74172172b9fe459bc666ad;hp=1663a028a47a1a4d36130f479ba24b9f20a7cf9c;hpb=af00ca81e1787ce59e10cd21b8ee49a246256958;p=~andy%2Fgtk
diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c
index 1663a028a..fe8beb694 100644
--- a/gtk/gtkmountoperation-x11.c
+++ b/gtk/gtkmountoperation-x11.c
@@ -15,9 +15,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
/*
@@ -43,7 +41,8 @@
#include
#if defined(__OpenBSD__)
-#include
+#include
+#include
#include
#include
#endif
@@ -725,46 +724,44 @@ pid_get_command_line (GPid pid)
static GPid
pid_get_parent (GPid pid)
{
- struct kinfo_proc *proc;
- int count;
- kvm_t *kvm;
- GPid ppid = 0;
+ struct kinfo_proc kp;
+ size_t len;
+ GPid ppid;
+
+ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
+ sizeof(struct kinfo_proc), 0 };
- kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
- if (kvm == NULL)
- return 0;
+ if (sysctl(mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ return (-1);
+ mib[5] = (len / sizeof(struct kinfo_proc));
- proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
- if (count == 1)
- ppid = proc->p_ppid;
+ if (sysctl(mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
+ return -1;
+
+ ppid = kp.p_ppid;
- kvm_close (kvm);
return ppid;
}
static gchar *
pid_get_env (GPid pid, const gchar *key)
{
- kvm_t *kvm;
- struct kinfo_proc *proc;
- char **strs;
+ size_t len = PATH_MAX;
+ char **strs = NULL;
char *ret;
char *end;
int key_len;
- int count;
int i;
- kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
- if (kvm == NULL)
- return NULL;
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ENV };
+
+ strs = (char **)realloc(strs, len);
key_len = strlen (key);
ret = NULL;
- proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
- if (proc != NULL)
+ if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) != -1)
{
- strs = kvm_getenvv (kvm, proc, 0);
for (i = 0; strs[i] != NULL; i++)
{
if (g_str_has_prefix (strs[i], key) && (*(strs[i] + key_len) == '='))
@@ -779,35 +776,33 @@ pid_get_env (GPid pid, const gchar *key)
}
}
- kvm_close (kvm);
+ g_free (strs);
return ret;
}
static gchar *
pid_get_command_line (GPid pid)
{
- kvm_t *kvm;
- struct kinfo_proc *proc;
- int count;
- char **strs;
- char *ret;
+ size_t len = PATH_MAX;
+ char **strs = NULL;
+ char *ret = NULL;
char *end;
- kvm = kvm_openfiles (NULL, NULL, NULL, KVM_NO_FILES, NULL);
- if (kvm == NULL)
- return NULL;
+ int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV };
- proc = kvm_getprocs (kvm, KERN_PROC_PID, pid, sizeof (struct kinfo_proc), &count);
- if (proc == NULL)
- return NULL;
+ strs = (char **)realloc(strs, len);
+
+ if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) == -1) {
+ g_free (strs);
+ return ret;
+ }
- strs = kvm_getargv (kvm, proc, 0);
ret = g_strjoinv (" ", strs);
/* skip invalid UTF-8 */
if (!g_utf8_validate (ret, -1, (const gchar **) &end))
*end = '\0';
- kvm_close (kvm);
+ g_free (strs);
return ret;
}