Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions include/omicron/pty.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* PTY: crea el par master/slave, lanza el hijo ya aislado y bombea E/S. */
#ifndef OMICRON_PTY_H
#define OMICRON_PTY_H
#pragma once

#include <sys/types.h>

#ifndef OM_POLICY_FWD
#define OM_POLICY_FWD
typedef struct om_policy om_policy;
#endif

/* Códigos de salida reservados del hijo: distinguen "no se ejecutó" de "falló". */
#define OM_EXIT_SANDBOX 127 /* el sandbox no se pudo aplicar; nunca hubo exec */
Expand All @@ -26,6 +22,4 @@ int om_pty_pump(om_pty *t);

int om_pty_resize(om_pty *t, unsigned rows, unsigned cols);
int om_pty_wait(om_pty *t, int *status);
void om_pty_kill(om_pty *t);

#endif /* OMICRON_PTY_H */
void om_pty_kill(om_pty *t);
60 changes: 48 additions & 12 deletions src/pty.c
Original file line number Diff line number Diff line change
@@ -1,45 +1,81 @@
/* Dueño: LevtCode. Portable: usar posix_openpt, no openpty (evita #ifdef). */
#include "omicron/pty.h"

/* Macro del compilador para poder usar posix_openpt. (Debe declararse casi al principio del código) */
#define _XOPEN_SOURCE 600

#include "omicron/pty.h"
#include "omicron/sandbox.h"

#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int om_pty_spawn(char *const argv[], const om_policy *p, om_pty *t)
int om_pty_spawn(char *const argv[], const om_policy *pol, om_pty *pty)
{
(void)argv;
(void)p;
(void)t;
(void)pol;
(void)pty;
/* Orden obligatorio en el hijo: cerrar fds ANTES de om_sandbox_apply. */
errno = ENOSYS;
return -1;

// Hay que corregir muchas cosas, de momento, hacemos que la ejecución llegue hasta aquí
// y termine de forma segura.
char *slave_name;

pty->master_fd = posix_openpt(O_RDWR | O_NOCTTY);
if (pty->master_fd == -1) {
perror("Error in posix_openpt");
return EXIT_FAILURE;
}

if (grantpt(pty->master_fd) == -1) {
perror("Error in grantpt");
close(pty->master_fd);
return EXIT_FAILURE;
}

if (unlockpt(pty->master_fd) == -1) {
perror("Error in unlockpt");
close(pty->master_fd);
return EXIT_FAILURE;
}

slave_name = ptsname(pty->master_fd);
if (slave_name == NULL) {
perror("Error in ptsname");
close(pty->master_fd);
return EXIT_FAILURE;
}
}

int om_pty_pump(om_pty *t)
int om_pty_pump(om_pty *pty)
{
(void)t;
(void)pty;
errno = ENOSYS;
return -1;
}

int om_pty_resize(om_pty *t, unsigned rows, unsigned cols)
int om_pty_resize(om_pty *pty, unsigned rows, unsigned cols)
{
(void)t;
(void)pty;
(void)rows;
(void)cols;
errno = ENOSYS;
return -1;
}

int om_pty_wait(om_pty *t, int *status)
int om_pty_wait(om_pty *pty, int *status)
{
(void)t;
(void)pty;
(void)status;
errno = ENOSYS;
return -1;
}

void om_pty_kill(om_pty *t)
void om_pty_kill(om_pty *pty)
{
(void)t;
(void)pty;
}
Loading