summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
Commit message (Collapse)AuthorAge
* merge _alpm_logaction into alpm_logactionAndrew Gregory2015-05-12
| | | | | Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
* close stdin before running install scriptsAndrew Gregory2015-03-26
| | | | | | | | | 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>
* Update copyright notices for 2015Allan McRae2015-02-01
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Merge branch 'maint'Allan McRae2015-01-21
|\
| * fix geometric growth in _alpm_greedy_growDaniel Micay2015-01-21
| | | | | | | | | | | | | | | | 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>
* | _alpm_run_chroot: only close working directory if it was openedAllan McRae2014-12-27
|/ | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* wrap fgets to retry on EINTRAndrew Gregory2014-09-23
| | | | | | | | | | 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>
* move _alpm_lstat into util-commonAndrew Gregory2014-08-03
| | | | Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
* Update the event callbackOlivier Brunel2014-03-03
| | | | | | | | | | | | 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>
* util: Add _alpm_realloc() and _alpm_greedy_grow()Florian Pritz2014-03-03
| | | | | | These will be used in the following patches. Signed-off-by: Florian Pritz <bluewind@xinu.at>
* Remove ts and sw from vim modeline when noet is setFlorian Pritz2014-01-28
| | | | | | | | | | | | 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>
* Use O_CLOEXEC as much as possible when opening filesDan McGee2014-01-06
| | | | | | | | | | | | | | | | | | | 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>
* Update copyright years for 2014Allan McRae2014-01-06
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Close file descirptor before forkWolfgang Bumiller2013-12-15
| | | | | | | | | | | | | 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>
* Fix whitespace and other formatting issuesJason St. John2013-11-15
| | | | | | | | | 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>
* alpm: log errors for scriptlets terminated by a signalDave Reisner2013-09-04
| | | | | | | Fixes FS#36618. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
* Remove setlocale usage from the backendAllan McRae2013-07-30
| | | | | | | | 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>
* do not check error from close(2)Dave Reisner2013-07-05
| | | | | | | | | | | | | | | 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>
* Enable inverted patterns in NoExtract and NoUpgrade.Patrick Steinhardt2013-06-26
| | | | | | | | 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>
* Fix spelling errors using 'codespell' toolAnatol Pomozov2013-04-18
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* Save and restore old locale when manipulating via setlocaleDan McGee2013-03-14
| | | | | | | | | | 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>
* Use libarchive compat header for relevant symbolsDave Reisner2013-01-29
| | | | | Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
* add caller prefix to alpm_logactionAndrew Gregory2013-01-28
| | | | | | | 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>
* Make path to ldconfig configurableAllan McRae2013-01-28
| | | | | | | | | 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>
* Revert execvp and related commitsAllan McRae2013-01-28
| | | | | | | | | This reverts commit 4a8c2852a887d2b1aaa43be3071ab586eb24b9e3. This reverts commit 993700bc6b12cd291544d2a22845f480e8a7925e. This reverts commit bb4d2b72c1d35ab9d65d632be0dcaf00cfa7d600. This reverts commit 60b192e3836a150eb6950ce52241efebbee00f11. Signed-off-by: Allan McRae <allan@archlinux.org>
* Do not use full path for ldconfigAllan McRae2013-01-17
| | | | | | | | | | | 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>
* Use execvp for running programs in chrootAllan McRae2013-01-17
| | | | | | | 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>
* Fix space between control structure and open parensGerardo Exequiel Pozzi2013-01-04
| | | | | Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
* Fix missing spaces in operatorsGerardo Exequiel Pozzi2013-01-04
| | | | | Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
* Split common utility functions for libalpm and pacmanAllan McRae2013-01-04
| | | | | | | | | | | | 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>
* Update copyright year for 2013Allan McRae2013-01-03
| | | | Signed-off-by: Allan McRae <allan@archlinux.org>
* coding style fixesFlorian Pritz2012-08-07
| | | | | Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Dan McGee <dan@archlinux.org>
* util: fix line length calc in _alpm_archive_fgetsDave Reisner2012-08-01
| | | | | | | | | | | | | | | | 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>
* add line length parameter to _alpm_strip_newlineDave Reisner2012-06-25
| | | | | | | | | 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>
* add real_line_size to alpm_read_bufferDave Reisner2012-06-25
| | | | | | | | | 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>
* Convert ALLOC_FAIL macro into a functionDan McGee2012-04-29
| | | | | | | | | | | | | 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>
* Various tweaks to support building with excessive GCC warning flagsDan McGee2012-04-08
| | | | | | | | | 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>
* Remove _alpm_csumAllan McRae2012-03-08
| | | | | | | 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>
* Use "mode" in _alpm_makepath_modeAllan McRae2012-02-20
| | | | | | | | 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>
* util: reduce pointer hell in _alpm_makepath_modeDave Reisner2012-02-20
| | | | | | | | | | | | 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>
* Reset errno before opening archiveAllan McRae2012-02-13
| | | | | | | | | | | | | | | | | | | 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>
* use _alpm_access in a few more places for increased debugging infoFlorian Pritz2012-02-13
| | | | | | | | | | | | | 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>
* Remove rmrf implementation from backendDan McGee2012-01-23
| | | | | | | | | 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>
* Merge branch 'maint'Dan McGee2012-01-23
|\ | | | | | | | | | | Conflicts: lib/libalpm/diskspace.c src/pacman/util.h
| * Update copyright on changed files since beginning of yearDan McGee2012-01-18
| | | | | | | | Signed-off-by: Dan McGee <dan@archlinux.org>
| * util.c, rmrf(): only create string when neededOlivier Brunel2012-01-18
| | | | | | | | | | | | | | | | 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>
| * Use isdigit() rather than character range comparisonsDan McGee2012-01-18
| | | | | | | | | | | | This is safer and guaranteed to work with even exotic character sets. Signed-off-by: Dan McGee <dan@archlinux.org>
* | Fix segfaults on opening invalid archive filesDan McGee2012-01-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "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>
* | Simplify hash function to a single multiplicationDan McGee2011-12-31
| | | | | | | | | | | | | | | | | | | | 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>
* | Remove strtrim function from backendDan McGee2011-12-23
| | | | | | | | | | | | | | 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>