END ========== LOCAL ============ END POINT POINT REMOTE #endif #include "ndmagents.h" int ndmis_reinit_remote (struct ndm_session *sess) { struct ndm_image_stream *is = &sess->plumb.image_stream; NDMOS_MACRO_ZEROFILL(&is->remote); ndmchan_initialize (&is->remote.listen_chan, "image-stream-listen"); ndmchan_initialize (&is->remote.sanity_chan, "image-stream-sanity"); ndmchan_initialize (&is->chan, "image-stream"); ndmchan_setbuf (&is->chan, is->buf, sizeof is->buf); return 0; }
END ========== LOCAL ============ END POINT POINT REMOTE #endif #include "ndmagents.h" int ndmis_reinit_remote (struct ndm_session *sess) { struct ndm_image_stream *is = sess->plumb.image_stream; struct ndm_tape_agent * ta = sess->tape_acb; NDMOS_MACRO_ZEROFILL (&is->remote); ndmchan_initialize (&is->remote.listen_chan, "image-stream-listen"); ndmchan_initialize (&is->remote.sanity_chan, "image-stream-sanity"); ndmchan_initialize (&is->chan, "image-stream"); if (!is->buf) { is->buflen = ta->mover_state.record_size; is->buf = NDMOS_API_MALLOC (is->buflen); if (!is->buf) { return -1; } NDMOS_MACRO_ZEROFILL_SIZE (is->buf, is->buflen); } ndmchan_setbuf (&is->chan, is->buf, is->buflen); return 0; }
int ndmda_pipe_fork_exec (struct ndm_session *sess, char *cmd, int is_backup) { struct ndm_data_agent * da = &sess->data_acb; struct ndmchan * ch; int errpipe[2]; int datpipe[2]; int wrppipe[2]; int nullfd; int rc = -1; ndmalogf (sess, 0, 2, "Starting %s", cmd); nullfd = open ("/dev/null", 2); if (nullfd < 0) { return rc; } rc = pipe (errpipe); if (rc < 0) { close (nullfd); return rc; } rc = pipe (datpipe); if (rc < 0) { close (nullfd); close (errpipe[0]); close (errpipe[1]); return rc; } rc = pipe (wrppipe); if (rc < 0) { close (nullfd); close (errpipe[0]); close (errpipe[1]); close (datpipe[0]); close (datpipe[1]); return rc; } rc = fork(); if (rc < 0) { close (nullfd); close (errpipe[0]); close (errpipe[1]); close (datpipe[0]); close (datpipe[1]); close (wrppipe[0]); close (wrppipe[1]); return rc; } if (rc == 0) { /* child */ dup2 (errpipe[1], 2); dup2 (wrppipe[1], 3); close (errpipe[0]); close (wrppipe[0]); if (is_backup) { dup2 (nullfd, 0); dup2 (datpipe[1], 1); close (datpipe[0]); } else { dup2 (datpipe[0], 0); dup2 (nullfd, 1); close (datpipe[1]); } /* * 0 -- formatter stdin * 1 -- formatter stdout * 2 -- formatter stderr * 3 -- formatter wrap chan (wraplib.c) */ for (rc = 4; rc < 100; rc++) { close(rc); } execl ("/bin/sh", "sh", "-c", cmd, NULL); fprintf (stderr, "EXEC FAILED %s\n", cmd); exit(127); } /* parent */ close (nullfd); ch = &da->formatter_error; ndmchan_initialize (ch, "dfp-error"); ndmchan_setbuf (ch, da->fmt_error_buf, sizeof da->fmt_error_buf); close (errpipe[1]); ndmos_condition_pipe_fd (sess, errpipe[0]); ndmchan_start_read (ch, errpipe[0]); ch = &da->formatter_wrap; ndmchan_initialize (ch, "dfp-wrap"); ndmchan_setbuf (ch, da->fmt_wrap_buf, sizeof da->fmt_wrap_buf); close (wrppipe[1]); ndmos_condition_pipe_fd (sess, wrppipe[0]); ndmchan_start_read (ch, wrppipe[0]); ch = &da->formatter_image; ndmchan_initialize (ch, "dfp-image"); ndmchan_setbuf (ch, da->fmt_image_buf, sizeof da->fmt_image_buf); if (is_backup) { ndmalogf (sess, 0, 2, "backup..."); close (datpipe[1]); ndmos_condition_pipe_fd (sess, datpipe[0]); ndmchan_start_read (ch, datpipe[0]); } else { ndmalogf (sess, 0, 2, "recover..."); close (datpipe[0]); ndmos_condition_pipe_fd (sess, datpipe[1]); ndmchan_start_write (ch, datpipe[1]); } da->formatter_pid = rc; return rc; /* PID */ }