1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Clean up minor issues in sysinstall(8).

This commit is contained in:
Jonas 'Sortie' Termansen 2021-01-15 21:22:05 +01:00
parent 69513b4396
commit 84b008e455
5 changed files with 45 additions and 23 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen.
* Copyright (c) 2015, 2016, 2021 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -69,7 +69,8 @@ void unscan_filesystem(struct blockdevice* bdev)
void scan_filesystem(struct blockdevice* bdev)
{
enum filesystem_error fserr = blockdevice_inspect_filesystem(&bdev->fs, bdev);
enum filesystem_error fserr =
blockdevice_inspect_filesystem(&bdev->fs, bdev);
if ( fserr == FILESYSTEM_ERROR_ABSENT ||
fserr == FILESYSTEM_ERROR_UNRECOGNIZED )
return;
@ -94,7 +95,8 @@ void scan_device(struct harddisk* hd)
{
unscan_device(hd);
struct blockdevice* bdev = &hd->bdev;
enum partition_error parterr = blockdevice_get_partition_table(&bdev->pt, bdev);
enum partition_error parterr =
blockdevice_get_partition_table(&bdev->pt, bdev);
if ( parterr == PARTITION_ERROR_ABSENT ||
parterr == PARTITION_ERROR_UNRECOGNIZED )
{
@ -261,9 +263,14 @@ bool load_mountpoints(const char* fstab_path,
FILE* fp = fopen(fstab_path, "r");
if ( !fp )
return false;
struct mountpoint* mountpoints = NULL;
struct mountpoint* mountpoints = malloc(sizeof(struct mountpoint));
if ( !mountpoints )
{
fclose(fp);
return false;
}
size_t mountpoints_used = 0;
size_t mountpoints_length = 0;
size_t mountpoints_length = 1;
char* line = NULL;
size_t line_size;
ssize_t line_length;
@ -276,11 +283,9 @@ bool load_mountpoints(const char* fstab_path,
continue;
if ( mountpoints_used == mountpoints_length )
{
size_t new_length = 2 * mountpoints_length;
if ( !new_length )
new_length = 16;
struct mountpoint* new_mountpoints = (struct mountpoint*)
reallocarray(mountpoints, new_length, sizeof(struct mountpoint));
reallocarray(mountpoints, mountpoints_length,
2 * sizeof(struct mountpoint));
if ( !new_mountpoints )
{
free_mountpoints(mountpoints, mountpoints_used);
@ -289,7 +294,7 @@ bool load_mountpoints(const char* fstab_path,
return false;
}
mountpoints = new_mountpoints;
mountpoints_length = new_length;
mountpoints_length *= 2;
}
struct mountpoint* mountpoint = &mountpoints[mountpoints_used++];
memset(mountpoint, 0, sizeof(*mountpoint));
@ -326,7 +331,7 @@ bool mountpoint_mount(struct mountpoint* mountpoint)
// TODO: It would be ideal to get an exclusive lock so that no other
// processes have currently mounted that filesystem.
struct blockdevice* bdev = fs->bdev;
const char* bdev_path = bdev->p ? bdev->p->path : bdev->hd->path;
const char* bdev_path = path_of_blockdevice(bdev);
assert(bdev_path);
if ( fs->flags & FILESYSTEM_FLAG_FSCK_MUST && !fsck(fs) )
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, 2017, 2020 Jonas 'Sortie' Termansen.
* Copyright (c) 2015, 2016, 2017, 2020, 2021 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -92,9 +92,11 @@ void mkdir_or_chmod_or_die(const char* path, mode_t mode)
{
if ( chmod(path, mode) == 0 )
return;
err(2, "chmod: %s", path);
warn("chmod: %s", path);
_exit(2);
}
err(2, "mkdir: %s", path);
warn("mkdir: %s", path);
_exit(2);
}
void write_random_seed(const char* path)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, 2017 Jonas 'Sortie' Termansen.
* Copyright (c) 2015, 2016, 2017, 2021 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -91,7 +91,12 @@ static char* os_release_eval(const char* string)
doubly_quote = !doubly_quote;
else
{
fputc((unsigned char) c, fp);
if ( fputc((unsigned char) c, fp) == EOF )
{
fclose(fp);
free(result);
return NULL;
}
escaped = false;
}
}

View file

@ -135,6 +135,7 @@ static bool should_install_bootloader_path(const char* mnt,
}
free(release_path);
free(release_errpath);
release_free(&release);
char* conf_path;
if ( asprintf(&conf_path, "%s/etc/upgrade.conf", mnt) < 0 )
{
@ -402,6 +403,8 @@ int main(void)
if ( !mkdtemp(etc) )
err(2, "mkdtemp: %s", "/tmp/etc.XXXXXX");
etc_made = true;
// Export for the convenience of users escaping to a shell.
setenv("SYSINSTALL_ETC", fs, 1);
if ( chdir(etc) < 0 )
err(2, "chdir: %s", etc);
@ -859,6 +862,7 @@ int main(void)
if ( !mkdtemp(fs) )
err(2, "mkdtemp: %s", "/tmp/fs.XXXXXX");
fs_made = true;
// Export for the convenience of users escaping to a shell.
setenv("SYSINSTALL_TARGET", fs, 1);
for ( size_t i = 0; i < mountpoints_used; i++ )

View file

@ -142,6 +142,7 @@ static void search_installation_path(const char* mnt, struct blockdevice* bdev)
if ( asprintf(&machine_path, "%s/etc/machine", mnt) < 0 )
{
warn("%s: malloc", path_of_blockdevice(bdev));
free_mountpoints(mountpoints, mountpoints_used);
release_free(&release);
return;
}
@ -150,12 +151,14 @@ static void search_installation_path(const char* mnt, struct blockdevice* bdev)
if ( !machine )
{
warn("%s/etc/machine", path_of_blockdevice(bdev));
free_mountpoints(mountpoints, mountpoints_used);
release_free(&release);
return;
}
if ( !add_installation(bdev, &release, mountpoints, mountpoints_used,
machine) )
{
free(machine);
free_mountpoints(mountpoints, mountpoints_used);
release_free(&release);
return;
@ -278,7 +281,7 @@ static void preserve_src(const char* where)
if ( mkdir("oldsrc", 0755) < 0 )
{
warn("oldsrc");
_exit(1);
_exit(2);
}
}
time_t now = time(NULL);
@ -298,7 +301,7 @@ static void preserve_src(const char* where)
if ( !mkdtemp(buf) )
{
warnx("failed to find location to store old /%s", where);
_exit(1);
_exit(2);
}
rmdir(buf);
}
@ -307,7 +310,7 @@ static void preserve_src(const char* where)
if ( rename(where, buf) < 0 )
{
warn("rename: %s -> %s", where, buf);
_exit(1);
_exit(2);
}
}
@ -502,6 +505,9 @@ int main(void)
if ( !mkdtemp(fs) )
err(2, "mkdtemp: %s", "/tmp/fs.XXXXXX");
fs_made = true;
// Export for the convenience of users escaping to a shell.
setenv("SYSINSTALL_TARGET", fs, 1);
struct installation* target = NULL;
while ( true )
@ -817,7 +823,7 @@ int main(void)
if ( rename("src", "src.tmp") < 0 )
{
warn("rename: /src -> /src.tmp");
_exit(1);
_exit(2);
}
}
install_manifest("src", "", ".", (const char*[]){}, 0);
@ -826,12 +832,12 @@ int main(void)
if ( rename("src", "newsrc") < 0 )
{
warn("rename: /src -> /newsrc");
_exit(1);
_exit(2);
}
if ( rename("src.tmp", "src") < 0 )
{
warn("rename: /src.tmp -> /src");
_exit(1);
_exit(2);
}
}
}