apptrace.c revision 900524f30cbbebc670e146a87587f355b9f633ee
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <apptrace.h>
#include <libintl.h>
#include <locale.h>
#ifdef TRUE
#endif
#ifdef FALSE
#endif
#define TRUE 1
#define FALSE 0
/* Various list pointers */
static char *fromlist;
static char *fromexcl;
static char *tolist;
static char *toexcl;
static char *iflist;
static char *ifexcl;
static char *viflist;
static char *vifexcl;
/* The supported options */
static char const *optlet = "F:fo:T:t:v:";
/* basename(argv[0]) */
static char const *command;
/* The environment variables that'll get picked up by apptrace.so.1 */
static char const *APPTRACE_BINDTO = "APPTRACE_BINDTO=";
static char const *APPTRACE_BINDTO_EXCLUDE = "APPTRACE_BINDTO_EXCLUDE=";
static char const *APPTRACE_BINDFROM = "APPTRACE_BINDFROM=";
static char const *APPTRACE_BINDFROM_EXCLUDE = "APPTRACE_BINDFROM_EXCLUDE=";
static char const *APPTRACE_OUTPUT = "APPTRACE_OUTPUT=";
static char const *APPTRACE_PID = "APPTRACE_PID=";
static char const *APPTRACE_INTERFACES = "APPTRACE_INTERFACES=";
static char const *APPTRACE_INTERFACES_EXCLUDE = "APPTRACE_INTERFACES_EXCLUDE=";
static char const *APPTRACE_VERBOSE = "APPTRACE_VERBOSE=";
static char const *APPTRACE_VERBOSE_EXCLUDE = "APPTRACE_VERBOSE_EXCLUDE=";
/* Some default values for the above */
static char *LD_AUDIT = "LD_AUDIT=/usr/lib/abi/apptrace.so.1";
static char *LD_AUDIT_64 =
"LD_AUDIT_64=/usr/lib/abi/sparcv9/apptrace.so.1";
static char *LD_AUDIT_64 =
"LD_AUDIT_64=/usr/lib/abi/amd64/apptrace.so.1";
#else
#endif
static char const *one = "1";
/* The local support functions */
static void usage(char const *);
static void stuffenv(char const *, char const *);
static char *buildlist(char **, char const *);
int
{
int opt;
int stat_loc;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* Squirrel the basename of the command name away. */
command++;
else
switch (opt) {
case 'F':
if (*optarg == '!')
else
break;
case 'f':
break;
case 'o':
break;
case 'T':
if (*optarg == '!')
else
break;
case 't':
if (*optarg == '!')
else
break;
case 'v':
if (*optarg == '!')
else
break;
default:
break;
}
}
/*
* Whack the argument vector so that the remainder will be
* ready for passing to exec
*/
/*
* If there was a problem with the options, or there was no command
* to be run, then give the usage message and bugout.
*/
}
/*
* This is where the environment gets setup.
*/
/*
* It is the setting of the LD_AUDIT environment variable
* that tells ld.so.1 to enable link auditing when the child
* is exec()ed.
*/
(void) putenv(LD_AUDIT_64);
/*
* The environment is now all setup.
* For those about to rock, we salute you!
*/
switch (pid) {
/* Error */
case -1:
break;
/* Child */
case 0:
/*
* Usual failure is argv[0] does not exist or is
* not executable.
*/
}
break;
/* Parent */
default:
if (wret == -1) {
gettext("%s: waitpid failed: %s\n"),
}
gettext("%s: "
"waitpid returned %ld when child pid was %ld\n"),
}
if (WIFSIGNALED(stat_loc)) {
#ifdef DEBUG
stderr);
(void) putenv("LD_AUDIT=");
(void) putenv("LD_AUDIT_64=");
#endif
}
}
/* Normal return from main() */
return (WEXITSTATUS(stat_loc));
}
return (0);
/* NOTREACHED */
}
/*
* Take a string in the form "VAR=" and another in the
* form "value" and paste them together.
*/
static void
{
char *stuff;
}
}
/*
* If *dst is empty, use strdup to duplicate src.
* Otherwise: dst = dst + "," + src;
*/
static char *
{
int len;
char *p;
/*
* If dst is still empty then dup,
* if dup succeeds set dst.
*/
if (p == NULL)
goto error;
*dst = p;
return (p);
}
/* +2 because of the comma we add below */
goto error;
*dst = p;
return (*dst);
/* NOTREACHED */
}
static void
{
"[-T [!]tracetolist][-o outputfile]\n"
" [-t calls][-v calls] prog [prog arguments]\n"
" -F <bindfromlist>\n"
" A comma separated list of libraries that are to be\n"
" traced. Only calls from these libraries will be\n"
" traced. The default is to trace calls from the\n"
" main executable.\n"
" If <bindfromlist> begins with a ! then it defines\n"
" a list of libraries to exclude from the trace.\n"
" -T <bindtolist>\n"
" A comma separated list of libraries that are to be\n"
" traced. Only calls to these libraries will be\n"
" traced. The default is to trace all calls.\n"
" If <bindtolist> begins with a ! then it defines\n"
" a list of libraries to exclude from the trace.\n"
" -o <outputfile>\n"
" %s output will be directed to 'outputfile'.\n"
" by default it is placed on stderr\n"
" -f\n"
" Follow all children created by fork() and also\n"
" print apptrace output for the children. This also\n"
" causes a 'pid' to be added to each output line\n"
" -t <tracelist>\n"
" A comma separated list of interfaces to trace.\n"
" A list preceded by ! is an exlusion list.\n"
" -v <verboselist>\n"
" A comma separated list of interfaces to trace\n"
" verbosely.\n"
" A list preceded by ! is an exclusion list.\n"
" Interfaces matched in -v do not also need to be\n"
" named by -t\n"
" All lists may use shell style wild cards.\n"
" Leading path components or suffixes are not required when\n"
}