diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/callback.c | 24 | ||||
-rw-r--r-- | src/pacman/package.c | 4 | ||||
-rw-r--r-- | src/pacman/pacman.c | 36 | ||||
-rw-r--r-- | src/pacman/util.c | 11 | ||||
-rw-r--r-- | src/pacman/util.h | 6 |
5 files changed, 54 insertions, 27 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 59b40643..92a31f16 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -137,11 +137,9 @@ static void fill_progress(const int bar_percent, const int disp_percent, } printf("]"); } - /* print percent after progress bar */ + /* print display percent after progress bar */ if(proglen > 5) { - /* show total download percent if option is enabled */ - int p = config->totaldownload ? disp_percent : bar_percent; - printf(" %3d%%", p); + printf(" %3d%%", disp_percent); } if(bar_percent == 100) { @@ -435,6 +433,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) int len, wclen, wcwid, padwid; wchar_t *wcfname; + int totaldownload; off_t xfered, total; float rate = 0.0, timediff = 0.0, f_xfered = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; @@ -450,6 +449,12 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) /* only use TotalDownload if enabled and we have a callback value */ if(config->totaldownload && list_total) { + totaldownload = 1; + } else { + totaldownload = 0; + } + + if(totaldownload) { xfered = list_xfered + file_xfered; total = list_total; } else { @@ -462,8 +467,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) if(file_xfered == 0) { /* set default starting values, ensure we only call this once * if TotalDownload is enabled */ - if(!(config->totaldownload) - || (config->totaldownload && list_xfered == 0)) { + if(!totaldownload || (totaldownload && list_xfered == 0)) { gettimeofday(&initial_time, NULL); xfered_last = (off_t)0; rate_last = 0.0; @@ -500,7 +504,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) file_percent = (int)((float)file_xfered) / ((float)file_total) * 100; - if(config->totaldownload && list_total) { + if(totaldownload) { total_percent = (int)((float)list_xfered + file_xfered) / ((float)list_total) * 100; @@ -581,7 +585,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) free(fname); free(wcfname); - fill_progress(file_percent, total_percent, getcols() - infolen); + if(totaldownload) { + fill_progress(file_percent, total_percent, getcols() - infolen); + } else { + fill_progress(file_percent, file_percent, getcols() - infolen); + } return; } diff --git a/src/pacman/package.c b/src/pacman/package.c index fddce94a..71be2d8c 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -135,9 +135,11 @@ void dump_pkg_full(pmpkg_t *pkg, int level) /* Print additional package info if info flag passed more than once */ if(level > 1) { dump_pkg_backups(pkg); - printf("\n"); } + /* final newline to separate packages */ + printf("\n"); + FREELIST(depstrings); } diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 155f8da0..afe4ae44 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -36,6 +36,7 @@ #include <sys/utsname.h> /* uname */ #include <locale.h> /* setlocale */ #include <time.h> /* time_t */ +#include <errno.h> #if defined(PACMAN_DEBUG) && defined(HAVE_MCHECK_H) #include <mcheck.h> /* debug tracing (mtrace) */ #endif @@ -211,21 +212,34 @@ static void cleanup(int ret) { exit(ret); } +/** Write function that correctly handles EINTR. + */ +static ssize_t xwrite(int fd, const void *buf, size_t count) +{ + ssize_t ret; + while((ret = write(fd, buf, count)) == -1 && errno == EINTR); + return(ret); +} + /** Catches thrown signals. Performs necessary cleanup to ensure database is * in a consistant state. * @param signum the thrown signal */ static RETSIGTYPE handler(int signum) { - if(signum==SIGSEGV) - { - /* write a log message and write to stderr */ - pm_printf(PM_LOG_ERROR, _("segmentation fault\n")); - pm_fprintf(stderr, PM_LOG_ERROR, - _("Internal pacman error: Segmentation fault.\n" - "Please submit a full bug report with --debug if appropriate.\n")); + int out = fileno(stdout); + int err = fileno(stderr); + if(signum == SIGSEGV) { + const char *msg1 = "error: segmentation fault\n"; + const char *msg2 = "Internal pacman error: Segmentation fault.\n" + "Please submit a full bug report with --debug if appropriate.\n"; + /* write a error message to out, the rest to err */ + xwrite(out, msg1, strlen(msg1)); + xwrite(err, msg2, strlen(msg2)); exit(signum); } else if((signum == SIGINT)) { + const char *msg = "\nInterrupt signal received\n"; + xwrite(err, msg, strlen(msg)); if(alpm_trans_interrupt() == 0) { /* a transaction is being interrupted, don't exit pacman yet. */ return; @@ -233,7 +247,7 @@ static RETSIGTYPE handler(int signum) /* no commiting transaction, we can release it now and then exit pacman */ alpm_trans_release(); /* output a newline to be sure we clear any line we may be on */ - printf("\n"); + xwrite(out, "\n", 1); } cleanup(signum); } @@ -262,11 +276,13 @@ static void setlibpaths(void) cleanup(ret); } if(!config->dbpath) { - snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH); + /* omit leading slash from our static DBPATH, root handles it */ + snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH + 1); config->dbpath = strdup(path); } if(!config->logfile) { - snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE); + /* omit leading slash from our static LOGFILE path, root handles it */ + snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE + 1); config->logfile = strdup(path); } } diff --git a/src/pacman/util.c b/src/pacman/util.c index fd0d38c7..b80b09ad 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -59,7 +59,7 @@ int trans_init(pmtranstype_t type, pmtransflag_t flags) return(0); } -int trans_release() +int trans_release(void) { if(alpm_trans_release() == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), @@ -69,7 +69,7 @@ int trans_release() return(0); } -int needs_transaction() +int needs_transaction(void) { if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) { if((config->op == PM_OP_SYNC && !config->op_s_sync && @@ -85,7 +85,7 @@ int needs_transaction() } /* gets the current screen column width */ -int getcols() +int getcols(void) { if(!isatty(1)) { /* We will default to 80 columns if we're not a tty @@ -252,7 +252,7 @@ void indentprint(const char *str, int indent) { wchar_t *wcstr; const wchar_t *p; - int len, cidx; + int len, cidx, cols; if(!str) { return; @@ -267,6 +267,7 @@ void indentprint(const char *str, int indent) if(!p) { return; } + cols = getcols(); while(*p) { if(*p == L' ') { @@ -283,7 +284,7 @@ void indentprint(const char *str, int indent) while(q < next) { len += wcwidth(*q++); } - if(len > (getcols() - cidx - 1)) { + if(len > (cols - cidx - 1)) { /* wrap to a newline and reindent */ fprintf(stdout, "\n%-*s", indent, ""); cidx = indent; diff --git a/src/pacman/util.h b/src/pacman/util.h index cdb12bd6..64168587 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -37,9 +37,9 @@ #define UPDATE_SPEED_SEC 0.2f int trans_init(pmtranstype_t type, pmtransflag_t flags); -int trans_release(); -int needs_transaction(); -int getcols(); +int trans_release(void); +int needs_transaction(void); +int getcols(void); int makepath(const char *path); int rmrf(const char *path); char *mbasename(const char *path); |