Skip to content

Commit

Permalink
Copy the hostname from iOS to Linux sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jan 16, 2022
1 parent 1aaf48f commit 1089f0d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,7 @@ - (int)boot {
task_start(current);

#else
if (strchr(root.fileSystemRepresentation, '"') != NULL) {
NSLog(@"can't deal with double quote in rootfs path");
return _EINVAL;
}
NSArray<NSString *> *args = @[
];
NSArray<NSString *> *args = @[];
actuate_kernel([args componentsJoinedByString:@" "].UTF8String);
#endif

Expand All @@ -178,6 +173,15 @@ - (int)boot {
const char *DefaultRootPath() {
return [Roots.instance rootUrl:Roots.instance.defaultRoot].fileSystemRepresentation;
}

void SyncHostname(void) {
async_do_in_workqueue(^{
char hostname[256];
if (gethostname(hostname, sizeof(hostname)) < 0)
return;
linux_sethostname(hostname);
});
}
#endif

- (void)configureDns {
Expand Down Expand Up @@ -251,6 +255,12 @@ - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:
return YES;

bootError = [self boot];

[NSNotificationCenter.defaultCenter addObserverForName:UIApplicationWillEnterForegroundNotification object:UIApplication.sharedApplication queue:nil usingBlock:^(NSNotification * _Nonnull note) {
SyncHostname();
}];
SyncHostname();

return YES;
}

Expand Down
15 changes: 15 additions & 0 deletions app/LinuxInterop.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/file.h>
#include <linux/umh.h>
#include <linux/syscalls.h>
#include <linux/utsname.h>
#include <asm/irq.h>
#include <user/fs.h>
#include <user/irq.h>
Expand Down Expand Up @@ -146,3 +147,17 @@ void start_session(const char *exe, const char *const *argv, const char *const *
if (err < 0)
done(err, 0, NULL);
}

void linux_sethostname(const char *hostname) {
int len = strlen(hostname);
if (len > __NEW_UTS_LEN)
len = __NEW_UTS_LEN;
down_write(&uts_sem);
struct new_utsname *u = utsname();
if (strncmp(u->nodename, hostname, len) != 0) {
memcpy(u->nodename, hostname, len);
memset(u->nodename + len, 0, sizeof(u->nodename) - len);
uts_proc_notify(UTS_PROC_HOSTNAME);
}
up_write(&uts_sem);
}
2 changes: 2 additions & 0 deletions app/LinuxInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct file *ios_pty_open(nsobj_t *terminal_out);
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);
Expand Down

0 comments on commit 1089f0d

Please sign in to comment.