return 0;
}
-#if 0
static int pakfire_jail_stream_stdin(struct pakfire_jail* jail,
struct pakfire_jail_exec* ctx, const int fd) {
+ const char eof = 0x04;
int r;
- // Nothing to do if there is no stdin callback set
- if (!ctx->communicate.in) {
- DEBUG(jail->pakfire, "Callback for standard input is not set\n");
- return 0;
- }
-
// Skip if the writing pipe has already been closed
- if (ctx->pipes.stdin[1] < 0)
+ if (fd < 0)
return 0;
- DEBUG(jail->pakfire, "Streaming standard input...\n");
+ CTX_DEBUG(jail->ctx, "Streaming standard input...\n");
// Calling the callback
r = ctx->communicate.in(jail->pakfire, ctx->communicate.data, fd);
- DEBUG(jail->pakfire, "Standard input callback finished: %d\n", r);
+ switch (r) {
+ case EOF:
+ // The callback signaled that it has written everything
+ CTX_DEBUG(jail->ctx, "Closing standard input pipe\n");
- // The callback signaled that it has written everything
- if (r == EOF) {
- DEBUG(jail->pakfire, "Closing standard input pipe\n");
+ // Send EOF (Ctrl-D)
+ r = write(fd, &eof, sizeof(eof));
+ if (r < 0) {
+ CTX_ERROR(jail->ctx, "Could not write EOF: %s\n", strerror(errno));
+ return -errno;
+ }
- // Close the file-descriptor
- close(fd);
+ return 0;
- // Reset the file-descriptor so it won't be closed again later
- ctx->pipes.stdin[1] = -1;
+ case 0:
+ CTX_DEBUG(jail->ctx, "Standard input callback finished\n");
+ return 0;
- // Report success
- r = 0;
+ default:
+ CTX_ERROR(jail->ctx, "Standard input callback failed: %s\n", strerror(-r));
+ return r;
}
-
- return r;
}
-#endif
static int pakfire_jail_recv_fd(struct pakfire_jail* jail, int socket, int* fd) {
const size_t payload_length = sizeof(fd);
return r;
}
- printf("BUFFER %.*s\n", (int)ctx->pty.stdin.buffer.used, ctx->pty.stdin.buffer.data);
-
// We are done reading for now
ctx->pty.stdin.flags &= ~PAKFIRE_JAIL_PTY_READY_TO_READ;
// Write to the master
if (ctx->pty.master.flags & PAKFIRE_JAIL_PTY_READY_TO_WRITE) {
- r = pakfire_jail_drain_buffer(jail, ctx->pty.master.fd, &ctx->pty.stdin.buffer);
- if (r) {
- CTX_ERROR(jail->ctx, "Failed writing to the PTY: %s\n", strerror(-r));
- return r;
+ if (ctx->communicate.in) {
+ r = pakfire_jail_stream_stdin(jail, ctx, ctx->pty.master.fd);
+ if (r)
+ return r;
+
+ } else {
+ r = pakfire_jail_drain_buffer(jail, ctx->pty.master.fd, &ctx->pty.stdin.buffer);
+ if (r) {
+ CTX_ERROR(jail->ctx, "Failed writing to the PTY: %s\n", strerror(-r));
+ return r;
+ }
}
// We are done writing for now