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>
Linus Torvalds committed
Apr 2, 2006 at 13:28 UTC
fb7a6531e67333b22967bf5b96ef22a28f3b2552
1 file changed
+19
-8
pack-objects.c
+19
-8
@@ -53,7 +53,7 @@ static int nr_objects = 0, nr_alloc = 0;
53
static const char *base_name;
54
static unsigned char pack_file_sha1[20];
55
static int progress = 1;
56
-static volatile int progress_update = 0;
56
+static volatile sig_atomic_t progress_update = 0;
57
58
/*
59
* 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
685
686
static void progress_interval(int signum)
687
{
688
- signal(SIGALRM, progress_interval);
688
progress_update = 1;
689
}
690
@@ -820,6 +819,23 @@ static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout)
819
return 1;
820
}
821
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
+
839
int main(int argc, char **argv)
840
{
841
SHA_CTX ctx;
@@ -885,13 +901,8 @@ int main(int argc, char **argv)
901
prepare_packed_git();
902
903
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);
904
fprintf(stderr, "Generating pack...\n");
905
+ setup_progress_signal();
906
}
907
908
while (fgets(line, sizeof(line), stdin) != NULL) {