summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/trans.c
AgeCommit message (Collapse)AuthorFilesLines
2011-03-21Style change: return(x) --> return xDan McGee1-31/+31
This was discussed and more or less agreed upon on the mailing list. A huge checkin, but if we just do it and let people adjust the pain will end soon enough. Rebasing should be relatively straighforward for anyone that sees conflicts; just be sure you use the new return style if possible. The following semantic patch was used to do the change, along with some hand-massaging in order to preserve parenthesis where appropriate: The semantic match that finds this problem is as follows, although some hand-massaging was done in order to keep parenthesis where appropriate: (http://coccinelle.lip6.fr/) // <smpl> @@ expression a; @@ - return(a); + return a; // </smpl> A macros_file was also provided with the following content: Additional steps taken, mainly for ASSERT() macros: $ sed -i -e 's#return(NULL)#return NULL#' lib/libalpm/*.c $ sed -i -e 's#return(-1)#return -1#' lib/libalpm/*.c Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-28Check local DB version before continuing transactionDan McGee1-2/+13
Ensure we have a local DB version that is up to par with what we expect before we go down any road that might modify it. This should prevent stupid mistakes with the 3.5.X upgrade and people not running pacman-db-upgrade after the transaction as they will need to. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-28Move locking functions to where they are neededDan McGee1-7/+48
We only call these from the transaction init and teardown, so move them to that file, mark them static, and push more of the logic of handle manipulation into these functions. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-28Fix trans no-argument function definitionsDan McGee1-3/+3
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-27Fix double close of the lock fileJonathan Conder1-8/+5
According to FOPEN(3), using fclose on an fdopen'd file stream also closes the underlying file descriptor. This happened in _alpm_lckmk (util.c), which meant that when alpm_trans_release closed it again, the log file (which reused the original file descriptor) was closed instead. Signed-off-by: Jonathan Conder <jonno.conder@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2011-02-22Remove trans->skip_addDan McGee1-1/+0
This is old code that has since gone stale; we no longer ever add anything to this list so no need to keep it around and check the contents during extraction. Signed-off-by: Dan McGee <dan@archlinux.org>
2011-01-08Update copyright years for 2011Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2010-12-30Detect undefined PATH_MAXAllan McRae1-0/+1
POSIX does not require PATH_MAX be defined when there is not actual limit to its value. This affects HURD based systems. Work around this by defining PATH_MAX to 4096 (as on Linux) when this is not defined. Also, clean up inclusions of limits.h and remove autoconf check for this header as we do not use macro shields for its inclusion anyway. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2010-12-13Merge branch 'maint'Dan McGee1-1/+1
Conflicts: lib/libalpm/be_local.c lib/libalpm/trans.c
2010-12-11Fix possible null pointer deref in check_archDan McGee1-1/+1
If we have a corrupted database, a package can come through without an arch, causing the code to blow up when making strcmp() calls. It might even be possible with perfectly valid database entries lacking an 'arch =' line. This behavior was seen as at least one of the problems in FS#21668. Ensure pkgarch is not null before doing anything further. Signed-off-by: Dan McGee <dan@archlinux.org>
2010-10-13Move the cache stuff where it should beDan McGee1-1/+0
Cache bullshit only has relevance to be_files, so move it there. Signed-off-by: Dan McGee <dan@archlinux.org> [Allan: BIG rebase] Signed-off-by: Allan McRae <allan@archlinux.org>
2010-08-27use execv to avoid using sh just to run ldconfigJonathan Conder1-1/+4
Signed-off-by: Jonathan Conder <j@skurvy.no-ip.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2010-08-24fgets invocation cleanupDan McGee1-2/+3
From the fgets manpage: fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\0' is stored after the last character in the buffer. This means there is no need at all to do 'size - 1' math. Remove all of that and just use sizeof() for simplicity on the buffer we plan on reading into. Signed-off-by: Dan McGee <dan@archlinux.org>
2010-07-07Check return value of fgets callsAllan McRae1-2/+1
Prevents compiler warnings with -D_FORTIFY_SOURCE=2 Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2010-06-20Clarify testing within conditional statementsAllan McRae1-2/+2
Follow the HACKING guidelines and always use != 0 or == 0 rather than negation within conditional statements to improve clarity. Most of these are !strcmp usages which is the example of what not to do in the HACKING document. Signed-off-by: Allan McRae <allan@archlinux.org>
2010-03-15Bump copyright dates to 2010Dan McGee1-1/+1
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-11-16Refactor do/while cycle and multiple while cyclesLaszlo Papp1-1/+4
* It makes the code clearer to read/understand * Cppcheck tool doesn't show this anymore: [./util.c:215]: (error) Resource leak: fd [Dan: don't change the coding style] Signed-off-by: Dan McGee <dan@archlinux.org>
2009-10-19Size handling was changed in fgets() functionsLaszlo Papp1-1/+2
Pacman's fgets function in the API used hardcoded numbers to identify the size. This is not good practice, so replace them with sizeof handling. Signed-off-by: Laszlo Papp <djszapi@archlinux.us> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-10-11Rework the alpm_unpack functionsXavier Chantry1-1/+1
Add support to extract a list of entries Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-10-11typing: a few more fixes for special int typesDan McGee1-2/+2
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-09-12Change the interface for target loadingXavier Chantry1-94/+0
-int alpm_trans_sysupgrade(int enable_downgrade); -int alpm_trans_sync(char *target); -int alpm_trans_add(char *target); -int alpm_trans_remove(char *target); +int alpm_sync_sysupgrade(int enable_downgrade); +int alpm_sync_target(char *target); +int alpm_sync_dbtarget(char *db, char *target); +int alpm_add_target(char *target); +int alpm_remove_target(char *target); * functions renaming * add new sync_dbtarget which allows to specify the db * repo/ syntax handling is moved to frontend ( should implement FS#15141) * group handling is moved to backend ( see http://www.archlinux.org/pipermail/pacman-dev/2009-June/008847.html )
2009-09-09Remove transaction typeXavier Chantry1-198/+173
This basically started with this change : /* Transaction */ struct __pmtrans_t { - pmtranstype_t type; pmtransflag_t flags; pmtransstate_t state; - alpm_list_t *packages; /* list of (pmpkg_t *) */ + alpm_list_t *add; /* list of (pmpkg_t *) */ + alpm_list_t *remove; /* list of (pmpkg_t *) */ And then I have to modify all the code accordingly.
2009-09-09Use sync.c for upgrade transaction prepare and commitNagy Gabor1-13/+3
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798. Now an upgrade transaction is just a sync transaction internally (in alpm), so all sync features are available with -U as well: * conflict resolving * sync dependencies from sync repos * remove unresolvable targets See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html for the concept. We use "mixed" target list, where PKG_FROM_FILE origin indicates local package file, PKG_FROM_CACHE indicates sync package. The front-end can add only one type of packages (depending on transaction type) atm, but if alpm resolves dependencies for -U, we may get a real mixed trans->packages list. _alpm_pkg_free_trans() was modified so that it can handle both target types _alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead _alpm_add_commit() was renamed to _alpm_upgrade_targets() sync.c (and deps.c) was modified slightly to handle mixed target lists, the modifications are straightforward. There is one notable change here: We don't create new upgrade trans in sync.c, we replace the pkgcache entries with the loaded package files in the target list (this is a bit hackish) and call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is not accessible anymore), but it doesn't hurt anything with pacman front-end, so it will be fixed later (otherwise this patch would be huge). I updated the documentation of -U and I added a new pactest, upgrade090.py, to test the syncdeps feature of -U. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-09-06Check package arch before installingXavier Chantry1-0/+33
This implements FS#15622 Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-07-23Introduce -SuuNagy Gabor1-2/+2
If the user switches from unstable repo to a stable one, it is quite hard to sync its system with the new repo (the user will see many "Local is newer than stable" messages, nothing more). That's why I introduced -Suu, which treats a sync package like an upgrade, iff the package version doesn't match with the local one's. I added a new pactest (sync104.py) to test this, and I updated the documentation of -Su. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Dan: slight doc reword] Signed-off-by: Dan McGee <dan@archlinux.org>
2009-07-16Run ldconfig inside chroot.Xavier Chantry1-87/+1
This fixes FS#15294. The code to run a command inside a chroot was refactored from the _alpm_runscriptlet function to _alpm_run_chroot. Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
2009-07-01Update copyright headers and messagesDan McGee1-1/+2
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-07Introduce _alpm_pkg_free_trans()Nagy Gabor1-6/+1
The main purpose of this function to make our code more readable. It frees transaction specific fields of pmpkg_t. (It is used when a package is removed from the target list.) Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-02Introduce PM_TRANS_FLAG_NOLOCKNagy Gabor1-12/+20
This flag indicates that the front-end will not call alpm_trans_commit(), so the database needn't be locked. This is the first step toward fixing FS#8905. If this flag is set, alpm_trans_commit() does nothing and returns with an error (that has new code: PM_ERR_TRANS_NOT_LOCKED). Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-04-11Remove pmsyncpkg_tNagy Gabor1-1/+6
pmsyncpkg_t data sructure was removed: 1. pmpkg_t.reason is used instead of pmsyncpkg_t.newreason. (The target packages come from sync repos, so we can use this field without any problems. Upgrade transaction also uses this field to store this info.) 2. pmsyncpkg_t.removes was moved to pmpkg_t.removes. This step requires careful programming, because we don't duplicate packages when we add them to trans->packages. So we modify sync pkgcache when we add this transaction-only info to our package. Hence it is important to free this list when we remove any package from the target list (remove_unresolvable, remove_conflicts, trans_free), otherwise this could confuse the new sync transactions (with non-pacman GUI). Overall, our code became ~100 line shorter, and we can call our helper functions directly on trans->packages in sync.c, we don't need to maintain parallel package lists. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-03-15Revert "popen does NOT require /bin/sh in a subchroot"Xavier Chantry1-7/+0
This reverts commit 9558639d8009483fbf422b138d020745986f82f1. This change was wrong, popen does require /bin/sh in a subchroot. 1) pacman -S lilo -r root Notice no error 2) rm root/bin/sh ; pacman -S lilo -r root Notice an error : error: scriptlet failed to execute correctly Actually, we already get an explicit error here, when popen is run, so there is no need to check for bin/sh explicitely. Besides this check was problematic in some cases. For example, bash itself has a scriptlet, but only post_install and post_upgrade, no pre_install and pre_upgrade. However, since bash has a scriptlet, runscriptlet will also be called before bash is installed. It won't do anything since the scriptlet has no pre_install function. But if we keep the check, we will still get "error : no /bin/sh". Conflicts: lib/libalpm/trans.c Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2009-03-15runscriptlet : Flush open fds before fork() to avoid cloning buffersXavier Chantry1-0/+3
This is a bug I noticed 2 years ago : http://www.nabble.com/Re%3A-logging-output-crazy-to11437357.html#a11479679 I thought I fixed it with 57d77eab32c01cd7572a11f76480a3724d09c029 But the bug was still here. Reading man fork, this part caught my attention: * The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two descriptors share open file status flags, current file offset, and signal-driven I/O attributes (see the description of F_SETOWN and F_SETSIG in fcntl(2)). Since the open file descriptors are inherited, it is probably a good idea to flush them before forking. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2008-11-01-Qu reworkNagy Gabor1-12/+1
From now on -Qu is an "outdated package" filter on local database. (This is a behaviour change.) This patch fixes some memleaks and makes the code cleaner, for details see my comment on FS#7884. FS#11868 is implemented. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
2008-10-29Merge branch 'maint'Dan McGee1-3/+3
2008-10-19Correctly close the pipe used for scriptlet executionDan McGee1-3/+3
We never had a call to pclose() in here before, leaving our file descriptor in some sort of limbo state. In addition, clean up some of the other logic such as directly calling exit(1) on a popen() failure rather than going to our cleanup block, and handling and respecting the exit status of the subprocess correctly. Signed-off-by: Dan McGee <dan@archlinux.org>
2008-10-13Merge branch 'maint'Dan McGee1-3/+2
2008-10-13libalpm: handle syscall interruption correctlyDan McGee1-3/+2
It is possible to throw EINTR from a system call such as open(), close(), or waitpid() if custom signal handlers are set up and they are not initialized with the SA_RESTART flag. This was noticed by Andreas Radke when ^C (SIGINT) was given during the call to waitpid(), causing it to throw the EINTR error and we could not accommodate it. Simply wrap these calls in a simple loop that allows us to retry the call if interrupted. Signed-off-by: Dan McGee <dan@archlinux.org>
2008-09-03Remove unnecessary initialization in new functionsDan McGee1-9/+0
We don't need to zero things out, we are already using calloc for this purpose. Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-16_alpm_db_add_pkgincache reworkNagy Gabor1-2/+1
Commit 8240da6cb3ff95ad480efe3e1876104024398fae broke some alpm hierarchy and introduced a new memleak (trans->packages was never freed in case of add transaction, even if the transaction wasn't committed), so it is reverted now. We follow a different approach to reduce memory usage: _alpm_db_add_pkgincache doesn't duplicate the whole package before adding it to the cache, only the package name and version (INFRQ_BASE). This method needs very small extra memory (compared to the reverted method), and after transaction commit we use less memory than before (since the big 'files' fields are not copied to cache), this is useful in GUIs. Note: The old add_pkgincache was a bit broken, since pkg->origin wasn't filled in correctly. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Acked-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2008-06-16Use access() instead of stat() when possibleDan McGee1-4/+4
We were using the stat() system call in quite a few places when we didn't actually need anything the stat struct returned- we were simply checking for file existence. access() will be more efficient in those cases. Before (strace pacman -Ss pacman): % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 33.16 0.005987 0 19016 stat64 After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 34.85 0.003863 0 12633 1 access 7.95 0.000881 0 6391 7 stat64 Signed-off-by: Dan McGee <dan@archlinux.org>
2008-04-07Remove unnecessary header file, move one macro to util.cDan McGee1-1/+0
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-03-18Kill PM_TRANS_TYPE_ADD.Chantry Xavier1-3/+0
This was totally useless. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2008-03-11Remove trans->targetsNagy Gabor1-18/+0
Its implementation was quite broken: * add_loadtarget() might have silently filtered out some targets when replacing an older version. * This was used in sync.c to determine whether a target is implicit or not, which is incorrect behavior. Before this patch we silently removed user confirmed replacements; now we always warn on a replacement. * remove001.py behavior was quite odd in adding same target 5 times to the target list, we can change this behavior to be a failure. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Xav: changed remove001 pactest accordingly] Signed-off-by: Chantry Xavier <shiningxc@gmail.com> [Dan: rewrote commit message] Signed-off-by: Dan McGee <dan@archlinux.org>
2008-01-24libalpm/cache.c : don't duplicate packages in pkgcache.Chantry Xavier1-1/+2
Edit _alpm_db_add_pkgincache to not duplicate packages, because this is not needed, is slower, and uses more memory. This made the max memory usage during base reinstall go from 10.4MB to 9.7MB. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2008-01-14FS#9183 : force correct permissions on tmp/.Jaroslaw Swierczynski1-1/+1
[Xav: removed unneeded makepath_internal function, and fixed the permission value : 1777 -> 01777] Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-29Allow NULL parameter in alpm_trans_commitAllan McRae1-1/+3
Fixes FS#7380: alpm crashes on passing NULL to alpm_trans_commit in a sync operation. Adds check that data parameter is not NULL in several functions. Signed-off-by: Allan McRae <mcrae_allan@hotmail.com> [Dan: fix whitespace] Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-11popen does NOT require /bin/sh in a subchrootAaron Griffin1-3/+3
I appears that when chrooted, the /bin/sh used by popen is that of the parent process. This is true until the process forks once chrooted, which we do not want to do. As such, this actually makes things nicer. We don't need a /bin/sh in a chroot to run install scriptlets, and don't need to check for it in the root directory Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-11Correct scriptlet usage patternAaron Griffin1-5/+2
The new pattern is as follows: . /path/to/scriptlet post_upgrade X Y This requires less frameworking in the install scripts (the three lines that shift and eval a function are nasty) Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
2007-12-11Update GNU GPL boilerplate and copyright datesDan McGee1-4/+2
Update the GPL boilerplate to direct people to the GNU website for a copy of the license, as well as bump all of Judd's copyrights to 2007. Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-25Fix a memleak in _alpm_sync_free.Chantry Xavier1-8/+2
An alpm_list_free call was missing. Also make use of alpm_list_free_inner in both _alpm_sync_free and _alpm_trans_free. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>