diff options
Diffstat (limited to 'usr/src/lib/libshell/common/bltins/shiocmd_solaris.c')
-rw-r--r-- | usr/src/lib/libshell/common/bltins/shiocmd_solaris.c | 323 |
1 files changed, 0 insertions, 323 deletions
diff --git a/usr/src/lib/libshell/common/bltins/shiocmd_solaris.c b/usr/src/lib/libshell/common/bltins/shiocmd_solaris.c index 0f49eb982f..55e0e0357c 100644 --- a/usr/src/lib/libshell/common/bltins/shiocmd_solaris.c +++ b/usr/src/lib/libshell/common/bltins/shiocmd_solaris.c @@ -857,329 +857,6 @@ extern int b_stat(int argc, char *argv[], void *extra) return(0); } -static const char sh_optpoll[] = -"[-?\n@(#)$Id: poll (AT&T Labs Research) 2007-12-20 $\n]" -"[-author?Roland Mainz <roland.mainz@nrubsig.org]" -"[-license?http://www.opensource.org/licenses/cpl1.0.txt]" -"[+NAME? poll - input/output multiplexing]" -"[+DESCRIPTION?The poll command provides applications with a mechanism " - "for multiplexing input/output over a set of file descriptors. " - "For each member of the array variable \bvar\b, " - "poll examines the given file descriptor in the subscript \b.fd\b " - "for the event(s) specified in the subscript \b.events\b." - "The poll command identifies those file descriptors on which an " - "application can read or write data, or on which certain events have " - "occurred.]" -"[+?The \bvar\b argument specifies the file descriptors to be examined " - "and the events of interest for each file descriptor. " - "It is a array of structured variables with one member for each open " - "file descriptor of interest. The array's members contain the following " - "subscripts:]{" - "[+?\b.fd\b # file descriptor]" - "[+?\b.events\b # requested events]" - "[+?\b.revents\b # returned event]" - "}" -"[+?The \bfd\b variable specifies an open file descriptor and the " - "\bevents\b and \brevents\b members are strings constructed from " - "a concaternation of the following event flags, seperated by '|':]" - "{ " - "[+POLLIN?Data other than high priority data may be " - "read without blocking. For STREAMS, this " - "flag is set in revents even if the message " - "is of zero length.]" - "[+POLLRDNORM?Normal data (priority band equals 0) may be " - "read without blocking. For STREAMS, this " - "flag is set in revents even if the message " - "is of zero length.]" - "[+POLLRDBAND?Data from a non-zero priority band may be " - "read without blocking. For STREAMS, this " - "flag is set in revents even if the message " - "is of zero length.]" - "[+POLLPRI?High priority data may be received without " - "blocking. For STREAMS, this flag is set in " - "revents even if the message is of zero " - "length.]" - "[+POLLOUT?Normal data (priority band equals 0) may be " - "written without blocking.]" - "[+POLLWRNORM?The same as POLLOUT.]" - "[+POLLWRBAND?Priority data (priority band > 0) may be " - "written. This event only examines bands " - "that have been written to at least once.]" - "[+POLLERR?An error has occurred on the device or " - "stream. This flag is only valid in the " - "revents bitmask; it is not used in the " - "events member.]" - "[+POLLHUP?A hangup has occurred on the stream. This " - "event and POLLOUT are mutually exclusive; a " - "stream can never be writable if a hangup has " - "occurred. However, this event and POLLIN, " - ", POLLRDBAND, or POLLPRI are not " - "mutually exclusive. This flag is only valid " - "in the revents bitmask; it is not used in " - "the events member.]" - "[+POLLNVAL?The specified fd value does not belong to an " - "open file. This flag is only valid in the " - "revents member; it is not used in the events " - "member.]" - "}" -"]" - -"[+?If the value fd is less than 0, events is ignored and " - "revents is set to 0 in that entry on return from poll.]" - -"[+?The results of the poll query are stored in the revents " - "member in the \bvar\b structure. POLL*-strings are set in the \brevents\b " - "variable to indicate which of the requested events are true. " - "If none are true, the \brevents\b will be an empty string when " - "the poll command returns. The event flags " - "POLLHUP, POLLERR, and POLLNVAL are always set in \brevents\b " - "if the conditions they indicate are true; this occurs even " - "though these flags were not present in events.]" - -"[+?If none of the defined events have occurred on any selected " - "file descriptor, poll waits at least timeout milliseconds " - "for an event to occur on any of the selected file descriptors. " - "On a computer where millisecond timing accuracy is not " - "available, timeout is rounded up to the nearest legal value " - "available on that system. If the value timeout is 0, poll " - "returns immediately. If the value of timeout is -1, poll " - "blocks until a requested event occurs or until the call is " - "interrupted.]" - -"[+?The poll function supports regular files, terminal and " - "pseudo-terminal devices, STREAMS-based files, FIFOs and " - "pipes. The behavior of poll on elements of fds that refer " - "to other types of file is unspecified.]" - -"[+?The poll function supports sockets.]" - -"[+?A file descriptor for a socket that is listening for connections " - "will indicate that it is ready for reading, once connections " - "are available. A file descriptor for a socket that " - "is connecting asynchronously will indicate that it is ready " - "for writing, once a connection has been established.]" - -"[+?Regular files always poll TRUE for reading and writing.]" - -"[c:fdcount]:[fdcount?Upon successful completion, a non-negative value is " - "returned. A positive value indicates the total number of " - "file descriptors that has been selected (that is, file " - "descriptors for which the revents member is non-zero). A " - "value of 0 indicates that the call timed out and no file " - "descriptors have been selected. Upon failure, -1 is returned.]" -"[t:timeout]:[seconds?Timeout in seconds. If the value timeout is 0, " - "poll returns immediately. If the value of timeout is -1, poll " - "blocks until a requested event occurs or until the call is " - "interrupted.]" -"[T:mtimeout]:[milliseconds?Timeout in milliseconds. If the value timeout is 0, " - "poll returns immediately. If the value of timeout is -1, poll " - "blocks until a requested event occurs or until the call is " - "interrupted.]" -"\n" -"\nvar\n" -"\n" -"[+EXIT STATUS?]{" - "[+0?Success.]" - "[+>0?An error occurred.]" -"}" -"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bpoll\b(2)]" -; - -/* - * |mystpcpy| - like |strcpy()| but returns the end of the buffer - * - * Copy string s2 to s1. s1 must be large enough. - * return s1-1 (position of string terminator ('\0') in destnation buffer). - */ -static -char *mystpcpy(char *s1, const char *s2) -{ - while (*s1++ = *s2++) - ; - return (s1-1); -} - -static -Namval_t *nv_open_fmt(Dt_t *dict, int flags, const char *namefmt, ...) -{ - char varnamebuff[PATH_MAX]; - va_list ap; - - va_start(ap, namefmt); - vsnprintf(varnamebuff, sizeof(varnamebuff), namefmt, ap); - va_end(ap); - - return nv_open(varnamebuff, dict, flags); -} - -static -int poll_strtoevents(const char *str) -{ - int events = 0; - - if (strstr(str, "POLLIN")) events |= POLLIN; - if (strstr(str, "POLLRDNORM")) events |= POLLRDNORM; - if (strstr(str, "POLLRDBAND")) events |= POLLRDBAND; - if (strstr(str, "POLLPRI")) events |= POLLPRI; - if (strstr(str, "POLLOUT")) events |= POLLOUT; - if (strstr(str, "POLLWRNORM")) events |= POLLWRNORM; - if (strstr(str, "POLLWRBAND")) events |= POLLWRBAND; - if (strstr(str, "POLLERR")) events |= POLLERR; - if (strstr(str, "POLLHUP")) events |= POLLHUP; - if (strstr(str, "POLLNVAL")) events |= POLLNVAL; - - return events; -} - - -static -void poll_eventstostr(char *s, int events) -{ - *s='\0'; - if (!events) - return; - - if (events & POLLIN) s=mystpcpy(s, "POLLIN|"); - if (events & POLLRDNORM) s=mystpcpy(s, "POLLRDNORM|"); - if (events & POLLRDBAND) s=mystpcpy(s, "POLLRDBAND|"); - if (events & POLLPRI) s=mystpcpy(s, "POLLPRI|"); - if (events & POLLOUT) s=mystpcpy(s, "POLLOUT|"); - if (events & POLLWRNORM) s=mystpcpy(s, "POLLWRNORM|"); - if (events & POLLWRBAND) s=mystpcpy(s, "POLLWRBAND|"); - if (events & POLLERR) s=mystpcpy(s, "POLLERR|"); - if (events & POLLHUP) s=mystpcpy(s, "POLLHUP|"); - if (events & POLLNVAL) s=mystpcpy(s, "POLLNVAL|"); - - /* Remove trailling '|' */ - s--; - if(*s=='|') - *s='\0'; -} - -#undef getconf -#define getconf(x) strtol(astconf(x,NiL,NiL),NiL,0) - -extern int b_poll(int argc, char *argv[], void *extra) -{ - register Namval_t *np; - register int n; - Shell_t *shp = sh_contexttoshell(extra); - char *varname; - int fd; - unsigned int numpollfd = 0; - int i; - char *s; - double timeout = -1.; - char buff[256]; - char *pollfdcountvarname = NULL; - long open_max, - bpoll_max; - - if ((open_max = getconf("OPEN_MAX")) <= 0) - open_max = OPEN_MAX; - /* |bpoll_max| needs to be larger than |OPEN_MAX| to make sure we - * can listen to different sets of events per fd. - */ - bpoll_max = open_max*2L; - - while (n = optget(argv, sh_optpoll)) switch (n) - { - case 't': - case 'T': - errno = 0; - timeout = strtod(opt_info.arg, (char **)NULL); - if (errno != 0) - errormsg(SH_DICT, ERROR_system(1), "%s: invalid timeout", opt_info.arg); - - /* -t uses seconds, -T milliseconds */ - if (n == 't') - timeout *= 1000.; - break; - case 'c': - pollfdcountvarname = opt_info.arg; - break; - case ':': - errormsg(SH_DICT, 2, "%s", opt_info.arg); - break; - case '?': - errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg); - break; - } - argc -= opt_info.index; - argv += opt_info.index; - if(argc!=1) - errormsg(SH_DICT, ERROR_usage(2), optusage((char*)0)); - - varname = argv[0]; - -#ifdef __GNUC__ - /* - * Allocate one extra array entry to keep ctfconvert+gcc builds - * happy until CR #6379193 is fixed. - */ - struct pollfd pollfd[bpoll_max+1]; -#else - struct pollfd pollfd[bpoll_max]; -#endif - for(i=0 ; i < bpoll_max ; i++) - { - np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_NOADD, "%s[%d].fd", varname, i); - if (!np) - break; - fd = (int)nv_getnum(np); - if (fd < 0 || fd > OPEN_MAX) - errormsg(SH_DICT, ERROR_system(1), "invalid pollfd fd"); - nv_close(np); - pollfd[i].fd = fd; - - np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_NOADD, "%s[%d].events", varname, i); - if (!np) - errormsg(SH_DICT, ERROR_system(1), "missing pollfd events"); - - s = nv_getval(np); - if (!s) - errormsg(SH_DICT, ERROR_system(1), "missing pollfd events value"); - pollfd[i].events = poll_strtoevents(s); - nv_close(np); - - pollfd[i].revents = 0; - - numpollfd++; - } - - if (i == bpoll_max) - errormsg(SH_DICT, ERROR_system(1), "cannot handle more than %d entries.", bpoll_max); - - n = poll(pollfd, numpollfd, timeout); - /* FixMe: EGAIN and EINTR may require extra handling */ - if (n < 0) - errormsg(SH_DICT, ERROR_system(1), "failure"); - - if (pollfdcountvarname) - { - int32_t v = n; - - np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL, "%s", pollfdcountvarname); - if (!np) - errormsg(SH_DICT, ERROR_system(1), "couldn't create poll count variable %s", pollfdcountvarname); - nv_putval(np, (char *)&v, NV_INTEGER); - nv_close(np); - } - - for(i=0 ; i < numpollfd ; i++) - { - np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL, "%s[%d].revents", varname, i); - if (!np) - errormsg(SH_DICT, ERROR_system(1), "couldn't create pollfd %s[%d].revents", varname, i); - - poll_eventstostr(buff, pollfd[i].revents); - - nv_putval(np, buff, 0); - nv_close(np); - } - - return(0); -} static const char sh_optrewind[] = "[-?\n@(#)$Id: rewind (AT&T Labs Research) 2007-05-07 $\n]" |