Skip to content

Commit 72fdfb5

Browse files
Jason RiedyJunio C Hamano
authored andcommitted
Use sigaction and SA_RESTART in read-tree.c; add option in Makefile.
Might as well ape the sigaction change in read-tree.c to avoid the same potential problems. The fprintf status output will be overwritten in a second, so don't bother guarding it. Do move the fputc after disabling SIGALRM to ensure we go to the next line, though. Also add a NO_SA_RESTART option in the Makefile in case someone doesn't have SA_RESTART but does restart (maybe older HP/UX?). We want the builder to chose this specifically in case the system both lacks SA_RESTART and does not restart stdio calls; a compat #define in git-compat-utils.h would silently allow broken systems. Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 687dd75 commit 72fdfb5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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)