Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'egil/fix-crashdump-default/OTP-10602' into maint-r15

* egil/fix-crashdump-default/OTP-10602:
  erts: Change default of erl_crash.dump
  • Loading branch information...
commit 99e66ce7f6bd42a380fc474f49af3130922ee11f 2 parents 2eb32af + 7d92675
authored
18  erts/emulator/beam/break.c
@@ -657,6 +657,7 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
657 657
     char dumpnamebuf[MAXPATHLEN];
658 658
     char* dumpname;
659 659
     int secs;
  660
+    int env_erl_crash_dump_seconds_set = 1;
660 661
 
661 662
     if (ERTS_SOMEONE_IS_CRASH_DUMPING)
662 663
 	return;
@@ -681,6 +682,8 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
681 682
 
682 683
     envsz = sizeof(env);
683 684
     /* ERL_CRASH_DUMP_SECONDS not set
  685
+     * if we have a heart port, break immediately
  686
+     * otherwise dump crash indefinitely (until crash is complete)
684 687
      * same as ERL_CRASH_DUMP_SECONDS = 0
685 688
      * - do not write dump
686 689
      * - do not set an alarm
@@ -702,8 +705,10 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
702 705
      */
703 706
 	
704 707
     if (erts_sys_getenv__("ERL_CRASH_DUMP_SECONDS", env, &envsz) != 0) {
705  
-	return; /* break immediately */
  708
+	env_erl_crash_dump_seconds_set = 0;
  709
+	secs = -1;
706 710
     } else {
  711
+	env_erl_crash_dump_seconds_set = 1;
707 712
 	secs = atoi(env);
708 713
     }
709 714
 
@@ -711,7 +716,16 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
711 716
 	return;
712 717
     }
713 718
 
714  
-    erts_sys_prepare_crash_dump(secs);
  719
+    /* erts_sys_prepare_crash_dump returns 1 if heart port is found, otherwise 0
  720
+     * If we don't find heart (0) and we don't have ERL_CRASH_DUMP_SECONDS set
  721
+     * we should continue writing a dump
  722
+     *
  723
+     * beware: secs -1 means no alarm
  724
+     */
  725
+
  726
+    if (erts_sys_prepare_crash_dump(secs) && !env_erl_crash_dump_seconds_set ) {
  727
+	return;
  728
+    }
715 729
 
716 730
     if (erts_sys_getenv__("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0)
717 731
 	dumpname = "erl_crash.dump";
2  erts/emulator/beam/sys.h
@@ -652,7 +652,7 @@ void erts_sys_schedule_interrupt_timed(int set, erts_short_time_t msec);
652 652
 void erts_sys_main_thread(void);
653 653
 #endif
654 654
 
655  
-extern void erts_sys_prepare_crash_dump(int secs);
  655
+extern int erts_sys_prepare_crash_dump(int secs);
656 656
 extern void erts_sys_pre_init(void);
657 657
 extern void erl_sys_init(void);
658 658
 extern void erl_sys_args(int *argc, char **argv);
52  erts/emulator/sys/unix/sys.c
@@ -686,7 +686,7 @@ static RETSIGTYPE break_handler(int sig)
686 686
 }
687 687
 #endif /* 0 */
688 688
 
689  
-static ERTS_INLINE void
  689
+static ERTS_INLINE int
690 690
 prepare_crash_dump(int secs)
691 691
 {
692 692
 #define NUFBUF (3)
@@ -698,19 +698,35 @@ prepare_crash_dump(int secs)
698 698
     Eterm *hp = heap;
699 699
     Eterm list = NIL;
700 700
     int heart_fd[2] = {-1,-1};
  701
+    int has_heart = 0;
701 702
 
702 703
     UseTmpHeapNoproc(NUFBUF);
703 704
 
704 705
     if (ERTS_PREPARED_CRASH_DUMP)
705  
-	return; /* We have already been called */
  706
+	return 0; /* We have already been called */
706 707
 
707 708
     heart_port = erts_get_heart_port();
  709
+
  710
+    /* Positive secs means an alarm must be set
  711
+     * 0 or negative means no alarm
  712
+     *
  713
+     * Set alarm before we try to write to a port
  714
+     * we don't want to hang on a port write with
  715
+     * no alarm.
  716
+     *
  717
+     */
  718
+
  719
+    if (secs >= 0) {
  720
+	alarm((unsigned int)secs);
  721
+    }
  722
+
708 723
     if (heart_port) {
709 724
 	/* hearts input fd
710 725
 	 * We "know" drv_data is the in_fd since the port is started with read|write
711 726
 	 */
712 727
 	heart_fd[0] = (int)heart_port->drv_data;
713 728
 	heart_fd[1] = (int)driver_data[heart_fd[0]].ofd;
  729
+	has_heart   = 1;
714 730
 
715 731
 	list = CONS(hp, make_small(8), list); hp += 2;
716 732
 
@@ -752,20 +768,14 @@ prepare_crash_dump(int secs)
752 768
 	erts_silence_warn_unused_result(nice(nice_val));
753 769
     }
754 770
 
755  
-    /* Positive secs means an alarm must be set
756  
-     * 0 or negative means no alarm
757  
-     */
758  
-    if (secs > 0) {
759  
-	alarm((unsigned int)secs);
760  
-    }
761 771
     UnUseTmpHeapNoproc(NUFBUF);
762 772
 #undef NUFBUF
  773
+    return has_heart;
763 774
 }
764 775
 
765  
-void
766  
-erts_sys_prepare_crash_dump(int secs)
  776
+int erts_sys_prepare_crash_dump(int secs)
767 777
 {
768  
-    prepare_crash_dump(secs);
  778
+    return prepare_crash_dump(secs);
769 779
 }
770 780
 
771 781
 static ERTS_INLINE void
@@ -802,12 +812,22 @@ static RETSIGTYPE request_break(int signum)
802 812
 static ERTS_INLINE void
803 813
 sigusr1_exit(void)
804 814
 {
805  
-   /* We do this at interrupt level, since the main reason for
806  
-      wanting to generate a crash dump in this way is that the emulator
807  
-      is hung somewhere, so it won't be able to poll any flag we set here.
808  
-      */
  815
+    char env[21]; /* enough to hold any 64-bit integer */
  816
+    size_t envsz;
  817
+    int i, secs = -1;
  818
+
  819
+    /* We do this at interrupt level, since the main reason for
  820
+     * wanting to generate a crash dump in this way is that the emulator
  821
+     * is hung somewhere, so it won't be able to poll any flag we set here.
  822
+     */
809 823
     ERTS_SET_GOT_SIGUSR1;
810  
-    prepare_crash_dump((int)0);
  824
+
  825
+    envsz = sizeof(env);
  826
+    if ((i = erts_sys_getenv_raw("ERL_CRASH_DUMP_SECONDS", env, &envsz)) >= 0) {
  827
+	secs = i != 0 ? 0 : atoi(env);
  828
+    }
  829
+
  830
+    prepare_crash_dump(secs);
811 831
     erl_exit(1, "Received SIGUSR1\n");
812 832
 }
813 833
 
4  erts/emulator/sys/vxworks/sys.c
@@ -296,10 +296,10 @@ void sys_sigrelease(int sig)
296 296
   sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)NULL);
297 297
 }
298 298
 
299  
-void
  299
+int
300 300
 erts_sys_prepare_crash_dump(void)
301 301
 {
302  
-    
  302
+    return 0;
303 303
 }
304 304
 
305 305
 /* register signal handlers XXX - they don't work, need to find out why... */
7  erts/emulator/sys/win32/sys.c
@@ -255,8 +255,7 @@ void erl_sys_args(int* argc, char** argv)
255 255
 #endif
256 256
 }
257 257
 
258  
-void
259  
-erts_sys_prepare_crash_dump(int secs)
  258
+int erts_sys_prepare_crash_dump(int secs)
260 259
 {
261 260
     Port *heart_port;
262 261
     Eterm heap[3];
@@ -271,10 +270,14 @@ erts_sys_prepare_crash_dump(int secs)
271 270
 
272 271
 	/* send to heart port, CMD = 8, i.e. prepare crash dump =o */
273 272
 	erts_write_to_port(NIL, heart_port, list);
  273
+
  274
+	return 1;
274 275
     }
275 276
 
276 277
     /* Windows - free file descriptors are hopefully available */
277 278
     /* Alarm not used on windows */
  279
+
  280
+    return 0;
278 281
 }
279 282
 
280 283
 static void

0 notes on commit 99e66ce

Please sign in to comment.
Something went wrong with that request. Please try again.