/*
* 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
*/
/*
*/
/*
* tpcom: Threaded Print Comment
*
* tpcom is a threaded version of the pcom program. It will create
* a new thread for each new ELF descriptor that it examines. It
* will then examine each elf descriptor and print the .comment section
* if found.
*
* This program demonstrates that libelf is MT-Safe and the usage
* of elf_begin(ELF_C_READ).
*/
#include <stdio.h>
#include <libelf.h>
#include <gelf.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <thread.h>
/*
* arguments to be passed into process_elf().
*/
typedef struct {
int pe_fd;
} pe_args;
/* group output */
/* of comment sections */
static void
{
file, elf_errmsg(0));
return;
}
/*
* Do a string compare to examine each section header
* to see if it is a ".comment" section. If it is then
* this is the section we want to process.
*/
file, elf_errmsg(0));
return;
}
int i;
char *ptr;
(void) mutex_lock(&printlock);
/*
* Get the data associated with the .comment
* section.
*/
"%s: elf_getdata() failed: %s\n",
file, elf_errmsg(0));
(void) mutex_unlock(&printlock);
return;
}
/*
* Data in a .comment section is a list of 'null'
* terminated strings. The following will print
* one string per line.
*/
if (ptr[i]) {
}
(void) putchar('\n');
(void) mutex_unlock(&printlock);
}
}
}
static void
{
case ELF_K_ELF:
break;
case ELF_K_AR:
cmd = ELF_C_READ;
int rc;
"%s: elf_getarhdr() failed: %s\n",
}
(void *(*)(void *))process_elf,
(void *)_pep, THR_DETACHED, 0)) != 0) {
"thr_create() failed, rc = %d\n", rc);
}
}
break;
default:
(void) mutex_lock(&printlock);
"%s: unexpected elf_kind(): 0x%x\n",
(void) mutex_unlock(&printlock);
}
}
thr_exit(0);
}
int
{
int i;
if (argc < 2) {
return (1);
}
/*
* Initialize the elf library, must be called before elf_begin()
* can be called.
*/
"elf_version() failed: %s\n", elf_errmsg(0));
return (1);
}
/*
* create an arbitrary number of LWP's to run the
* threads that will be created.
*/
if (thr_setconcurrency(NUMLWPS) != 0) {
return (1);
}
for (i = 1; i < argc; i++) {
int fd;
int rc;
char *elf_fname;
perror("open");
continue;
}
/*
* for each file.
*/
(void) mutex_lock(&printlock);
elf_errmsg(0));
(void) mutex_unlock(&printlock);
continue;
}
(void *)pep, THR_DETACHED, 0)) != 0) {
(void) mutex_lock(&printlock);
"thr_create() failed with code: %d\n", rc);
(void) mutex_unlock(&printlock);
return (1);
}
}
thr_exit(0);
return (0);
}