JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 3: Extended Library Functions
search filter icon
search icon

Document Information

Preface

Extended Library Functions - Part 1

Extended Library Functions - Part 2

Extended Library Functions - Part 3

gelf_update_move(3ELF)

gelf_update_phdr(3ELF)

gelf_update_rel(3ELF)

gelf_update_rela(3ELF)

gelf_update_shdr(3ELF)

gelf_update_sym(3ELF)

gelf_update_syminfo(3ELF)

gelf_update_symshndx(3ELF)

gelf_xlatetof(3ELF)

gelf_xlatetom(3ELF)

getacdir(3BSM)

getacflg(3BSM)

getacinfo(3BSM)

getacmin(3BSM)

getacna(3BSM)

getauclassent(3BSM)

getauclassent_r(3BSM)

getauclassnam(3BSM)

getauclassnam_r(3BSM)

getauditflags(3BSM)

getauditflagsbin(3BSM)

getauditflagschar(3BSM)

getauevent(3BSM)

getauevent_r(3BSM)

getauevnam(3BSM)

getauevnam_r(3BSM)

getauevnonam(3BSM)

getauevnum(3BSM)

getauevnum_r(3BSM)

getauthattr(3SECDB)

getauthnam(3SECDB)

getauuserent(3BSM)

getauuserent_r(3BSM)

getauusernam(3BSM)

getauusernam_r(3BSM)

getddent(3BSM)

getddnam(3BSM)

getdefaultproj(3PROJECT)

getdevicerange(3TSOL)

getexecattr(3SECDB)

getexecprof(3SECDB)

getexecuser(3SECDB)

getfauditflags(3BSM)

getpathbylabel(3TSOL)

getplabel(3TSOL)

getprofattr(3SECDB)

getproflist(3SECDB)

getprofnam(3SECDB)

getprojbyid(3PROJECT)

getprojbyname(3PROJECT)

getprojent(3PROJECT)

getprojidbyname(3PROJECT)

getuserattr(3SECDB)

getusernam(3SECDB)

getuserrange(3TSOL)

getuseruid(3SECDB)

getzoneidbylabel(3TSOL)

getzonelabelbyid(3TSOL)

getzonelabelbyname(3TSOL)

getzonerootbyid(3TSOL)

getzonerootbylabel(3TSOL)

getzonerootbyname(3TSOL)

gl_abandon_line(3TECLA)

gl_append_history(3TECLA)

gl_automatic_history(3TECLA)

gl_bind_keyseq(3TECLA)

gl_catch_blocked(3TECLA)

gl_change_terminal(3TECLA)

gl_clear_history(3TECLA)

gl_completion_action(3TECLA)

gl_configure_getline(3TECLA)

gl_customize_completion(3TECLA)

gl_display_text(3TECLA)

gl_echo_mode(3TECLA)

gl_erase_terminal(3TECLA)

gl_error_message(3TECLA)

gl_get_line(3TECLA)

gl_group_history(3TECLA)

gl_handle_signal(3TECLA)

gl_ignore_signal(3TECLA)

gl_inactivity_timeout(3TECLA)

gl_io_mode(3TECLA)

gl_last_signal(3TECLA)

gl_limit_history(3TECLA)

gl_list_signals(3TECLA)

gl_load_history(3TECLA)

gl_lookup_history(3TECLA)

gl_normal_io(3TECLA)

gl_pending_io(3TECLA)

gl_prompt_style(3TECLA)

gl_query_char(3TECLA)

gl_range_of_history(3TECLA)

gl_raw_io(3TECLA)

gl_read_char(3TECLA)

gl_register_action(3TECLA)

gl_replace_prompt(3TECLA)

gl_resize_history(3TECLA)

gl_return_status(3TECLA)

gl_save_history(3TECLA)

gl_set_term_size(3TECLA)

gl_show_history(3TECLA)

gl_size_of_history(3TECLA)

gl_state_of_history(3TECLA)

gl_terminal_size(3TECLA)

gl_toggle_history(3TECLA)

gl_trap_signal(3TECLA)

gl_tty_signals(3TECLA)

gl_watch_fd(3TECLA)

gmatch(3GEN)

h_alloc(3TSOL)

HBA_CloseAdapter(3HBAAPI)

HBA_FreeLibrary(3HBAAPI)

HBA_GetAdapterAttributes(3HBAAPI)

HBA_GetAdapterName(3HBAAPI)

HBA_GetAdapterPortAttributes(3HBAAPI)

HBA_GetBindingCapability(3HBAAPI)

HBA_GetBindingSupport(3HBAAPI)

HBA_GetDiscoveredPortAttributes(3HBAAPI)

HBA_GetEventBuffer(3HBAAPI)

HBA_GetFC4Statistics(3HBAAPI)

HBA_GetFcpPersistentBinding(3HBAAPI)

HBA_GetFCPStatistics(3HBAAPI)

HBA_GetFcpTargetMapping(3HBAAPI)

HBA_GetFcpTargetMappingV2(3HBAAPI)

HBA_GetNumberOfAdapters(3HBAAPI)

HBA_GetPersistentBindingV2(3HBAAPI)

HBA_GetPortAttributesByWWN(3HBAAPI)

HBA_GetPortStatistics(3HBAAPI)

HBA_GetRNIDMgmtInfo(3HBAAPI)

HBA_GetVendorLibraryAttributes(3HBAAPI)

HBA_GetVersion(3HBAAPI)

HBA_GetWrapperLibraryAttributes(3HBAAPI)

HBA_LoadLibrary(3HBAAPI)

HBA_OpenAdapter(3HBAAPI)

HBA_OpenAdapterByWWN(3HBAAPI)

HBA_RefreshAdapterConfiguration(3HBAAPI)

HBA_RefreshInformation(3HBAAPI)

HBA_RegisterForAdapterAddEvents(3HBAAPI)

HBA_RegisterForAdapterEvents(3HBAAPI)

HBA_RegisterForAdapterPortEvents(3HBAAPI)

HBA_RegisterForAdapterPortStatEvents(3HBAAPI)

HBA_RegisterForLinkEvents(3HBAAPI)

HBA_RegisterForTargetEvents(3HBAAPI)

HBA_RemoveAllPersistentBindings(3HBAAPI)

HBA_RemoveCallback(3HBAAPI)

HBA_RemovePersistentBinding(3HBAAPI)

HBA_ResetStatistics(3HBAAPI)

HBA_ScsiInquiryV2(3HBAAPI)

HBA_ScsiReadCapacityV2(3HBAAPI)

HBA_ScsiReportLUNsV2(3HBAAPI)

HBA_SendCTPassThru(3HBAAPI)

HBA_SendCTPassThruV2(3HBAAPI)

HBA_SendLIRR(3HBAAPI)

HBA_SendReadCapacity(3HBAAPI)

HBA_SendReportLUNs(3HBAAPI)

HBA_SendRLS(3HBAAPI)

HBA_SendRNID(3HBAAPI)

HBA_SendRNIDV2(3HBAAPI)

HBA_SendRPL(3HBAAPI)

HBA_SendRPS(3HBAAPI)

HBA_SendScsiInquiry(3HBAAPI)

HBA_SendSRL(3HBAAPI)

HBA_SetBindingSupport(3HBAAPI)

HBA_SetPersistentBindingV2(3HBAAPI)

HBA_SetRNIDMgmtInfo(3HBAAPI)

hextob(3TSOL)

h_free(3TSOL)

htobclear(3TSOL)

htobsl(3TSOL)

hypot(3M)

hypotf(3M)

hypotl(3M)

idn_decodename2(3EXT)

idn_decodename(3EXT)

idn_enable(3EXT)

idn_encodename(3EXT)

idn_nameinit(3EXT)

IFDHCloseChannel(3SMARTCARD)

IFDHControl(3SMARTCARD)

IFDHCreateChannel(3SMARTCARD)

IFDHCreateChannelByName(3SMARTCARD)

IFDHGetCapabilities(3SMARTCARD)

IFDHICCPresence(3SMARTCARD)

IFDHPowerICC(3SMARTCARD)

IFDHSetCapabilities(3SMARTCARD)

IFDHSetProtocolParameters(3SMARTCARD)

IFDHTransmitToICC(3SMARTCARD)

ilogb(3M)

ilogbf(3M)

ilogbl(3M)

inproj(3PROJECT)

isencrypt(3GEN)

isfinite(3M)

isgreater(3M)

isgreaterequal(3M)

isinf(3M)

isless(3M)

islessequal(3M)

islessgreater(3M)

isnan(3M)

isnormal(3M)

isunordered(3M)

j0(3M)

j0f(3M)

j0l(3M)

j1(3M)

j1f(3M)

j1l(3M)

jn(3M)

jnf(3M)

jnl(3M)

kstat(3KSTAT)

Kstat(3PERL)

kstat_chain_update(3KSTAT)

kstat_close(3KSTAT)

kstat_data_lookup(3KSTAT)

kstat_lookup(3KSTAT)

kstat_open(3KSTAT)

kstat_read(3KSTAT)

kstat_write(3KSTAT)

kva_match(3SECDB)

kvm_close(3KVM)

kvm_getcmd(3KVM)

kvm_getproc(3KVM)

kvm_getu(3KVM)

kvm_kread(3KVM)

kvm_kwrite(3KVM)

kvm_nextproc(3KVM)

kvm_nlist(3KVM)

kvm_open(3KVM)

kvm_read(3KVM)

kvm_setproc(3KVM)

kvm_uread(3KVM)

kvm_uwrite(3KVM)

kvm_write(3KVM)

la_activity(3EXT)

la_amd64_pltenter(3EXT)

labelbuilder(3TSOL)

labelclipping(3TSOL)

label_to_str(3TSOL)

la_i86_pltenter(3EXT)

la_objfilter(3EXT)

la_objopen(3EXT)

la_objsearch(3EXT)

la_pltexit(3EXT)

la_pltexit64(3EXT)

la_preinit(3EXT)

la_sparcv8_pltenter(3EXT)

la_sparcv9_pltenter(3EXT)

la_symbind32(3EXT)

la_symbind64(3EXT)

la_version(3EXT)

ld_atexit(3ext)

ld_atexit64(3ext)

ldexp(3M)

ldexpf(3M)

ldexpl(3M)

ld_file(3ext)

ld_file64(3ext)

ld_input_done(3ext)

ld_input_section(3ext)

ld_input_section64(3ext)

ld_open(3ext)

ld_open64(3ext)

ld_section(3ext)

ld_section64(3ext)

ld_start(3ext)

ld_start64(3ext)

ld_support(3ext)

ld_version(3ext)

lgamma(3M)

lgammaf(3M)

lgammaf_r(3M)

lgammal(3M)

lgammal_r(3M)

lgamma_r(3M)

lgrp_affinity_get(3LGRP)

lgrp_affinity_set(3LGRP)

lgrp_children(3LGRP)

lgrp_cookie_stale(3LGRP)

lgrp_cpus(3LGRP)

lgrp_fini(3LGRP)

lgrp_home(3LGRP)

lgrp_init(3LGRP)

lgrp_latency(3LGRP)

lgrp_latency_cookie(3LGRP)

lgrp_mem_size(3LGRP)

lgrp_nlgrps(3LGRP)

lgrp_parents(3LGRP)

lgrp_resources(3LGRP)

lgrp_root(3LGRP)

lgrp_version(3LGRP)

lgrp_view(3LGRP)

libpicl(3PICL)

libpicltree(3PICLTREE)

libtecla_version(3TECLA)

libtnfctl(3TNF)

llrint(3M)

llrintf(3M)

llrintl(3M)

llround(3M)

llroundf(3M)

llroundl(3M)

log10(3M)

log10f(3M)

log10l(3M)

log1p(3M)

log1pf(3M)

log1pl(3M)

log2(3M)

log2f(3M)

log2l(3M)

log(3M)

logb(3M)

logbf(3M)

logbl(3M)

logf(3M)

logl(3M)

lrint(3M)

lrintf(3M)

lrintl(3M)

lround(3M)

lroundf(3M)

lroundl(3M)

maillock(3MAIL)

mailunlock(3MAIL)

match_execattr(3SECDB)

matherr(3M)

m_create_layout(3LAYOUT)

md4(3EXT)

MD4Final(3EXT)

MD4Init(3EXT)

MD4Update(3EXT)

md5(3EXT)

md5_calc(3EXT)

MD5Final(3EXT)

MD5Init(3EXT)

MD5Update(3EXT)

m_destroy_layout(3LAYOUT)

media_findname(3VOLMGT)

media_getattr(3VOLMGT)

media_getid(3VOLMGT)

media_setattr(3VOLMGT)

m_getvalues_layout(3LAYOUT)

mkdirp(3GEN)

m_label(3TSOL)

m_label_alloc(3TSOL)

m_label_dup(3TSOL)

m_label_free(3TSOL)

modf(3M)

modff(3M)

modfl(3M)

mp(3MP)

MP_AssignLogicalUnitToTPG(3MPAPI)

MP_CancelOverridePath(3MPAPI)

MP_CompareOIDs(3MPAPI)

MP_DeregisterForObjectPropertyChanges(3MPAPI)

MP_DeregisterForObjectVisibilityChanges(3MPAPI)

MP_DeregisterPlugin(3MPAPI)

MP_DisableAutoFailback(3MPAPI)

MP_DisableAutoProbing(3MPAPI)

MP_DisablePath(3MPAPI)

MP_EnableAutoFailback(3MPAPI)

Extended Library Functions - Part 4

Extended Library Functions - Part 5

Extended Library Functions - Part 6

gl_io_mode

, gl_raw_io

, gl_normal_io

, gl_tty_signals

, gl_abandon_line

, gl_handle_signal

, gl_pending_io

- use gl_get_line() from an external event loop

Synopsis

cc [ flag… ] file-ltecla [ library… ] 
#include <libtecla.h>

int gl_io_mode(GetLine *gl, GlIOMode mode);
int gl_raw_io(GetLine *gl);
int gl_normal_io(GetLine *gl);
int gl_tty_signals(void (*term_handler)(int), void (*susp_handler)(int),
     void (*cont_handler)(int), void (*size_handler)(int));
void gl_abandon_line(GetLine *gl);
void gl_handle_signal(int signo, GetLine *gl, int ngl);
GlPendingIO gl_pending_io(GetLine *gl);

Description

The gl_get_line(3TECLA) function supports two different I/O modes. These are selected by calling the gl_io_mode() function. The mode argument of gl_io_mode() specifies the new I/O mode and must be one of the following.

GL_NORMAL_MODE

Select the normal blocking-I/O mode. In this mode gl_get_line() does not return until either an error occurs of the user finishes entering a new line.

GL_SERVER_MODE

Select non-blocking server I/O mode. In this mode, since non-blocking terminal I/O is used, the entry of each new input line typically requires many calls to gl_get_line() from an external I/O-driven event loop.

Newly created GetLine objects start in normal I/O mode, so to switch to non-blocking server mode requires an initial call to gl_io_mode().

Server I/O Mode

In non-blocking server I/O mode, the application is required to have an event loop that calls gl_get_line() whenever the terminal file descriptor can perform the type I/O that gl_get_line() is waiting for. To determine which type of I/O gl_get_line() is waiting for, the application calls the gl_pending_io() function. The return value is one of the following two enumerated values.

GLP_READ

gl_get_line() is waiting to write a character to the terminal.

GLP_WRITE

gl_get_line() is waiting to read a character from the keyboad.

If the application is using either the select(3C) or poll(2) function to watch for I/O on a group of file descriptors, then it should call the gl_pending_io() function before each call to these functions to determine which direction of I/O it should tell them to watch for, and configure their arguments accordingly. In the case of the select() function, this means using the FD_SET() macro to add the terminal file descriptor either to the set of file descriptors to be watched for readability or the set to be watched for writability.

As in normal I/O mode, the return value of gl_get_line() is either a pointer to a completed input line or NULL. However, whereas in normal I/O mode a NULL return value always means that an error occurred, in non-blocking server mode, NULL is also returned when gl_get_line() cannot read or write to the terminal without blocking. Thus in non-blocking server mode, in order to determine when a NULL return value signifies that an error occurred or not, it is necessary to call the gl_return_status() function. If this function returns the enumerated value GLR_BLOCKED, gl_get_line() is waiting for I/O and no error has occurred.

When gl_get_line() returns NULL and gl_return_status() indicates that this is due to blocked terminal I/O, the application should call gl_get_line() again when the type of I/O reported by gl_pending_io() becomes possible. The prompt, start_line and start_pos arguments of gl_get_line() will be ignored on these calls. If you need to change the prompt of the line that is currently being edited, you can call the gl_replace_prompt(3TECLA) function between calls to gl_get_line().

Giving Up The Terminal

A complication that is unique to non-blocking server mode is that it requires that the terminal be left in raw mode between calls to gl_get_line(). If this were not the case, the external event loop would not be able to detect individual key-presses, and the basic line editing implemented by the terminal driver would clash with the editing provided by gl_get_line(). When the terminal needs to be used for purposes other than entering a new input line with gl_get_line(), it needs to be restored to a usable state. In particular, whenever the process is suspended or terminated, the terminal must be returned to a normal state. If this is not done, then depending on the characteristics of the shell that was used to invoke the program, the user could end up with a hung terminal. To this end, the gl_normal_io() function is provided for switching the terminal back to the state that it was in when raw mode was last established.

The gl_normal_io() function first flushes any pending output to the terminal, then moves the cursor to the start of the terminal line which follows the end of the incompletely entered input line. At this point it is safe to suspend or terminate the process, and it is safe for the application to read and write to the terminal. To resume entry of the input line, the application should call the gl_raw_io() function.

The gl_normal_io() function starts a new line, redisplays the partially completed input line (if any), restores the cursor position within this line to where it was when gl_normal_io() was called, then switches back to raw, non-blocking terminal mode ready to continue entry of the input line when gl_get_line() is next called.

Note that in non-blocking server mode, if gl_get_line() is called after a call to gl_normal_io(), without an intervening call to gl_raw_io(), gl_get_line() will call gl_raw_mode() itself, and the terminal will remain in this mode when gl_get_line() returns.

Signal Handling

In the previous section it was pointed out that in non-blocking server mode, the terminal must be restored to a sane state whenever a signal is received that either suspends or terminates the process. In normal I/O mode, this is done for you by gl_get_line(), but in non-blocking server mode, since the terminal is left in raw mode between calls to gl_get_line(), this signal handling has to be done by the application. Since there are many signals that can suspend or terminate a process, as well as other signals that are important to gl_get_line(), such as the SIGWINCH signal, which tells it when the terminal size has changed, the gl_tty_signals() function is provided for installing signal handlers for all pertinent signals.

The gl_tty_signals() function uses gl_get_line()'s internal list of signals to assign specified signal handlers to groups of signals. The arguments of this function are as follows.

term_handler

This is the signal handler that is used to trap signals that by default terminate any process that receives them (for example, SIGINT or SIGTERM).

susp_handler

This is the signal handler that is used to trap signals that by default suspend any process that receives them, (for example, SIGTSTP or SIGTTOU).

cont_handler

This is the signal handler that is used to trap signals that are usually sent when a process resumes after being suspended (usually SIGCONT). Beware that there is nothing to stop a user from sending one of these signals at other times.

size_handler

This signal handler is used to trap signals that are sent to processes when their controlling terminals are resized by the user (for example, SIGWINCH).

These arguments can all be the same, if so desired, and SIG_IGN (ignore this signal) or SIG_DFL (use the system-provided default signal handler) can be specified instead of a function where pertinent. In particular, it is rarely useful to trap SIGCONT, so the cont_handler argument will usually be SIG_DFL or SIG_IGN.

The gl_tty_signals() function uses the POSIX sigaction(2) function to install these signal handlers, and it is careful to use the sa_mask member of each sigaction structure to ensure that only one of these signals is ever delivered at a time. This guards against different instances of these signal handlers from simultaneously trying to write to common global data, such as a shared sigsetjmp(3C) buffer or a signal-received flag. The signal handlers installed by this function should call the gl_handle_signal().

The signo argument tells this function which signal it is being asked to respond to, and the gl argument should be a pointer to the first element of an array of ngl GetLine objects. If your application has only one of these objects, pass its pointer as the gl argument and specify ngl as 1.

Depending on the signal that is being handled, this function does different things.

Process termination signals

If the signal that was caught is one of those that by default terminates any process that receives it, then gl_handle_signal() does the following steps.

  1. First it blocks the delivery of all signals that can be blocked (ie. SIGKILL and SIGSTOP cannot be blocked).

  2. Next it calls gl_normal_io() for each of the ngl GetLine objects. Note that this does nothing to any of the GetLine objects that are not currently in raw mode.

  3. Next it sets the signal handler of the signal to its default, process-termination disposition.

  4. Next it re-sends the process the signal that was caught.

  5. Finally it unblocks delivery of this signal, which results in the process being terminated.

Process suspension signals

If the default disposition of the signal is to suspend the process, the same steps are executed as for process termination signals, except that when the process is later resumed, gl_handle_signal() continues, and does the following steps.

  1. It re-blocks delivery of the signal.

  2. It reinstates the signal handler of the signal to the one that was displaced when its default disposition was substituted.

  3. For any of the GetLine objects that were in raw mode when gl_handle_signal() was called, gl_handle_signal() then calls gl_raw_io(), to resume entry of the input lines on those terminals.

  4. Finally, it restores the signal process mask to how it was when gl_handle_signal() was called.

Note that the process is suspended or terminated using the original signal that was caught, rather than using the uncatchable SIGSTOP and SIGKILL signals. This is important, because when a process is suspended or terminated, the parent of the process may wish to use the status value returned by the wait system call to figure out which signal was responsible. In particular, most shells use this information to print a corresponding message to the terminal. Users would be rightly confused if when their process received a SIGPIPE signal, the program responded by sending itself a SIGKILL signal, and the shell then printed out the provocative statement, "Killed!".

Interrupting The Event Loop

If a signal is caught and handled when the application's event loop is waiting in select() or poll(), these functions will be aborted with errno set to EINTR. When this happens the event loop should call gl_pending_io() before calling select() or poll() again. It should then arrange for select() or poll() to wait for the type of I/O that gl_pending_io() reports. This is necessary because any signal handler that calls gl_handle_signal() will frequently change the type of I/O that gl_get_line() is waiting for.

If a signal arrives between the statements that configure the arguments of select() or poll() and the calls to these functions, the signal will not be seen by these functions, which will then not be aborted. If these functions are waiting for keyboard input from the user when the signal is received, and the signal handler arranges to redraw the input line to accommodate a terminal resize or the resumption of the process. This redisplay will be delayed until the user presses the next key. Apart from puzzling the user, this clearly is not a serious problem. However there is a way, albeit complicated, to completely avoid this race condition. The following steps illustrate this.

  1. Block all of the signals that gl_get_line() catches, by passing the signal set returned by gl_list_signals() to sigprocmask(2).

  2. Call gl_pending_io() and set up the arguments of select() or poll() accordingly.

  3. Call sigsetjmp(3C) with a non-zero savemask argument.

  4. Initially this sigsetjmp() statement will return zero, indicating that control is not resuming there after a matching call to siglongjmp(3C).

  5. Replace all of the handlers of the signals that gl_get_line() is configured to catch, with a signal handler that first records the number of the signal that was caught, in a file-scope variable, then calls siglongjmp() with a non-zero val argument, to return execution to the above sigsetjmp() statement. Registering these signal handlers can conveniently be done using the gl_tty_signals() function.

  6. Set the file-scope variable that the above signal handler uses to record any signal that is caught to -1, so that we can check whether a signal was caught by seeing if it contains a valid signal number.

  7. Now unblock the signals that were blocked in step 1. Any signal that was received by the process in between step 1 and now will now be delivered, and trigger our signal handler, as will any signal that is received until we block these signals again.

  8. Now call select() or poll().

  9. When select returns, again block the signals that were unblocked in step 7.

    If a signal is arrived any time during the above steps, our signal handler will be triggered and cause control to return to the sigsetjmp() statement, where this time, sigsetjmp() will return non-zero, indicating that a signal was caught. When this happens we simply skip the above block of statements, and continue with the following statements, which are executed regardless of whether or not a signal is caught. Note that when sigsetjmp() returns, regardless of why it returned, the process signal mask is returned to how it was when sigsetjmp() was called. Thus the following statements are always executed with all of our signals blocked.

  10. Reinstate the signal handlers that were displaced in step 5.

  11. Check wether a signal was caught, by checking the file-scope variable that the signal handler records signal numbers in.

  12. If a signal was caught, send this signal to the application again and unblock only this signal so that it invokes the signal handler which was just reinstated in step 10.

  13. Unblock all of the signals that were blocked in step 7.

Signals Caught By gl_get_line()

Since the application is expected to handle signals in non-blocking server mode, gl_get_line() does not attempt to duplicate this when it is being called. If one of the signals that it is configured to catch is sent to the application while gl_get_line() is being called, gl_get_line() reinstates the caller's signal handlers, then immediately before returning, re-sends the signal to the process to let the application's signal handler handle it. If the process is not terminated by this signal, gl_get_line() returns NULL, and a following call to gl_return_status() returns the enumerated value GLR_SIGNAL.

Aborting Line Input

Often, rather than letting it terminate the process, applications respond to the SIGINT user-interrupt signal by aborting the current input line. This can be accomplished in non-blocking server-I/O mode by not calling gl_handle_signal() when this signal is caught, but by calling instead the gl_abandon_line() function. This function arranges that when gl_get_line() is next called, it first flushes any pending output to the terminal, discardes the current input line, outputs a new prompt on the next line, and finally starts accepting input of a new input line from the user.

Signal Safe Functions

Provided that certain rules are followed, the gl_normal_io(), gl_raw_io(), gl_handle_signal(), and gl_abandon_line() functions can be written to be safely callable from signal handlers. Other functions in this library should not be called from signal handlers. For this to be true, all signal handlers that call these functions must be registered in such a way that only one instance of any one of them can be running at one time. The way to do this is to use the POSIX sigaction() function to register all signal handlers, and when doing this, use the sa_mask member of the corresponding sigaction structure to indicate that all of the signals whose handlers invoke the above functions should be blocked when the current signal is being handled. This prevents two signal handlers from operating on a GetLine object at the same time.

To prevent signal handlers from accessing a GetLine object while gl_get_line() or any of its associated public functions are operating on it, all public functions associated with gl_get_line(), including gl_get_line() itself, temporarily block the delivery of signals when they are accessing GetLine objects. Beware that the only signals that they block are the signals that gl_get_line() is currently configured to catch, so be sure that if you call any of the above functions from signal handlers, that the signals that these handlers are assigned to are configured to be caught by gl_get_line(). See gl_trap_signal(3TECLA).

Using Timeouts To Poll

If instead of using select() or poll() to wait for I/O your application needs only to get out of gl_get_line() periodically to briefly do something else before returning to accept input from the user, use the gl_inactivity_timeout(3TECLA) function in non-blocking server mode to specify that a callback function that returns GLTO_CONTINUE should be called whenever gl_get_line() has been waiting for I/O for more than a specified amount of time. When this callback is triggered, gl_get_line() will return NULL and a following call to gl_return_status() will return GLR_BLOCKED.

The gl_get_line() function will not return until the user has not typed a key for the specified interval, so if the interval is long and the user keeps typing, gl_get_line() might not return for a while. There is no guarantee that it will return in the time specified.

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Evolving
MT-Level
MT-Safe

See Also

cpl_complete_word(3TECLA), ef_expand_file(3TECLA), gl_get_line(3TECLA), libtecla(3LIB), pca_lookup_file(3TECLA), attributes(5), tecla(5)