cn_proc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * cn_proc.h - process events connector
  3. *
  4. * Copyright (C) Matt Helsley, IBM Corp. 2005
  5. * Based on cn_fork.h by Nguyen Anh Quynh and Guillaume Thouvenin
  6. * Original copyright notice follows:
  7. * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
  8. * Copyright (C) 2005 Guillaume Thouvenin <guillaume.thouvenin@bull.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #ifndef CN_PROC_H
  25. #define CN_PROC_H
  26. #include <linux/types.h>
  27. #include <linux/time.h>
  28. #include <linux/connector.h>
  29. /*
  30. * Userspace sends this enum to register with the kernel that it is listening
  31. * for events on the connector.
  32. */
  33. enum proc_cn_mcast_op {
  34. PROC_CN_MCAST_LISTEN = 1,
  35. PROC_CN_MCAST_IGNORE = 2
  36. };
  37. /*
  38. * From the user's point of view, the process
  39. * ID is the thread group ID and thread ID is the internal
  40. * kernel "pid". So, fields are assigned as follow:
  41. *
  42. * In user space - In kernel space
  43. *
  44. * parent process ID = parent->tgid
  45. * parent thread ID = parent->pid
  46. * child process ID = child->tgid
  47. * child thread ID = child->pid
  48. */
  49. struct proc_event {
  50. enum what {
  51. /* Use successive bits so the enums can be used to record
  52. * sets of events as well
  53. */
  54. PROC_EVENT_NONE = 0x00000000,
  55. PROC_EVENT_FORK = 0x00000001,
  56. PROC_EVENT_EXEC = 0x00000002,
  57. PROC_EVENT_UID = 0x00000004,
  58. PROC_EVENT_GID = 0x00000040,
  59. /* "next" should be 0x00000400 */
  60. /* "last" is the last process event: exit */
  61. PROC_EVENT_EXIT = 0x80000000
  62. } what;
  63. __u32 cpu;
  64. struct timespec timestamp;
  65. union { /* must be last field of proc_event struct */
  66. struct {
  67. __u32 err;
  68. } ack;
  69. struct fork_proc_event {
  70. pid_t parent_pid;
  71. pid_t parent_tgid;
  72. pid_t child_pid;
  73. pid_t child_tgid;
  74. } fork;
  75. struct exec_proc_event {
  76. pid_t process_pid;
  77. pid_t process_tgid;
  78. } exec;
  79. struct id_proc_event {
  80. pid_t process_pid;
  81. pid_t process_tgid;
  82. union {
  83. __u32 ruid; /* task uid */
  84. __u32 rgid; /* task gid */
  85. } r;
  86. union {
  87. __u32 euid;
  88. __u32 egid;
  89. } e;
  90. } id;
  91. struct exit_proc_event {
  92. pid_t process_pid;
  93. pid_t process_tgid;
  94. __u32 exit_code, exit_signal;
  95. } exit;
  96. } event_data;
  97. };
  98. #ifdef __KERNEL__
  99. #ifdef CONFIG_PROC_EVENTS
  100. void proc_fork_connector(struct task_struct *task);
  101. void proc_exec_connector(struct task_struct *task);
  102. void proc_id_connector(struct task_struct *task, int which_id);
  103. void proc_exit_connector(struct task_struct *task);
  104. #else
  105. static inline void proc_fork_connector(struct task_struct *task)
  106. {}
  107. static inline void proc_exec_connector(struct task_struct *task)
  108. {}
  109. static inline void proc_id_connector(struct task_struct *task,
  110. int which_id)
  111. {}
  112. static inline void proc_exit_connector(struct task_struct *task)
  113. {}
  114. #endif /* CONFIG_PROC_EVENTS */
  115. #endif /* __KERNEL__ */
  116. #endif /* CN_PROC_H */