1/* 2 * LsofTest.h -- header file for lsof tests 3 */ 4 5 6/* 7 * Copyright 2002 Purdue Research Foundation, West Lafayette, Indiana 8 * 47907. All rights reserved. 9 * 10 * Written by Victor A. Abell 11 * 12 * This software is not subject to any license of the American Telephone 13 * and Telegraph Company or the Regents of the University of California. 14 * 15 * Permission is granted to anyone to use this software for any purpose on 16 * any computer system, and to alter it and redistribute it freely, subject 17 * to the following restrictions: 18 * 19 * 1. Neither the authors nor Purdue University are responsible for any 20 * consequences of the use of this software. 21 * 22 * 2. The origin of this software must not be misrepresented, either by 23 * explicit claim or by omission. Credit to the authors and Purdue 24 * University must appear in documentation and sources. 25 * 26 * 3. Altered versions must be plainly marked as such, and must not be 27 * misrepresented as being the original software. 28 * 29 * 4. This notice may not be removed or altered. 30 */ 31 32 33/* 34 * $Id: LsofTest.h,v 1.12 2008/07/05 16:21:07 abe Exp $ 35 */ 36 37 38#if !defined(LSOF_TEST_H) 39#define LSOF_TEST_H 1 40 41 42/* 43 * The _PROTOTYPE macro provides strict ANSI C prototypes if __STDC__ 44 * is defined, and old-style K&R prototypes otherwise. 45 * 46 * (With thanks to Andy Tanenbaum) 47 */ 48 49# if defined(__STDC__) 50#define _PROTOTYPE(function, params) function params 51# else /* !defined(__STDC__) */ 52#define _PROTOTYPE(function, params) function() 53# endif /* defined(__STDC__) */ 54 55 56/* 57 * The following define keeps gcc>=2.7 from complaining about the failure 58 * of the Exit() function to return. 59 * 60 * Paul Eggert <eggert@twinsun.com> supplied it. 61 */ 62 63# if defined(__GNUC__) && !(__GNUC__<2 || (__GNUC__==2 && __GNUC_MINOR__<7)) 64#define exiting __attribute__((__noreturn__)) 65# else /* !gcc || gcc<2.7 */ 66#define exiting 67# endif /* gcc && gcc>=2.7 */ 68 69 70/* 71 * Necessary header files. 72 */ 73 74#include <stdio.h> 75#include <ctype.h> 76#include <errno.h> 77#include <signal.h> 78 79#include <sys/types.h> 80#include <sys/param.h> 81#include <sys/stat.h> 82 83 84/* 85 * Definitions that may be revoked by a particular dialect. 86 */ 87 88#define USE_GETCWD /* use the POSIX getcwd() function in 89 * place of getwd() */ 90#define USE_LSOF_C_OPT /* use lsof's -C option */ 91#undef USE_LSOF_X_OPT /* don't use lsof's -X option */ 92 93 94# if defined(LT_DIAL_aix) 95/* 96 * AIX-specific items 97 */ 98 99#include <fcntl.h> 100#include <stdlib.h> 101#include <string.h> 102#include <unistd.h> 103#include <sys/access.h> 104#undef USE_LSOF_C_OPT 105#define USE_LSOF_X_OPT 106# endif /* defined(LT_DIAL_aix) */ 107 108 109# if defined(LT_DIAL_bsdi) 110/* 111 * OpenBSD-specific items 112 */ 113 114#include <fcntl.h> 115#include <stdlib.h> 116#include <string.h> 117#include <unistd.h> 118#include <sys/wait.h> 119# endif /* defined(LT_DIAL_bsdi) */ 120 121 122# if defined(LT_DIAL_darwin) 123/* 124 * Darwin-specific items 125 */ 126 127#include <fcntl.h> 128#include <stdlib.h> 129#include <string.h> 130#include <unistd.h> 131#include <sys/wait.h> 132#undef USE_LSOF_C_OPT 133# endif /* defined(LT_DIAL_darwin) */ 134 135 136# if defined(LT_DIAL_du) 137/* 138 * DEC_OSF/1|Digital_UNIX|Tru64_UNIX-specific items 139 */ 140 141#include <fcntl.h> 142#include <string.h> 143#include <unistd.h> 144#include <sys/wait.h> 145 146# if LT_VERS<50000 147#define snprintf snpf /* use lsof's snpf() */ 148# endif /* LT_VERS<50000 */ 149# endif /* defined(LT_DIAL_du) */ 150 151 152# if defined(LT_DIAL_freebsd) 153/* 154 * FreeBSD-specific items 155 */ 156 157#include <fcntl.h> 158#include <stdlib.h> 159#include <string.h> 160#include <unistd.h> 161#include <sys/wait.h> 162# endif /* defined(LT_DIAL_freebsd) */ 163 164 165# if defined(LT_DIAL_linux) 166/* 167 * Linux-specific items 168 */ 169 170#include <fcntl.h> 171#include <stdlib.h> 172#include <string.h> 173#include <unistd.h> 174#include <sys/wait.h> 175#undef USE_LSOF_C_OPT 176# endif /* defined(LT_DIAL_linux) */ 177 178 179# if defined(LT_DIAL_hpux) 180/* 181 * HP-UX-specific items 182 */ 183 184#include <fcntl.h> 185#include <stdlib.h> 186#include <string.h> 187#include <strings.h> 188#include <unistd.h> 189# endif /* defined(LT_DIAL_hpux) */ 190 191 192# if defined(LT_DIAL_netbsd) 193/* 194 * NetBSD-specific items 195 */ 196 197#include <fcntl.h> 198#include <stdlib.h> 199#include <string.h> 200#include <unistd.h> 201#include <sys/wait.h> 202# endif /* defined(LT_DIAL_netbsd) */ 203 204 205# if defined(LT_DIAL_openbsd) 206/* 207 * OpenBSD-specific items 208 */ 209 210#include <fcntl.h> 211#include <stdlib.h> 212#include <string.h> 213#include <unistd.h> 214#include <sys/wait.h> 215# endif /* defined(LT_DIAL_openbsd) */ 216 217 218# if defined(LT_DIAL_ou) 219/* 220 * OpenUNIX-specific items 221 */ 222 223#include <fcntl.h> 224#include <stdlib.h> 225#include <string.h> 226#include <unistd.h> 227# endif /* defined(LT_DIAL_ou) */ 228 229 230# if defined(LT_DIAL_osr) 231/* 232 * OSR-specific items 233 */ 234 235#include <fcntl.h> 236#include <stdlib.h> 237#include <string.h> 238#include <unistd.h> 239# endif /* defined(LT_DIAL_osr) */ 240 241 242# if defined(LT_DIAL_ns) 243/* 244 * NEXTSTEP-specific items 245 */ 246 247#include <stdlib.h> 248#include <string.h> 249#include <sys/file.h> 250#include <sys/wait.h> 251 252typedef int pid_t; 253#define snprintf snpf 254 255#undef USE_GETCWD 256# endif /* defined(LT_DIAL_ns) */ 257 258 259# if defined(LT_DIAL_solaris) 260/* 261 * Solaris-specific items 262 */ 263 264#include <fcntl.h> 265#include <stdlib.h> 266#include <strings.h> 267#include <unistd.h> 268#include <sys/wait.h> 269 270# if defined(LT_VPATH) 271#undef USE_LSOF_C_OPT 272#endif /* defined(LT_VPATH) */ 273# endif /* defined(LT_DIAL_solaris) */ 274 275 276# if defined(LT_DIAL_uw) 277/* 278 * UnixWare-specific items 279 */ 280 281#include <fcntl.h> 282#include <stdlib.h> 283#include <string.h> 284#include <unistd.h> 285# endif /* defined(LT_DIAL_uw) */ 286 287 288/* 289 * Local definitions, including ones may have been left undefined by 290 * dialect-specific header files 291 */ 292 293#define LT_DONT_DO_TEST "this test does not run on this dialect." 294#define LT_DEF_LSOF_PATH "../lsof" 295 296# if !defined(MAXPATHLEN) 297#define MAXPATHLEN 1024 298# endif /* !defined(MAXPATHLEN) */ 299 300 301/* 302 * Local structure definitions 303 */ 304 305typedef struct LTdev { /* local device parameters */ 306 unsigned int maj; /* major device number */ 307 unsigned int min; /* minor device number */ 308 unsigned int unit; /* unit number (where applicable) */ 309} LTdev_t; 310 311typedef struct LTfldo { /* lsof field output information */ 312 char ft; /* field identifier (see the LSOF_FID_* 313 * definitions in ../lsof_fields.h) */ 314 char *v; /* field value character string */ 315} LTfldo_t; 316#define LT_FLDO_ALLOC 16 /* LTfldo_t allocation increment */ 317 318 319/* 320 * Lsof test library global variable external declarations: 321 * 322 * these global variables may be found in LTlib.c. 323 */ 324 325extern int LsofFd; /* lsof pipe FD */ 326extern FILE *LsofFs; /* stream for lsof pipe FD */ 327extern char *LsofPath; /* path to lsof executable */ 328extern pid_t LsofPid; /* PID of lsof child process */ 329extern int LTopt_h; /* "-h" option's switch value */ 330extern char *LTopt_p; /* "-p path" option's path value */ 331extern int MsgStat; /* message status */ 332 333 334/* 335 * External declarations 336 */ 337 338extern int errno; /* error number */ 339 340 341/* 342 * Lsof test library function prototypes: 343 * 344 * these functions may be found in LTlib.c. 345 */ 346 347_PROTOTYPE(extern char *CanRdKmem,(void)); 348_PROTOTYPE(extern char *ConvStatDev,(dev_t *dev, LTdev_t *ldev)); 349_PROTOTYPE(extern char *ConvLsofDev,(char *dev, LTdev_t *ldev)); 350_PROTOTYPE(extern char *ExecLsof,(char **opt)); 351_PROTOTYPE(extern char *IsLsofExec,(void)); 352_PROTOTYPE(extern void LTlibClean,(void)); 353_PROTOTYPE(extern char *MkStrCpy,(char *src, int *len)); 354_PROTOTYPE(extern LTfldo_t *RdFrLsof,(int *nf, char **em)); 355_PROTOTYPE(extern void PrtMsg,(char *mp, char *pn)); 356_PROTOTYPE(extern void PrtMsgX,(char *mp, char *pn, void (*f)(), int xv)); 357_PROTOTYPE(extern int ScanArg,(int ac, char *av[], char *opt, char *pn)); 358_PROTOTYPE(extern void StopLsof,(void)); 359 360#endif /* LSOF_TEST_H */ 361