mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 14:25:15 +00:00
get_starttime: add support for GNU Hurd using the mach task_info call.
This is currently Hurd-specific but could be made Mach-generic as long as the equivalent of pid2task() is available.
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
sudo_dso_public int main(int argc, char *argv[]);
|
||||
|
||||
#if defined(sudo_kinfo_proc) || defined(__linux__) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC)
|
||||
#if defined(sudo_kinfo_proc) || defined(__linux__) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__gnu_hurd__)
|
||||
|
||||
#ifdef __linux__
|
||||
static int
|
||||
|
@@ -47,6 +47,12 @@
|
||||
# include <sys/pstat.h>
|
||||
#endif
|
||||
|
||||
#if defined(__gnu_hurd__)
|
||||
# include <hurd.h>
|
||||
# include <mach/task_info.h>
|
||||
# include <mach/time_value.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -298,6 +304,31 @@ get_starttime(pid_t pid, struct timespec *starttime)
|
||||
"unable to get start time for %d via pstat_getproc", (int)pid);
|
||||
debug_return_int(-1);
|
||||
}
|
||||
#elif defined(__gnu_hurd__)
|
||||
int
|
||||
get_starttime(pid_t pid, struct timespec *starttime)
|
||||
{
|
||||
mach_msg_type_number_t count;
|
||||
struct task_basic_info info;
|
||||
kern_return_t error;
|
||||
task_t target;
|
||||
debug_decl(get_starttime, SUDOERS_DEBUG_UTIL);
|
||||
|
||||
target = pid2task(pid);
|
||||
if (target != MACH_PORT_NULL) {
|
||||
count = sizeof(info) / sizeof(integer_t);
|
||||
error = task_info(target, TASK_BASIC_INFO, (task_info_t)&info, &count);
|
||||
if (error == KERN_SUCCESS) {
|
||||
starttime->tv_sec = info.creation_time.seconds;
|
||||
starttime->tv_nsec = info.creation_time.microseconds * 1000;
|
||||
debug_return_int(0);
|
||||
}
|
||||
}
|
||||
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to get start time for %d via task_info", (int)pid);
|
||||
debug_return_int(-1);
|
||||
}
|
||||
#else
|
||||
int
|
||||
get_starttime(pid_t pid, struct timespec *starttime)
|
||||
|
Reference in New Issue
Block a user