/* Linux-specific functions to retrieve OS data.
-
+
Copyright (C) 2009-2018 Free Software Foundation, Inc.
This file is part of GDB.
#define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1)
/* Returns the CPU core that thread PTID is currently running on. */
-
+
/* Compute and return the processor core of a given thread. */
int
{
std::string stat_path = string_printf ("/proc/%lld/stat", pid);
gdb_file_up fp = gdb_fopen_cloexec (stat_path, "r");
-
+
command[0] = '\0';
-
+
if (fp)
{
/* sizeof (cmd) should be greater or equal to TASK_COMM_LEN (in
char cmd[18];
PID_T stat_pid;
int items_read = fscanf (fp.get (), "%lld %17s", &stat_pid, cmd);
-
+
if (items_read == 2 && pid == stat_pid)
{
cmd[strlen (cmd) - 1] = '\0'; /* Remove trailing parenthesis. */
{
char buf[1024];
size_t read_bytes = fread (buf, 1, sizeof (buf), f.get ());
-
+
if (read_bytes)
{
commandline = (char *) xrealloc (commandline, len + read_bytes + 1);
user_from_uid (char *user, int maxlen, uid_t uid)
{
struct passwd *pwentry = getpwuid (uid);
-
+
if (pwentry)
{
strncpy (user, pwentry->pw_name, maxlen);
char procentry[sizeof ("/proc/") + MAX_PID_T_STRLEN];
sprintf (procentry, "/proc/%lld", pid);
-
+
if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
{
*owner = statbuf.st_uid;
}
xfree (cores);
-
+
buffer_xml_printf (
&buffer,
"<item>"
command_line ? command_line : "",
cores_str);
- xfree (command_line);
+ xfree (command_line);
xfree (cores_str);
}
-
+
closedir (dirp);
}
xfree (command_line);
}
- }
+ }
buffer_grow_str0 (&buffer, "</osdata>\n");
buf = buffer_finish (&buffer);
std::string pathname
= string_printf ("/proc/%s/task", dp->d_name);
-
+
pid = atoi (dp->d_name);
command_from_pid (command, sizeof (command), pid);
remote_address, &remote_port,
&state,
&uid);
-
+
if (result == 6)
{
union socket_addr locaddr, remaddr;
&locaddr.sin.sin_addr.s_addr);
sscanf (remote_address, "%X",
&remaddr.sin.sin_addr.s_addr);
-
+
locaddr.sin.sin_port = htons (local_port);
remaddr.sin.sin_port = htons (remote_port);
locaddr.sin6.sin6_port = htons (local_port);
remaddr.sin6.sin6_port = htons (remote_port);
-
+
locaddr.sin6.sin6_flowinfo = 0;
remaddr.sin6.sin6_flowinfo = 0;
locaddr.sin6.sin6_scope_id = 0;
addr_size = sizeof (struct sockaddr_in6);
}
-
+
locaddr.sa.sa_family = remaddr.sa.sa_family = family;
-
+
result = getnameinfo (&locaddr.sa, addr_size,
local_address, sizeof (local_address),
local_service, sizeof (local_service),
| (tcp ? 0 : NI_DGRAM));
if (result)
continue;
-
+
result = getnameinfo (&remaddr.sa, addr_size,
remote_address,
sizeof (remote_address),
| (tcp ? 0 : NI_DGRAM));
if (result)
continue;
-
+
user_from_uid (user, sizeof (user), uid);
-
+
buffer_xml_printf (
buffer,
"<item>"
"<column name=\"remote port\">%s</column>"
"<column name=\"state\">%s</column>"
"<column name=\"user\">%s</column>"
- "<column name=\"family\">%s</column>"
+ "<column name=\"family\">%s</column>"
"<column name=\"protocol\">%s</column>"
"</item>",
local_address,
else
{
time_t t = (time_t) seconds;
-
+
strncpy (time, ctime (&t), maxlen);
time[maxlen - 1] = '\0';
}
group_from_gid (char *group, int maxlen, gid_t gid)
{
struct group *grentry = getgrgid (gid);
-
+
if (grentry)
{
strncpy (group, grentry->gr_name, maxlen);
TIME_T atime, dtime, ctime;
unsigned int perms;
int items_read;
-
+
items_read = sscanf (buf,
"%d %d %o %d %lld %lld %d %u %u %u %u %lld %lld %lld",
&key, &shmid, &perms, &size,
char cuser[UT_NAMESIZE], cgroup[UT_NAMESIZE];
char ccmd[32], lcmd[32];
char atime_str[32], dtime_str[32], ctime_str[32];
-
+
user_from_uid (user, sizeof (user), uid);
group_from_gid (group, sizeof (group), gid);
user_from_uid (cuser, sizeof (cuser), cuid);
group_from_gid (cgroup, sizeof (cgroup), cgid);
-
+
command_from_pid (ccmd, sizeof (ccmd), cpid);
command_from_pid (lcmd, sizeof (lcmd), lpid);
-
+
time_from_time_t (atime_str, sizeof (atime_str), atime);
time_from_time_t (dtime_str, sizeof (dtime_str), dtime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
-
+
buffer_xml_printf (
&buffer,
"<item>"
}
while (!feof (fp.get ()));
}
-
+
buffer_grow_str0 (&buffer, "</osdata>\n");
saved_buf = buffer_finish (&buffer);
len_avail = strlen (saved_buf);
if (fp)
{
char buf[8192];
-
+
do
{
if (fgets (buf, sizeof (buf), fp.get ()))
int semid;
TIME_T otime, ctime;
int items_read;
-
+
items_read = sscanf (buf,
"%d %d %o %u %d %d %d %d %lld %lld",
&key, &semid, &perms, &nsems,
&uid, &gid, &cuid, &cgid,
&otime, &ctime);
-
+
if (items_read == 10)
{
char user[UT_NAMESIZE], group[UT_NAMESIZE];
char cuser[UT_NAMESIZE], cgroup[UT_NAMESIZE];
char otime_str[32], ctime_str[32];
-
+
user_from_uid (user, sizeof (user), uid);
group_from_gid (group, sizeof (group), gid);
user_from_uid (cuser, sizeof (cuser), cuid);
group_from_gid (cgroup, sizeof (cgroup), cgid);
-
+
time_from_time_t (otime_str, sizeof (otime_str), otime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
-
+
buffer_xml_printf (
&buffer,
"<item>"
saved_buf = NULL;
buffer_init (&buffer);
buffer_grow_str (&buffer, "<osdata type=\"message queues\">\n");
-
+
gdb_file_up fp = gdb_fopen_cloexec ("/proc/sysvipc/msg", "r");
if (fp)
{
char buf[8192];
-
+
do
{
if (fgets (buf, sizeof (buf), fp.get ()))
int msqid;
TIME_T stime, rtime, ctime;
int items_read;
-
+
items_read = sscanf (buf,
"%d %d %o %u %u %lld %lld %d %d %d %d %lld %lld %lld",
&key, &msqid, &perms, &cbytes, &qnum,
&lspid, &lrpid, &uid, &gid, &cuid, &cgid,
&stime, &rtime, &ctime);
-
+
if (items_read == 14)
{
char user[UT_NAMESIZE], group[UT_NAMESIZE];
char cuser[UT_NAMESIZE], cgroup[UT_NAMESIZE];
char lscmd[32], lrcmd[32];
char stime_str[32], rtime_str[32], ctime_str[32];
-
+
user_from_uid (user, sizeof (user), uid);
group_from_gid (group, sizeof (group), gid);
user_from_uid (cuser, sizeof (cuser), cuid);
group_from_gid (cgroup, sizeof (cgroup), cgid);
-
+
command_from_pid (lscmd, sizeof (lscmd), lspid);
command_from_pid (lrcmd, sizeof (lrcmd), lrpid);
-
+
time_from_time_t (stime_str, sizeof (stime_str), stime);
time_from_time_t (rtime_str, sizeof (rtime_str), rtime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
-
+
buffer_xml_printf (
&buffer,
"<item>"
if (fp)
{
char buf[8192];
-
+
do
{
if (fgets (buf, sizeof (buf), fp.get ()))
if (strcmp (annex, osdata_table[i].type) == 0)
{
gdb_assert (readbuf);
-
+
return (osdata_table[i].getter) (readbuf, offset, len);
}
}