Skip to content

Commit fb7a653

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Fix Solaris stdio signal handling stupidities
This uses sigaction() to install the SIGALRM handler with SA_RESTART, so that Solaris stdio doesn't break completely when a signal interrupts a read. Thanks to Jason Riedy for confirming the silly Solaris signal behaviour. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 473d404 commit fb7a653

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

pack-objects.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int nr_objects = 0, nr_alloc = 0;
5353
static const char *base_name;
5454
static unsigned char pack_file_sha1[20];
5555
static int progress = 1;
56-
static volatile int progress_update = 0;
56+
static volatile sig_atomic_t progress_update = 0;
5757

5858
/*
5959
* The object names in objects array are hashed with this hashtable,
@@ -685,7 +685,6 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
685685

686686
static void progress_interval(int signum)
687687
{
688-
signal(SIGALRM, progress_interval);
689688
progress_update = 1;
690689
}
691690

@@ -820,6 +819,23 @@ static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout)
820819
return 1;
821820
}
822821

822+
static void setup_progress_signal(void)
823+
{
824+
struct sigaction sa;
825+
struct itimerval v;
826+
827+
memset(&sa, 0, sizeof(sa));
828+
sa.sa_handler = progress_interval;
829+
sigemptyset(&sa.sa_mask);
830+
sa.sa_flags = SA_RESTART;
831+
sigaction(SIGALRM, &sa, NULL);
832+
833+
v.it_interval.tv_sec = 1;
834+
v.it_interval.tv_usec = 0;
835+
v.it_value = v.it_interval;
836+
setitimer(ITIMER_REAL, &v, NULL);
837+
}
838+
823839
int main(int argc, char **argv)
824840
{
825841
SHA_CTX ctx;
@@ -885,13 +901,8 @@ int main(int argc, char **argv)
885901
prepare_packed_git();
886902

887903
if (progress) {
888-
struct itimerval v;
889-
v.it_interval.tv_sec = 1;
890-
v.it_interval.tv_usec = 0;
891-
v.it_value = v.it_interval;
892-
signal(SIGALRM, progress_interval);
893-
setitimer(ITIMER_REAL, &v, NULL);
894904
fprintf(stderr, "Generating pack...\n");
905+
setup_progress_signal();
895906
}
896907

897908
while (fgets(line, sizeof(line), stdin) != NULL) {

0 commit comments

Comments
 (0)