2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "ndmagents.h"
40 #ifndef NDMOS_OPTION_NO_DATA_AGENT
44 ndmda_pipe_fork_exec (struct ndm_session *sess, char *cmd, int is_backup)
46 struct ndm_data_agent * da = &sess->data_acb;
54 ndmalogf (sess, 0, 2, "Starting %s", cmd);
56 nullfd = open ("/dev/null", 2);
100 dup2 (wrppipe[1], 3);
106 dup2 (datpipe[1], 1);
109 dup2 (datpipe[0], 0);
115 * 0 -- formatter stdin
116 * 1 -- formatter stdout
117 * 2 -- formatter stderr
118 * 3 -- formatter wrap chan (wraplib.c)
120 for (rc = 4; rc < 100; rc++) {
124 execl ("/bin/sh", "sh", "-c", cmd, NULL);
126 fprintf (stderr, "EXEC FAILED %s\n", cmd);
133 ch = &da->formatter_error;
134 ndmchan_initialize (ch, "dfp-error");
135 ndmchan_setbuf (ch, da->fmt_error_buf, sizeof da->fmt_error_buf);
137 ndmos_condition_pipe_fd (sess, errpipe[0]);
138 ndmchan_start_read (ch, errpipe[0]);
140 ch = &da->formatter_wrap;
141 ndmchan_initialize (ch, "dfp-wrap");
142 ndmchan_setbuf (ch, da->fmt_wrap_buf, sizeof da->fmt_wrap_buf);
144 ndmos_condition_pipe_fd (sess, wrppipe[0]);
145 ndmchan_start_read (ch, wrppipe[0]);
147 ch = &da->formatter_image;
148 ndmchan_initialize (ch, "dfp-image");
149 ndmchan_setbuf (ch, da->fmt_image_buf, sizeof da->fmt_image_buf);
152 ndmalogf (sess, 0, 2, "backup...");
154 ndmos_condition_pipe_fd (sess, datpipe[0]);
155 ndmchan_start_read (ch, datpipe[0]);
157 ndmalogf (sess, 0, 2, "recover...");
159 ndmos_condition_pipe_fd (sess, datpipe[1]);
160 ndmchan_start_write (ch, datpipe[1]);
163 da->formatter_pid = rc;
169 ndmda_add_to_cmd_with_escapes (char *cmd, char *word, char *special)
171 char * cmd_lim = &cmd[NDMDA_MAX_CMD-3];
177 if (p != cmd) *p++ = ' ';
179 while ((c = *word++) != 0) {
181 return -1; /* overflow */
182 if (c == '\\' || strchr (special, c))
192 ndmda_add_to_cmd (char *cmd, char *word)
194 return ndmda_add_to_cmd_with_escapes (cmd, word, " \t`'\"*?[]$");
198 ndmda_add_to_cmd_allow_file_wildcards (char *cmd, char *word)
200 return ndmda_add_to_cmd_with_escapes (cmd, word, " \t`'\"$");
203 #endif /* !NDMOS_OPTION_NO_DATA_AGENT */