Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2014-08-06 16:36:00 -0400
committerAllan McRae <allan@archlinux.org>2014-09-23 21:43:16 +1000
commitc792262b137a5f2daddac22f82e7d8d98d0d7d31 (patch)
treed3177e6c722a96da72503a912d4c5fded0ef78e8 /lib
parent9c066dff439ba453f4c362e1875b794cf3f362ed (diff)
wrap fgets to retry on EINTR
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/be_local.c14
-rw-r--r--lib/libalpm/trans.c2
-rw-r--r--lib/libalpm/util.c3
3 files changed, 10 insertions, 9 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 1b333e44..091ed4c8 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -616,7 +616,7 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info,
}
#define READ_NEXT() do { \
- if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \
+ if(safe_fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \
_alpm_strip_newline(line, 0); \
} while(0)
@@ -627,7 +627,7 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info,
#define READ_AND_STORE_ALL(f) do { \
char *linedup; \
- if(fgets(line, sizeof(line), fp) == NULL) {\
+ if(safe_fgets(line, sizeof(line), fp) == NULL) {\
if(!feof(fp)) goto error; else break; \
} \
if(_alpm_strip_newline(line, 0) == 0) break; \
@@ -636,7 +636,7 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info,
} while(1) /* note the while(1) and not (0) */
#define READ_AND_SPLITDEP(f) do { \
- if(fgets(line, sizeof(line), fp) == NULL) {\
+ if(safe_fgets(line, sizeof(line), fp) == NULL) {\
if(!feof(fp)) goto error; else break; \
} \
if(_alpm_strip_newline(line, 0) == 0) break; \
@@ -682,7 +682,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
}
free(path);
while(!feof(fp)) {
- if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) {
+ if(safe_fgets(line, sizeof(line), fp) == NULL && !feof(fp)) {
goto error;
}
if(_alpm_strip_newline(line, 0) == 0) {
@@ -771,13 +771,13 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
goto error;
}
free(path);
- while(fgets(line, sizeof(line), fp)) {
+ while(safe_fgets(line, sizeof(line), fp)) {
_alpm_strip_newline(line, 0);
if(strcmp(line, "%FILES%") == 0) {
size_t files_count = 0, files_size = 0, len;
alpm_file_t *files = NULL;
- while(fgets(line, sizeof(line), fp) &&
+ while(safe_fgets(line, sizeof(line), fp) &&
(len = _alpm_strip_newline(line, 0))) {
if(!_alpm_greedy_grow((void **)&files, &files_size,
(files_size ? files_size + sizeof(alpm_file_t) : 8 * sizeof(alpm_file_t)))) {
@@ -797,7 +797,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
info->files.count = files_count;
info->files.files = files;
} else if(strcmp(line, "%BACKUP%") == 0) {
- while(fgets(line, sizeof(line), fp) && _alpm_strip_newline(line, 0)) {
+ while(safe_fgets(line, sizeof(line), fp) && _alpm_strip_newline(line, 0)) {
alpm_backup_t *backup;
CALLOC(backup, 1, sizeof(alpm_backup_t), goto error);
if(_alpm_split_backup(line, &backup)) {
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 4a176086..aebd8dd2 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -280,7 +280,7 @@ static int grep(const char *fn, const char *needle)
}
while(!feof(fp)) {
char line[1024];
- if(fgets(line, sizeof(line), fp) == NULL) {
+ if(safe_fgets(line, sizeof(line), fp) == NULL) {
continue;
}
/* TODO: this will not work if the search string
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 6dab0de2..43d0d7be 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -576,8 +576,9 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
.type = ALPM_EVENT_SCRIPTLET_INFO,
.line = line
};
- if(fgets(line, PATH_MAX, pipe_file) == NULL)
+ if(safe_fgets(line, PATH_MAX, pipe_file) == NULL) {
break;
+ }
alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line);
EVENT(handle, &event);
}