1 /* Copyright (C) 1998-99 Martin Baulig 2 Copyright (C) 2004 Nicolás Lichtmaier 3 This file is part of LibGTop 1.0. 4 5 Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. 6 7 Modified by Nicolás Lichtmaier to give open process files. 8 9 LibGTop is free software; you can redistribute it and/or modify it 10 under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, 12 or (at your option) any later version. 13 14 LibGTop is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with LibGTop; see the file COPYING. If not, write to the 21 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 Boston, MA 02110-1301, USA. 23 */ 24 25 #ifndef __GLIBTOP_PROC_OPEN_FILES_H__ 26 #define __GLIBTOP_PROC_OPEN_FILES_H__ 27 28 #include <glibtop.h> 29 #include <glibtop/global.h> 30 31 32 G_BEGIN_DECLS 33 34 #define GLIBTOP_PROC_OPEN_FILES_NUMBER 0 35 #define GLIBTOP_PROC_OPEN_FILES_TOTAL 1 36 #define GLIBTOP_PROC_OPEN_FILES_SIZE 2 37 38 #define GLIBTOP_MAX_PROC_OPEN_FILES 3 39 40 #define GLIBTOP_FILE_ENTRY_FD 0 41 #define GLIBTOP_FILE_ENTRY_NAME 1 42 #define GLIBTOP_FILE_ENTRY_TYPE 2 43 #define GLIBTOP_FILE_ENTRY_INETSOCKET_DST_HOST 3 44 #define GLIBTOP_FILE_ENTRY_INETSOCKET_DST_PORT 4 45 46 #define GLIBTOP_MAX_OPEN_FILE_ENTRY 5 47 48 #define GLIBTOP_OPEN_FILENAME_LEN 215 49 /* ready for IPv6 */ 50 #define GLIBTOP_OPEN_DEST_HOST_LEN 46 51 52 enum glibtop_file_type { 53 GLIBTOP_FILE_TYPE_FILE = 1, 54 GLIBTOP_FILE_TYPE_PIPE = 2, 55 GLIBTOP_FILE_TYPE_INETSOCKET = 4, 56 GLIBTOP_FILE_TYPE_LOCALSOCKET = 8, 57 GLIBTOP_FILE_TYPE_INET6SOCKET = 16 58 }; 59 60 typedef struct _glibtop_open_files_entry glibtop_open_files_entry; 61 62 typedef struct _glibtop_proc_open_files glibtop_proc_open_files; 63 64 struct _glibtop_open_files_entry 65 { 66 int fd; 67 guint16 type; /* An "enum glibtop_file_type" value. */ 68 union { 69 /* When type == GLIBTOP_FILE_TYPE_INETSOCKET or 70 * when type == GLIBTOP_FILE_TYPE_INET6SOCKET */ 71 struct { 72 char dest_host[GLIBTOP_OPEN_DEST_HOST_LEN+1]; 73 int dest_port; 74 } sock; 75 76 /* When type == GLIBTOP_FILE_TYPE_FILE */ 77 struct { 78 char name[GLIBTOP_OPEN_FILENAME_LEN+1]; 79 } file; 80 81 /* When type == GLIBTOP_FILE_TYPE_LOCALSOCKET */ 82 struct { 83 char name[GLIBTOP_OPEN_FILENAME_LEN+1]; 84 } localsock; 85 86 } info; 87 }; 88 89 struct _glibtop_proc_open_files 90 { 91 guint64 flags; 92 guint64 number; /* GLIBTOP_PROC_OPEN_FILES_NUMBER */ 93 guint64 total; /* GLIBTOP_PROC_OPEN_FILES_TOTAL */ 94 guint64 size; /* GLIBTOP_PROC_OPEN_FILES_SIZE */ 95 }; 96 97 /** 98 * glibtop_get_proc_open_files: 99 * @buf: 100 * @pid: 101 * 102 * Returns: (transfer full) (array zero-terminated=1): 103 */ 104 105 glibtop_open_files_entry * 106 glibtop_get_proc_open_files(glibtop_proc_open_files *buf, pid_t pid); 107 108 #if GLIBTOP_SUID_PROC_OPEN_FILES 109 #define glibtop_get_proc_open_files_r glibtop_get_proc_open_files_p 110 #else 111 #define glibtop_get_proc_open_files_r glibtop_get_proc_open_files_s 112 #endif 113 114 115 /** 116 * glibtop_get_proc_open_files_l: 117 * @server: 118 * @buf: (out): 119 * @pid: 120 * 121 * Returns: (transfer full) (array zero-terminated=1): 122 */ 123 124 glibtop_open_files_entry * 125 glibtop_get_proc_open_files_l (glibtop *server, glibtop_proc_open_files *buf, pid_t pid); 126 127 #if GLIBTOP_SUID_PROC_OPEN_FILES 128 void _glibtop_init_proc_open_files_p (glibtop *server); 129 130 131 /** 132 * glibtop_get_proc_open_files_p: 133 * @server: 134 * @buf: (out): 135 * @pid: 136 * 137 * Returns: (transfer full) (array zero-terminated=1): 138 */ 139 140 glibtop_open_files_entry * 141 glibtop_get_proc_open_files_p (glibtop *server, glibtop_proc_open_files *buf, pid_t pid); 142 #else 143 void _glibtop_init_proc_open_files_s (glibtop *server); 144 145 glibtop_open_files_entry * 146 glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid); 147 #endif 148 149 GType glibtop_open_files_entry_get_type (void) G_GNUC_CONST; 150 GType glibtop_proc_open_files_get_type (void) G_GNUC_CONST; 151 152 G_END_DECLS 153 154 #endif 155