Skip to content

Commit 4c61b7d

Browse files
author
Junio C Hamano
committed
Merge branch 'lt/fix-sol-pack'
* lt/fix-sol-pack: Use sigaction and SA_RESTART in read-tree.c; add option in Makefile. safe_fgets() - even more anal fgets() pack-objects: be incredibly anal about stdio semantics Fix Solaris stdio signal handling stupidities
2 parents fc9957b + 72fdfb5 commit 4c61b7d

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

pack-objects.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int nr_objects = 0, nr_alloc = 0, nr_result = 0;
5858
static const char *base_name;
5959
static unsigned char pack_file_sha1[20];
6060
static int progress = 1;
61-
static volatile int progress_update = 0;
61+
static volatile sig_atomic_t progress_update = 0;
6262

6363
/*
6464
* The object names in objects array are hashed with this hashtable,
@@ -879,7 +879,6 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
879879

880880
static void progress_interval(int signum)
881881
{
882-
signal(SIGALRM, progress_interval);
883882
progress_update = 1;
884883
}
885884

@@ -1025,6 +1024,23 @@ static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout)
10251024
return 1;
10261025
}
10271026

1027+
static void setup_progress_signal(void)
1028+
{
1029+
struct sigaction sa;
1030+
struct itimerval v;
1031+
1032+
memset(&sa, 0, sizeof(sa));
1033+
sa.sa_handler = progress_interval;
1034+
sigemptyset(&sa.sa_mask);
1035+
sa.sa_flags = SA_RESTART;
1036+
sigaction(SIGALRM, &sa, NULL);
1037+
1038+
v.it_interval.tv_sec = 1;
1039+
v.it_interval.tv_usec = 0;
1040+
v.it_value = v.it_interval;
1041+
setitimer(ITIMER_REAL, &v, NULL);
1042+
}
1043+
10281044
int main(int argc, char **argv)
10291045
{
10301046
SHA_CTX ctx;
@@ -1090,18 +1106,24 @@ int main(int argc, char **argv)
10901106
prepare_packed_git();
10911107

10921108
if (progress) {
1093-
struct itimerval v;
1094-
v.it_interval.tv_sec = 1;
1095-
v.it_interval.tv_usec = 0;
1096-
v.it_value = v.it_interval;
1097-
signal(SIGALRM, progress_interval);
1098-
setitimer(ITIMER_REAL, &v, NULL);
10991109
fprintf(stderr, "Generating pack...\n");
1110+
setup_progress_signal();
11001111
}
11011112

1102-
while (fgets(line, sizeof(line), stdin) != NULL) {
1113+
for (;;) {
11031114
unsigned char sha1[20];
11041115

1116+
if (!fgets(line, sizeof(line), stdin)) {
1117+
if (feof(stdin))
1118+
break;
1119+
if (!ferror(stdin))
1120+
die("fgets returned NULL, not EOF, not error!");
1121+
if (errno != EINTR)
1122+
die("fgets: %s", strerror(errno));
1123+
clearerr(stdin);
1124+
continue;
1125+
}
1126+
11051127
if (line[0] == '-') {
11061128
if (get_sha1_hex(line+1, sha1))
11071129
die("expected edge sha1, got garbage:\n %s",

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)