diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/db.c | 29 | ||||
-rw-r--r-- | src/list.c | 33 | ||||
-rw-r--r-- | src/list.h | 7 | ||||
-rw-r--r-- | src/package.c | 6 | ||||
-rw-r--r-- | src/pacman.c | 17 | ||||
-rw-r--r-- | src/pacman.h | 2 | ||||
-rw-r--r-- | src/util.c | 4 | ||||
-rw-r--r-- | src/util.h | 2 |
8 files changed, 62 insertions, 38 deletions
@@ -61,44 +61,21 @@ void db_close(pacdb_t* db) return; } + /* frees pkgcache if necessary and returns a new package * cache from db */ PMList* db_loadpkgs(pacdb_t *db) { pkginfo_t *info; - pkginfo_t **arr = NULL; - unsigned int arrct = 0; - int i; PMList *cache = NULL; rewinddir(db->dir); while((info = db_scan(db, NULL, INFRQ_DESC | INFRQ_DEPENDS)) != NULL) { /* add to the collective */ - /* we load all package names into a linear array first, so qsort can handle it */ - if(arr == NULL) { - arr = (pkginfo_t**)malloc(sizeof(pkginfo_t*)); - arrct++; - } else { - arr = (pkginfo_t**)realloc(arr, (++arrct)*sizeof(pkginfo_t*)); - } - if(arr == NULL) { - fprintf(stderr, "error: out of memory\n"); - exit(1); - } - arr[arrct-1] = info; + cache = list_add_sorted(cache, info, pkgcmp); } - /* sort the package list */ - qsort(arr, (size_t)arrct, sizeof(pkginfo_t*), pkgcmp); - - /* now load them into the proper PMList */ - for(i = 0; i < arrct; i++) { - cache = list_add(cache, arr[i]); - } - - FREE(arr); - return(cache); } @@ -645,7 +622,7 @@ PMList* db_find_conflicts(pacdb_t *db, PMList *targets, char *root) if(dbpkg2 && !is_in(filestr, p1->files) && is_in(filestr, dbpkg2->files)) { ok = 1; } - FREE(dbpkg2); + FREEPKG(dbpkg2); } } } @@ -223,4 +223,37 @@ void list_display(const char *title, PMList *list) } } + +/* Add items to a list in sorted order. Use the given + * comparision func to determine order. + */ +PMList* list_add_sorted(PMList *list, void *data, cmp_fn sortfunc) +{ + PMList *add; + PMList *prev = NULL; + PMList *iter = list; + + add = list_new(); + add->data = data; + + /* Find insertion point. */ + while(iter) { + if(sortfunc(add->data, iter->data) <= 0) break; + prev = iter; + iter = iter->next; + } + + /* Insert node before insertion point. */ + add->prev = prev; + add->next = iter; + if(iter != NULL) iter->prev = add; /* Not at end. */ + if(prev != NULL) { + prev->next = add; /* In middle. */ + } else { + list = add; /* Start or empty, new list head. */ + } + + return(list); +} + /* vim: set ts=2 sw=2 noet: */ @@ -30,6 +30,11 @@ typedef struct __pmlist_t { struct __pmlist_t* next; } PMList; + +/* Sort comparison callback function declaration. */ +typedef int (*cmp_fn) (const void *, const void *); + + PMList* list_new(); void list_free(PMList* list); PMList* list_add(PMList* list, void* data); @@ -42,6 +47,8 @@ int list_strcmp(const void *s1, const void *s2); PMList *list_sort(PMList *list); void list_display(const char *title, PMList *list); +PMList* list_add_sorted(PMList *list, void *data, cmp_fn sortfunc); + #endif /* vim: set ts=2 sw=2 noet: */ diff --git a/src/package.c b/src/package.c index 435d18d2..992110b9 100644 --- a/src/package.c +++ b/src/package.c @@ -284,10 +284,10 @@ void freepkg(pkginfo_t *pkg) */ int pkgcmp(const void *p1, const void *p2) { - pkginfo_t **pkg1 = (pkginfo_t**)p1; - pkginfo_t **pkg2 = (pkginfo_t**)p2; + pkginfo_t *pkg1 = (pkginfo_t*)p1; + pkginfo_t *pkg2 = (pkginfo_t*)p2; - return(strcmp(pkg1[0]->name, pkg2[0]->name)); + return(strcmp(pkg1->name, pkg2->name)); } /* Test for existence of a package in a PMList* diff --git a/src/pacman.c b/src/pacman.c index 4d06dd32..df0c7454 100644 --- a/src/pacman.c +++ b/src/pacman.c @@ -115,6 +115,7 @@ int main(int argc, char *argv[]) char *ptr = NULL; pacdb_t *db_local = NULL; char *cenv = NULL; + uid_t myuid; cenv = getenv("COLUMNS"); if(cenv) { @@ -144,6 +145,13 @@ int main(int argc, char *argv[]) return(ret); } + /* see if we're root or not */ + myuid = geteuid(); + if(!myuid && getenv("FAKEROOTKEY")) { + /* fakeroot doesn't count, we're non-root */ + myuid = 99; + } + /* check for permission */ pm_access = READ_ONLY; if(pmo_op != PM_MAIN && pmo_op != PM_QUERY && pmo_op != PM_DEPTEST) { @@ -151,7 +159,7 @@ int main(int argc, char *argv[]) (pmo_s_search || pmo_s_printuris || pmo_group || pmo_q_list || pmo_q_info)) { /* special case: PM_SYNC can be used w/ pmo_s_search by any user */ } else { - if(geteuid() != 0) { + if(myuid) { fprintf(stderr, "error: you cannot perform this operation unless you are root.\n"); return(1); } @@ -178,7 +186,7 @@ int main(int argc, char *argv[]) if(pmo_usesyslog) { openlog("pacman", 0, LOG_USER); } - if(pmo_logfile && geteuid() == 0) { + if(pmo_logfile && myuid == 0) { /* open the log file */ logfd = fopen(pmo_logfile, "a"); if(logfd == NULL) { @@ -1664,7 +1672,6 @@ int pacman_add(pacdb_t *db, PMList *targets) /* see if this is an upgrade. if so, remove the old package first */ if(pmo_upgrade) { if(is_pkgin(info, pm_packages)) { - PMList* tmp = list_new(); int retcode; printf("upgrading %s... ", info->name); @@ -1701,10 +1708,10 @@ int pacman_add(pacdb_t *db, PMList *targets) } if(oldpkg) { - list_add(tmp, strdup(info->name)); + PMList* tmp = list_add(NULL, strdup(info->name)); vprint("removing old package first...\n"); retcode = pacman_remove(db, tmp); - list_free(tmp); + FREELIST(tmp); if(retcode == 1) { fprintf(stderr, "\nupgrade aborted.\n"); return(1); diff --git a/src/pacman.h b/src/pacman.h index 157cb623..d7f30fc3 100644 --- a/src/pacman.h +++ b/src/pacman.h @@ -22,7 +22,7 @@ #define _PAC_PACMAN_H #ifndef PACVER -#define PACVER "2.8.3" +#define PACVER "2.8.4" #endif #ifndef PKGDIR @@ -33,7 +33,7 @@ #include "util.h" /* borrowed and modified from Per Liden's pkgutils (http://crux.nu) */ -int gzopen_frontend(char *pathname, int oflags, int mode) +long gzopen_frontend(char *pathname, int oflags, int mode) { char* gzoflags; int fd; @@ -63,7 +63,7 @@ int gzopen_frontend(char *pathname, int oflags, int mode) return -1; } - return (int)gzf; + return (long)gzf; } int unpack(char *archive, const char *prefix, const char *fn) @@ -28,7 +28,7 @@ #define FREE(p) { if (p) { free(p); (p)= NULL; }} -int gzopen_frontend(char *pathname, int oflags, int mode); +long gzopen_frontend(char *pathname, int oflags, int mode); int unpack(char *archive, const char *prefix, const char *fn); int copyfile(char *src, char *dest); int makepath(char *path); |