Project

General

Profile

Feature #137 » dyson-polkitunixprocess.c.patch

don't do that ;-) - Igor Pashev, 2013-06-23 10:53 AM

View differences:

policykit-1-0.105/src/polkit/polkitunixprocess.c 2013-06-23 14:44:35.778728343 +0400
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#ifdef HAVE_SOLARIS
#include <procfs.h>
#endif
#include "polkitunixprocess.h"
#include "polkitsubject.h"
......
}
#ifdef HAVE_SOLARIS
static int
get_pid_psinfo (pid_t pid, struct psinfo *ps)
static gboolean
get_pid_psinfo (pid_t pid, psinfo_t *ps)
{
char pname[32];
int procfd;
......
(void) snprintf(pname, sizeof(pname), "/proc/%d/psinfo", pid);
if ((procfd = open(pname, O_RDONLY)) == -1)
{
return -1;
return FALSE;
}
if (read(procfd, ps, sizeof(struct psinfo)) < 0)
if (read(procfd, ps, sizeof(psinfo_t)) < 0)
{
(void) close(procfd);
return -1;
return FALSE;
}
(void) close(procfd);
return 0;
return TRUE;
}
#endif
......
GError **error)
{
guint64 start_time;
#ifndef HAVE_FREEBSD
start_time = 0;
#ifdef HAVE_LINUX
gchar *filename;
gchar *contents;
size_t length;
......
gchar *p;
gchar *endp;
start_time = 0;
contents = NULL;
filename = g_strdup_printf ("/proc/%d/stat", pid);
......
out:
g_free (filename);
g_free (contents);
#else
#elif HAVE_FREEBSD
struct kinfo_proc p;
start_time = 0;
if (! get_kinfo_proc (pid, &p))
{
g_set_error (error,
......
start_time = (guint64) p.ki_start.tv_sec;
out:
#elif HAVE_SOLARIS
psinfo_t p;
if (!get_pid_psinfo (pid, &p))
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"Error obtaining start time for %d (%s)",
(gint) pid,
g_strerror (errno));
goto out;
}
start_time = (guint64) p.pr_start.tv_sec;
out:
#else
#warning Your system is not supported
#endif
return start_time;
......
GError **error)
{
gint result;
gchar *contents;
gchar **lines;
#ifdef HAVE_FREEBSD
struct kinfo_proc p;
#else
#elif HAVE_LINUX
gchar *contents;
gchar **lines;
gchar filename[64];
guint n;
#elif HAVE_SOLARIS
psinfo_t p;
#else
#warning Your system is not supported
#endif
g_return_val_if_fail (POLKIT_IS_UNIX_PROCESS (process), 0);
g_return_val_if_fail (error == NULL || *error == NULL, 0);
result = 0;
lines = NULL;
contents = NULL;
#ifdef HAVE_FREEBSD
if (get_kinfo_proc (process->pid, &p) == 0)
if (!get_kinfo_proc (process->pid, &p))
{
g_set_error (error,
POLKIT_ERROR,
......
}
result = p.ki_uid;
#else
out:
#elif HAVE_SOLARIS
if (!get_pid_psinfo (process->pid, &p))
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"get_pid_psinfo() failed for pid %d: %s",
process->pid,
g_strerror (errno));
goto out;
}
result = p.pr_uid;
out:
#elif HAVE_LINUX
lines = NULL;
contents = NULL;
/* see 'man proc' for layout of the status file
*
......
POLKIT_ERROR_FAILED,
"Didn't find any line starting with `Uid:' in file %s",
filename);
#endif
out:
g_strfreev (lines);
g_free (contents);
#else
#warning Your system is not supported
#endif
return result;
}
policykit-1-0.105/configure.ac 2013-06-23 11:59:07.222669274 +0400
dnl ---------------------------------------------------------------------------
case "$host_os" in
*linux*)
AC_DEFINE([HAVE_LINUX], 1, [Is this a Linux system?])
;;
*solaris*)
AC_DEFINE([HAVE_SOLARIS], 1, [Is this a Solaris system?])
(2-2/3)