share()


Convert a local channel into a shared global channel.

Syntax

share( channel , name )

Parameter

Parameter

Definition

channel

process I/O channel number that was returned when the channel was opened using the fopen() or popen() function

name

character string used to identify the shared channel in the table of global channels BMC Software recommends that you specify a nonnumeric name to avoid conflicts with numbers used internally for local channels. Using a number for name does not actually cause the share() function to fail but will raise a PSL run-time warning. The share() function will dutifully place the specified numeric name in the global table, leading to potential conflicts with local channels in close(), read(), write(), and readln() functions.

Description

The share() function is the main function for using shared channels. The share() function propagates an existing localchannel into the table of global channels as name. Channels opened by either the popen() or fopen() functions can be shared. 

If the share() function is successful, it returns 0. The local channel is no longer available in the process that opened it and does not require a close() function. In fact, the close() function will return an error since it will not find the local channel. 

The share() function will fail, returning -1 and setting the PSL errno variable under the following conditions:

  • local channel does not exist
  • global channel name already exists in the global channel table

Upon failure, the local channel is unchanged and still available. No global channel is added. 

A global channel is referred to by name when passed to the read(), readln(), write(), and close() functions. These functions will first search the local channel table containing only channel numbers and then the global channel table.

The share() function and the Knowledge Module Developer

The PATROL Agent performs no explicit cleanup of the shared channels. It is up to the Knowledge Module developer to clean up as well as possible. Unfortunately, there is no easy way to intercept a console request to deactivate an application or parameter and hence doing so for an application using shared channels will most likely not terminate the external process. 

For a brute-force cleanup, it is possible to use close( name,3) to remove a global channel and terminate its external process. It is also possible to write a "cleanup all shared channels" menu command using the get_chan_info() function to return a list of shared channels and close() to remove them.

Example

The following PSL script uses t he share() func tion to convert a local channel into a shared global channel:

 

chan = fopen("/etc/passwd"."r");
share(chan,"passwd_handle");
# read from the global channel
while ((user = readln("passwd_handle")) != EOF)
{
printf("%s\n",user);
}

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*