Skip to content

Commit

Permalink
Linux IXSupport: Inital version of IXRun
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyEBaldwin committed Feb 9, 2021
1 parent 9f9df5d commit a0a1d1a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions mixed/Linux/IXSupport/c/main
Expand Up @@ -132,6 +132,64 @@ _kernel_oserror *command_handler(const char *arg_string, int argc, int cmd_no, v
ix_dup2(a, b);
break;
}
case CMD_IXRun: {
char *cmd[argc + 1];

char *env[] = {0};
int pipes[2];
ix_pipe2(pipes, ix_O_CLOEXEC);
int ptmx = ix_open("/dev/ptmx", ix_O_RDWR | ix_O_CLOEXEC, 0);
int pid = __PVirt_fork(pipes);
ix_close(pipes[0]);
ix_close(pipes[1]);
if (pid == 0) {
char *out = (char *)arg_string;
char **arg = cmd;
char c = *arg_string;
while(c >= ' ') {
while(c == ' ') c = *++arg_string; // Skip spaces
*arg++ = out;
while(c > ' ') {
if (c== '"' || c == '\'') {
char q = *++arg_string;
while(q != c && q >= ' ') {
*out++ = q;
q = *++arg_string;
}
c = *++arg_string;
} else {
*out++ = c;
c = *++arg_string;
}
}
*out++ = 0;
}
*arg = 0;

int zero = 0;
ix_ioctl(ptmx, ix_TIOCSPTLCK, &zero);
int pts_no;
ix_ioctl(ptmx, ix_TIOCGPTN, &pts_no);
char ptsname[20];
sprintf(ptsname, "/dev/pts/%i", pts_no);
int pts = ix_open(ptsname, ix_O_RDWR | ix_O_CLOEXEC, 0);
ix_dup2(pts, 1);
ix_dup2(pts, 2);

int e = ix_execve(cmd[0], cmd, 0);
ix_exit(-e);
} else if (pid != 0) {
char buff[256];
int c = 0;
do {
c = ix_read(ptmx, &buff, sizeof(buff));
if (c > 0) _swix(OS_WriteN, _INR(0, 1), buff, c);
} while(c > 0);
int wstatus;
ix_waitpid(pid, &wstatus, 0);
}
ix_close(ptmx);
}
}
return 0;
}
2 changes: 1 addition & 1 deletion mixed/Linux/IXSupport/cmhg/IXSupportHdr
Expand Up @@ -38,4 +38,4 @@ swi-chunk-base-number: 0x59EC0
swi-decoding-table: IXSupport LinuxSyscall ConvertError
swi-handler-code: swi_handler

command-keyword-table:command_handler IXFS(max-args:0), IXFSBoot(max-args:0), IXDup2(min-args:2, max-args:2);
command-keyword-table:command_handler IXFS(max-args:0), IXFSBoot(max-args:0), IXDup2(min-args:2, max-args:2), IXRun(min-args:1, max-args:255);
1 change: 1 addition & 0 deletions mixed/Linux/Tests/PreDesk_NoAbort
Expand Up @@ -22,6 +22,7 @@ AppSlot 1M
BASIC -quit <Test$Dir>.TimeRuns
If "<Test$System>"="Linux" Then BASIC -quit <Test$Dir>.PVirt_Linking
BASIC -quit <Test$Dir>.File_Truncate
If "<Test$System>"="Linux" Then IXRun /usr/bin/env RISC_OS_Alias_IXFSBoot="IXRun /bin/ls -l /dev/fd/" /Built/qemu-link /RISC_OS --abort-on-input
BASIC -quit <Test$Dir>.Transient_Registers
If "<Test$System>"="Linux" Then BASIC -quit <Test$Dir>.CryptRandTest
If "<Test$NetOK>"="YES" Then BASIC -quit <Test$Dir>.Socket_Test
Expand Down

0 comments on commit a0a1d1a

Please sign in to comment.