Skip to content

Commit

Permalink
Run the apk repository management in Linux too
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jan 16, 2022
1 parent 01b9a12 commit 464dd63
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
20 changes: 10 additions & 10 deletions app/CurrentRoot.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "kernel/calls.h"
#include "fs/path.h"

#ifdef ISH_LINUX
#import "LinuxInterop.h"
#endif

int fs_ish_version;
int fs_ish_apk_version;

Expand Down Expand Up @@ -36,15 +40,9 @@ static int remove_directory(const char *path) {
return generic_rmdirat(AT_PWD, path);
}
#else
static ssize_t read_file(const char *path, char *buf, size_t size) {
return _ENOSYS;
}
static ssize_t write_file(const char *path, const char *buf, size_t size) {
return _ENOSYS;
}
static int remove_directory(const char *path) {
return _ENOSYS;
}
#define read_file linux_read_file
#define write_file linux_write_file
#define remove_directory linux_remove_directory
#endif

void FsInitialize() {
Expand Down Expand Up @@ -104,7 +102,9 @@ void FsUpdateRepositories() {
fs_ish_apk_version = currentVersion.intValue;
write_file("/ish/apk-version", currentVersionFile.UTF8String, [currentVersionFile lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
remove_directory("/ish/apk");
[NSNotificationCenter.defaultCenter postNotificationName:FsUpdatedNotification object:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[NSNotificationCenter.defaultCenter postNotificationName:FsUpdatedNotification object:nil];
});
}

NSString *const FsUpdatedNotification = @"FsUpdatedNotification";
22 changes: 21 additions & 1 deletion app/LinuxInterop.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void session_cleanup(struct subprocess_info *info) {
kfree(session);
}

void start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done) {
void linux_start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done) {
struct ish_session *session = kzalloc(sizeof(*session), GFP_KERNEL);
session->tty = ios_pty_open(&session->terminal);
session->callback = done;
Expand All @@ -161,3 +161,23 @@ void linux_sethostname(const char *hostname) {
}
up_write(&uts_sem);
}

ssize_t linux_read_file(const char *path, char *buf, size_t size) {
struct file *filp = filp_open(path, O_RDONLY, 0);
if (IS_ERR(filp))
return PTR_ERR(filp);
ssize_t res = vfs_read(filp, buf, size, NULL);
filp_close(filp, NULL);
if (res >= size)
return -ENAMETOOLONG;
return res;
}
ssize_t linux_write_file(const char *path, const char *buf, size_t size) {
struct file *filp = filp_open(path, O_WRONLY, 0);
ssize_t res = vfs_write(filp, buf, size, NULL);
filp_close(filp, NULL);
return res;
}
int linux_remove_directory(const char *path) {
return ksys_rmdir(path);
}
22 changes: 15 additions & 7 deletions app/LinuxInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#include <linux/fs.h>
#endif

void actuate_kernel(const char *cmdline);

void async_do_in_irq(void (^block)(void));
void async_do_in_workqueue(void (^block)(void));
void async_do_in_ios(void (^block)(void));
void sync_do_in_workqueue(void (^block)(void (^done)(void)));

// call into ios from kernel:

void actuate_kernel(const char *cmdline);

void ReportPanic(const char *message);
void ConsoleLog(const char *data, unsigned len);
const char *DefaultRootPath(void);
Expand All @@ -44,14 +46,20 @@ struct linux_tty_callbacks {
struct file *ios_pty_open(nsobj_t *terminal_out);
#endif

typedef void (^StartSessionDoneBlock)(int retval, int pid, nsobj_t terminal);
void start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done);

void linux_sethostname(const char *hostname);

nsobj_t Terminal_terminalWithType_number(int type, int number);
void Terminal_setLinuxTTY(nsobj_t _self, struct linux_tty *tty);
int Terminal_sendOutput_length(nsobj_t _self, const char *data, int size);
int Terminal_roomForOutput(nsobj_t _self);

// call into kernel from ios:

typedef void (^StartSessionDoneBlock)(int retval, int pid, nsobj_t terminal);
void linux_start_session(const char *exe, const char *const *argv, const char *const *envp, StartSessionDoneBlock done);

void linux_sethostname(const char *hostname);

ssize_t linux_read_file(const char *path, char *buf, size_t size);
ssize_t linux_write_file(const char *path, const char *buf, size_t size);
int linux_remove_directory(const char *path);

#endif /* LinuxInterop_h */
4 changes: 4 additions & 0 deletions app/LinuxRoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <uapi/linux/mount.h>
#include "LinuxInterop.h"

void FsInitialize(void);

static __init int ish_rootfs(void) {
rootfs_mounted = true;

Expand All @@ -32,6 +34,8 @@ static __init int ish_rootfs(void) {

do_mount(".", "/", NULL, MS_MOVE, NULL);
ksys_chroot(".");

FsInitialize();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion app/TerminalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ - (int)startSession {
__block int sessionPid = 0;
__block int err = 1;
sync_do_in_workqueue(^(void (^done)(void)) {
start_session(argv[0], argv, envp, ^(int retval, int pid, nsobj_t term) {
linux_start_session(argv[0], argv, envp, ^(int retval, int pid, nsobj_t term) {
err = retval;
if (term)
terminal = CFBridgingRelease(term);
Expand Down

0 comments on commit 464dd63

Please sign in to comment.