xref: /onnv-gate/usr/src/lib/libfsmgt/common/cmd.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <unistd.h>
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <poll.h>
34*0Sstevel@tonic-gate #include <sys/wait.h>
35*0Sstevel@tonic-gate #include <errno.h>
36*0Sstevel@tonic-gate #include <strings.h>
37*0Sstevel@tonic-gate #include <sys/stropts.h>
38*0Sstevel@tonic-gate #include "libfsmgt.h"
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #define	MASKVAL (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)
41*0Sstevel@tonic-gate #define	STDOUT 1
42*0Sstevel@tonic-gate #define	STDERR 2
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * Public methods
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /*
49*0Sstevel@tonic-gate  * Method: cmd_execute_command
50*0Sstevel@tonic-gate  *
51*0Sstevel@tonic-gate  * Description: Executes the given command and returns the output written to
52*0Sstevel@tonic-gate  * stdout and stderr in two separate file descriptors to be read by the caller.
53*0Sstevel@tonic-gate  * It is recommended that the caller use the cmd_retrieve_string method or
54*0Sstevel@tonic-gate  * another polling method to read from the file descriptors especially in the
55*0Sstevel@tonic-gate  * case that the command output is expected to be lengthy.
56*0Sstevel@tonic-gate  *
57*0Sstevel@tonic-gate  * Parameters:
58*0Sstevel@tonic-gate  *	- char *cmd - The command to execute.
59*0Sstevel@tonic-gate  *	- int *output_filedes - The file descriptor to which the stdout output
60*0Sstevel@tonic-gate  *	is written.
61*0Sstevel@tonic-gate  *	- int *err_filedes -  The file descriptor to which the stderr output
62*0Sstevel@tonic-gate  *	is written.
63*0Sstevel@tonic-gate  *
64*0Sstevel@tonic-gate  * Returns:
65*0Sstevel@tonic-gate  *	- int - This value will always be zero.  This was intended to be the
66*0Sstevel@tonic-gate  *	the exit status of the executed command, but in the case of the
67*0Sstevel@tonic-gate  *	execution of a command with a large amount of output (ex: ls of a large
68*0Sstevel@tonic-gate  *	directory) we can't wait for the exec'd command to exit.  This is
69*0Sstevel@tonic-gate  *	because of the way that file descriptors work.  When the child process,
70*0Sstevel@tonic-gate  *	or the process executing the command, writes of 'x' amount of data to
71*0Sstevel@tonic-gate  *	a file desciptor (fd), the fd reaches a threshold and will lock and wait
72*0Sstevel@tonic-gate  *	for a reader to read before writing anymore data.  In this case, we
73*0Sstevel@tonic-gate  *	don't have a reader since the caller reads from the file descriptors,
74*0Sstevel@tonic-gate  *	not the parent process.
75*0Sstevel@tonic-gate  *	The result is that the parent process cannot be allowed to wait for the
76*0Sstevel@tonic-gate  *	child process to exit.  Hence, cannot get the exit status of the
77*0Sstevel@tonic-gate  *	executed command.
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate int
cmd_execute_command(char * cmd,int * output_filedes,int * err_filedes)80*0Sstevel@tonic-gate cmd_execute_command(char *cmd, int *output_filedes, int *err_filedes) {
81*0Sstevel@tonic-gate 	pid_t child_pid;
82*0Sstevel@tonic-gate 	int output[2];
83*0Sstevel@tonic-gate 	int error[2];
84*0Sstevel@tonic-gate 	int ret_val;
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	if (pipe(output) == -1) {
87*0Sstevel@tonic-gate 		return (errno);
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	if (pipe(error) == -1) {
91*0Sstevel@tonic-gate 		return (errno);
92*0Sstevel@tonic-gate 	}
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 	if ((child_pid = fork()) == -1) {
95*0Sstevel@tonic-gate 		return (errno);
96*0Sstevel@tonic-gate 	}
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 	if (child_pid == 0) {
99*0Sstevel@tonic-gate 		/*
100*0Sstevel@tonic-gate 		 * We are in the child.
101*0Sstevel@tonic-gate 		 */
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate 		/*
104*0Sstevel@tonic-gate 		 * Close the file descriptors we aren't using.
105*0Sstevel@tonic-gate 		 */
106*0Sstevel@tonic-gate 		close(output[0]);
107*0Sstevel@tonic-gate 		close(error[0]);
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate 		/*
110*0Sstevel@tonic-gate 		 * Close stdout and dup to output[1]
111*0Sstevel@tonic-gate 		 */
112*0Sstevel@tonic-gate 		if (close(STDOUT) == -1) {
113*0Sstevel@tonic-gate 			exit(errno);
114*0Sstevel@tonic-gate 		}
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate 		if (dup(output[1]) == -1) {
117*0Sstevel@tonic-gate 			exit(errno);
118*0Sstevel@tonic-gate 		}
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate 		close(output[1]);
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 		/*
123*0Sstevel@tonic-gate 		 * Close stderr and dup to error[1]
124*0Sstevel@tonic-gate 		 */
125*0Sstevel@tonic-gate 		if (close(STDERR) == -1) {
126*0Sstevel@tonic-gate 			exit(errno);
127*0Sstevel@tonic-gate 		}
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 		if (dup(error[1]) == -1) {
130*0Sstevel@tonic-gate 			exit(errno);
131*0Sstevel@tonic-gate 		}
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate 		close(error[1]);
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 		if (execl("/usr/bin/sh", "sh", "-c", cmd, (char *)0) == -1) {
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 			exit(errno);
138*0Sstevel@tonic-gate 		} else {
139*0Sstevel@tonic-gate 			exit(0);
140*0Sstevel@tonic-gate 		}
141*0Sstevel@tonic-gate 	}
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	/*
144*0Sstevel@tonic-gate 	 * We are in the parent
145*0Sstevel@tonic-gate 	 */
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	/*
148*0Sstevel@tonic-gate 	 * Close the file descriptors we aren't using.
149*0Sstevel@tonic-gate 	 */
150*0Sstevel@tonic-gate 	close(output[1]);
151*0Sstevel@tonic-gate 	close(error[1]);
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 	*output_filedes = output[0];
154*0Sstevel@tonic-gate 	*err_filedes = error[0];
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate 	/*
157*0Sstevel@tonic-gate 	 * Do not wait for the child process to exit.  Just return.
158*0Sstevel@tonic-gate 	 */
159*0Sstevel@tonic-gate 	ret_val = 0;
160*0Sstevel@tonic-gate 	return (ret_val);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate } /* cmd_execute_command */
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate /*
165*0Sstevel@tonic-gate  * Method: cmd_execute_command_and_retrieve_string
166*0Sstevel@tonic-gate  *
167*0Sstevel@tonic-gate  * Description: Executes the given string and returns the output as it is
168*0Sstevel@tonic-gate  * output as it is written to stdout and stderr in the return string.
169*0Sstevel@tonic-gate  *
170*0Sstevel@tonic-gate  * Parameters:
171*0Sstevel@tonic-gate  *	- char *cmd - the command to execute.
172*0Sstevel@tonic-gate  *	- int *errp - the error indicator.  This will be set to a non-zero
173*0Sstevel@tonic-gate  *	upon error.
174*0Sstevel@tonic-gate  *
175*0Sstevel@tonic-gate  * Returns:
176*0Sstevel@tonic-gate  *	char * - The output of the command to stderr and stdout.
177*0Sstevel@tonic-gate  */
178*0Sstevel@tonic-gate char *
cmd_execute_command_and_retrieve_string(char * cmd,int * errp)179*0Sstevel@tonic-gate cmd_execute_command_and_retrieve_string(char *cmd, int *errp) {
180*0Sstevel@tonic-gate 	pid_t child_pid;
181*0Sstevel@tonic-gate 	int output[2];
182*0Sstevel@tonic-gate 	int err;
183*0Sstevel@tonic-gate 	int status;
184*0Sstevel@tonic-gate 	char *ret_val;
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	*errp = 0;
187*0Sstevel@tonic-gate 	if (pipe(output) == -1) {
188*0Sstevel@tonic-gate 		*errp = errno;
189*0Sstevel@tonic-gate 		return (NULL);
190*0Sstevel@tonic-gate 	}
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate 	if ((child_pid = fork()) == -1) {
193*0Sstevel@tonic-gate 		*errp = errno;
194*0Sstevel@tonic-gate 		return (NULL);
195*0Sstevel@tonic-gate 	}
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	if (child_pid == 0) {
198*0Sstevel@tonic-gate 		/*
199*0Sstevel@tonic-gate 		 * We are in the child.
200*0Sstevel@tonic-gate 		 */
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 		/*
203*0Sstevel@tonic-gate 		 * Close the unused file descriptor.
204*0Sstevel@tonic-gate 		 */
205*0Sstevel@tonic-gate 		close(output[0]);
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate 		/*
208*0Sstevel@tonic-gate 		 * Close stdout and dup to output[1]
209*0Sstevel@tonic-gate 		 */
210*0Sstevel@tonic-gate 		if (close(STDOUT) == -1) {
211*0Sstevel@tonic-gate 			*errp = errno;
212*0Sstevel@tonic-gate 			exit(*errp);
213*0Sstevel@tonic-gate 		}
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate 		if (dup(output[1]) == -1) {
216*0Sstevel@tonic-gate 			*errp = errno;
217*0Sstevel@tonic-gate 			exit(*errp);
218*0Sstevel@tonic-gate 		}
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 		/*
221*0Sstevel@tonic-gate 		 * Close stderr and dup to output[1]
222*0Sstevel@tonic-gate 		 */
223*0Sstevel@tonic-gate 		if (close(STDERR) == -1) {
224*0Sstevel@tonic-gate 			*errp = errno;
225*0Sstevel@tonic-gate 			exit(*errp);
226*0Sstevel@tonic-gate 		}
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 		if (dup(output[1]) == -1) {
229*0Sstevel@tonic-gate 			*errp = errno;
230*0Sstevel@tonic-gate 			exit(*errp);
231*0Sstevel@tonic-gate 		}
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate 		close(output[1]);
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate 		if (execl("/usr/bin/sh", "sh", "-c", cmd, (char *)0) == -1) {
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 			*errp = errno;
238*0Sstevel@tonic-gate 			exit(*errp);
239*0Sstevel@tonic-gate 		} else {
240*0Sstevel@tonic-gate 			exit(0);
241*0Sstevel@tonic-gate 		}
242*0Sstevel@tonic-gate 	}
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate 	/*
245*0Sstevel@tonic-gate 	 * We are in the parent
246*0Sstevel@tonic-gate 	 */
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate 	/*
249*0Sstevel@tonic-gate 	 * Close the file descriptors we are not using.
250*0Sstevel@tonic-gate 	 */
251*0Sstevel@tonic-gate 	close(output[1]);
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate 	/*
254*0Sstevel@tonic-gate 	 * Wait for the child process to exit.
255*0Sstevel@tonic-gate 	 */
256*0Sstevel@tonic-gate 	while ((wait(&status) != child_pid)) {
257*0Sstevel@tonic-gate 		ret_val = cmd_retrieve_string(output[0], &err);
258*0Sstevel@tonic-gate 	}
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate 	/*
261*0Sstevel@tonic-gate 	 * Evaluate the wait status and set the evaluated value to
262*0Sstevel@tonic-gate 	 * the value of errp.
263*0Sstevel@tonic-gate 	 */
264*0Sstevel@tonic-gate 	*errp = WEXITSTATUS(status);
265*0Sstevel@tonic-gate 
266*0Sstevel@tonic-gate 	ret_val = cmd_retrieve_string(output[0], &err);
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 	/*
269*0Sstevel@tonic-gate 	 * Caller must free space allocated for ret_val with free()
270*0Sstevel@tonic-gate 	 */
271*0Sstevel@tonic-gate 	return (ret_val);
272*0Sstevel@tonic-gate } /* cmd_execute_command_and_retrieve_string */
273*0Sstevel@tonic-gate 
274*0Sstevel@tonic-gate /*
275*0Sstevel@tonic-gate  * Method: cmd_retrieve_string
276*0Sstevel@tonic-gate  *
277*0Sstevel@tonic-gate  * Description: Returns the data written to the file descriptor passed in.
278*0Sstevel@tonic-gate  *
279*0Sstevel@tonic-gate  * Parameters:
280*0Sstevel@tonic-gate  *	- int filedes - The file descriptor to be read.
281*0Sstevel@tonic-gate  *	- int *errp - The error indicator.  This will be set to a non-zero
282*0Sstevel@tonic-gate  *	value upon error.
283*0Sstevel@tonic-gate  *
284*0Sstevel@tonic-gate  * Returns:
285*0Sstevel@tonic-gate  *	- char * - The data read from the file descriptor.
286*0Sstevel@tonic-gate  */
287*0Sstevel@tonic-gate char *
cmd_retrieve_string(int filedes,int * errp)288*0Sstevel@tonic-gate cmd_retrieve_string(int filedes, int *errp) {
289*0Sstevel@tonic-gate 	int returned_value = 0;
290*0Sstevel@tonic-gate 	int buffer_size = 1024;
291*0Sstevel@tonic-gate 	int len;
292*0Sstevel@tonic-gate 	char *ret_val;
293*0Sstevel@tonic-gate 	char *buffer;
294*0Sstevel@tonic-gate 	boolean_t stop_loop = B_FALSE;
295*0Sstevel@tonic-gate 	struct pollfd pollfds[1];
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	*errp = 0;
298*0Sstevel@tonic-gate 	/*
299*0Sstevel@tonic-gate 	 * Read from the file descriptor passed into the function.  This
300*0Sstevel@tonic-gate 	 * will read data written to the file descriptor on a FIFO basis.
301*0Sstevel@tonic-gate 	 * Care must be taken to make sure to get all data from the file
302*0Sstevel@tonic-gate 	 * descriptor.
303*0Sstevel@tonic-gate 	 */
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate 	ret_val = (char *)calloc((size_t)1, (size_t)sizeof (char));
306*0Sstevel@tonic-gate 	ret_val[0] = '\0';
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 	/*
310*0Sstevel@tonic-gate 	 * Set up the pollfd structure with appropriate information.
311*0Sstevel@tonic-gate 	 */
312*0Sstevel@tonic-gate 	pollfds[0].fd = filedes;
313*0Sstevel@tonic-gate 	pollfds[0].events = MASKVAL;
314*0Sstevel@tonic-gate 	pollfds[0].revents = 0;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 	while (stop_loop == B_FALSE) {
317*0Sstevel@tonic-gate 		char *tmp_string;
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate 		switch (poll(pollfds, 1, INFTIM)) {
320*0Sstevel@tonic-gate 			case -1:
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 			case 0:
323*0Sstevel@tonic-gate 				/*
324*0Sstevel@tonic-gate 				 * Nothing to read yet so continue.
325*0Sstevel@tonic-gate 				 */
326*0Sstevel@tonic-gate 				continue;
327*0Sstevel@tonic-gate 			default:
328*0Sstevel@tonic-gate 				buffer = (char *)calloc(
329*0Sstevel@tonic-gate 					(size_t)(buffer_size + 1),
330*0Sstevel@tonic-gate 					(size_t)sizeof (char));
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 				if (buffer == NULL) {
333*0Sstevel@tonic-gate 					/*
334*0Sstevel@tonic-gate 					 * Out of memory
335*0Sstevel@tonic-gate 					 */
336*0Sstevel@tonic-gate 					*errp = errno;
337*0Sstevel@tonic-gate 					return (NULL);
338*0Sstevel@tonic-gate 				}
339*0Sstevel@tonic-gate 
340*0Sstevel@tonic-gate 				/*
341*0Sstevel@tonic-gate 				 * Call read to read from the filedesc.
342*0Sstevel@tonic-gate 				 */
343*0Sstevel@tonic-gate 				returned_value = read(filedes, buffer,
344*0Sstevel@tonic-gate 					buffer_size);
345*0Sstevel@tonic-gate 				if (returned_value <= 0) {
346*0Sstevel@tonic-gate 					/*
347*0Sstevel@tonic-gate 					 * Either we errored or didn't read any
348*0Sstevel@tonic-gate 					 * bytes of data.
349*0Sstevel@tonic-gate 					 * returned_value == -1 represents an
350*0Sstevel@tonic-gate 					 * error.
351*0Sstevel@tonic-gate 					 * returned value == 0 represents 0
352*0Sstevel@tonic-gate 					 * bytes read.
353*0Sstevel@tonic-gate 					 */
354*0Sstevel@tonic-gate 					stop_loop = B_TRUE;
355*0Sstevel@tonic-gate 					continue;
356*0Sstevel@tonic-gate 				}
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate 				len = strlen(buffer);
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 				/*
361*0Sstevel@tonic-gate 				 * Allocate space for the new string.
362*0Sstevel@tonic-gate 				 */
363*0Sstevel@tonic-gate 				tmp_string =
364*0Sstevel@tonic-gate 				(char *)calloc((size_t)(len+strlen(ret_val)+1),
365*0Sstevel@tonic-gate 						(size_t)sizeof (char));
366*0Sstevel@tonic-gate 
367*0Sstevel@tonic-gate 				if (tmp_string == NULL) {
368*0Sstevel@tonic-gate 					/*
369*0Sstevel@tonic-gate 					 * Out of memory
370*0Sstevel@tonic-gate 					 */
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate 					*errp = errno;
373*0Sstevel@tonic-gate 					return (NULL);
374*0Sstevel@tonic-gate 				}
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 				/*
377*0Sstevel@tonic-gate 				 * Concatenate the the new string in 'buffer'
378*0Sstevel@tonic-gate 				 * with whatever is in the 'ret_val' buffer.
379*0Sstevel@tonic-gate 				 */
380*0Sstevel@tonic-gate 				snprintf(tmp_string, (size_t)(len +
381*0Sstevel@tonic-gate 					strlen(ret_val) + 1), "%s%s",
382*0Sstevel@tonic-gate 					ret_val, buffer);
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate 				(void) free(ret_val);
385*0Sstevel@tonic-gate 				ret_val = strdup(tmp_string);
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 				if (ret_val == NULL) {
388*0Sstevel@tonic-gate 					/*
389*0Sstevel@tonic-gate 					 * Out of memory
390*0Sstevel@tonic-gate 					 */
391*0Sstevel@tonic-gate 					*errp = errno;
392*0Sstevel@tonic-gate 					return (NULL);
393*0Sstevel@tonic-gate 				}
394*0Sstevel@tonic-gate 				(void) free(tmp_string);
395*0Sstevel@tonic-gate 				(void) free(buffer);
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate 		} /* switch (poll(pollfds, 1, INFTIM)) */
398*0Sstevel@tonic-gate 
399*0Sstevel@tonic-gate 	} /* while (stop_loop == B_FALSE) */
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate 	return (ret_val);
402*0Sstevel@tonic-gate } /* cmd_retrieve_string */
403