File: zro_shlibs.c

package info (click to toggle)
fis-gtm 7.1-006-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,908 kB
  • sloc: ansic: 344,906; asm: 5,184; csh: 4,859; sh: 2,000; awk: 294; makefile: 73; sed: 13
file content (85 lines) | stat: -rw-r--r-- 2,524 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/****************************************************************
 *								*
 * Copyright (c) 2011-2021 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "gtm_string.h"
#include <dlfcn.h>

#include "lv_val.h"
#include "fgncal.h"
#include "parse_file.h"
#include "zro_shlibs.h"
#include "zroutines.h"
#include "error.h"

error_def(ERR_SYSCALL);
error_def(ERR_TEXT);

/* Routine to lookup given shlib_name to see if we already have it open. If yes, just
 * return its handle. Else, dlopen the shared library and return its handle.
 */
void *zro_shlibs_find(char *shlib_name)
{
	open_shlib	*oshlb;
	void		*handle;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	for (oshlb = TREF(open_shlib_root); oshlb; oshlb = oshlb->next)
	{	/* Brute force lookup of library - infrequent activity plus few libs mean we
		 * won't make the effort to hash this (typically 0-5 libs max.
		 */
		if (0 == strcmp(shlib_name, oshlb->shlib_name))
		{
			assert(oshlb->shlib_handle);
			return oshlb->shlib_handle;
		}
	}
	/* Library was not found. Open it and create a new entry */
	handle = fgn_getpak(shlib_name, ERROR);
	oshlb = malloc(SIZEOF(open_shlib));
	oshlb->shlib_handle = handle;
	strcpy(oshlb->shlib_name, shlib_name);
	oshlb->next = TREF(open_shlib_root);
	TREF(open_shlib_root) = oshlb;
	return handle;
}


/* Routine called to dlclose() all of the known libraries in our list so they are
 * detached allowing potentially new(er) versions to be linked in.
 */
void zro_shlibs_unlink_all(void)
{
	open_shlib	*oshlb, *oshlb_next;
	char		*dlerr;
	int		status, len;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	for (oshlb = TREF(open_shlib_root); oshlb; oshlb = oshlb_next)
	{	/* Cycle through list close all libraries and releasing the elements */
		oshlb_next = oshlb->next;
		status = dlclose(oshlb->shlib_handle);
		if (0 != status)
		{
			dlerr = dlerror();
			len = STRLEN(dlerr);
			RTS_ERROR_ABT(VARLSTCNT(11) ERR_SYSCALL,
				5, RTS_ERROR_LITERAL("dlclose()"), CALLFROM, ERR_TEXT, 2, len, dlerr);
		}
		free(oshlb);
	}
	TREF(open_shlib_root) = NULL;
	zro_load(TADR(dollar_zroutines));	/* Reloads the shared libraries we need */
}