Signals are special because they run asynchronously, making them
non-trivial to handle correctly. Move the handlers a separate file to
offset them from the normal code and make them easier to separate into
individual functions without further cluttering pacman.c
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
signal(7) lists a set of functions that can safely be called from within
a signal handler. Even fileno and strlen are not guaranteed to be safe.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Our signal handler provides a way to gracefully interrupt a transaction
and should always be set.
The check appears to have originally been copied directly from the glibc
manual.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
On SIGTERM pacman was exiting immediately, even in the middle of
a transaction. In this case we should leave the lock file in place as
an indication that the database may not be in a consistent state.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Memory allocation/deallocation functions are not safe to call from
signal handlers. Just remove the lock file if there is one and exit
immediately.
Fixes: FS#46375, FS#45995, FS#47011
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
alpm_unlock is a limited version of alpm_release that does nothing but
the actual unlinking of the lock file and is therefore safe to call from
signal handlers.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Returning -1 is useless since we don't provide any way
to determine why it failed.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
When replacing a file with a directory, any files inside the new
directory cannot possibly exist on the filesystem and can be skipped.
This allows cross-package symlink-to-directory transitions when there
are files with the same name under both the symlinked directory and the
new directory.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
libarchive will not extract a directory over an existing directory
symlink, making it impossible to replace a symlink with a directory
across packages. Adding the ARCHIVE_EXTRACT_UNLINK and
ARCHIVE_EXTRACT_SECURE_SYMLINKS causes libarchive to unlink the existing
symlink and prevents it from extracting any paths that contain
a symlink, which we should not be doing anyway.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
When a symlink to a directory is changing to a directory, any package file
inside the new directory can create an unexpected conflict with the filesystem.
Reported by Neofytos and Luca from Chakra.
Signed-off-by: Allan McRae <allan@archlinux.org>
Large file support is enabled by our configure script as required. If anything
linking to libalpm does not also define large file support, there will be
differences in the size of off_t which are not caught until runtime.
Add the required CFLAGS to the pkg-config file so that users of libalpm know
what flags are required.
Signed-off-by: Allan McRae <allan@archlinux.org>
If the script output does not end in a newline there could still be data
in the buffer after the poll loop.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Newlines clutter tap output and can potentially confuse TAP parsers.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Approach the detection of variables of the wrong type using an approach
similar to that used for construction of .SRCINFO files. While doing silly
things in bash could still result in false negatives, this approach should
be very robust to generatinf false positives results.
Signed-off-by: Allan McRae <allan@archlinux.org>
Negative subscripts to indexed arrays are not supported before 4.2. However,
since substring expansion works on arrays, we can specify an offset of -1 to
be taken relative to one greater than the maximum index of the specified
array (see Parameter Expansion section of the bash man page). This works with
both Bash 4.1 and 4.2, and 4.1 is already the oldest supported by pacman.
Signed-off-by: Aaron Campbell <aaron@monkey.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
Otherwise any invalid targets following a successful match will not get
an error message.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Targets are never modified so we can just use the original copy.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
The difference between a sync target having an unmet dependency and
breaking a dependency for an installed package is a common source of
confusion.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
If given size 0 POSIX allows realloc to return a pointer that is not
suitable for use.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Completion now works as expected with a comma-separated sequence.
Signed-off-by: Mohammad Alsaleh <CE.Mohammad.AlSaleh@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
If a hook path equals or exceeds PATH_MAX characters the path will be
left unterminated. Pre-calculating the path length also allows us to
use the more efficient memcpy over strncpy.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
run_split_packaging did not preserve the $pkgname array correctly, and
would create duplicate entries in the list during restore.
After restoring the backup (a b c) would become (a b c b c).
This probably went unnoticed because during --install, pacman would
reconcile the duplicates.
Signed-off-by: Allan McRae <allan@archlinux.org>
Also, use FREE() instead of free() in _alpm_backup_free()
to set the pointers to NULL.
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>