summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/util.c
AgeCommit message (Collapse)AuthorFilesLines
2015-05-12merge _alpm_logaction into alpm_logactionAndrew Gregory1-44/+0
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2015-03-26close stdin before running install scriptsAndrew Gregory1-0/+1
libalpm does not guarantee that script output will be presented to the user or that stdin will be connected to a terminal. Close stdin so that scripts do not attempt to use it for user interaction. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2015-02-01Update copyright notices for 2015Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2015-01-21Merge branch 'maint'Allan McRae1-1/+1
2015-01-21fix geometric growth in _alpm_greedy_growDaniel Micay1-1/+1
It was allocating the required size rather than the calculated new size, resulting in pathological incremental reallocations. Signed-off-by: Daniel Micay <danielmicay@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-12-27_alpm_run_chroot: only close working directory if it was openedAllan McRae1-1/+3
Signed-off-by: Allan McRae <allan@archlinux.org>
2014-09-23wrap fgets to retry on EINTRAndrew Gregory1-1/+2
The read() underlying fgets() can be interrupted by a signal handler causing fgets() to return NULL. Before we started handling SIGWINCH, the odds of interrupting a read were low and typically resulted in termination anyway. Replace all fgets calls with a wrapper that retries in EINTR. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-08-03move _alpm_lstat into util-commonAndrew Gregory1-25/+0
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-03-03Update the event callbackOlivier Brunel1-1/+5
Instead of using two void* arguments for all events, we now send one pointer to an alpm_event_t struct. This contains the type of event that was triggered. With this information, the pointer can then be typecasted to the event-specific struct in order to get additional arguments. Signed-off-by: Olivier Brunel <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-03util: Add _alpm_realloc() and _alpm_greedy_grow()Florian Pritz1-0/+62
These will be used in the following patches. Signed-off-by: Florian Pritz <bluewind@xinu.at>
2014-01-28Remove ts and sw from vim modeline when noet is setFlorian Pritz1-1/+1
Forcing vim users to view files with a tabstop of 2 seems really unnecessary when noet is set. I find it much easier to read code with ts=4 and I dislike having to override the modeline by hand. Command run: find . -type f -exec sed -i '/vim.* noet/s# ts=2 sw=2##' {} + Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06Use O_CLOEXEC as much as possible when opening filesDan McGee1-7/+7
When calling open(), use O_CLOEXEC as much as possible to ensure the file descriptor is closed when and if a process using libalpm forks. For most of these cases, and especially in utility functions, the file descriptor is opened and closed in the same function, so we don't have too much to worry about. However, for things like the log file and database lock file, we should ensure descriptors aren't left hanging around for children to touch. This patch is inspired by the problem in FS#36161, where an open file descriptor to the current working directory prevents chroot() from working on FreeBSD. We don't need this file descriptor in the child process, so open it (and now several others) with O_CLOEXEC. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06Update copyright years for 2014Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-12-15Close file descirptor before forkWolfgang Bumiller1-0/+1
FreeBSD chroot(2) fails with EPERM when a directory file descriptor is open with either `kern.chroot_allow_open_directories` being 0, or when the process already is inside a chroot. This is exposed in alpm_run_chroot that uses opendir() to open a file descriptor to the current directory before doing the forking and chrooting. Since the file descriptor is not used in the forked process, we close it. Fixes FS#36161. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-11-15Fix whitespace and other formatting issuesJason St. John1-3/+3
This commit: -- replaces space-based indents with tabs per the coding standards -- removes extraneous whitespace (e.g. extra spaces between function args) -- adds missing braces for a one-line if statement Signed-off-by: Jason St. John <jstjohn@purdue.edu>
2013-09-04alpm: log errors for scriptlets terminated by a signalDave Reisner1-0/+9
Fixes FS#36618. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-07-30Remove setlocale usage from the backendAllan McRae1-15/+0
Using setlocale in the backend is bound to lead to frontend issues and we have have been using epoch in our databases since April 2007 (commit 47622eef). Remove support for old style times. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-07-05do not check error from close(2)Dave Reisner1-14/+14
On operating systems we support, the behavior is always such that the kernel will do the right thing as far as invalidating the file descriptor, regardless of the eventual return value. Therefore, potentially looping and calling close multiple times is wrong. At best, we call close again on an invalid FD and throw a spurious EBADF error. At worst, we might close an FD which doesn't belong to us when a multi-threaded application opens its own file descriptor between iterations of the loop. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-06-26Enable inverted patterns in NoExtract and NoUpgrade.Patrick Steinhardt1-0/+31
It is now possible to invert patterns in NoExtract and NoUpgrade. This feature allows users to whitelist certain files that were previously blacklisted by another entry. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-04-18Fix spelling errors using 'codespell' toolAnatol Pomozov1-3/+3
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-14Save and restore old locale when manipulating via setlocaleDan McGee1-1/+5
We shouldn't assume a frontend program didn't explicitly set the LC_TIME setting to a value not in the environment, which is what we previously assumed. Save the old locale before forcing the 'C' locale and restore it when we are done. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-29Use libarchive compat header for relevant symbolsDave Reisner1-3/+4
Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-28add caller prefix to alpm_logactionAndrew Gregory1-4/+9
prefix defaults to "UNKOWN" if null or an empty string is provided. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-28Make path to ldconfig configurableAllan McRae1-2/+2
The FHS (2.3) says having ldconfig in /sbin is optional and it is usually located in /usr/sbin. So /sbin/ldconfig should not be hard coded in pacman. Instead, provide a configure option --with-ldconfig that defaults to the current path. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-28Revert execvp and related commitsAllan McRae1-7/+10
This reverts commit 4a8c2852a887d2b1aaa43be3071ab586eb24b9e3. This reverts commit 993700bc6b12cd291544d2a22845f480e8a7925e. This reverts commit bb4d2b72c1d35ab9d65d632be0dcaf00cfa7d600. This reverts commit 60b192e3836a150eb6950ce52241efebbee00f11. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-17Do not use full path for ldconfigAllan McRae1-7/+4
The ldconfig binary is not guaranteed to be in /sbin. Change to calling just "ldconfig" rather than using the full path. This removed the check that the ldconfig binary exists. However, it is a reasonable assumption that it will exist if its configuration file does. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-17Use execvp for running programs in chrootAllan McRae1-3/+3
This makes us more robust to utilities changing paths. There is no functional change when a full path is specified. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Fix space between control structure and open parensGerardo Exequiel Pozzi1-1/+1
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Fix missing spaces in operatorsGerardo Exequiel Pozzi1-8/+8
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Split common utility functions for libalpm and pacmanAllan McRae1-33/+0
There is duplicated code in the util.c files in the libalpm and pacman source code. Split this into a separate file so that it can be shared via a symlink. This prevents code divergence between the two code bases. Also, move mbasename and mdirname from pacman/util.c into util-common.c in preparation for the following patch that uses them to add an extension to pacsave files. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-03Update copyright year for 2013Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-08-08coding style fixesFlorian Pritz1-2/+2
Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-08-01util: fix line length calc in _alpm_archive_fgetsDave Reisner1-2/+4
74274b5dc347ba70 which added the real_line_size to the buffer struct didn't properly account for what happens when archive_fgets has to loop more than once to find the end of a line. In most cases, this isn't a problem, but could potentially cause a longer line such as PGP signature to be improperly read. This patch fixes the oversight and focuses on only calculating the line length when we hit the end of line marker. The effective length is then calculated via pointer arithmetic as: (start_of_last_read + read_length) - start_of_line Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-26add line length parameter to _alpm_strip_newlineDave Reisner1-3/+5
If known, callers can pass the line size to this function in order to avoid an strlen call. Otherwise, they simply pass 0 and _alpm_strip_newline will do the call instead. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-06-26add real_line_size to alpm_read_bufferDave Reisner1-2/+2
We inevitably call strlen() or similar on the line returned from _alpm_archive_fgets(), so include the line size of the interesting line in the struct. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-30Convert ALLOC_FAIL macro into a functionDan McGee1-0/+5
This path is rarely (read: never) taken in any normal run of the code, so injecting the fprintf() call everywhere with the macro is a bit overkill. Instead, add a lightweight _alpm_alloc_fail() function that gets called instead. This does have a reasonable effect on the size of the generated code; most places using the macros provided by util.c have their code size reduced. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-09Various tweaks to support building with excessive GCC warning flagsDan McGee1-7/+10
This fixes a bunch of small issues in order to enable a clean successful build with a crazy number of GCC warning flags. A lot of these changes are covered by -Wshadow, -Wformat-security, and -Wstrict-overflow=5. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-09Remove _alpm_csumAllan McRae1-3/+3
The enum alpm_pkgvalidation_t is essentially a more generic version of _alpm_csum, so use it instead. Signed-off-by: Allan McRae <allan@archlinux.org>
2012-02-21Use "mode" in _alpm_makepath_modeAllan McRae1-2/+2
It seems that if we pass the permissions that we want the created directory to have, then we should probably use it... Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-20util: reduce pointer hell in _alpm_makepath_modeDave Reisner1-25/+30
Simplify the implementation: - allocate and manipulate a copy of the passed in path rather than building out a path as the while loop progresses - use simple pointer arithmetic to skip uninteresting cases - use mkdir(3)'s return value and errno to detect failure Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-13Reset errno before opening archiveAllan McRae1-0/+1
Set errno to 0 at the start of _alpm_open_archive as it is not set when archive_read_open_fd fails. This can result in _alpm_pkg_load_internal thinking errno == ENOENT and setting the wrong pm_errno. e.g. Before: > testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format Cannot find the given file. After: > testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format Cannot open the given file. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-13use _alpm_access in a few more places for increased debugging infoFlorian Pritz1-1/+1
pacman -U <pkg> returns a bogus "could not find or read package" if the file is on a fuse file system that doesn't allow root access. Debug output isn't very helpful here either so we should log why the access check failed. The other 2 checks already log something when failing so logging a more specific error won't hurt either. Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-23Remove rmrf implementation from backendDan McGee1-46/+0
This moves the code for removal of local database entries right into be_local.c, which was the last user of the rmrf() function we had in our utility source file. We can simplify the implementation and make it non-recursive as we know the structure of the local database entries. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-23Merge branch 'maint'Dan McGee1-5/+5
Conflicts: lib/libalpm/diskspace.c src/pacman/util.h
2012-01-19Update copyright on changed files since beginning of yearDan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-19util.c, rmrf(): only create string when neededOlivier Brunel1-3/+3
The entry's name is only used when not "." or ".." so only print the string then. Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-18Use isdigit() rather than character range comparisonsDan McGee1-1/+1
This is safer and guaranteed to work with even exotic character sets. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-08Fix segfaults on opening invalid archive filesDan McGee1-8/+13
"invalid" in this case simply means files that may or may not be archives. Discovered via a `pacman -Sc` operation with delta files in the package cache directory, but can be triggered if any file is passed to `pacman -Ql` that isn't an archive, for instance, or if the sync database file is not an archive. Fix it up so we are more careful about calling archive_read_finish() only on archives that are valid and have not already been closed, and teach our archive open function to set the returned archive to NULL if we aren't going to be returning something valid anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-01-01Simplify hash function to a single multiplicationDan McGee1-1/+1
More than likely the compiler will do the three operation breakdown we had here before (2 shifts + subtraction), but let the compiler do the optimizations and make the actual operation more obvious. This actually slightly shrinks the function binary size, likely due to instruction reordering or something. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-12-23Remove strtrim function from backendDan McGee1-41/+0
The last user of this was the code in the backend for loading packages, but this no longer uses it. Signed-off-by: Dan McGee <dan@archlinux.org>