12264Sjacobs /* 22264Sjacobs * CDDL HEADER START 32264Sjacobs * 42264Sjacobs * The contents of this file are subject to the terms of the 52264Sjacobs * Common Development and Distribution License (the "License"). 62264Sjacobs * You may not use this file except in compliance with the License. 72264Sjacobs * 82264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92264Sjacobs * or http://www.opensolaris.org/os/licensing. 102264Sjacobs * See the License for the specific language governing permissions 112264Sjacobs * and limitations under the License. 122264Sjacobs * 132264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 142264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 162264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 172264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 182264Sjacobs * 192264Sjacobs * CDDL HEADER END 202264Sjacobs */ 212264Sjacobs 222264Sjacobs /* 23*7132Sps29005 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 242264Sjacobs * Use is subject to license terms. 252264Sjacobs * 262264Sjacobs */ 272264Sjacobs 282264Sjacobs /* $Id: psm.c 146 2006-03-24 00:26:54Z njacobs $ */ 292264Sjacobs 302264Sjacobs #pragma ident "%Z%%M% %I% %E% SMI" 312264Sjacobs 322264Sjacobs #include <stdio.h> 332264Sjacobs #include <unistd.h> 342264Sjacobs #include <errno.h> 352264Sjacobs #include <string.h> 362264Sjacobs #include <dlfcn.h> 372264Sjacobs #include <papi_impl.h> 382264Sjacobs 392264Sjacobs #ifndef RTLD_GROUP 402264Sjacobs #define RTLD_GROUP 0 412264Sjacobs #endif /* RTLD_GROUP */ 422264Sjacobs 432264Sjacobs #ifndef PSM_DIR 442264Sjacobs #define PSM_DIR "/usr/lib/print" 452264Sjacobs #endif 462264Sjacobs 472264Sjacobs papi_status_t 482264Sjacobs psm_open(service_t *svc, char *scheme) 492264Sjacobs { 502264Sjacobs papi_status_t result = PAPI_OK; 51*7132Sps29005 char path[BUFSIZ]; 522264Sjacobs 53*7132Sps29005 if ((scheme == NULL) || (strchr(scheme, '/') != NULL)) 542264Sjacobs return (PAPI_BAD_ARGUMENT); 552264Sjacobs 56*7132Sps29005 snprintf(path, sizeof (path), PSM_DIR "/psm-%s.so", scheme); 572264Sjacobs 582264Sjacobs svc->so_handle = dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_GROUP); 592264Sjacobs if (svc->so_handle == NULL) { /* failed, set the result/message */ 602264Sjacobs if ((access(path, F_OK) < 0) && (errno == ENOENT)) 612264Sjacobs result = PAPI_URI_SCHEME; 622264Sjacobs else 632264Sjacobs result = PAPI_NOT_POSSIBLE; 642264Sjacobs #ifdef DEBUG 652264Sjacobs detailed_error(svc, "psm_open(%s): %s: %s", scheme, path, 662264Sjacobs dlerror()); 672264Sjacobs #endif 682264Sjacobs } 692264Sjacobs 702264Sjacobs return (result); 712264Sjacobs } 722264Sjacobs 732264Sjacobs void 742264Sjacobs psm_close(void *handle) 752264Sjacobs { 762264Sjacobs dlclose(handle); 772264Sjacobs } 782264Sjacobs 792264Sjacobs void * 802264Sjacobs psm_sym(service_t *svc, char *name) 812264Sjacobs { 822264Sjacobs char *error = "invalid input"; 832264Sjacobs void *func = NULL; 842264Sjacobs 852264Sjacobs if ((svc != NULL) && (svc->so_handle != NULL) && (name != NULL)) { 862264Sjacobs if ((func = dlsym(svc->so_handle, name)) == NULL) 872264Sjacobs error = dlerror(); 882264Sjacobs } 892264Sjacobs #ifdef DEBUG 902264Sjacobs if (func == NULL) 912264Sjacobs detailed_error(svc, "psm_sym(%s): %s", name, error); 922264Sjacobs #endif 932264Sjacobs 942264Sjacobs return (func); 952264Sjacobs } 96