/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Includes
*/
#ifndef DEBUG
#endif
#include <assert.h>
#include <limits.h>
#include <values.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <thread.h>
#include <errno.h>
#include "tnf_trace.h"
/*
* Defines
*/
/*
* Declarations
*/
extern void thr_probe_setup(void *);
/*
* Globals
*/
NULL,
};
static char *file_start;
/*
* Two Project Private Interfaces between prex and libtnfprobe -
* tnf_trace_file_name and tnf_trace_file_size (three now ...)
*/
TNF_ALLOC_REUSABLE, /* mode */
tnfw_b_alloc, /* alloc */
tnfw_b_xcommit, /* commit */
tnfw_b_xabort, /* rollback */
{
B_FALSE /* tnfw_w_initialized */
/* rest of struct is null */
},
0 /* busy */
};
/*
* tnf_process_enable: exported API to turn on tracing for the process
* (on by default).
*/
void
tnf_process_enable(void)
{
}
/*
* tnf_process_disable: exported API to turn off tracing for the process.
*/
void
tnf_process_disable(void)
{
}
/*
* _tnf_trace_initialize
* prex is responsible for creating and zeroing the trace file. So,
* this routine expects the file to be there. It does try to handle
* the case where prex (run as root) for probing a setuid root program
* created the trace file as root. But, by the time the first probe is
* hit (and this function is called), the program has reduced it's
* privilege to its real user id - so the open fails. In this case,
* this function unlinks the trace file and creates it again with its
* current user id. The unlink can fail if the user does not have
* write permission in the directory where the trace file is - if so,
* tracing is set to broken.
*/
int
_tnf_trace_initialize(void)
{
int fd;
int created_file = 0;
/*
* if this is a MT program and the primordial thread hasn't been
* setup yet, can't start tracing yet - THREAD_REG hasn't been
* initialized, so we can't call open() in libthread.
*/
/*
* Use dlsym to check for the present of thr_probe_setup.
*/
(thr_main() == -1)) {
return (0);
}
/*
* lock is needed to to prevent multiple threads from
* mmapping the file.
*/
return (1);
}
if (fd < 0) {
/*
* fix for bug 1197494: permission denied when
* trying to open the file - happens for setuid root
* programs - prex creates the file with root ownership
*/
goto SetBroken;
}
/* try creating it rather than opening it */
if (fd < 0) {
goto SetBroken;
}
/*
* expand file to needed size - ftruncate is not
* portable, hence using lseek + write.
*/
goto SetBroken;
}
goto SetBroken;
}
created_file = 1;
} else {
goto SetBroken;
}
}
/* mmap the file */
goto SetBroken;
}
if (created_file == 1) {
/* explicitly zero the file XXX - performance problem */
}
goto SetBroken;
}
/* successful return */
return (1);
return (0);
}
/*
* _tnf_sched_init
*/
void
{
/* thr_self() is stubbed out by libc for a non-threaded pgm */
}