GCredentials: add getter/setter for the Unix process ID

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687920
This commit is contained in:
Simon McVittie 2012-11-08 14:08:24 +00:00 committed by Matthias Clasen
parent 602714a8da
commit 8f65536504
4 changed files with 48 additions and 0 deletions

View File

@ -2487,6 +2487,7 @@ g_credentials_set_native
g_credentials_is_same_user
g_credentials_get_unix_user
g_credentials_set_unix_user
g_credentials_get_unix_pid
<SUBSECTION Standard>
G_CREDENTIALS
G_IS_CREDENTIALS

View File

@ -441,6 +441,48 @@ g_credentials_get_unix_user (GCredentials *credentials,
return ret;
}
/**
* g_credentials_get_unix_pid:
* @credentials: A #GCredentials
* @error: Return location for error or %NULL.
*
* Tries to get the UNIX process identifier from @credentials. This
* method is only available on UNIX platforms.
*
* This operation can fail if #GCredentials is not supported on the
* OS or if the native credentials type does not contain information
* about the UNIX process ID.
*
* Returns: The UNIX process ID, or -1 if @error is set.
*
* Since: 2.36
*/
pid_t
g_credentials_get_unix_pid (GCredentials *credentials,
GError **error)
{
pid_t ret;
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), -1);
g_return_val_if_fail (error == NULL || *error == NULL, -1);
#ifdef __linux__
ret = credentials->native.pid;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
ret = credentials->native.cmcred_pid;
#elif defined(__OpenBSD__)
ret = credentials->native.pid;
#else
ret = -1;
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
_("GCredentials does not contain a process ID on this OS"));
#endif
return ret;
}
/**
* g_credentials_set_unix_user:
* @credentials: A #GCredentials.
@ -488,4 +530,5 @@ g_credentials_set_unix_user (GCredentials *credentials,
return ret;
}
#endif /* G_OS_UNIX */

View File

@ -64,6 +64,9 @@ gboolean g_credentials_is_same_user (GCredentials *credentials,
GError **error);
#ifdef G_OS_UNIX
GLIB_AVAILABLE_IN_2_36
pid_t g_credentials_get_unix_pid (GCredentials *credentials,
GError **error);
uid_t g_credentials_get_unix_user (GCredentials *credentials,
GError **error);
gboolean g_credentials_set_unix_user (GCredentials *credentials,

View File

@ -1228,6 +1228,7 @@ g_credentials_get_native
g_credentials_set_native
g_credentials_is_same_user
#ifdef G_OS_UNIX
g_credentials_get_unix_pid
g_credentials_get_unix_user
g_credentials_set_unix_user
#endif