Updated with Tizen:Base source codes
[external/procps.git] / ps / common.h
1 /*
2  * Copyright 1998-2002 by Albert Cahalan; all rights resered.         
3  * This file may be used subject to the terms and conditions of the
4  * GNU Library General Public License Version 2, or any later version  
5  * at your option, as published by the Free Software Foundation.
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU Library General Public License for more details.
10  */
11
12 #ifndef PROCPS_PS_H
13 #define PROCPS_PS_H
14
15 #include "../proc/procps.h"
16 #include "../proc/escape.h"
17 #include "../proc/readproc.h"
18
19 #if 0
20 #define trace(args...) printf(## args)
21 #else
22 #define trace(args...)
23 #endif
24
25
26 /***************** GENERAL DEFINE ********************/
27
28
29 /* selection list */
30 #define SEL_RUID 1
31 #define SEL_EUID 2
32 #define SEL_SUID 3
33 #define SEL_FUID 4
34 #define SEL_RGID 5
35 #define SEL_EGID 6
36 #define SEL_SGID 7
37 #define SEL_FGID 8
38 #define SEL_PGRP 9
39 #define SEL_PID  10
40 #define SEL_TTY  11
41 #define SEL_SESS 12
42 #define SEL_COMM 13
43 #define SEL_PPID 14
44
45 /* Since an enum could be smashed by a #define, it would be bad. */
46 #define U98  0 /* Unix98 standard */    /* This must be 0 */
47 #define XXX  1 /* Common extension */
48 #define DEC  2 /* Digital Unix */
49 #define AIX  3 /* AIX */
50 #define SCO  4 /* SCO */
51 #define LNX  5 /* Linux original :-) */
52 #define BSD  6 /* FreeBSD and OpenBSD */
53 #define SUN  7 /* SunOS 5 (Solaris) */
54 #define HPU  8 /* HP-UX */
55 #define SGI  9 /* Irix */
56 #define SOE 10 /* IBM's S/390 OpenEdition */
57 #define TST 11 /* test code */
58
59 /*
60  * Try not to overflow the output buffer:
61  *    32 pages for env+cmd
62  *    64 kB pages on IA-64
63  *    4 chars for "\377", or 1 when mangling to '?'  (ESC_STRETCH)
64  *    plus some slack for other stuff
65  * That is about 8.5 MB on IA-64, or 0.6 MB on i386
66  *
67  * Sadly, current kernels only supply one page of env/command data.
68  * The buffer is now protected with a guard page, and via other means
69  * to avoid hitting the guard page.
70  */
71
72 /* output buffer size */
73 #define OUTBUF_SIZE (2 * 64*1024 * ESC_STRETCH)
74
75 /******************* PS DEFINE *******************/
76
77 // Column flags
78 // Justification control for flags field comes first.
79 #define CF_JUST_MASK                0x0f
80 //      CF_AIXHACK                     0
81 #define CF_USER                        1 // left if text, right if numeric
82 #define CF_LEFT                        2
83 #define CF_RIGHT                       3
84 #define CF_UNLIMITED                   4
85 #define CF_WCHAN                       5 // left if text, right if numeric
86 #define CF_SIGNAL                      6 // right in 9, or 16 if screen_cols>107
87 // Then the other flags
88 #define CF_PIDMAX             0x00000010 // react to pid_max
89 // Only one allowed; use separate bits to catch errors.
90 #define CF_PRINT_THREAD_ONLY  0x10000000
91 #define CF_PRINT_PROCESS_ONLY 0x20000000
92 #define CF_PRINT_EVERY_TIME   0x40000000
93 #define CF_PRINT_AS_NEEDED    0x80000000 // means we have no clue, so assume EVERY TIME
94 #define CF_PRINT_MASK         0xf0000000
95
96 #define needs_for_select (PROC_FILLSTAT | PROC_FILLSTATUS)
97
98 /* thread_flags */
99 #define TF_B_H         0x0001
100 #define TF_B_m         0x0002
101 #define TF_U_m         0x0004
102 #define TF_U_T         0x0008
103 #define TF_U_L         0x0010
104 #define TF_show_proc   0x0100  // show the summary line
105 #define TF_show_task   0x0200  // show the per-thread lines
106 #define TF_show_both   0x0400  // distinct proc/task format lists
107 #define TF_loose_tasks 0x0800  // let sorting break up task groups (BSDish)
108 #define TF_no_sort     0x1000  // don't know if thread-grouping should survive a sort
109 #define TF_no_forest   0x2000  // don't see how to do threads w/ forest option
110 #define TF_must_use    0x4000  // options only make sense if LWP/SPID column added
111
112 /* personality control flags */
113 #define PER_BROKEN_o      0x0001
114 #define PER_BSD_h         0x0002
115 #define PER_BSD_m         0x0004
116 #define PER_IRIX_l        0x0008
117 #define PER_FORCE_BSD     0x0010
118 #define PER_GOOD_o        0x0020
119 #define PER_OLD_m         0x0040
120 #define PER_NO_DEFAULT_g  0x0080
121 #define PER_ZAP_ADDR      0x0100
122 #define PER_SANE_USER     0x0200
123 #define PER_HPUX_x        0x0400
124 #define PER_SVR4_x        0x0800
125 #define PER_BSD_COLS      0x1000
126 #define PER_UNIX_COLS     0x2000
127
128 /* Simple selections by bit mask */
129 #define SS_B_x 0x01
130 #define SS_B_g 0x02
131 #define SS_U_d 0x04
132 #define SS_U_a 0x08
133 #define SS_B_a 0x10
134
135 /* predefined format flags such as:  -l -f l u s -j */
136 #define FF_Uf 0x0001 /* -f */
137 #define FF_Uj 0x0002 /* -j */
138 #define FF_Ul 0x0004 /* -l */
139 #define FF_Bj 0x0008 /* j */
140 #define FF_Bl 0x0010 /* l */
141 #define FF_Bs 0x0020 /* s */
142 #define FF_Bu 0x0040 /* u */
143 #define FF_Bv 0x0080 /* v */
144 #define FF_LX 0x0100 /* X */
145 #define FF_Lm 0x0200 /* m */  /* overloaded: threads, sort, format */
146 #define FF_Fc 0x0400 /* --context */  /* Flask security context format */
147
148 /* predefined format modifier flags such as:  -l -f l u s -j */
149 #define FM_c 0x0001 /* -c */
150 #define FM_j 0x0002 /* -j */  /* only set when !sysv_j_format */
151 #define FM_y 0x0004 /* -y */
152 //#define FM_L 0x0008 /* -L */
153 #define FM_P 0x0010 /* -P */
154 #define FM_M 0x0020 /* -M */
155 //#define FM_T 0x0040 /* -T */
156 #define FM_F 0x0080 /* -F */  /* -F also sets the regular -f flags */
157
158 /* sorting & formatting */
159 /* U,B,G is Unix,BSD,Gnu and then there is the option itself */
160 #define SF_U_O      1
161 #define SF_U_o      2
162 #define SF_B_O      3
163 #define SF_B_o      4
164 #define SF_B_m      5       /* overloaded: threads, sort, format */
165 #define SF_G_sort   6
166 #define SF_G_format 7
167
168 /* headers */
169 #define HEAD_SINGLE 0  /* default, must be 0 */
170 #define HEAD_NONE   1
171 #define HEAD_MULTI  2
172
173
174 /********************** GENERAL TYPEDEF *******************/
175
176 /* Other fields that might be useful:
177  *
178  * char *name;     user-defined column name (format specification)
179  * int reverse;    sorting in reverse (sort specification)
180  *
181  * name in place of u
182  * reverse in place of n
183  */
184
185 typedef union sel_union {
186   pid_t pid;
187   pid_t ppid;
188   uid_t uid;
189   gid_t gid;
190   dev_t tty;
191   char  cmd[16];  /* this is _not_ \0 terminated */
192 } sel_union;
193
194 typedef struct selection_node {
195   struct selection_node *next;
196   sel_union *u;  /* used if selection type has a list of values */
197   int n;         /* used if selection type has a list of values */
198   int typecode;
199 } selection_node;
200
201 typedef struct sort_node {
202   struct sort_node *next;
203   int (*sr)(const proc_t* P, const proc_t* Q); /* sort function */
204   int reverse;   /* can sort backwards */
205   int typecode;
206   int need;
207 } sort_node;
208
209 typedef struct format_node {
210   struct format_node *next;
211   char *name;                             /* user can override default name */
212   int (*pr)(char *restrict const outbuf, const proc_t *restrict const pp); // print function
213 /*  int (* const sr)(const proc_t* P, const proc_t* Q); */ /* sort function */
214   int width;
215   int need;
216   int vendor;                             /* Vendor that invented this */
217   int flags;
218   int typecode;
219 } format_node;
220
221 typedef struct format_struct {
222   const char *spec; /* format specifier */
223   const char *head; /* default header in the POSIX locale */
224   int (* const pr)(char *restrict const outbuf, const proc_t *restrict const pp); // print function
225   int (* const sr)(const proc_t* P, const proc_t* Q); /* sort function */
226   const int width;
227   const int need;       /* data we will need (files to read, etc.) */
228   const int vendor; /* Where does this come from? */
229   const int flags;
230 } format_struct;
231
232 /* though ps-specific, needed by general file */
233 typedef struct macro_struct {
234   const char *spec; /* format specifier */
235   const char *head; /* default header in the POSIX locale */
236 } macro_struct;
237
238 /**************** PS TYPEDEF ***********************/
239
240 typedef struct aix_struct {
241   const int   desc; /* 1-character format code */
242   const char *spec; /* format specifier */
243   const char *head; /* default header in the POSIX locale */
244 } aix_struct;
245
246 typedef struct shortsort_struct {
247   const int   desc; /* 1-character format code */
248   const char *spec; /* format specifier */
249 } shortsort_struct;
250
251 /* Save these options for later: -o o -O O --format --sort */
252 typedef struct sf_node {
253   struct sf_node *next;  /* next arg */
254   format_node *f_cooked;  /* convert each arg alone, then merge */
255   sort_node   *s_cooked;  /* convert each arg alone, then merge */
256   char *sf;
257   int sf_code;
258 } sf_node;
259
260 /********************* UNDECIDED GLOBALS **************/
261
262 /* output.c */
263 extern void show_one_proc(const proc_t *restrict const p, const format_node *restrict fmt);
264 extern void print_format_specifiers(void);
265 extern const aix_struct *search_aix_array(const int findme);
266 extern const shortsort_struct *search_shortsort_array(const int findme);
267 extern const format_struct *search_format_array(const char *findme);
268 extern const macro_struct *search_macro_array(const char *findme);
269 extern void init_output(void);
270 extern int pr_nop(char *restrict const outbuf, const proc_t *restrict const pp);
271
272 /* global.c */
273 extern void reset_global(void);
274
275 /* global.c */
276 extern int             all_processes;
277 extern const char     *bsd_j_format;
278 extern const char     *bsd_l_format;
279 extern const char     *bsd_s_format;
280 extern const char     *bsd_u_format;
281 extern const char     *bsd_v_format;
282 extern int             bsd_c_option;
283 extern int             bsd_e_option;
284 extern uid_t           cached_euid;
285 extern dev_t           cached_tty;
286 extern char            forest_prefix[4 * 32*1024 + 100];
287 extern int             forest_type;
288 extern unsigned        format_flags;     /* -l -f l u s -j... */
289 extern format_node    *format_list; /* digested formatting options */
290 extern unsigned        format_modifiers; /* -c -j -y -P -L... */
291 extern int             header_gap;
292 extern int             header_type; /* none, single, multi... */
293 extern int             include_dead_children;
294 extern int             lines_to_next_header;
295 extern int             max_line_width;
296 extern const char     *namelist_file;
297 extern int             negate_selection;
298 extern int             page_size;  // "int" for math reasons?
299 extern unsigned        personality;
300 extern int             prefer_bsd_defaults;
301 extern int             running_only;
302 extern int             screen_cols;
303 extern int             screen_rows;
304 extern unsigned long   seconds_since_boot;
305 extern selection_node *selection_list;
306 extern unsigned        simple_select;
307 extern sort_node      *sort_list;
308 extern const char     *sysv_f_format;
309 extern const char     *sysv_fl_format;
310 extern const char     *sysv_j_format;
311 extern const char     *sysv_l_format;
312 extern unsigned        thread_flags;
313 extern int             unix_f_option;
314 extern int             user_is_number;
315 extern int             wchan_is_number;
316
317 /************************* PS GLOBALS *********************/
318
319 /* sortformat.c */
320 extern int defer_sf_option(const char *arg, int source);
321 extern const char *process_sf_options(int localbroken);
322 extern void reset_sortformat(void);
323
324 /* select.c */
325 extern int want_this_proc(proc_t *buf);
326 extern const char *select_bits_setup(void);
327
328 /* help.c */
329 extern const char *help_message;
330
331 /* global.c */
332 extern void self_info(void);
333
334 /* parser.c */
335 extern int arg_parse(int argc, char *argv[]);
336
337 #endif