Skip to content

Commit 7941602

Browse files
author
Junio C Hamano
committed
Merge branch 'lt/fix-sol-pack' into next
* lt/fix-sol-pack: Use sigaction and SA_RESTART in read-tree.c; add option in Makefile. safe_fgets() - even more anal fgets()
2 parents 1bdbb57 + 72fdfb5 commit 7941602

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

pack-objects.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,10 @@ int main(int argc, char **argv)
11181118
break;
11191119
if (!ferror(stdin))
11201120
die("fgets returned NULL, not EOF, not error!");
1121-
if (errno == EINTR)
1122-
continue;
1123-
die("fgets: %s", strerror(errno));
1121+
if (errno != EINTR)
1122+
die("fgets: %s", strerror(errno));
1123+
clearerr(stdin);
1124+
continue;
11241125
}
11251126

11261127
if (line[0] == '-') {

read-tree.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,26 @@ static void unlink_entry(char *name)
273273

274274
static void progress_interval(int signum)
275275
{
276-
signal(SIGALRM, progress_interval);
277276
progress_update = 1;
278277
}
279278

279+
static void setup_progress_signal(void)
280+
{
281+
struct sigaction sa;
282+
struct itimerval v;
283+
284+
memset(&sa, 0, sizeof(sa));
285+
sa.sa_handler = progress_interval;
286+
sigemptyset(&sa.sa_mask);
287+
sa.sa_flags = SA_RESTART;
288+
sigaction(SIGALRM, &sa, NULL);
289+
290+
v.it_interval.tv_sec = 1;
291+
v.it_interval.tv_usec = 0;
292+
v.it_value = v.it_interval;
293+
setitimer(ITIMER_REAL, &v, NULL);
294+
}
295+
280296
static void check_updates(struct cache_entry **src, int nr)
281297
{
282298
static struct checkout state = {
@@ -289,8 +305,6 @@ static void check_updates(struct cache_entry **src, int nr)
289305
unsigned last_percent = 200, cnt = 0, total = 0;
290306

291307
if (update && verbose_update) {
292-
struct itimerval v;
293-
294308
for (total = cnt = 0; cnt < nr; cnt++) {
295309
struct cache_entry *ce = src[cnt];
296310
if (!ce->ce_mode || ce->ce_flags & mask)
@@ -302,12 +316,8 @@ static void check_updates(struct cache_entry **src, int nr)
302316
total = 0;
303317

304318
if (total) {
305-
v.it_interval.tv_sec = 1;
306-
v.it_interval.tv_usec = 0;
307-
v.it_value = v.it_interval;
308-
signal(SIGALRM, progress_interval);
309-
setitimer(ITIMER_REAL, &v, NULL);
310319
fprintf(stderr, "Checking files out...\n");
320+
setup_progress_signal();
311321
progress_update = 1;
312322
}
313323
cnt = 0;
@@ -341,8 +351,8 @@ static void check_updates(struct cache_entry **src, int nr)
341351
}
342352
}
343353
if (total) {
344-
fputc('\n', stderr);
345354
signal(SIGALRM, SIG_IGN);
355+
fputc('\n', stderr);
346356
}
347357
}
348358

0 commit comments

Comments
 (0)