#define MAX_LINE_LENGTH 16384
-struct pakfire_pty_stdio {
+typedef struct pakfire_pty_stdio {
// File Descriptor
int fd;
unsigned close_fd:1;
// Event Source
sd_event_source* event;
-};
+} pakfire_pty_stdio;
struct pakfire_pty {
pakfire_ctx* ctx;
int socket[2];
// The master PTY
- struct pakfire_pty_stdio master;
+ pakfire_pty_stdio master;
// The path to the PTY
char path[PATH_MAX];
// Standard Input
- struct pakfire_pty_stdio stdin;
- struct pakfire_pty_stdio stdout;
+ pakfire_pty_stdio stdin;
+ pakfire_pty_stdio stdout;
// SIGWINCH Event
sd_event_source* sigwinch_event;
} state;
};
-static int pakfire_pty_same_inode(struct pakfire_pty* pty, int fd1, int fd2) {
+static int pakfire_pty_same_inode(pakfire_pty* pty, int fd1, int fd2) {
struct stat stat1;
struct stat stat2;
int r;
return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
}
-static int pakfire_pty_restore_attrs(struct pakfire_pty* pty,
- struct pakfire_pty_stdio* stdio) {
+static int pakfire_pty_restore_attrs(pakfire_pty* pty,
+ pakfire_pty_stdio* stdio) {
int flags;
int r;
return 0;
}
-static int pakfire_pty_store_attrs(struct pakfire_pty* pty,
- struct pakfire_pty_stdio* stdio) {
+static int pakfire_pty_store_attrs(pakfire_pty* pty,
+ pakfire_pty_stdio* stdio) {
int r;
// Store all attributes
return 0;
}
-static int pakfire_pty_disconnect(struct pakfire_pty* pty) {
+static int pakfire_pty_disconnect(pakfire_pty* pty) {
DEBUG(pty->ctx, "Disconnecting the PTY\n");
// Clear events
return 0;
}
-static int pakfire_pty_drained(struct pakfire_pty* pty) {
+static int pakfire_pty_drained(pakfire_pty* pty) {
int q;
int r;
return 1;
}
-static int pakfire_pty_done(struct pakfire_pty* pty, int code) {
+static int pakfire_pty_done(pakfire_pty* pty, int code) {
// Don't run this more than once
if (pty->state == PAKFIRE_PTY_STATE_DONE)
return 0;
/*
This function handles the forwarding between the different pipes...
*/
-static int pakfire_pty_forward(struct pakfire_pty* pty) {
+static int pakfire_pty_forward(pakfire_pty* pty) {
int did_something;
int r;
Forwards any window size changes.
*/
static int pakfire_pty_SIGWINCH(sd_event_source* source, const struct signalfd_siginfo* si, void* data) {
- struct pakfire_pty* pty = data;
+ pakfire_pty* pty = data;
struct winsize size;
int r;
return 0;
}
-static int pakfire_pty_drain(struct pakfire_pty* pty) {
+static int pakfire_pty_drain(pakfire_pty* pty) {
// Log action
DEBUG(pty->ctx, "Draining requested\n");
}
static int pakfire_pty_exit(sd_event_source* source, void* data) {
- struct pakfire_pty* self = data;
+ pakfire_pty* self = data;
int r;
DEBUG(self->ctx, "Exiting the PTY...\n");
return pakfire_pty_done(self, 0);
}
-static int pakfire_pty_activity(struct pakfire_pty* pty, struct pakfire_pty_stdio* stdio, uint32_t events) {
+static int pakfire_pty_activity(pakfire_pty* pty, pakfire_pty_stdio* stdio, uint32_t events) {
// Do we have data to read?
if (events & (EPOLLIN|EPOLLHUP))
stdio->io |= PAKFIRE_PTY_READY_TO_READ;
}
static int pakfire_pty_master(sd_event_source* source, int fd, uint32_t events, void* data) {
- struct pakfire_pty* pty = data;
+ pakfire_pty* pty = data;
return pakfire_pty_activity(pty, &pty->master, events);
}
static int pakfire_pty_stdin(sd_event_source* source, int fd, uint32_t events, void* data) {
- struct pakfire_pty* pty = data;
+ pakfire_pty* pty = data;
return pakfire_pty_activity(pty, &pty->stdin, events);
}
static int pakfire_pty_stdout(sd_event_source* source, int fd, uint32_t events, void* data) {
- struct pakfire_pty* pty = data;
+ pakfire_pty* pty = data;
return pakfire_pty_activity(pty, &pty->stdout, events);
}
);
}
-static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) {
+static int pakfire_pty_enable_raw_mode(pakfire_pty* pty) {
struct termios raw_attrs;
int same;
int r;
return 0;
}
-static int pakfire_pty_reopen(struct pakfire_pty* pty, int fd, int flags) {
+static int pakfire_pty_reopen(pakfire_pty* pty, int fd, int flags) {
char path[PATH_MAX];
int existing_flags;
off_t offset;
/*
Sets up PTY forwarding...
*/
-static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) {
+static int pakfire_pty_setup_forwarding(pakfire_pty* pty) {
struct winsize size;
int r;
/*
Sends the master file descriptor to the parent process...
*/
-static int pakfire_pty_send_master(struct pakfire_pty* pty) {
+static int pakfire_pty_send_master(pakfire_pty* pty) {
const size_t payload_length = sizeof(pty->master.fd);
char buffer[CMSG_SPACE(payload_length)];
int r;
/*
Received the master file descriptor from the child process...
*/
-static int pakfire_pty_recv_master(struct pakfire_pty* pty) {
+static int pakfire_pty_recv_master(pakfire_pty* pty) {
const size_t payload_length = sizeof(pty->master.fd);
char buffer[CMSG_SPACE(payload_length)];
int r;
Called when the master socket is being received from the child process.
*/
static int pakfire_pty_setup(sd_event_source* source, int fd, uint32_t events, void* data) {
- struct pakfire_pty* pty = data;
+ pakfire_pty* pty = data;
int r;
// Receive the master file descriptor
return 0;
}
-static void pakfire_pty_free(struct pakfire_pty* pty) {
+static void pakfire_pty_free(pakfire_pty* pty) {
pakfire_pty_disconnect(pty);
if (pty->socket[0] >= 0)
free(pty);
}
-int pakfire_pty_create(struct pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop) {
- struct pakfire_pty* p = NULL;
+int pakfire_pty_create(pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop) {
+ pakfire_pty* p = NULL;
int r;
// Allocate a new object
return r;
}
-struct pakfire_pty* pakfire_pty_ref(struct pakfire_pty* pty) {
+pakfire_pty* pakfire_pty_ref(pakfire_pty* pty) {
++pty->nrefs;
return pty;
}
-struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty) {
+pakfire_pty* pakfire_pty_unref(pakfire_pty* pty) {
if (--pty->nrefs > 0)
return pty;
/*
Sets up the terminal in the child process...
*/
-static int pakfire_pty_setup_terminal(struct pakfire_pty* pty) {
+static int pakfire_pty_setup_terminal(pakfire_pty* pty) {
int fd = -EBADF;
int r;
/*
Allocates a new PTY and must be called from the child process...
*/
-int pakfire_pty_open(struct pakfire_pty* pty) {
+int pakfire_pty_open(pakfire_pty* pty) {
int r;
// Allocate a new PTY