~ubuntu-branches/ubuntu/saucy/procps/saucy

« back to all changes in this revision

Viewing changes to debian/patches/top_c_resize.patch

  • Committer: Package Import Robot
  • Author(s): Oliver Grawert
  • Date: 2012-06-20 13:12:40 UTC
  • mfrom: (2.1.21 sid)
  • Revision ID: package-import@ubuntu.com-20120620131240-923p0d8q88bmk3ac
Tags: 1:3.3.3-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/sysctl.d (Ubuntu-specific):
    + 10-console-messages.conf: stop low-level kernel messages on console.
    + 10-kernel-hardening.conf: add the kptr_restrict setting
    + 10-keyboard.conf.powerpc: mouse button emulation on PowerPC.
    + 10-network-security.conf: enable rp_filter and SYN-flood protection.
    + 10-ptrace.conf: describe new PTRACE setting.
    + 10-zeropage.conf: safe mmap_min_addr value for graceful fall-back.
    + README: describe how this directory is supposed to work.
  - debian/upstart (Ubuntu-specific): upstart configuration to replace old
    style sysv init script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Author: <hesso@pool.math.tu-berlin.de>
2
 
Description: Prevent top from segfaulting when the display is shrinked to only
3
 
a few (read: 3 or less) lines.
4
 
Index: b/top.c
5
 
===================================================================
6
 
--- a/top.c     2009-11-24 21:00:35.000000000 +1100
7
 
+++ b/top.c     2009-11-24 21:00:39.000000000 +1100
8
 
@@ -140,7 +140,7 @@
9
 
            are exploited in a macro and represent 90% of our optimization.
10
 
            The Stdout_buf is transparent to our code and regardless of whose
11
 
            buffer is used, stdout is flushed at frame end or if interactive. */
12
 
-static char *Pseudo_scrn;
13
 
+static PSEUDO_SCREEN_t Pseudo_scrn;
14
 
 static int   Pseudo_row, Pseudo_cols, Pseudo_size;
15
 
 #ifndef STDOUT_IOLBF
16
 
         // less than stdout's normal buffer but with luck mostly '\n' anyway
17
 
@@ -2431,7 +2431,10 @@
18
 
    Pseudo_cols = Screen_cols + CLRBUFSIZ + 1;
19
 
    if (Batch) Pseudo_size = ROWBUFSIZ + 1;
20
 
    else       Pseudo_size = Pseudo_cols * Screen_rows;
21
 
-   Pseudo_scrn = alloc_r(Pseudo_scrn, Pseudo_size);
22
 
+   if( Pseudo_scrn.buf == NULL || Pseudo_size > Pseudo_scrn.mem_size ) {
23
 
+      Pseudo_scrn.buf = alloc_r(Pseudo_scrn.buf, Pseudo_size);
24
 
+      Pseudo_scrn.mem_size = Pseudo_size;
25
 
+   }
26
 
 
27
 
    // force rebuild of column headers AND libproc/readproc requirements
28
 
    Frames_libflags = 0;
29
 
@@ -3315,7 +3318,7 @@
30
 
    //       reframewins(), who also builds each window's column headers
31
 
    if (!Frames_libflags) {
32
 
       reframewins();
33
 
-      memset(Pseudo_scrn, '\0', Pseudo_size);
34
 
+      memset(Pseudo_scrn.buf, '\0', Pseudo_size);
35
 
    }
36
 
    Pseudo_row = Msg_row = scrlins = 0;
37
 
    ppt = summary_show();
38
 
Index: b/top.h
39
 
===================================================================
40
 
--- a/top.h     2009-11-24 20:53:04.000000000 +1100
41
 
+++ b/top.h     2009-11-24 21:00:39.000000000 +1100
42
 
@@ -135,7 +135,7 @@
43
 
    int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg);   \
44
 
    putp ( Batch ? _str :                                   \
45
 
    ({                                                 \
46
 
-      char *restrict const _pse = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols];  \
47
 
+      char *restrict const _pse = &Pseudo_scrn.buf[Pseudo_row++ * Pseudo_cols];  \
48
 
       memcmp(_pse, _str, _len) ? memcpy(_pse, _str, _len) : "\n";  \
49
 
    })                                \
50
 
    );                   \
51
 
@@ -149,7 +149,11 @@
52
 
    int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg);   \
53
 
    if (Batch) _ptr = _str;                                   \
54
 
    else {                                                 \
55
 
-      _ptr = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols];  \
56
 
+      if (Pseudo_row * Pseudo_cols + _len > Pseudo_size) { \
57
 
+         Pseudo_scrn.buf = realloc(Pseudo_scrn.buf, Pseudo_row * Pseudo_cols + _len); \
58
 
+        Pseudo_scrn.mem_size = Pseudo_size = Pseudo_row * Pseudo_cols + _len; \
59
 
+      } \
60
 
+      _ptr = &Pseudo_scrn.buf[Pseudo_row++ * Pseudo_cols];  \
61
 
       if (memcmp(_ptr, _str, _len)) {                \
62
 
          memcpy(_ptr, _str, _len);                \
63
 
       } else {                                 \
64
 
@@ -237,6 +241,11 @@
65
 
    RCW_t  win [4];              // a 'WIN_t.rc' for each of the 4 windows
66
 
 } RCF_t;
67
 
 
68
 
+typedef struct PSEUDO_SCREEN_t {
69
 
+   char *buf;
70
 
+   int mem_size;
71
 
+} PSEUDO_SCREEN_t;
72
 
+
73
 
 // The scaling 'type' used with scale_num() -- this is how
74
 
 // the passed number is interpreted should scaling be necessary
75
 
 enum scale_num {