mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Modernize tix temporary files and directory creation.
This commit is contained in:
parent
beaa824076
commit
9ccfdb9990
6 changed files with 40 additions and 46 deletions
|
@ -42,11 +42,6 @@ SYSROOT=$(make_dir_path_absolute "$SYSROOT")
|
||||||
SORTIX_PORTS_DIR=$(make_dir_path_absolute "$SORTIX_PORTS_DIR")
|
SORTIX_PORTS_DIR=$(make_dir_path_absolute "$SORTIX_PORTS_DIR")
|
||||||
SORTIX_REPOSITORY_DIR=$(make_dir_path_absolute "$SORTIX_REPOSITORY_DIR")
|
SORTIX_REPOSITORY_DIR=$(make_dir_path_absolute "$SORTIX_REPOSITORY_DIR")
|
||||||
|
|
||||||
# Create a temporary directory in which out-of-directory builds will happen.
|
|
||||||
if [ -z "$BUILDTMP" ]; then
|
|
||||||
export BUILDTMP=$(mktemp -d)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Decide the optimization options with which the ports will be built.
|
# Decide the optimization options with which the ports will be built.
|
||||||
if [ -z "${OPTLEVEL+x}" ]; then OPTLEVEL="-Os"; fi
|
if [ -z "${OPTLEVEL+x}" ]; then OPTLEVEL="-Os"; fi
|
||||||
if [ -z "${PORTS_OPTLEVEL+x}" ]; then PORTS_OPTLEVEL="$OPTLEVEL"; fi
|
if [ -z "${PORTS_OPTLEVEL+x}" ]; then PORTS_OPTLEVEL="$OPTLEVEL"; fi
|
||||||
|
|
|
@ -23,11 +23,6 @@ fi
|
||||||
# Make paths absolute for later use.
|
# Make paths absolute for later use.
|
||||||
SORTIX_PORTS_DIR=$(make_dir_path_absolute "$SORTIX_PORTS_DIR")
|
SORTIX_PORTS_DIR=$(make_dir_path_absolute "$SORTIX_PORTS_DIR")
|
||||||
|
|
||||||
# Create a temporary directory in which out-of-directory builds will happen.
|
|
||||||
if [ -z "$BUILDTMP" ]; then
|
|
||||||
export BUILDTMP=$(mktemp -d)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect all packages.
|
# Detect all packages.
|
||||||
get_all_packages() {
|
get_all_packages() {
|
||||||
for PACKAGE in $(ls "$SORTIX_PORTS_DIR"); do
|
for PACKAGE in $(ls "$SORTIX_PORTS_DIR"); do
|
||||||
|
|
|
@ -74,7 +74,7 @@ int main(int argc, char* argv[])
|
||||||
char* input_tarball_path = NULL;
|
char* input_tarball_path = NULL;
|
||||||
char* output_directory = strdup(".");
|
char* output_directory = strdup(".");
|
||||||
char* output = NULL;
|
char* output = NULL;
|
||||||
char* tmp = strdup(getenv_def("TMP", "/tmp"));
|
char* tmp = strdup(getenv_def("TMPDIR", "/tmp"));
|
||||||
|
|
||||||
const char* argv0 = argv[0];
|
const char* argv0 = argv[0];
|
||||||
for ( int i = 0; i < argc; i++ )
|
for ( int i = 0; i < argc; i++ )
|
||||||
|
@ -155,9 +155,9 @@ int main(int argc, char* argv[])
|
||||||
if ( !output )
|
if ( !output )
|
||||||
output = print_string("%s/%s.porttix.tar.xz", output_directory, package_name);
|
output = print_string("%s/%s.porttix.tar.xz", output_directory, package_name);
|
||||||
|
|
||||||
char* tmp_root = print_string("%s/tmppid.%ju", tmp, (uintmax_t) getpid());
|
char* tmp_root = print_string("%s/porttix.XXXXXX", tmp);
|
||||||
if ( mkdir_p(tmp_root, 0755) != 0 )
|
if ( !mkdtemp(tmp_root) )
|
||||||
error(1, errno, "mkdir: `%s'", tmp_root);
|
error(1, errno, "mkdtemp: `%s'", tmp_root);
|
||||||
|
|
||||||
on_exit(cleanup_file_or_directory, tmp_root);
|
on_exit(cleanup_file_or_directory, tmp_root);
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char* output_directory = strdup(".");
|
char* output_directory = strdup(".");
|
||||||
char* output = NULL;
|
char* output = NULL;
|
||||||
char* tmp = strdup(getenv_def("TMP", "/tmp"));
|
char* tmp = strdup(getenv_def("TMPDIR", "/tmp"));
|
||||||
|
|
||||||
const char* argv0 = argv[0];
|
const char* argv0 = argv[0];
|
||||||
for ( int i = 0; i < argc; i++ )
|
for ( int i = 0; i < argc; i++ )
|
||||||
|
@ -120,9 +120,9 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
const char* porttix_path = argv[1];
|
const char* porttix_path = argv[1];
|
||||||
|
|
||||||
char* tmp_in_root = print_string("%s/tmppid.%ju.in", tmp, (uintmax_t) getpid());
|
char* tmp_in_root = print_string("%s/srctixin.XXXXXX", tmp);
|
||||||
if ( mkdir_p(tmp_in_root, 0755) != 0 )
|
if ( !mkdtemp(tmp_in_root) )
|
||||||
error(1, errno, "mkdir: `%s'", tmp_in_root);
|
error(1, errno, "mkdtemp: `%s'", tmp_in_root);
|
||||||
on_exit(cleanup_file_or_directory, tmp_in_root);
|
on_exit(cleanup_file_or_directory, tmp_in_root);
|
||||||
|
|
||||||
if ( fork_and_wait_or_death() )
|
if ( fork_and_wait_or_death() )
|
||||||
|
@ -150,9 +150,9 @@ int main(int argc, char* argv[])
|
||||||
error(1, errno, "`%s'", porttixinfo_path);
|
error(1, errno, "`%s'", porttixinfo_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* tmp_out_root = print_string("%s/tmppid.%ju.out", tmp, (uintmax_t) getpid());
|
char* tmp_out_root = print_string("%s/srctixout.XXXXXX", tmp);
|
||||||
if ( mkdir_p(tmp_out_root, 0755) != 0 )
|
if ( !mkdtemp(tmp_out_root) )
|
||||||
error(1, errno, "mkdir: `%s'", tmp_out_root);
|
error(1, errno, "mkdtemp: `%s'", tmp_out_root);
|
||||||
on_exit(cleanup_file_or_directory, tmp_out_root);
|
on_exit(cleanup_file_or_directory, tmp_out_root);
|
||||||
|
|
||||||
char* package_name = NULL;
|
char* package_name = NULL;
|
||||||
|
|
|
@ -239,9 +239,9 @@ void emit_compiler_sysroot_cross_wrapper(metainfo_t* minfo,
|
||||||
|
|
||||||
void emit_pkg_config_wrapper(metainfo_t* minfo)
|
void emit_pkg_config_wrapper(metainfo_t* minfo)
|
||||||
{
|
{
|
||||||
char* bindir = print_string("%s/tmppid.%ju.bin", minfo->tmp, (uintmax_t) getpid());
|
char* bindir = print_string("%s/bin.XXXXXX", minfo->tmp);
|
||||||
if ( mkdir_p(bindir, 0755) != 0 )
|
if ( !mkdtemp(bindir) )
|
||||||
error(1, errno, "mkdir: `%s'", bindir);
|
error(1, errno, "mkdtemp: `%s'", bindir);
|
||||||
|
|
||||||
on_exit(cleanup_file_or_directory, strdup(bindir));
|
on_exit(cleanup_file_or_directory, strdup(bindir));
|
||||||
|
|
||||||
|
@ -582,10 +582,10 @@ void BuildPackage(metainfo_t* minfo)
|
||||||
bool use_build_dir = parse_boolean(use_build_dir_var);
|
bool use_build_dir = parse_boolean(use_build_dir_var);
|
||||||
if ( use_build_dir )
|
if ( use_build_dir )
|
||||||
{
|
{
|
||||||
minfo->build_dir = print_string("%s/tmppid.%ju", minfo->tmp,
|
minfo->build_dir = print_string("%s/build.XXXXXX", minfo->tmp);
|
||||||
(uintmax_t) getpid());
|
if ( !mkdtemp(minfo->build_dir) )
|
||||||
if ( mkdir_p(minfo->build_dir, 0755) != 0 )
|
error(1, errno, "mkdtemp: `%s'", minfo->build_dir);
|
||||||
error(1, errno, "mkdir: `%s'", minfo->build_dir);
|
on_exit(cleanup_file_or_directory, strdup(minfo->build_dir));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
minfo->build_dir = strdup(minfo->package_dir);
|
minfo->build_dir = strdup(minfo->package_dir);
|
||||||
|
@ -623,18 +623,14 @@ void BuildPackage(metainfo_t* minfo)
|
||||||
if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_BUILD, minfo) )
|
if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_BUILD, minfo) )
|
||||||
Make(minfo, build_target, NULL, true, subdir);
|
Make(minfo, build_target, NULL, true, subdir);
|
||||||
|
|
||||||
char* tardir_rel = print_string("%s/%s", minfo->tmp, "tmp-tixbuild");
|
char* tardir_rel = print_string("%s/%s", minfo->tmp, "tix.XXXXXX");
|
||||||
char* destdir_rel = print_string("%s/%s", minfo->tmp, "tmp-tixbuild/data");
|
if ( !mkdtemp(tardir_rel) )
|
||||||
char* tixdir_rel = print_string("%s/%s", minfo->tmp, "tmp-tixbuild/tix");
|
error(1, errno, "mkdtemp: `%s'", tardir_rel);
|
||||||
char* tixinfo_rel = print_string("%s/%s", minfo->tmp, "tmp-tixbuild/tix/tixinfo");
|
on_exit(cleanup_file_or_directory, strdup(tardir_rel));
|
||||||
|
|
||||||
while ( mkdir(tardir_rel, 0755) != 0 )
|
char* destdir_rel = print_string("%s/%s", tardir_rel, "data");
|
||||||
{
|
char* tixdir_rel = print_string("%s/%s", tardir_rel, "tix");
|
||||||
if ( errno != EEXIST )
|
char* tixinfo_rel = print_string("%s/%s", tardir_rel, "tix/tixinfo");
|
||||||
error(1, errno, "mkdir: `%s'", tardir_rel);
|
|
||||||
if ( rmdir(tardir_rel) != 0 )
|
|
||||||
error(1, errno, "rmdir: `%s'", tardir_rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mkdir(destdir_rel, 0755) != 0 )
|
if ( mkdir(destdir_rel, 0755) != 0 )
|
||||||
error(1, errno, "mkdir: `%s'", destdir_rel);
|
error(1, errno, "mkdir: `%s'", destdir_rel);
|
||||||
|
@ -734,7 +730,7 @@ void BuildPackage(metainfo_t* minfo)
|
||||||
unlink(tixinfo_rel);
|
unlink(tixinfo_rel);
|
||||||
rmdir(destdir_rel);
|
rmdir(destdir_rel);
|
||||||
rmdir(tixdir_rel);
|
rmdir(tixdir_rel);
|
||||||
rmdir(tardir_rel);
|
//rmdir(tardir_rel); // Keep around to avoid on_exit handler race.
|
||||||
|
|
||||||
free(tardir_rel);
|
free(tardir_rel);
|
||||||
free(destdir_rel);
|
free(destdir_rel);
|
||||||
|
@ -822,7 +818,7 @@ int main(int argc, char* argv[])
|
||||||
metainfo_t minfo;
|
metainfo_t minfo;
|
||||||
memset(&minfo, 0, sizeof(minfo));
|
memset(&minfo, 0, sizeof(minfo));
|
||||||
minfo.build = NULL;
|
minfo.build = NULL;
|
||||||
minfo.destination = NULL;
|
minfo.destination = strdup(".");
|
||||||
minfo.host = NULL;
|
minfo.host = NULL;
|
||||||
char* generation_string = strdup(DEFAULT_GENERATION);
|
char* generation_string = strdup(DEFAULT_GENERATION);
|
||||||
minfo.makeflags = strdup_null(getenv_def("MAKEFLAGS", NULL));
|
minfo.makeflags = strdup_null(getenv_def("MAKEFLAGS", NULL));
|
||||||
|
@ -832,7 +828,7 @@ int main(int argc, char* argv[])
|
||||||
minfo.sysroot = NULL;
|
minfo.sysroot = NULL;
|
||||||
minfo.target = NULL;
|
minfo.target = NULL;
|
||||||
minfo.tar = strdup("tar");
|
minfo.tar = strdup("tar");
|
||||||
minfo.tmp = strdup(getenv_def("BUILDTMP", "."));
|
minfo.tmp = strdup(getenv_def("TMPDIR", "/tmp"));
|
||||||
char* start_step_string = strdup("start");
|
char* start_step_string = strdup("start");
|
||||||
char* end_step_string = strdup("end");
|
char* end_step_string = strdup("end");
|
||||||
|
|
||||||
|
|
16
tix/util.h
16
tix/util.h
|
@ -776,20 +776,28 @@ void cleanup_file_or_directory(int, void* path_ptr)
|
||||||
{
|
{
|
||||||
if ( original_pid != getpid() )
|
if ( original_pid != getpid() )
|
||||||
return;
|
return;
|
||||||
const char* path = (const char*) path_ptr;
|
pid_t pid = fork();
|
||||||
if ( fork_and_wait_or_death(false) )
|
if ( pid < 0 )
|
||||||
|
{
|
||||||
|
error(0, errno, "fork");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( pid == 0 )
|
||||||
{
|
{
|
||||||
const char* cmd_argv[] =
|
const char* cmd_argv[] =
|
||||||
{
|
{
|
||||||
"rm",
|
"rm",
|
||||||
"-rf",
|
"-rf",
|
||||||
"--",
|
"--",
|
||||||
path,
|
(const char*) path_ptr,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
execvp(cmd_argv[0], (char* const*) cmd_argv);
|
execvp(cmd_argv[0], (char* const*) cmd_argv);
|
||||||
error(127, errno, "%s", cmd_argv[0]);
|
error(0, errno, "%s", cmd_argv[0]);
|
||||||
|
_exit(127);
|
||||||
}
|
}
|
||||||
|
int code;
|
||||||
|
waitpid(pid, &code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
mode_t get_umask_value()
|
mode_t get_umask_value()
|
||||||
|
|
Loading…
Add table
Reference in a new issue