1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

Kernel: Added the ability to set the hostname via new syscall

Userland/hostname: Now takes parameter to set the hostname
LibC/unistd: Added sethostname function
This commit is contained in:
Luke Payne 2020-04-26 15:59:47 +10:00 committed by Andreas Kling
parent 03f68a51af
commit f191b84b50
7 changed files with 40 additions and 9 deletions

View file

@ -36,14 +36,24 @@ int main(int argc, char** argv)
return 1;
}
(void)argc;
(void)argv;
char buffer[HOST_NAME_MAX];
int rc = gethostname(buffer, sizeof(buffer));
if (rc < 0) {
printf("gethostname() error: %s\n", strerror(errno));
return 1;
if (argc == 1) {
char buffer[HOST_NAME_MAX];
int rc = gethostname(buffer, sizeof(buffer));
if (rc < 0) {
printf("gethostname() error: %s\n", strerror(errno));
return 1;
}
printf("%s\n", buffer);
}
printf("%s\n", buffer);
else if (argc == 2) {
if (strlen(argv[1]) >= HOST_NAME_MAX) {
printf("hostname must be less than %i characters\n", HOST_NAME_MAX);
return 1;
}
else {
sethostname(argv[1], strlen(argv[1]));
}
}
return 0;
}