ash: fix for last commit
[oweals/busybox.git] / init / bootchartd.c
index c7388c99e3d82bbfdb3ac36473362bc5b6a2bf9f..b5dd174399bdb6e57e0c81187c36808e284ddb66 100644 (file)
@@ -8,45 +8,46 @@
 //kbuild:lib-$(CONFIG_BOOTCHARTD) += bootchartd.o
 
 //config:config BOOTCHARTD
-//config:      bool "bootchartd"
+//config:      bool "bootchartd (10 kb)"
 //config:      default y
 //config:      help
-//config:        bootchartd is commonly used to profile the boot process
-//config:        for the purpose of speeding it up. In this case, it is started
-//config:        by the kernel as the init process. This is configured by adding
-//config:        the init=/sbin/bootchartd option to the kernel command line.
+//config:      bootchartd is commonly used to profile the boot process
+//config:      for the purpose of speeding it up. In this case, it is started
+//config:      by the kernel as the init process. This is configured by adding
+//config:      the init=/sbin/bootchartd option to the kernel command line.
 //config:
-//config:        It can also be used to monitor the resource usage of a specific
-//config:        application or the running system in general. In this case,
-//config:        bootchartd is started interactively by running bootchartd start
-//config:        and stopped using bootchartd stop.
+//config:      It can also be used to monitor the resource usage of a specific
+//config:      application or the running system in general. In this case,
+//config:      bootchartd is started interactively by running bootchartd start
+//config:      and stopped using bootchartd stop.
 //config:
 //config:config FEATURE_BOOTCHARTD_BLOATED_HEADER
 //config:      bool "Compatible, bloated header"
 //config:      default y
 //config:      depends on BOOTCHARTD
 //config:      help
-//config:        Create extended header file compatible with "big" bootchartd.
-//config:        "Big" bootchartd is a shell script and it dumps some
-//config:        "convenient" info int the header, such as:
-//config:          title = Boot chart for `hostname` (`date`)
-//config:          system.uname = `uname -srvm`
-//config:          system.release = `cat /etc/DISTRO-release`
-//config:          system.cpu = `grep '^model name' /proc/cpuinfo | head -1` ($cpucount)
-//config:          system.kernel.options = `cat /proc/cmdline`
-//config:        This data is not mandatory for bootchart graph generation,
-//config:        and is considered bloat. Nevertheless, this option
-//config:        makes bootchartd applet to dump a subset of it.
+//config:      Create extended header file compatible with "big" bootchartd.
+//config:      "Big" bootchartd is a shell script and it dumps some
+//config:      "convenient" info int the header, such as:
+//config:              title = Boot chart for `hostname` (`date`)
+//config:              system.uname = `uname -srvm`
+//config:              system.release = `cat /etc/DISTRO-release`
+//config:              system.cpu = `grep '^model name' /proc/cpuinfo | head -1` ($cpucount)
+//config:              system.kernel.options = `cat /proc/cmdline`
+//config:      This data is not mandatory for bootchart graph generation,
+//config:      and is considered bloat. Nevertheless, this option
+//config:      makes bootchartd applet to dump a subset of it.
 //config:
 //config:config FEATURE_BOOTCHARTD_CONFIG_FILE
 //config:      bool "Support bootchartd.conf"
 //config:      default y
 //config:      depends on BOOTCHARTD
 //config:      help
-//config:        Enable reading and parsing of $PWD/bootchartd.conf
-//config:        and /etc/bootchartd.conf files.
+//config:      Enable reading and parsing of $PWD/bootchartd.conf
+//config:      and /etc/bootchartd.conf files.
 
 #include "libbb.h"
+#include "common_bufsiz.h"
 /* After libbb.h, since it needs sys/types.h on some systems */
 #include <sys/utsname.h>
 
 struct globals {
        char jiffy_line[COMMON_BUFSIZE];
 } FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
-#define INIT_G() do { } while (0)
+#define G (*(struct globals*)bb_common_bufsiz1)
+#define INIT_G() do { setup_common_bufsiz(); } while (0)
 
 static void dump_file(FILE *fp, const char *filename)
 {
@@ -170,7 +171,9 @@ static int dump_procs(FILE *fp, int look_for_login_process)
                        p++;
                        strchrnul(p, ')')[0] = '\0';
                        /* Is it gdm, kdm or a getty? */
-                       if (((p[0] == 'g' || p[0] == 'k' || p[0] == 'x') && p[1] == 'd' && p[2] == 'm')
+                       if (((p[0] == 'g' || p[0] == 'k' || p[0] == 'x')
+                            && p[1] == 'd' && p[2] == 'm' && p[3] == '\0'
+                           )
                         || strstr(p, "getty")
                        ) {
                                found_login_process = 1;
@@ -189,11 +192,11 @@ static char *make_tempdir(void)
        if (!tempdir) {
 #ifdef __linux__
                /* /tmp is not writable (happens when we are used as init).
-                * Try to mount a tmpfs, them cd and lazily unmount it.
+                * Try to mount a tmpfs, then cd and lazily unmount it.
                 * Since we unmount it at once, we can mount it anywhere.
                 * Try a few locations which are likely ti exist.
                 */
-               static const char dirs[] = "/mnt\0""/tmp\0""/boot\0""/proc\0";
+               static const char dirs[] ALIGN1 = "/mnt\0""/tmp\0""/boot\0""/proc\0";
                const char *try_dir = dirs;
                while (mount("none", try_dir, "tmpfs", MS_SILENT, "size=16m") != 0) {
                        try_dir += strlen(try_dir) + 1;