Port build utilities to musl.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-08-10 01:29:04 +02:00
parent 91a6ee7919
commit 848eaaf593
16 changed files with 361 additions and 367 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2016 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
@ -17,8 +17,8 @@
* Convert a binary file to a C array.
*/
#include <err.h>
#include <errno.h>
#include <error.h>
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
@ -77,7 +77,7 @@ void get_short_option_variable(char c, char** varptr,
{
if ( *ip + 1 == argc )
{
error(0, 0, "option requires an argument -- '%c'", c);
warnx("option requires an argument -- '%c'", c);
fprintf(stderr, "Try `%s --help' for more information.\n", argv0);
exit(1);
}
@ -224,9 +224,9 @@ int main(int argc, char* argv[])
const char* output_path = arg_output;
if ( flag_extern && flag_static )
error(1, 0, "the --extern and --static are mutually incompatible");
errx(1, "the --extern and --static are mutually incompatible");
if ( flag_forward && flag_raw )
error(1, 0, "the --forward and --raw are mutually incompatible");
errx(1, "the --forward and --raw are mutually incompatible");
if ( !arg_type )
arg_type = strdup("unsigned char");
@ -295,7 +295,7 @@ int main(int argc, char* argv[])
}
if ( output_path && !freopen(output_path, "w", stdout) )
error(1, errno, "%s", output_path);
err(1, "%s", output_path);
if ( flag_guard && guard )
{
@ -356,7 +356,7 @@ int main(int argc, char* argv[])
fp = fopen(arg, "r");
}
if ( !fp )
error(1, errno, "%s", arg);
err(1, "%s", arg);
int ic;
while ( (ic = fgetc(fp)) != EOF )
{
@ -370,7 +370,7 @@ int main(int argc, char* argv[])
}
}
if ( ferror(fp) )
error(1, errno, "fgetc: %s", arg);
err(1, "fgetc: %s", arg);
if ( fp != stdin )
fclose(fp);
}
@ -399,7 +399,7 @@ int main(int argc, char* argv[])
}
if ( ferror(stdout) || fflush(stdout) == EOF )
error(1, errno, "%s", output_path ? output_path : "stdout");
err(1, "%s", output_path ? output_path : "stdout");
return 0;
}

View File

@ -19,8 +19,8 @@
#include <assert.h>
#include <endian.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
@ -394,7 +394,7 @@ int main(int argc, char* argv[])
{
if ( i + 1 == argc )
{
error(0, 0, "option requires an argument -- 'o'");
warnx("option requires an argument -- 'o'");
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
exit(125);
}
@ -605,7 +605,7 @@ int main(int argc, char* argv[])
}
free(line);
if ( ferror(input) )
error(1, errno, "%s", input_path);
err(1, "%s", input_path);
fclose(input);
if ( verbose )
@ -670,7 +670,7 @@ int main(int argc, char* argv[])
FILE* output = fopen(output_path, "w");
if ( !output )
error(1, errno, "%s", output_path);
err(1, "%s", output_path);
uint32_t compression_algorithm;
void (*compressor)(FILE*, struct kblayout_action*, size_t);

View File

@ -22,12 +22,6 @@
#include <stdint.h>
#include <sys/cdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#define INITRD_ALGO_CRC32 0
#define INITRD_ALGO_NONE 1
@ -95,8 +89,4 @@ typedef struct initrd_dirent
char name[0];
} initrd_dirent_t;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -18,8 +18,9 @@
*/
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <ioleast.h>
#include <stdbool.h>
@ -28,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sortix/initrd.h>
#include "serialize.h"
@ -254,39 +256,39 @@ int main(int argc, char* argv[])
compact_arguments(&argc, &argv);
if ( argc == 1 )
error(1, 0, "No initrd specified");
errx(1, "No initrd specified");
const char* initrd = argv[1];
if ( argc == 2 )
error(1, 0, "No command specified");
errx(1, "No command specified");
const char* cmd = argv[2];
if ( argc == 3 )
error(1, 0, "No path specified");
errx(1, "No path specified");
const char* path = argv[3];
int fd = open(initrd, O_RDONLY);
if ( fd < 0 ) { error(1, errno, "open: %s", initrd); }
if ( fd < 0 ) { err(1, "open: %s", initrd); }
initrd_superblock_t* sb = GetSuperBlock(fd);
if ( !sb ) { error(1, errno, "read: %s", initrd); }
if ( !sb ) { err(1, "read: %s", initrd); }
if ( path[0] != '/' ) { error(1, ENOENT, "%s", path); }
if ( path[0] != '/' ) { errno = ENOENT; err(1, "%s", path); }
initrd_inode_t* root = GetInode(fd, sb, sb->root);
if ( !root ) { error(1, errno, "read: %s", initrd); }
if ( !root ) { err(1, "read: %s", initrd); }
initrd_inode_t* inode = ResolvePath(fd, sb, root, path+1);
if ( !inode ) { error(1, errno, "%s", path); }
if ( !inode ) { err(1, "%s", path); }
free(root);
if ( !strcmp(cmd, "cat") )
{
if ( !PrintFile(fd, sb, inode) ) { error(1, errno, "%s", path); }
if ( !PrintFile(fd, sb, inode) ) { err(1, "%s", path); }
}
else if ( !strcmp(cmd, "ls") )
{
initrd_inode_t* dir = inode;
if ( !ListDirectory(fd, sb, dir, all) ) { error(1, errno, "%s", path); }
if ( !ListDirectory(fd, sb, dir, all) ) { err(1, "%s", path); }
}
else
{

View File

@ -23,8 +23,8 @@
#include <assert.h>
#include <dirent.h>
#include <endian.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <ioleast.h>
#include <stdalign.h>
@ -179,7 +179,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
struct stat st;
if ( lstat(real_path, &st) != 0 )
{
error(0, errno, "stat: %s", real_path);
warn("stat: %s", real_path);
return NULL;
}
@ -204,7 +204,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
char* real_path_clone = strdup(real_path);
if ( !real_path_clone )
{
error(0, errno, "strdup");
warn("strdup");
free(node);
return NULL;
}
@ -225,7 +225,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
DIR* dir = opendir(real_path);
if ( !dir )
{
error(0, errno, "opendir: %s", real_path);
warn("opendir: %s", real_path);
FreeNode(node);
return NULL;
}
@ -243,7 +243,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
char* virt_subpath = (char*) malloc(virt_subpath_len+1);
if ( !virt_subpath )
{
error(0, errno, "malloc");
warn("malloc");
successful = false;
break;
}
@ -262,7 +262,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
if ( !real_subpath )
{
free(virt_subpath);
error(0, errno, "malloc");
warn("malloc");
successful = false;
break;
}
@ -291,7 +291,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
struct DirEntry* newdirents = (struct DirEntry*) realloc(node->dirents, newsize);
if ( !newdirents )
{
error(0, errno, "realloc");
warn("realloc");
successful = false;
break;
}
@ -302,7 +302,7 @@ struct Node* RecursiveSearch(const char* real_path, const char* virt_path,
char* nameclone = strdup(entry->d_name);
if ( !nameclone )
{
error(0, errno, "strdup");
warn("strdup");
successful = false;
break;
}
@ -337,7 +337,7 @@ struct Node* MergeNodes(struct Node* a, struct Node* b)
malloc(sizeof(struct DirEntry) * dirents_length);
if ( !dirents )
{
error(0, errno, "malloc");
warn("malloc");
FreeNode(a);
FreeNode(b);
return NULL;
@ -423,17 +423,17 @@ bool WriteNode(struct initrd_superblock* sb, int fd, const char* outputname,
char name[NAME_SIZE];
ssize_t namelen = readlink(node->path, name, NAME_SIZE);
if ( namelen < 0 )
return error(0, errno, "readlink: %s", node->path), false;
return warn("readlink: %s", node->path), false;
filesize = (uint32_t) namelen;
if ( pwriteall(fd, name, filesize, dataoff) < filesize )
return error(0, errno, "read: %s", node->path), false;
return warn("read: %s", node->path), false;
dataoff += filesize;
}
else if ( S_ISREG(node->mode) ) // Regular file
{
int nodefd = open(node->path, O_RDONLY);
if ( nodefd < 0 )
return error(0, errno, "open: %s", node->path), false;
return warn("open: %s", node->path), false;
const size_t BUFFER_SIZE = 16UL * 1024UL;
uint8_t buffer[BUFFER_SIZE];
ssize_t amount;
@ -442,14 +442,14 @@ bool WriteNode(struct initrd_superblock* sb, int fd, const char* outputname,
if ( pwriteall(fd, buffer, amount, dataoff) < (size_t) amount )
{
close(nodefd);
return error(0, errno, "write: %s", outputname), false;
return warn("write: %s", outputname), false;
}
dataoff += amount;
filesize += amount;
}
close(nodefd);
if ( amount < 0 )
return error(0, errno, "read: %s", node->path), false;
return warn("read: %s", node->path), false;
}
else if ( S_ISDIR(node->mode) ) // Directory
{
@ -470,13 +470,13 @@ bool WriteNode(struct initrd_superblock* sb, int fd, const char* outputname,
import_initrd_dirent(&dirent);
ssize_t nameamt = pwriteall(fd, name, namelen+1, dataoff + entsize);
if ( hdramt < (ssize_t) entsize || nameamt < (ssize_t) (namelen+1) )
return error(0, errno, "write: %s", outputname), false;
return warn("write: %s", outputname), false;
size_t padding = dirent.reclen - (entsize + (namelen+1));
for ( size_t n = 0; n < padding; n++ )
{
uint8_t nul = 0;
if ( pwrite(fd, &nul, 1, dataoff+entsize+namelen+1+n) != 1 )
return error(0, errno, "write: %s", outputname), false;
return warn("write: %s", outputname), false;
}
filesize += dirent.reclen;
dataoff += dirent.reclen;
@ -498,7 +498,7 @@ bool WriteNode(struct initrd_superblock* sb, int fd, const char* outputname,
export_initrd_inode(&inode);
assert((inodepos & (alignof(inode)-1)) == 0 );
if ( pwriteall(fd, &inode, inodesize, inodepos) < inodesize )
return error(0, errno, "write: %s", outputname), false;
return warn("write: %s", outputname), false;
import_initrd_inode(&inode);
uint32_t increment = dataoff - origfssize;
@ -559,14 +559,14 @@ bool FormatFD(const char* outputname, int fd, uint32_t inodecount,
export_initrd_superblock(&sb);
if ( pwriteall(fd, &sb, sizeof(sb), 0) < sizeof(sb) )
{
error(0, errno, "write: %s", outputname);
warn("write: %s", outputname);
return false;
}
import_initrd_superblock(&sb);
if ( ftruncate(fd, sb.fssize) < 0 )
{
error(0, errno, "truncate: %s", outputname);
warn("truncate: %s", outputname);
return false;
}
@ -667,7 +667,7 @@ int main(int argc, char* argv[])
{
if ( i + 1 == argc )
{
error(0, 0, "option requires an argument -- 'o'");
warnx("option requires an argument -- 'o'");
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
exit(125);
}
@ -690,7 +690,7 @@ int main(int argc, char* argv[])
{
FILE* fp = fopen(arg_filter, "r");
if ( !fp )
error(1, errno, "%s", arg_filter);
err(1, "%s", arg_filter);
if ( !AddRulesFromFile(fp, arg_filter) )
exit(1);
fclose(fp);
@ -701,7 +701,7 @@ int main(int argc, char* argv[])
{
FILE* fp = fopen(arg_manifest, "r");
if ( !fp )
error(1, errno, "%s", arg_manifest);
err(1, "%s", arg_manifest);
if ( !AddManifestFromFile(fp, arg_manifest) )
exit(1);
fclose(fp);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2015, 2016 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
@ -18,8 +18,8 @@
*/
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <libgen.h>
#include <stdarg.h>
#include <stdbool.h>
@ -193,8 +193,7 @@ bool AddRulesFromFile(FILE* fp, const char* fpname)
value = false;
else
{
error(0, 0, "%s:%zu: not a boolean '%s'", fpname,
line_num, parameter);
warnx("%s:%zu: not a boolean '%s'", fpname, line_num, parameter);
goto error_out;
}
if ( !default_inclusion_determined )
@ -208,8 +207,7 @@ bool AddRulesFromFile(FILE* fp, const char* fpname)
{
if ( !*parameter )
{
error(0, 0, "%s:%zu: no parameter given", fpname,
line_num);
warnx("%s:%zu: no parameter given", fpname, line_num);
goto error_out;
}
const char* pattern = parameter;
@ -223,8 +221,7 @@ bool AddRulesFromFile(FILE* fp, const char* fpname)
}
else
{
error(0, 0, "%s:%zu: line not understood: '%s'", fpname,
line_num, line);
warnx("%s:%zu: line not understood: '%s'", fpname, line_num, line);
goto error_out;
}
}
@ -232,7 +229,7 @@ bool AddRulesFromFile(FILE* fp, const char* fpname)
if ( ferror(fp) )
{
error_out_errno:
error(0, errno, "%s", fpname);
warn("%s", fpname);
error_out:
ChangeRulesAmount(rules_at_start);
return false;
@ -258,7 +255,7 @@ bool AddManifestPath(const char* path)
char** new_manifest = (char**) realloc(manifest, new_size);
if ( !new_manifest )
{
error(0, errno, "malloc");
warn("malloc");
return false;
}
manifest = new_manifest;
@ -267,7 +264,7 @@ bool AddManifestPath(const char* path)
char* copy = strdup(path);
if ( !copy )
{
error(0, errno, "malloc");
warn("malloc");
return false;
}
manifest[manifest_used++] = copy;
@ -289,7 +286,7 @@ bool AddManifestFromFile(FILE* fp, const char* fpname)
free(line);
if ( ferror(fp) )
{
error(0, errno, "%s", fpname);
warn("%s", fpname);
return false;
}
if ( !AddManifestPath("/") ||
@ -299,7 +296,7 @@ bool AddManifestFromFile(FILE* fp, const char* fpname)
char* fpname_copy = strdup(fpname);
if ( !fpname_copy )
{
error(0, errno, "malloc");
warn("malloc");
return false;
}
const char* fpname_basename = basename(fpname_copy);
@ -307,7 +304,7 @@ bool AddManifestFromFile(FILE* fp, const char* fpname)
if ( asprintf(&manifest_path, "/tix/manifest/%s", fpname_basename) < 0 )
{
free(fpname_copy);
error(0, errno, "malloc");
warn("malloc");
return false;
}
free(fpname_copy);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2015, 2016 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
@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
@ -129,7 +129,7 @@ int main(int argc, char* argv[])
const char* input_srctix_path = argv[1];
if ( !IsDirectory(input_srctix_path) )
error(1, errno, "`%s'", input_srctix_path);
err(1, "`%s'", input_srctix_path);
char* tixbuildinfo_path = print_string("%s/tixbuildinfo", input_srctix_path);
@ -139,7 +139,7 @@ int main(int argc, char* argv[])
if ( errno == ENOENT )
fprintf(stderr, "%s: `%s' doesn't appear to be a source tix:\n",
argv0, input_srctix_path);
error(1, errno, "`%s'", tixbuildinfo_path);
err(1, "`%s'", tixbuildinfo_path);
}
const char* package_name = strdup(dictionary_get(&package_info, "pkg.name"));
@ -147,11 +147,7 @@ int main(int argc, char* argv[])
if ( !output )
output = print_string("%s/%s.porttix.tar.xz", output_directory, package_name);
char* tmp_root = print_string("%s/porttix.XXXXXX", tmp);
if ( !mkdtemp(tmp_root) )
error(1, errno, "mkdtemp: `%s'", tmp_root);
on_exit(cleanup_file_or_directory, tmp_root);
initialize_tmp(tmp, "porttix");
const char* tarball_basename = non_modify_basename(input_tarball_path);
@ -160,21 +156,21 @@ int main(int argc, char* argv[])
char* porttix_path = print_string("%s/%s", tmp_root, package_name);
if ( mkdir_p(porttix_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", porttix_path);
err(1, "mkdir: `%s'", porttix_path);
char* srctix_path = print_string("%s/%s", tmp_root, rel_srctix_path);
if ( mkdir_p(srctix_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", srctix_path);
err(1, "mkdir: `%s'", srctix_path);
char* normalized_path = print_string("%s/%s", tmp_root, rel_normalized_path);
if ( mkdir_p(normalized_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", normalized_path);
err(1, "mkdir: `%s'", normalized_path);
// Create the porttixinfo file.
char* porttixinfo_path = join_paths(porttix_path, "porttixinfo");
FILE* porttixinfo_fp = fopen(porttixinfo_path, "w");
if ( !porttixinfo_fp )
error(1, errno, "`%s'", porttixinfo_path);
err(1, "`%s'", porttixinfo_path);
fprintf(porttixinfo_fp, "package_name %s\n", package_name);
// Copy the input source tix to the temporary root.
@ -191,7 +187,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
// If no tarball exists, then package up the source directory!
@ -203,7 +199,7 @@ int main(int argc, char* argv[])
char* work_dir = dirname(strdup(srctix_path));
char* subdir_name = dirname(strdup(srctix_path));
if ( chdir(work_dir) != 0 )
error(1, errno, "chdir: `%s'", work_dir);
err(1, "chdir: `%s'", work_dir);
const char* cmd_argv[] =
{
"tar",
@ -216,7 +212,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
}
@ -236,7 +232,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
}
@ -255,7 +251,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
}
@ -272,23 +268,23 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
fprintf(porttixinfo_fp, "tar_extract %s\n", tarball_basename);
// Create the normalization patch.
int normalized_fd = open(normalized_path, O_RDONLY | O_DIRECTORY);
if ( normalized_fd < 0 )
error(1, errno, "`%s'", normalized_path);
err(1, "`%s'", normalized_path);
char* patch_normalize_path = join_paths(porttix_path, "patch.normalize");
FILE* patch_normalize_fp = fopen(patch_normalize_path, "w");
if ( !patch_normalize_fp )
error(1, errno, "`%s'", patch_normalize_path);
err(1, "`%s'", patch_normalize_path);
int pipes[2];
if ( pipe(pipes) )
error(1, errno, "pipe");
err(1, "pipe");
pid_t tar_pid = fork_or_death();
if ( !tar_pid )
{
@ -304,7 +300,7 @@ int main(int argc, char* argv[])
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
close(pipes[1]);
FILE* tar_fp = fdopen(pipes[0], "r");
@ -337,14 +333,14 @@ int main(int argc, char* argv[])
}
free(line);
if ( ferror(tar_fp) )
error(1, errno, "getline: tar");
err(1, "getline: tar");
fclose(tar_fp);
int tar_exit_status;
waitpid(tar_pid, &tar_exit_status, 0);
if ( !WIFEXITED(tar_exit_status) || WEXITSTATUS(tar_exit_status) != 0 )
{
error(1, 0, "Unable to list contents of `%s'.", porttix_tarball_path);
errx(1, "Unable to list contents of `%s'.", porttix_tarball_path);
exit(WEXITSTATUS(tar_exit_status));
}
@ -360,9 +356,9 @@ int main(int argc, char* argv[])
{
close(1);
if ( open(patch_path, O_WRONLY | O_CREAT | O_TRUNC, 0644) != 1 )
error(1, errno, "`%s'", patch_path);
err(1, "`%s'", patch_path);
if ( chdir(tmp_root) != 0 )
error(1, errno, "chdir(`%s')", tmp_root);
err(1, "chdir(`%s')", tmp_root);
const char* cmd_argv[] =
{
"diff",
@ -374,7 +370,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(patch_path);
fprintf(porttixinfo_fp, "apply_patch patch.patch\n");
@ -384,9 +380,9 @@ int main(int argc, char* argv[])
if ( fork_and_wait_or_death_def(false) )
{
if ( redirect(patch_exec_path, O_WRONLY | O_CREAT | O_TRUNC, 0644) != 0 )
error(1, errno, "`%s'", patch_exec_path);
err(1, "`%s'", patch_exec_path);
if ( chdir(tmp_root) != 0 )
error(1, errno, "chdir(`%s')", tmp_root);
err(1, "chdir(`%s')", tmp_root);
const char* cmd_argv[] =
{
"tix-execdiff",
@ -396,7 +392,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(patch_exec_path);
fprintf(porttixinfo_fp, "apply_execpatch patch.execpatch\n");
@ -420,7 +416,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
return 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2015, 2016 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
@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
@ -105,17 +105,18 @@ int main(int argc, char* argv[])
compact_arguments(&argc, &argv);
if ( argc <= 1 )
error(1, 0, "No archived port tix specified");
errx(1, "No archived port tix specified");
if ( 3 <= argc )
error(1, 0, "extra operand");
errx(1, "extra operand");
initialize_tmp(tmp, "srctix");
const char* porttix_path = argv[1];
char* tmp_in_root = print_string("%s/srctixin.XXXXXX", tmp);
if ( !mkdtemp(tmp_in_root) )
error(1, errno, "mkdtemp: `%s'", tmp_in_root);
on_exit(cleanup_file_or_directory, tmp_in_root);
char* tmp_in_root = print_string("%s/in", tmp_root);
if ( mkdir(tmp_in_root, 0777) < 0 )
err(1, "mkdir: %s", tmp_in_root);
if ( fork_and_wait_or_death() )
{
@ -129,7 +130,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
char* porttixinfo_path = join_paths(tmp_in_root, "porttixinfo");
@ -137,15 +138,14 @@ int main(int argc, char* argv[])
if ( !porttixinfo_fp )
{
if ( errno == ENOENT )
error(0, 0, "`%s' doesn't appear to be an archived port tix",
porttix_path);
error(1, errno, "`%s'", porttixinfo_path);
warnx("`%s' doesn't appear to be an archived port tix",
porttix_path);
err(1, "`%s'", porttixinfo_path);
}
char* tmp_out_root = print_string("%s/srctixout.XXXXXX", tmp);
if ( !mkdtemp(tmp_out_root) )
error(1, errno, "mkdtemp: `%s'", tmp_out_root);
on_exit(cleanup_file_or_directory, tmp_out_root);
char* tmp_out_root = print_string("%s/out", tmp_root);
if ( mkdir(tmp_out_root, 0777) < 0 )
err(1, "mkdir: %s", tmp_out_root);
char* package_name = NULL;
char* srctix_path = NULL;
@ -159,8 +159,7 @@ int main(int argc, char* argv[])
line[--line_len] = '\0';
char* first_space = strchr(line, ' ');
if ( !first_space )
error(1, errno, "`%s`: malformed line `%s'",
porttixinfo_path, line);
err(1, "`%s`: malformed line `%s'", porttixinfo_path, line);
*first_space = '\0';
const char* function = line;
const char* parameter = first_space + 1;
@ -168,23 +167,23 @@ int main(int argc, char* argv[])
if ( !strcmp(function, "package_name") )
{
if ( package_name )
error(1, errno, "`%s`: unexpected additional package name `%s'",
porttixinfo_path, parameter);
err(1, "`%s`: unexpected additional package name `%s'",
porttixinfo_path, parameter);
if ( !is_file_name(parameter) )
error(1, errno, "`%s`: malformed package name `%s'",
porttixinfo_path, parameter);
err(1, "`%s`: malformed package name `%s'",
porttixinfo_path, parameter);
package_name = strdup(parameter);
srctix_path = join_paths(tmp_out_root, package_name);
if ( mkdir_p(srctix_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", srctix_path);
err(1, "mkdir: `%s'", srctix_path);
}
else if ( !package_name )
error(1, errno, "`%s`: expected package name before `%s'",
err(1, "`%s`: expected package name before `%s'",
porttixinfo_path, function);
else if ( !strcmp(function, "tar_extract") )
{
if ( !is_file_name(parameter) )
error(1, errno, "`%s`: malformed tarball filename `%s'",
err(1, "`%s`: malformed tarball filename `%s'",
porttixinfo_path, parameter);
char* tarball_path = join_paths(tmp_in_root, parameter);
if ( fork_and_wait_or_death() )
@ -199,15 +198,15 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(tarball_path);
}
else if ( !strcmp(function, "apply_normalize") )
{
if ( !is_file_name(parameter) )
error(1, errno, "`%s`: malformed normalize filename `%s'",
porttixinfo_path, parameter);
err(1, "`%s`: malformed normalize filename `%s'",
porttixinfo_path, parameter);
char* rmpatch_path = join_paths(tmp_in_root, parameter);
if ( fork_and_wait_or_death() )
{
@ -220,15 +219,15 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(rmpatch_path);
}
else if ( !strcmp(function, "apply_patch") )
{
if ( !is_file_name(parameter) )
error(1, errno, "`%s`: malformed patch filename `%s'",
porttixinfo_path, parameter);
err(1, "`%s`: malformed patch filename `%s'",
porttixinfo_path, parameter);
char* patch_path = join_paths(tmp_in_root, parameter);
if ( fork_and_wait_or_death() )
{
@ -242,15 +241,15 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(patch_path);
}
else if ( !strcmp(function, "apply_execpatch") )
{
if ( !is_file_name(parameter) )
error(1, errno, "`%s`: malformed execpatch filename `%s'",
porttixinfo_path, parameter);
err(1, "`%s`: malformed execpatch filename `%s'",
porttixinfo_path, parameter);
char* execpatch_path = join_paths(tmp_in_root, parameter);
if ( fork_and_wait_or_death() )
{
@ -263,17 +262,17 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(execpatch_path);
}
else
error(1, errno, "`%s`: unsupported function `%s'",
porttixinfo_path, function);
err(1, "`%s`: unsupported function `%s'",
porttixinfo_path, function);
}
free(line);
if ( ferror(porttixinfo_fp) )
error(1, errno, "%s", porttixinfo_path);
err(1, "%s", porttixinfo_path);
fclose(porttixinfo_fp);
free(porttixinfo_path);
@ -295,7 +294,7 @@ int main(int argc, char* argv[])
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(srctix_path);

View File

@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
@ -115,7 +115,7 @@ bool has_in_path(const char* program)
{
pid_t child_pid = fork();
if ( child_pid < 0 )
error(1, errno, "fork: which %s", program);
err(1, "fork: which %s", program);
if ( child_pid )
{
int exitstatus;
@ -157,7 +157,7 @@ void emit_compiler_warning_wrapper(metainfo_t* minfo,
char* wrapper_path = print_string("%s/%s", bindir, name);
FILE* wrapper = fopen(wrapper_path, "w");
if ( !wrapper )
error(1, errno, "`%s'", wrapper_path);
err(1, "`%s'", wrapper_path);
// TODO: Find a portable shell way of doing this.
fprintf(wrapper, "#!/bin/bash\n");
fprint_shell_variable_assignment(wrapper, "PATH", getenv("PATH"));
@ -207,7 +207,7 @@ void emit_compiler_sysroot_wrapper(metainfo_t* minfo,
char* wrapper_path = print_string("%s/%s", bindir, name);
FILE* wrapper = fopen(wrapper_path, "w");
if ( !wrapper )
error(1, errno, "`%s'", wrapper_path);
err(1, "`%s'", wrapper_path);
fprint_shell_variable_assignment(wrapper, "PATH", getenv("PATH"));
if ( minfo->sysroot )
fprint_shell_variable_assignment(wrapper, "SYSROOT", minfo->sysroot);
@ -232,17 +232,15 @@ void emit_compiler_sysroot_cross_wrapper(metainfo_t* minfo,
void emit_pkg_config_wrapper(metainfo_t* minfo)
{
char* bindir = print_string("%s/bin.XXXXXX", minfo->tmp);
if ( !mkdtemp(bindir) )
error(1, errno, "mkdtemp: `%s'", bindir);
on_exit(cleanup_file_or_directory, strdup(bindir));
char* bindir = print_string("%s/bin", tmp_root);
if ( mkdir(bindir, 0777) < 0 )
err(1, "mkdir: %s", bindir);
// Create a pkg-config script for the build system.
char* pkg_config_for_build_path = print_string("%s/build-pkg-config", bindir);
FILE* pkg_config_for_build = fopen(pkg_config_for_build_path, "w");
if ( !pkg_config_for_build )
error(1, errno, "`%s'", pkg_config_for_build_path);
err(1, "`%s'", pkg_config_for_build_path);
fprintf(pkg_config_for_build, "#!/bin/sh\n");
fprint_shell_variable_assignment(pkg_config_for_build, "PATH", getenv("PATH"));
fprint_shell_variable_assignment(pkg_config_for_build, "PKG_CONFIG", getenv("PKG_CONFIG"));
@ -260,7 +258,7 @@ void emit_pkg_config_wrapper(metainfo_t* minfo)
char* pkg_config_path = print_string("%s/pkg-config", bindir);
FILE* pkg_config = fopen(pkg_config_path, "w");
if ( !pkg_config )
error(1, errno, "`%s'", pkg_config_path);
err(1, "`%s'", pkg_config_path);
fprintf(pkg_config, "#!/bin/sh\n");
fprint_shell_variable_assignment(pkg_config, "PATH", getenv("PATH"));
fprint_shell_variable_assignment(pkg_config, "PKG_CONFIG", getenv("PKG_CONFIG"));
@ -298,7 +296,7 @@ void emit_pkg_config_wrapper(metainfo_t* minfo)
}
else
{
error(1, errno, "mkdir: `%s': compiler warnings won't be saved", warnings_dir);
err(1, "mkdir: `%s': compiler warnings won't be saved", warnings_dir);
unsetenv("TIX_WARNINGS_DIR");
}
free(warnings_dir);
@ -422,9 +420,9 @@ void Configure(metainfo_t* minfo, const char* subdir)
parse_boolean(dictionary_get_def(pkg_info, "pkg.configure.with-build-sysroot",
"false"));
if ( chdir(minfo->build_dir) != 0 )
error(1, errno, "chdir: `%s'", minfo->build_dir);
err(1, "chdir: `%s'", minfo->build_dir);
if ( subdir && chdir(subdir) != 0 )
error(1, errno, "chdir: `%s/%s'", minfo->build_dir, subdir);
err(1, "chdir: `%s/%s'", minfo->build_dir, subdir);
SetNeededVariables(minfo);
string_array_t env_vars = string_array_make();
string_array_append_token_string(&env_vars, conf_extra_vars);
@ -482,7 +480,7 @@ void Configure(metainfo_t* minfo, const char* subdir)
string_array_append_token_string(&args, conf_extra_args);
string_array_append(&args, NULL);
recovery_execvp(args.strings[0], (char* const*) args.strings);
error(127, errno, "`%s'", args.strings[0]);
err(127, "`%s'", args.strings[0]);
}
}
@ -494,7 +492,7 @@ bool TestDirty(metainfo_t* minfo,
subdir = ".";
char* path;
if ( asprintf(&path, "%s/%s/%s", minfo->build_dir, subdir, candidate) < 0 )
error(1, errno, "asprintf");
err(1, "asprintf");
bool result = access(path, F_OK) == 0;
free(path);
return result;
@ -529,9 +527,9 @@ void Make(metainfo_t* minfo, const char* make_target, const char* destdir,
}
SetNeededVariables(minfo);
if ( chdir(minfo->build_dir) != 0 )
error(1, errno, "chdir: `%s'", minfo->build_dir);
err(1, "chdir: `%s'", minfo->build_dir);
if ( subdir && chdir(subdir) != 0 )
error(1, errno, "chdir: `%s/%s'", minfo->build_dir, subdir);
err(1, "chdir: `%s/%s'", minfo->build_dir, subdir);
if ( destdir )
setenv("DESTDIR", destdir, 1);
setenv("BUILD", minfo->build, 1);
@ -582,7 +580,7 @@ void Make(metainfo_t* minfo, const char* make_target, const char* destdir,
recovery_execvp(args.strings[0], (char* const*) args.strings);
else
execvp(args.strings[0], (char* const*) args.strings);
error(127, errno, "`%s'", args.strings[0]);
err(127, "`%s'", args.strings[0]);
}
}
@ -599,10 +597,9 @@ void BuildPackage(metainfo_t* minfo)
bool use_build_dir = parse_boolean(use_build_dir_var);
if ( use_build_dir )
{
minfo->build_dir = print_string("%s/build.XXXXXX", minfo->tmp);
if ( !mkdtemp(minfo->build_dir) )
error(1, errno, "mkdtemp: `%s'", minfo->build_dir);
on_exit(cleanup_file_or_directory, strdup(minfo->build_dir));
minfo->build_dir = print_string("%s/build", tmp_root);
if ( mkdir(minfo->build_dir, 0777) < 0 )
err(1, "mkdir %s", minfo->build_dir);
}
else
minfo->build_dir = strdup(minfo->package_dir);
@ -635,30 +632,29 @@ void BuildPackage(metainfo_t* minfo)
const char* install_target = dictionary_get_def(pinfo, "pkg.make.install-target", "install");
if ( !location_independent && !minfo->prefix )
error(1, 0, "error: %s is not location independent and you need to "
"specify the intended destination prefix using --prefix",
minfo->package_name);
errx(1, "error: %s is not location independent and you need to "
"specify the intended destination prefix using --prefix",
minfo->package_name);
if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_BUILD, minfo) )
Make(minfo, build_target, NULL, true, subdir);
char* tardir_rel = print_string("%s/%s", minfo->tmp, "tix.XXXXXX");
if ( !mkdtemp(tardir_rel) )
error(1, errno, "mkdtemp: `%s'", tardir_rel);
on_exit(cleanup_file_or_directory, strdup(tardir_rel));
char* tardir_rel = print_string("%s/%s", tmp_root, "tix");
if ( mkdir(tardir_rel, 0777) < 0 )
err(1, "mkdir: %s", tardir_rel);
char* destdir_rel = print_string("%s/%s", tardir_rel, "data");
char* tixdir_rel = print_string("%s/%s", tardir_rel, "tix");
char* tixinfo_rel = print_string("%s/%s", tardir_rel, "tix/tixinfo");
if ( mkdir(destdir_rel, 0755) != 0 )
error(1, errno, "mkdir: `%s'", destdir_rel);
err(1, "mkdir: `%s'", destdir_rel);
if ( mkdir(tixdir_rel, 0755) != 0 )
error(1, errno, "mkdir: `%s'", tixdir_rel);
err(1, "mkdir: `%s'", tixdir_rel);
char* destdir = canonicalize_file_name(destdir_rel);
char* destdir = realpath(destdir_rel, NULL);
if ( !destdir )
error(1, errno, "canonicalize_file_name: `%s'", destdir_rel);
err(1, "realpath: %s", destdir_rel);
if ( SHOULD_DO_BUILD_STEP(BUILD_STEP_INSTALL, minfo) )
Make(minfo, install_target, destdir, true, subdir);
@ -670,7 +666,7 @@ void BuildPackage(metainfo_t* minfo)
fork_and_wait_or_recovery() )
{
if ( chdir(minfo->package_dir) != 0 )
error(1, errno, "chdir: `%s'", minfo->package_dir);
err(1, "chdir: `%s'", minfo->package_dir);
setenv("TIX_BUILD_DIR", minfo->build_dir, 1);
setenv("TIX_SOURCE_DIR", minfo->package_dir, 1);
setenv("TIX_INSTALL_DIR", destdir, 1);
@ -695,7 +691,7 @@ void BuildPackage(metainfo_t* minfo)
NULL
};
recovery_execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
const char* tix_ext = ".tix.tar.xz";
@ -704,7 +700,7 @@ void BuildPackage(metainfo_t* minfo)
FILE* tixinfo_fp = fopen(tixinfo_rel, "w");
if ( !tixinfo_fp )
error(1, errno, "`%s'", tixinfo_rel);
err(1, "`%s'", tixinfo_rel);
const char* runtime_deps = dictionary_get(pinfo, "pkg.runtime-deps");
@ -720,7 +716,7 @@ void BuildPackage(metainfo_t* minfo)
fprintf(tixinfo_fp, "pkg.prefix=%s\n", minfo->prefix);
if ( ferror(tixinfo_fp) )
error(1, errno, "write: `%s'", tixinfo_rel);
err(1, "write: `%s'", tixinfo_rel);
fclose(tixinfo_fp);
@ -745,7 +741,7 @@ void BuildPackage(metainfo_t* minfo)
NULL
};
recovery_execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
}
@ -772,15 +768,15 @@ void VerifySourceTixInformation(metainfo_t* minfo)
string_array_t* pinfo = &minfo->package_info;
const char* tix_version = VerifyInfoVariable(pinfo, "tix.version", pipath);
if ( atoi(tix_version) != 1 )
error(1, 0, "error: `%s': tix version `%s' not supported", pipath,
tix_version);
errx(1, "error: `%s': tix version `%s' not supported", pipath,
tix_version);
const char* tix_class = VerifyInfoVariable(pinfo, "tix.class", pipath);
if ( !strcmp(tix_class, "tix") )
error(1, 0, "error: `%s': this object is a binary tix and is already "
"compiled.\n", pipath);
errx(1, "error: `%s': this object is a binary tix and is already "
"compiled.\n", pipath);
if ( strcmp(tix_class, "srctix") )
error(1, 0, "error: `%s': tix class `%s' is not `srctix': this object "
"is not suitable for compilation.", pipath, tix_class);
errx(1, "error: `%s': tix class `%s' is not `srctix': this object "
"is not suitable for compilation.", pipath, tix_class);
VerifyInfoVariable(pinfo, "pkg.name", pipath);
VerifyInfoVariable(pinfo, "pkg.build-system", pipath);
}
@ -847,7 +843,7 @@ int main(int argc, char* argv[])
minfo.sysroot = NULL;
minfo.target = NULL;
minfo.tar = strdup("tar");
minfo.tmp = strdup(getenv_def("TMPDIR", "/tmp"));
char* tmp = strdup(getenv_def("TMPDIR", "/tmp"));
char* start_step_string = strdup("start");
char* end_step_string = strdup("end");
@ -935,9 +931,11 @@ int main(int argc, char* argv[])
exit(1);
}
minfo.package_dir = canonicalize_file_name(argv[1]);
initialize_tmp(tmp, "tixbuild");
minfo.package_dir = realpath(argv[1], NULL);
if ( !minfo.package_dir )
error(1, errno, "canonicalize_file_name: `%s'", argv[1]);
err(1, "realpath: %s", argv[1]);
if ( minfo.build && !minfo.build[0] )
free(minfo.build), minfo.build = NULL;
@ -947,7 +945,7 @@ int main(int argc, char* argv[])
free(minfo.target), minfo.target = NULL;
if ( !minfo.build && !(minfo.build = GetBuildTriplet()) )
error(1, errno, "unable to determine build, use --build");
err(1, "unable to determine build, use --build");
if ( !minfo.host )
minfo.host = strdup(minfo.build);
if ( !minfo.target )
@ -957,7 +955,7 @@ int main(int argc, char* argv[])
minfo.exec_prefix = strdup(minfo.prefix);
if ( !IsDirectory(minfo.package_dir) )
error(1, errno, "`%s'", minfo.package_dir);
err(1, "`%s'", minfo.package_dir);
minfo.package_info_path = print_string("%s/tixbuildinfo",
minfo.package_dir);
@ -967,9 +965,8 @@ int main(int argc, char* argv[])
if ( !dictionary_append_file_path(package_info, minfo.package_info_path) )
{
if ( errno == ENOENT )
fprintf(stderr, "%s: `%s' doesn't appear to be a source .tix:\n",
argv0, minfo.package_dir);
error(1, errno, "`%s'", minfo.package_info_path);
warnx("`%s' doesn't appear to be a source .tix", minfo.package_dir);
err(1, "`%s'", minfo.package_info_path);
}
VerifySourceTixInformation(&minfo);

View File

@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
@ -117,7 +117,7 @@ int main(int argc, char* argv[])
if ( argc == 1 )
{
error(0, 0, "error: no command specified.");
warnx("error: no command specified.");
exit(1);
}
@ -125,30 +125,30 @@ int main(int argc, char* argv[])
if ( !strcmp(cmd, "create") )
{
if ( !platform && !(platform = GetBuildTriplet()) )
error(1, errno, "unable to determine platform, use --platform");
err(1, "unable to determine platform, use --platform");
char* tix_path = join_paths(collection, "tix");
if ( mkdir_p(tix_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", tix_path);
err(1, "mkdir: `%s'", tix_path);
char* tixdb_path = strdup(tix_path);
char* tixinfo_path = join_paths(tixdb_path, "tixinfo");
if ( mkdir_p(tixinfo_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", tixinfo_path);
err(1, "mkdir: `%s'", tixinfo_path);
free(tixinfo_path);
char* manifest_path = join_paths(tixdb_path, "manifest");
if ( mkdir_p(manifest_path, 0755) != 0 )
error(1, errno, "mkdir: `%s'", manifest_path);
err(1, "mkdir: `%s'", manifest_path);
free(manifest_path);
char* collection_conf_path = join_paths(tixdb_path, "collection.conf");
FILE* conf_fp = fopen(collection_conf_path, "wx");
if ( !conf_fp && errno == EEXIST )
error(1, 0, "error: `%s' already exists, a tix collection is "
"already installed at `%s'.", collection_conf_path,
collection);
errx(1, "error: `%s' already exists, a tix collection is "
"already installed at `%s'.", collection_conf_path,
collection);
fprintf(conf_fp, "tix.version=1\n");
fprintf(conf_fp, "tix.class=collection\n");
fprintf(conf_fp, "collection.generation=%i\n", generation);
@ -161,13 +161,13 @@ int main(int argc, char* argv[])
const char* repo_list_path = join_paths(tixdb_path, "repository.list");
FILE* repo_list_fp = fopen(repo_list_path, "w");
if ( !repo_list_fp )
error(1, errno, "`%s'", repo_list_path);
err(1, "`%s'", repo_list_path);
fclose(repo_list_fp);
const char* inst_list_path = join_paths(tixdb_path, "installed.list");
FILE* inst_list_fp = fopen(inst_list_path, "w");
if ( !inst_list_fp )
error(1, errno, "`%s'", inst_list_path);
err(1, "`%s'", inst_list_path);
fclose(inst_list_fp);
return 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2016 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
@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
@ -71,7 +71,7 @@ void execdiff(int tree_a, const char* tree_a_path,
{
DIR* dir_b = fdopendupdir(tree_b);
if ( !dir_b )
error(1, errno, "fdopendupdir(`%s`)", tree_b_path);
err(1, "fdopendupdir(`%s`)", tree_b_path);
struct dirent* entry;
while ( (entry = readdir(dir_b)) )
{
@ -89,7 +89,7 @@ void execdiff(int tree_a, const char* tree_a_path,
if ( subtree_a < 0 )
{
if ( !(errno == ENOTDIR || errno == ELOOP || errno == ENOENT) )
error(1, errno, "`%s/%s`", tree_b_path, entry->d_name);
err(1, "`%s/%s`", tree_b_path, entry->d_name);
execdiff(-1, NULL, subtree_b, subtree_b_path, subrelpath);
free(subtree_b_path);
close(subtree_b);
@ -107,7 +107,7 @@ void execdiff(int tree_a, const char* tree_a_path,
continue;
}
else if ( !(errno == ENOTDIR || errno == ELOOP) )
error(1, errno, "`%s/%s`", tree_b_path, entry->d_name);
err(1, "`%s/%s`", tree_b_path, entry->d_name);
int a_executableness = ftestexecutableat(tree_a, entry->d_name);
int b_executableness = ftestexecutableat(tree_b, entry->d_name);
@ -194,20 +194,20 @@ int main(int argc, char* argv[])
compact_arguments(&argc, &argv);
if ( argc < 3 )
error(1, 0, "You need to specify two directories");
errx(1, "You need to specify two directories");
if ( 3 < argc )
error(1, 0, "extra operand");
errx(1, "extra operand");
const char* tree_a_path = argv[1];
int tree_a = open(tree_a_path, O_RDONLY | O_DIRECTORY);
if ( tree_a < 0 )
error(1, errno, "`%s'", tree_a_path);
err(1, "`%s'", tree_a_path);
const char* tree_b_path = argv[2];
int tree_b = open(tree_b_path, O_RDONLY | O_DIRECTORY);
if ( tree_b < 0 )
error(1, errno, "`%s'", tree_b_path);
err(1, "`%s'", tree_b_path);
execdiff(tree_a, tree_a_path, tree_b, tree_b_path, ".");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2016 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
@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
@ -48,7 +48,7 @@ int fgetc_or_die(FILE* input, const char* input_path, size_t* line,
else
(*column)++;
if ( result == EOF && ferror(input) )
error(1, errno, "read: `%s'", input_path);
err(1, "read: `%s'", input_path);
return result;
}
@ -57,8 +57,8 @@ int fgetc_or_die_eof(FILE* input, const char* input_path, size_t* line,
{
int result = fgetc_or_die(input, input_path, line, column);
if ( result == EOF )
error(1, errno, "%s:%zu:%zu: unexpected end of file",
input_path, *line, *column);
errx(1, "%s:%zu:%zu: unexpected end of file",
input_path, *line, *column);
return result;
}
@ -82,11 +82,11 @@ void parse_fixed(const char* text, FILE* input, const char* input_path,
{
int ic = fgetc_or_die(input, input_path, line, column);
if ( ic == EOF )
error(1, errno, "%s:%zu:%zu: unexpected end of file, expected `%s'",
input_path, *line, *column, text + i);
errx(1, "%s:%zu:%zu: unexpected end of file, expected `%s'",
input_path, *line, *column, text + i);
if ( ic != (unsigned char) text[i] )
error(1, errno, "%s:%zu:%zu: parse error, expected `%s'", input_path,
*line, *column, text + i);
errx(1, "%s:%zu:%zu: parse error, expected `%s'", input_path,
*line, *column, text + i);
}
}
@ -109,9 +109,8 @@ bool execpatch(FILE* input, const char* input_path, bool check)
case '-': plus = false; break;
case '+': plus = true; break;
default:
error(1, errno, "%s:%zu:%zu: parse error, expected '-' or '+'",
input_path, line, column);
__builtin_unreachable();
errx(1, "%s:%zu:%zu: parse error, expected '-' or '+'",
input_path, line, column);
}
parse_fixed("x -- '", input, input_path, &line, &column);
while ( true )
@ -135,19 +134,19 @@ bool execpatch(FILE* input, const char* input_path, bool check)
buffer[buffer_used++] = ic;
}
if ( !buffer_used )
error(1, errno, "%s:%zu: unexpected empty path", input_path, line);
errx(1, "%s:%zu: unexpected empty path", input_path, line);
assert(buffer_length);
buffer[buffer_used] = '\0';
if ( buffer[0] == '/' )
error(1, errno, "%s:%zu: unexpected absolute path", input_path, line);
err(1, "%s:%zu: unexpected absolute path", input_path, line);
if ( does_path_contain_dotdot(buffer) )
error(1, errno, "%s:%zu: unexpected path with ..", input_path, line);
errx(1, "%s:%zu: unexpected path with ..", input_path, line);
if ( check )
continue;
struct stat st;
if ( fstatat(AT_FDCWD, buffer, &st, AT_SYMLINK_NOFOLLOW) != 0 )
{
error(0, errno, "chmod %cx: `%s'", plus ? '+' : '-', buffer);
warn("chmod %cx: `%s'", plus ? '+' : '-', buffer);
result = false;
continue;
}
@ -158,7 +157,7 @@ bool execpatch(FILE* input, const char* input_path, bool check)
new_mode &= ~0111;
if ( fchmodat(AT_FDCWD, buffer, new_mode, 0) != 0 )
{
error(0, errno, "chmod %cx: `%s'", plus ? '+' : '-', buffer);
warn("chmod %cx: `%s'", plus ? '+' : '-', buffer);
result = false;
continue;
}
@ -221,7 +220,7 @@ int main(int argc, char* argv[])
compact_arguments(&argc, &argv);
if ( 2 < argc )
error(1, 0, "extra operand");
errx(1, "extra operand");
const char* input_path = "<stdin>";
FILE* input = stdin;
@ -230,11 +229,11 @@ int main(int argc, char* argv[])
{
input_path = argv[1];
if ( !(input = fopen(input_path, "r")) )
error(1, errno, "`%s'", input_path);
err(1, "`%s'", input_path);
}
if ( directory && chdir(directory) != 0 )
error(1, errno, "chdir: `%s'", directory);
err(1, "chdir: `%s'", directory);
free(directory);
return execpatch(input, input_path, check) ? 0 : 1;

View File

@ -23,7 +23,7 @@
#include <assert.h>
#include <ctype.h>
#include <error.h>
#include <err.h>
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
@ -41,8 +41,8 @@
void TipTixCollection(const char* prefix)
{
error(0, 0, "error: `%s' isn't a tix collection, use \"tix-collection %s "
"create\" before " "installing packages.", prefix, prefix);
warnx("error: `%s' isn't a tix collection, use \"tix-collection %s "
"create\" before " "installing packages.", prefix, prefix);
}
void VerifyTixCollection(const char* prefix)
@ -51,7 +51,7 @@ void VerifyTixCollection(const char* prefix)
{
if ( errno == ENOENT )
TipTixCollection(prefix);
error(1, errno, "error: tix collection unavailable: `%s'", prefix);
err(1, "error: tix collection unavailable: `%s'", prefix);
}
}
@ -61,7 +61,7 @@ void VerifyTixDirectory(const char* prefix, const char* tix_dir)
{
if ( errno == ENOENT )
TipTixCollection(prefix);
error(1, errno, "error: tix database unavailable: `%s'", tix_dir);
err(1, "error: tix database unavailable: `%s'", tix_dir);
}
}
@ -69,23 +69,23 @@ void VerifyTixDatabase(const char* prefix,
const char* tixdb_path)
{
if ( !IsDirectory(tixdb_path) )
error(1, errno, "error: tix database unavailable: `%s'", tixdb_path);
err(1, "error: tix database unavailable: `%s'", tixdb_path);
char* info_path = join_paths(tixdb_path, "collection.conf");
if ( !IsFile(info_path) )
{
if ( errno == ENOENT )
TipTixCollection(prefix);
error(1, errno, "error: tix collection information unavailable: `%s'",
info_path);
err(1, "error: tix collection information unavailable: `%s'",
info_path);
}
char* installed_list_path = join_paths(tixdb_path, "installed.list");
FILE* installed_list_fp = fopen(installed_list_path, "a");
if ( !installed_list_fp )
{
error(0, errno, "error: unable to open `%s' for writing",
installed_list_path);
error(1, 0, "error: `%s': do you have sufficient permissions to "
"administer this tix collection?", prefix);
warn("error: unable to open `%s' for writing",
installed_list_path);
errx(1, "error: `%s': do you have sufficient permissions to "
"administer this tix collection?", prefix);
}
fclose(installed_list_fp);
free(installed_list_path);
@ -97,7 +97,7 @@ bool IsPackageInstalled(const char* tixdb_path, const char* package)
char* installed_list_path = join_paths(tixdb_path, "installed.list");
FILE* installed_list_fp = fopen(installed_list_path, "r");
if ( !installed_list_fp )
error(1, errno, "`%s'", installed_list_path);
err(1, "`%s'", installed_list_path);
bool ret = false;
char* line = NULL;
@ -115,7 +115,7 @@ bool IsPackageInstalled(const char* tixdb_path, const char* package)
}
free(line);
if ( ferror(installed_list_fp) )
error(1, errno, "`%s'", installed_list_path);
err(1, "`%s'", installed_list_path);
fclose(installed_list_fp);
free(installed_list_path);
@ -127,13 +127,13 @@ void MarkPackageAsInstalled(const char* tixdb_path, const char* package)
char* installed_list_path = join_paths(tixdb_path, "installed.list");
FILE* installed_list_fp = fopen(installed_list_path, "a");
if ( !installed_list_fp )
error(1, errno, "`%s'", installed_list_path);
err(1, "`%s'", installed_list_path);
fprintf(installed_list_fp, "%s\n", package);
fflush(installed_list_fp);
if ( ferror(installed_list_fp) || fclose(installed_list_fp) == EOF )
error(1, errno, "`%s'", installed_list_path);
err(1, "`%s'", installed_list_path);
free(installed_list_path);
}
@ -225,7 +225,7 @@ int main(int argc, char* argv[])
char* coll_conf_path = join_paths(tix_directory_path, "collection.conf");
string_array_t coll_conf = string_array_make();
if ( !dictionary_append_file_path(&coll_conf, coll_conf_path) )
error(1, errno, "`%s'", coll_conf_path);
err(1, "`%s'", coll_conf_path);
VerifyTixCollectionConfiguration(&coll_conf, coll_conf_path);
free(coll_conf_path);
@ -257,11 +257,11 @@ static int strcmp_indirect(const void* a_ptr, const void* b_ptr)
void InstallPackage(const char* tix_path)
{
if ( !IsFile(tix_path) )
error(1, errno, "`%s'", tix_path);
err(1, "`%s'", tix_path);
const char* tixinfo_path = "tix/tixinfo";
if ( !TarContainsFile(tix_path, tixinfo_path) )
error(1, 0, "`%s' doesn't contain a `%s' file", tix_path, tixinfo_path);
errx(1, "`%s' doesn't contain a `%s' file", tix_path, tixinfo_path);
string_array_t tixinfo = string_array_make();
FILE* tixinfo_fp = TarOpenFile(tix_path, tixinfo_path);
@ -279,25 +279,25 @@ void InstallPackage(const char* tix_path)
bool already_installed = IsPackageInstalled(tix_directory_path, package_name);
if ( already_installed && !reinstall )
error(1, 0, "error: package `%s' is already installed. Use --reinstall "
"to force reinstallation.", package_name);
errx(1, "error: package `%s' is already installed. Use --reinstall "
"to force reinstallation.", package_name);
if ( package_prefix && strcmp(coll_prefix, package_prefix) != 0 )
{
error(0, errno, "error: `%s' is compiled with the prefix `%s', but the "
"destination collection has the prefix `%s'.", tix_path,
package_prefix, coll_prefix);
error(1, errno, "you need to recompile the package with "
warn("error: `%s' is compiled with the prefix `%s', but the "
"destination collection has the prefix `%s'.", tix_path,
package_prefix, coll_prefix);
err(1, "you need to recompile the package with "
"--prefix=\"%s\".", coll_prefix);
}
if ( package_platform && strcmp(coll_platform, package_platform) != 0 )
{
error(0, errno, "error: `%s' is compiled with the platform `%s', but "
warn("error: `%s' is compiled with the platform `%s', but "
"the destination collection has the platform `%s'.",
tix_path, package_platform, coll_platform);
error(1, errno, "you need to recompile the package with "
"--host=%s\".", coll_platform);
err(1, "you need to recompile the package with "
"--host=%s\".", coll_platform);
}
printf("Installing `%s' into `%s'...\n", package_name, collection);
@ -308,7 +308,7 @@ void InstallPackage(const char* tix_path)
char* tixinfo_out_path = print_string("%s/tixinfo/%s", tix_directory_path, package_name);
int tixinfo_fd = open(tixinfo_out_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if ( tixinfo_fd < 0 )
error(1, errno, "%s", tixinfo_out_path);
err(1, "%s", tixinfo_out_path);
TarExtractFileToFD(tix_path, "tix/tixinfo", tixinfo_fd);
close(tixinfo_fd);
@ -319,7 +319,7 @@ void InstallPackage(const char* tix_path)
char* manifest_path = print_string("%s/manifest/%s", tix_directory_path, package_name);
FILE* manifest_fp = fopen(manifest_path, "w");
if ( !manifest_fp )
error(1, errno, "%s", manifest_path);
err(1, "%s", manifest_path);
for ( size_t i = 0; i < files.length; i++ )
{
char* str = files.strings[i];
@ -332,10 +332,10 @@ void InstallPackage(const char* tix_path)
while ( 2 <= len && str[len-1] == '/' )
str[--len] = '\0';
if ( fprintf(manifest_fp, "%s\n", str) < 0 )
error(1, errno, "%s", manifest_path);
err(1, "%s", manifest_path);
}
if ( ferror(manifest_fp) || fflush(manifest_fp) == EOF )
error(1, errno, "%s", manifest_path);
err(1, "%s", manifest_path);
fclose(manifest_fp);
string_array_reset(&files);
fclose(index_fp);
@ -357,7 +357,7 @@ void InstallPackage(const char* tix_path)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
free(data_and_prefix);

View File

@ -24,8 +24,8 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
@ -48,7 +48,7 @@ int fgetc_or_die(FILE* input, const char* input_path, size_t* line,
else
(*column)++;
if ( result == EOF && ferror(input) )
error(1, errno, "read: `%s'", input_path);
err(1, "read: `%s'", input_path);
return result;
}
@ -57,8 +57,8 @@ int fgetc_or_die_eof(FILE* input, const char* input_path, size_t* line,
{
int result = fgetc_or_die(input, input_path, line, column);
if ( result == EOF )
error(1, errno, "%s:%zu:%zu: unexpected end of file",
input_path, *line, *column);
err(1, "%s:%zu:%zu: unexpected end of file",
input_path, *line, *column);
return result;
}
@ -82,11 +82,11 @@ void parse_fixed(const char* text, FILE* input, const char* input_path,
{
int ic = fgetc_or_die(input, input_path, line, column);
if ( ic == EOF )
error(1, errno, "%s:%zu:%zu: unexpected end of file, expected `%s'",
input_path, *line, *column, text + i);
err(1, "%s:%zu:%zu: unexpected end of file, expected `%s'",
input_path, *line, *column, text + i);
if ( ic != (unsigned char) text[i] )
error(1, errno, "%s:%zu:%zu: parse error, expected `%s'", input_path,
*line, *column, text + i);
err(1, "%s:%zu:%zu: parse error, expected `%s'", input_path,
*line, *column, text + i);
}
}
@ -124,13 +124,13 @@ bool rmpatch(FILE* input, const char* input_path, bool check)
buffer[buffer_used++] = ic;
}
if ( !buffer_used )
error(1, errno, "%s:%zu: unexpected empty path", input_path, line);
err(1, "%s:%zu: unexpected empty path", input_path, line);
assert(buffer_length);
buffer[buffer_used] = '\0';
if ( buffer[0] == '/' )
error(1, errno, "%s:%zu: unexpected absolute path", input_path, line);
err(1, "%s:%zu: unexpected absolute path", input_path, line);
if ( does_path_contain_dotdot(buffer) )
error(1, errno, "%s:%zu: unexpected path with ..", input_path, line);
err(1, "%s:%zu: unexpected path with ..", input_path, line);
if ( check )
continue;
pid_t child_pid;
@ -139,9 +139,9 @@ bool rmpatch(FILE* input, const char* input_path, bool check)
int status;
waitpid(child_pid, &status, 0);
if ( WIFSIGNALED(status) )
error(128 + WTERMSIG(status), 0, "child with pid %ju was killed by "
"signal %i (%s).", (uintmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
errx(128 + WTERMSIG(status), "child with pid %ji was killed by "
"signal %i (%s).", (intmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
if ( WIFEXITED(status) && WEXITSTATUS(status) != 0 )
result = false;
continue;
@ -155,7 +155,7 @@ bool rmpatch(FILE* input, const char* input_path, bool check)
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
return result;
}
@ -215,7 +215,7 @@ int main(int argc, char* argv[])
compact_arguments(&argc, &argv);
if ( 2 < argc )
error(1, 0, "extra operand");
errx(1, "extra operand");
const char* input_path = "<stdin>";
FILE* input = stdin;
@ -224,11 +224,11 @@ int main(int argc, char* argv[])
{
input_path = argv[1];
if ( !(input = fopen(input_path, "r")) )
error(1, errno, "`%s'", input_path);
err(1, "`%s'", input_path);
}
if ( directory && chdir(directory) != 0 )
error(1, errno, "chdir: `%s'", directory);
err(1, "chdir: `%s'", directory);
free(directory);
return rmpatch(input, input_path, check) ? 0 : 1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2013, 2015, 2016 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
@ -24,7 +24,7 @@
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <error.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@ -90,11 +90,11 @@ string_array_t GetPackageDependencies(params_t* params, const char* pkg_name)
char* pkg_path = FindPackage(params, &params->repo_list, pkg_name);
if ( !pkg_path )
error(1, errno, "unable to locate package `%s'", pkg_name);
err(1, "unable to locate package `%s'", pkg_name);
const char* tixinfo_path = "tix/tixinfo";
if ( !TarContainsFile(pkg_path, tixinfo_path) )
error(1, 0, "`%s' doesn't contain a `%s' file", pkg_path, tixinfo_path);
errx(1, "`%s' doesn't contain a `%s' file", pkg_path, tixinfo_path);
string_array_t tixinfo = string_array_make();
FILE* tixinfo_fp = TarOpenFile(pkg_path, tixinfo_path);
@ -134,7 +134,7 @@ void InstallPackageOfName(params_t* params, const char* pkg_name)
{
char* pkg_path = FindPackage(params, &params->repo_list, pkg_name);
if ( !pkg_path )
error(1, errno, "unable to locate package `%s'", pkg_name);
err(1, "unable to locate package `%s'", pkg_name);
if ( fork_and_wait_or_death() )
{
@ -146,7 +146,7 @@ void InstallPackageOfName(params_t* params, const char* pkg_name)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "`%s'", cmd_argv[0]);
err(127, "`%s'", cmd_argv[0]);
}
free(pkg_path);
@ -223,30 +223,30 @@ int main(int argc, char* argv[])
char* coll_conf_path = join_paths(params.tixdb_path, "collection.conf");
params.coll_conf = string_array_make();
if ( !dictionary_append_file_path(&params.coll_conf, coll_conf_path) )
error(1, errno, "`%s'", coll_conf_path);
err(1, "`%s'", coll_conf_path);
VerifyTixCollectionConfiguration(&params.coll_conf, coll_conf_path);
free(coll_conf_path);
char* repo_list_path = join_paths(params.tixdb_path, "repository.list");
params.repo_list = string_array_make();
if ( !string_array_append_file_path(&params.repo_list, repo_list_path) )
error(1, errno, "`%s'", repo_list_path);
err(1, "`%s'", repo_list_path);
free(repo_list_path);
char* inst_list_path = join_paths(params.tixdb_path, "installed.list");
params.inst_list = string_array_make();
if ( !string_array_append_file_path(&params.inst_list, inst_list_path) )
error(1, errno, "`%s'", inst_list_path);
err(1, "`%s'", inst_list_path);
free(inst_list_path);
if ( argc == 1 )
error(1, 0, "error: no command specified.");
errx(1, "error: no command specified.");
const char* cmd = argv[1];
if ( !strcmp(cmd, "install") )
{
if ( argc == 2 )
error(1, 0, "expected list of packages to install after `install'");
errx(1, "expected list of packages to install after `install'");
string_array_t work = string_array_make();

View File

@ -22,6 +22,8 @@
#define DEFAULT_GENERATION "2"
extern char** environ;
bool does_path_contain_dotdot(const char* path)
{
size_t index = 0;
@ -383,7 +385,7 @@ pid_t fork_or_death(void)
{
pid_t child_pid = fork();
if ( child_pid < 0 )
error(1, errno, "fork");
err(1, "fork");
return child_pid;
}
@ -396,9 +398,9 @@ void waitpid_or_death_def(pid_t child_pid, bool die_on_error)
if ( WIFEXITED(status) && WEXITSTATUS(status) != 0 )
exit(WEXITSTATUS(status));
if ( WIFSIGNALED(status) )
error(128 + WTERMSIG(status), 0, "child with pid %ju was killed by "
"signal %i (%s).", (uintmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
errx(128 + WTERMSIG(status), "child with pid %ji was killed by "
"signal %i (%s).", (intmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
}
}
@ -539,7 +541,7 @@ bool TarContainsFile(const char* archive, const char* file)
{
int pipes[2];
if ( pipe(pipes) )
error(1, errno, "pipe");
err(1, "pipe");
pid_t tar_pid = fork_or_death();
if ( !tar_pid )
{
@ -554,7 +556,7 @@ bool TarContainsFile(const char* archive, const char* file)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
err(127, "%s", cmd_argv[0]);
}
close(pipes[1]);
FILE* fp = fdopen(pipes[0], "r");
@ -578,7 +580,7 @@ bool TarContainsFile(const char* archive, const char* file)
}
free(line);
if ( ferror(fp) )
error(1, errno, "getline: tar");
err(1, "getline: tar");
fclose(fp);
int tar_exit_status;
@ -589,7 +591,7 @@ bool TarContainsFile(const char* archive, const char* file)
WEXITSTATUS(tar_exit_status) != 0;
if ( errored && !sigpiped )
{
error(1, 0, "Unable to list contents of `%s'.", archive);
errx(1, "Unable to list contents of `%s'.", archive);
exit(WEXITSTATUS(tar_exit_status));
}
return ret;
@ -602,7 +604,7 @@ void TarExtractFileToFD(const char* archive, const char* file, int fd)
{
if ( dup2(fd, 1) < 0 )
{
error(0, errno, "dup2");
warn("dup2");
_exit(127);
}
close(fd);
@ -616,14 +618,14 @@ void TarExtractFileToFD(const char* archive, const char* file, int fd)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(0, errno, "%s", cmd_argv[0]);
warn("%s", cmd_argv[0]);
_exit(127);
}
int tar_exit_status;
waitpid(tar_pid, &tar_exit_status, 0);
if ( !WIFEXITED(tar_exit_status) || WEXITSTATUS(tar_exit_status) != 0 )
{
error(1, 0, "Unable to extract `%s/%s'", archive, file);
errx(1, "Unable to extract `%s/%s'", archive, file);
exit(WEXITSTATUS(tar_exit_status));
}
}
@ -632,10 +634,10 @@ FILE* TarOpenFile(const char* archive, const char* file)
{
FILE* fp = tmpfile();
if ( !fp )
error(1, errno, "tmpfile");
err(1, "tmpfile");
TarExtractFileToFD(archive, file, fileno(fp));
if ( fseeko(fp, 0, SEEK_SET) < 0 )
error(1, errno, "fseeko(tmpfile(), 0, SEEK_SET)");
err(1, "fseeko(tmpfile(), 0, SEEK_SET)");
return fp;
}
@ -646,7 +648,7 @@ void TarIndexToFD(const char* archive, int fd)
{
if ( dup2(fd, 1) < 0 )
{
error(0, errno, "dup2");
warn("dup2");
_exit(127);
}
close(fd);
@ -658,14 +660,14 @@ void TarIndexToFD(const char* archive, int fd)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(0, errno, "%s", cmd_argv[0]);
warn("%s", cmd_argv[0]);
_exit(127);
}
int tar_exit_status;
waitpid(tar_pid, &tar_exit_status, 0);
if ( !WIFEXITED(tar_exit_status) || WEXITSTATUS(tar_exit_status) != 0 )
{
error(1, 0, "Unable to list contents of `%s'", archive);
errx(1, "Unable to list contents of `%s'", archive);
exit(WEXITSTATUS(tar_exit_status));
}
}
@ -674,10 +676,10 @@ FILE* TarOpenIndex(const char* archive)
{
FILE* fp = tmpfile();
if ( !fp )
error(1, errno, "tmpfile");
err(1, "tmpfile");
TarIndexToFD(archive, fileno(fp));
if ( fseeko(fp, 0, SEEK_SET) < 0 )
error(1, errno, "fseeko(tmpfile(), 0, SEEK_SET)");
err(1, "fseeko(tmpfile(), 0, SEEK_SET)");
return fp;
}
@ -686,7 +688,7 @@ const char* VerifyInfoVariable(string_array_t* info, const char* var,
{
const char* ret = dictionary_get(info, var);
if ( !ret )
error(1, 0, "error: `%s': no `%s' variable declared", path, var);
errx(1, "error: `%s': no `%s' variable declared", path, var);
return ret;
}
@ -694,25 +696,25 @@ void VerifyTixInformation(string_array_t* tixinfo, const char* tix_path)
{
const char* tix_version = dictionary_get(tixinfo, "tix.version");
if ( !tix_version )
error(1, 0, "error: `%s': no `tix.version' variable declared",
tix_path);
errx(1, "error: `%s': no `tix.version' variable declared",
tix_path);
if ( atoi(tix_version) != 1 )
error(1, 0, "error: `%s': tix version `%s' not supported", tix_path,
tix_version);
errx(1, "error: `%s': tix version `%s' not supported", tix_path,
tix_version);
const char* tix_class = dictionary_get(tixinfo, "tix.class");
if ( !tix_class )
error(1, 0, "error: `%s': no `tix.class' variable declared", tix_path);
errx(1, "error: `%s': no `tix.class' variable declared", tix_path);
if ( !strcmp(tix_class, "srctix") )
error(1, 0, "error: `%s': this object is a source tix and needs to be "
"compiled into a binary tix prior to installation.",
tix_path);
errx(1, "error: `%s': this object is a source tix and needs to be "
"compiled into a binary tix prior to installation.",
tix_path);
if ( strcmp(tix_class, "tix") )
error(1, 0, "error: `%s': tix class `%s' is not `tix': this object is "
"not suitable for installation.", tix_path, tix_class);
errx(1, "error: `%s': tix class `%s' is not `tix': this object is "
"not suitable for installation.", tix_path, tix_class);
if ( !(dictionary_get(tixinfo, "tix.platform")) )
error(1, 0, "error: `%s': no `tix.platform' variable declared", tix_path);
errx(1, "error: `%s': no `tix.platform' variable declared", tix_path);
if ( !(dictionary_get(tixinfo, "pkg.name")) )
error(1, 0, "error: `%s': no `pkg.name' variable declared", tix_path);
errx(1, "error: `%s': no `pkg.name' variable declared", tix_path);
}
bool IsCollectionPrefixRatherThanCommand(const char* arg)
@ -742,9 +744,9 @@ void ParseOptionalCommandLineCollectionPrefix(char** collection, int* argcp,
void VerifyCommandLineCollection(char** collection)
{
if ( !*collection )
error(1, 0, "error: you need to specify which tix collection to "
"administer using --collection or giving the prefix as the "
"first argument.");
errx(1, "error: you need to specify which tix collection to administer "
"using --collection or giving the prefix as the first "
"argument.");
if ( !**collection )
{
@ -753,8 +755,8 @@ void VerifyCommandLineCollection(char** collection)
}
char* collection_rel = *collection;
if ( !(*collection = canonicalize_file_name(collection_rel)) )
error(1, errno, "canonicalize_file_name(`%s')", collection_rel);
if ( !(*collection = realpath(collection_rel, NULL)) )
err(1, "realpath: %s", collection_rel);
free(collection_rel);
}
@ -762,41 +764,35 @@ void VerifyTixCollectionConfiguration(string_array_t* info, const char* path)
{
const char* tix_version = dictionary_get(info, "tix.version");
if ( !tix_version )
error(1, 0, "error: `%s': no `tix.version' variable declared", path);
errx(1, "error: `%s': no `tix.version' variable declared", path);
if ( atoi(tix_version) != 1 )
error(1, 0, "error: `%s': tix version `%s' not supported", path,
tix_version);
errx(1, "error: `%s': tix version `%s' not supported", path,
tix_version);
const char* tix_class = dictionary_get(info, "tix.class");
if ( !tix_class )
error(1, 0, "error: `%s': no `tix.class' variable declared", path);
errx(1, "error: `%s': no `tix.class' variable declared", path);
if ( strcmp(tix_class, "collection") != 0 )
error(1, 0, "error: `%s': error: unexpected tix class `%s'.", path,
tix_class);
errx(1, "error: `%s': error: unexpected tix class `%s'.", path,
tix_class);
if ( !(dictionary_get(info, "collection.prefix")) )
error(1, 0, "error: `%s': no `collection.prefix' variable declared",
path);
errx(1, "error: `%s': no `collection.prefix' variable declared", path);
if ( !(dictionary_get(info, "collection.platform")) )
error(1, 0, "error: `%s': no `collection.platform' variable declared",
path);
errx(1, "error: `%s': no `collection.platform' variable declared",
path);
}
static pid_t original_pid;
__attribute__((constructor))
static void initialize_original_pid(void)
char* tmp_root = NULL;
static void cleanup_tmp(void)
{
original_pid = getpid();
}
void cleanup_file_or_directory(int status, void* path_ptr)
{
(void) status;
if ( original_pid != getpid() )
return;
if ( !tmp_root )
return;
pid_t pid = fork();
if ( pid < 0 )
{
error(0, errno, "fork");
warn("fork");
return;
}
if ( pid == 0 )
@ -806,15 +802,35 @@ void cleanup_file_or_directory(int status, void* path_ptr)
"rm",
"-rf",
"--",
(const char*) path_ptr,
(const char*) tmp_root,
NULL,
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(0, errno, "%s", cmd_argv[0]);
warn("%s", cmd_argv[0]);
_exit(127);
}
int code;
waitpid(pid, &code, 0);
free(tmp_root);
tmp_root = NULL;
}
void initialize_tmp(const char* tmp, const char* purpose)
{
if ( tmp_root )
errx(1, "error: initialize_tmp called twice");
if ( asprintf(&tmp_root, "%s/%s.XXXXXX", tmp, purpose) < 0 )
err(1, "error: asprintf");
if ( !mkdtemp(tmp_root) )
err(1, "mkdtemp: `%s'", tmp_root);
original_pid = getpid();
if ( atexit(cleanup_tmp) != 0 )
{
int errnum = errno;
cleanup_tmp();
errno = errnum;
err(1, "atexit");
}
}
mode_t get_umask_value(void)
@ -980,9 +996,7 @@ int recovery_execvp(const char* path, char* const* argv)
NULL
};
execvp(cmd_argv[0], (char* const*) cmd_argv);
error(127, errno, "%s", cmd_argv[0]);
__builtin_unreachable();
err(127, "%s", cmd_argv[0]);
}
bool fork_and_wait_or_recovery(void)
@ -1002,15 +1016,15 @@ bool fork_and_wait_or_recovery(void)
return false;
if ( WIFEXITED(status) )
error(0, 0, "child with pid %ju exited with status %i.",
(uintmax_t) child_pid, WEXITSTATUS(status));
warnx("child with pid %ju exited with status %i.",
(intmax_t) child_pid, WEXITSTATUS(status));
else if ( WIFSIGNALED(status) )
error(0, 0, "child with pid %ju was killed by signal %i (%s).",
(uintmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
warnx("child with pid %ji was killed by signal %i (%s).",
(intmax_t) child_pid, WTERMSIG(status),
strsignal(WTERMSIG(status)));
else
error(0, 0, "child with pid %ju exited in an unusual manner (%i).",
(uintmax_t) child_pid, status);
warnx("child with pid %ji exited in an unusual manner (%i).",
(intmax_t) child_pid, status);
if ( recovery_print_attempted_execution() )
return true;
@ -1039,7 +1053,7 @@ retry_ask_recovery_method:
{
fprintf(output, "\n");
fclose(output);
error(0, errno, "can't read line from standard input, aborting.");
warn("stdin");
exit_like_exit_status(status);
}
@ -1050,13 +1064,13 @@ retry_ask_recovery_method:
selection = (int) strtol(input, &input_end, 0);
if ( *input_end )
{
error(0, 0, "error: `%s' is not an allowed choice", input);
warnx("error: `%s' is not an allowed choice", input);
goto retry_ask_recovery_method;
}
if ( 5 < selection )
{
error(0, 0, "error: `%i' is not an allowed choice", selection);
warnx("error: `%i' is not an allowed choice", selection);
goto retry_ask_recovery_method;
}
}