summaryrefslogtreecommitdiff
path: root/gtk/gtkmountoperation-x11.c
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@gnome.org>2014-04-25 14:37:59 +0200
committerAntoine Jacoutot <ajacoutot@gnome.org>2014-04-25 14:37:59 +0200
commit8935d2f123878c31af69b6c6034069ad540b13c7 (patch)
tree25c9857f96f5b7e3206f7a82f74a7107a09ebb82 /gtk/gtkmountoperation-x11.c
parentfab2173b315c7d305b75f6aabb4da45922b44afa (diff)
downloadgtk+-8935d2f123878c31af69b6c6034069ad540b13c7.tar.gz
openbsd: properly set len for gtkmountoperation-x11
sysctl(3) is the correct way to get the lenght for len in this case. Also drop unused headers and change style to match the rest of the file.
Diffstat (limited to 'gtk/gtkmountoperation-x11.c')
-rw-r--r--gtk/gtkmountoperation-x11.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c
index fe8beb6949..4ecef653c5 100644
--- a/gtk/gtkmountoperation-x11.c
+++ b/gtk/gtkmountoperation-x11.c
@@ -41,9 +41,6 @@
#include <errno.h>
#if defined(__OpenBSD__)
-#include <stdlib.h>
-#include <sys/param.h>
-#include <fcntl.h>
#include <sys/sysctl.h>
#endif
@@ -731,11 +728,11 @@ pid_get_parent (GPid pid)
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
sizeof(struct kinfo_proc), 0 };
- if (sysctl(mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
return (-1);
mib[5] = (len / sizeof(struct kinfo_proc));
- if (sysctl(mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
+ if (sysctl (mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
return -1;
ppid = kp.p_ppid;
@@ -746,21 +743,23 @@ pid_get_parent (GPid pid)
static gchar *
pid_get_env (GPid pid, const gchar *key)
{
- size_t len = PATH_MAX;
- char **strs = NULL;
- char *ret;
+ size_t len;
+ char **strs;
+ char *ret = NULL;
char *end;
int key_len;
int i;
int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ENV };
- strs = (char **)realloc(strs, len);
+ if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ return ret;
+
+ strs = g_malloc0 (len);
key_len = strlen (key);
- ret = NULL;
- if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) != -1)
+ if (sysctl (mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) != -1)
{
for (i = 0; strs[i] != NULL; i++)
{
@@ -783,18 +782,20 @@ pid_get_env (GPid pid, const gchar *key)
static gchar *
pid_get_command_line (GPid pid)
{
- size_t len = PATH_MAX;
- char **strs = NULL;
- char *ret = NULL;
- char *end;
+ size_t len;
+ char **strs;
+ char *ret, *end;
int mib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV };
- strs = (char **)realloc(strs, len);
+ if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ return NULL;
+
+ strs = g_malloc0 (len);
- if (sysctl(mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) == -1) {
+ if (sysctl (mib, G_N_ELEMENTS (mib), strs, &len, NULL, 0) == -1) {
g_free (strs);
- return ret;
+ return NULL;
}
ret = g_strjoinv (" ", strs);