~ubuntu-branches/ubuntu/trusty/plymouth/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/initramfsless-boot.patch/src/main.c

  • Committer: Dmitrijs Ledkovs
  • Date: 2012-11-22 13:26:28 UTC
  • mfrom: (1016.2.4)
  • Revision ID: dmitrijs.ledkovs@canonical.com-20121122132628-0f8y3xhxb7aey5ns
* New upstream release:
  - drop, applied upstream upstream-add-generic-driver-to-drm-renderer-plugin.patch
  - drop, applied upstream invalid-event-source-workaround.patch
  - drop, raring has recent enough drm update-libdrm-nouveau-library-dependency.patch
  - rebase tty1-after-boot.patch
  - rebase misc-changes.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
typedef enum {
63
63
  PLY_MODE_BOOT,
64
 
  PLY_MODE_SHUTDOWN
 
64
  PLY_MODE_SHUTDOWN,
 
65
  PLY_MODE_UPDATES
65
66
} ply_mode_t;
66
67
 
67
68
typedef struct 
183
184
}
184
185
 
185
186
static void
 
187
on_change_mode (state_t     *state,
 
188
                const char  *mode)
 
189
{
 
190
  if (state->boot_splash == NULL)
 
191
    {
 
192
      ply_trace ("no splash set");
 
193
      return;
 
194
    }
 
195
 
 
196
  ply_trace ("updating mode to '%s'", mode);
 
197
  if (strcmp (mode, "boot-up") == 0)
 
198
    state->mode = PLY_BOOT_SPLASH_MODE_BOOT_UP;
 
199
  else if (strcmp (mode, "shutdown") == 0)
 
200
    state->mode = PLY_BOOT_SPLASH_MODE_SHUTDOWN;
 
201
  else if (strcmp (mode, "updates") == 0)
 
202
    state->mode = PLY_BOOT_SPLASH_MODE_UPDATES;
 
203
  else
 
204
    return;
 
205
 
 
206
  if (!ply_boot_splash_show (state->boot_splash, state->mode))
 
207
    {
 
208
      ply_trace ("failed to update splash");
 
209
      return;
 
210
    }
 
211
}
 
212
 
 
213
static void
 
214
on_system_update (state_t     *state,
 
215
                  int          progress)
 
216
{
 
217
  if (state->boot_splash == NULL)
 
218
    {
 
219
      ply_trace ("no splash set");
 
220
      return;
 
221
    }
 
222
 
 
223
  ply_trace ("setting system update to '%i'", progress);
 
224
  if (!ply_boot_splash_system_update (state->boot_splash, progress))
 
225
    {
 
226
      ply_trace ("failed to update splash");
 
227
      return;
 
228
    }
 
229
}
 
230
 
 
231
static void
186
232
flush_pending_messages (state_t *state)
187
233
{
188
234
  ply_list_node_t *node = ply_list_get_first_node (state->pending_messages);
475
521
on_display_message (state_t       *state,
476
522
                    const char    *message)
477
523
{
478
 
  ply_trace ("displaying message %s", message);
479
524
  if (state->boot_splash != NULL)
480
 
    ply_boot_splash_display_message (state->boot_splash, message);
 
525
    {
 
526
        ply_trace ("displaying message %s", message);
 
527
        ply_boot_splash_display_message (state->boot_splash, message);
 
528
    }
481
529
  else
482
 
    ply_list_append_data (state->messages, strdup(message));
 
530
    {
 
531
        ply_trace ("not displaying message %s as no splash", message);
 
532
        ply_list_append_data (state->messages, strdup(message));
 
533
    }
483
534
}
484
535
 
485
536
static void
590
641
    case PLY_MODE_SHUTDOWN:
591
642
      filename = SHUTDOWN_DURATION_FILE;
592
643
      break;
 
644
    case PLY_MODE_UPDATES:
 
645
      filename = NULL;
 
646
      break;
593
647
    default:
594
648
      fprintf (stderr, "Unhandled case in %s line %d\n", __FILE__, __LINE__);
595
649
      abort ();
611
665
      filename = PLYMOUTH_LOG_DIRECTORY "/boot.log";
612
666
      break;
613
667
    case PLY_MODE_SHUTDOWN:
 
668
    case PLY_MODE_UPDATES:
614
669
      filename = _PATH_DEVNULL;
615
670
      break;
616
671
    default:
634
689
      filename = PLYMOUTH_SPOOL_DIRECTORY "/boot.log";
635
690
      break;
636
691
    case PLY_MODE_SHUTDOWN:
 
692
    case PLY_MODE_UPDATES:
637
693
      filename = NULL;
638
694
      break;
639
695
    default:
999
1055
  dump_details_and_quit_splash (state);
1000
1056
}
1001
1057
 
1002
 
#ifdef PLY_ENABLE_GDM_TRANSITION
 
1058
#ifdef PLY_ENABLE_DEPRECATED_GDM_TRANSITION
1003
1059
static void
1004
1060
tell_gdm_to_transition (void)
1005
1061
{
1023
1079
      pid_file = NULL;
1024
1080
    }
1025
1081
 
1026
 
#ifdef PLY_ENABLE_GDM_TRANSITION
 
1082
#ifdef PLY_ENABLE_DEPRECATED_GDM_TRANSITION
1027
1083
  if (state->should_retain_splash &&
1028
1084
      state->mode == PLY_MODE_BOOT)
1029
1085
    {
1244
1300
  ply_boot_server_t *server;
1245
1301
 
1246
1302
  server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update,
 
1303
                                (ply_boot_server_change_mode_handler_t) on_change_mode,
 
1304
                                (ply_boot_server_system_update_handler_t) on_system_update,
1247
1305
                                (ply_boot_server_ask_for_password_handler_t) on_ask_for_password,
1248
1306
                                (ply_boot_server_ask_question_handler_t) on_ask_question,
1249
1307
                                (ply_boot_server_display_message_handler_t) on_display_message,
1528
1586
 
1529
1587
  state->local_console_terminal = ply_terminal_new (state->default_tty);
1530
1588
 
1531
 
  /* force frame-buffer plugin for shutdown so it sticks around after getting killed */
1532
 
  if (state->mode == PLY_MODE_SHUTDOWN)
1533
 
    renderer = ply_renderer_new (PLYMOUTH_PLUGIN_PATH "renderers/frame-buffer.so", NULL, state->local_console_terminal);
1534
 
  else
1535
 
    renderer = ply_renderer_new (NULL, NULL, state->local_console_terminal);
 
1589
  renderer = ply_renderer_new (NULL, NULL, state->local_console_terminal);
1536
1590
 
1537
1591
  if (!ply_renderer_open (renderer))
1538
1592
    {
1834
1888
      if (stream != NULL)
1835
1889
        {
1836
1890
          char *end;
 
1891
          char *stream_copy;
1837
1892
 
1838
 
          stream = strdup (stream);
1839
 
          end = stream + strcspn (stream, " \n");
 
1893
          stream_copy = strdup (stream);
 
1894
          end = stream_copy + strcspn (stream_copy, " \n");
1840
1895
          *end = '\0';
1841
1896
 
1842
 
          ply_trace ("streaming debug output to %s instead of screen", stream);
1843
 
          fd = open (stream, O_RDWR | O_NOCTTY | O_CREAT, 0600);
 
1897
          ply_trace ("streaming debug output to %s instead of screen", stream_copy);
 
1898
          fd = open (stream_copy, O_RDWR | O_NOCTTY | O_CREAT, 0600);
1844
1899
 
1845
1900
          if (fd < 0)
1846
1901
            {
1847
 
              ply_trace ("could not stream output to %s: %m", stream);
 
1902
              ply_trace ("could not stream output to %s: %m", stream_copy);
1848
1903
            }
1849
1904
          else
1850
1905
            {
1851
1906
              ply_logger_set_output_fd (ply_logger_get_error_default (), fd);
1852
1907
            }
1853
 
          free (stream);
 
1908
          free (stream_copy);
1854
1909
        }
1855
1910
    }
1856
1911
  else
1902
1957
  add_display_and_keyboard_for_terminal (state, terminal);
1903
1958
}
1904
1959
 
1905
 
static bool
 
1960
static int
1906
1961
add_consoles_from_file (state_t         *state,
1907
1962
                        ply_hashtable_t *consoles,
1908
1963
                        const char      *path)
1909
1964
{
1910
1965
  int fd;
1911
1966
  char contents[512] = "";
1912
 
  const char *remaining_command_line;
1913
 
  char *console;
 
1967
  ssize_t contents_length;
 
1968
  int num_consoles;
 
1969
  const char *remaining_file_contents;
1914
1970
 
1915
1971
  ply_trace ("opening %s", path);
1916
1972
  fd = open (path, O_RDONLY);
1918
1974
  if (fd < 0)
1919
1975
    {
1920
1976
      ply_trace ("couldn't open it: %m");
1921
 
      return false;
 
1977
      return 0;
1922
1978
    }
1923
1979
 
1924
1980
  ply_trace ("reading file");
1925
 
  if (read (fd, contents, sizeof (contents)))
 
1981
  contents_length = read (fd, contents, sizeof (contents));
 
1982
 
 
1983
  if (contents_length <= 0)
1926
1984
    {
1927
1985
      ply_trace ("couldn't read it: %m");
1928
1986
      close (fd);
1929
 
      return false;
 
1987
      return 0;
1930
1988
    }
1931
1989
  close (fd);
1932
1990
 
1933
 
  remaining_command_line = contents;
 
1991
  remaining_file_contents = contents;
 
1992
  num_consoles = 0;
1934
1993
 
1935
 
  console = NULL;
1936
 
  while (remaining_command_line != '\0')
 
1994
  while (remaining_file_contents < contents + contents_length)
1937
1995
    {
1938
 
      char *end;
 
1996
      char *console;
1939
1997
      size_t console_length;
1940
1998
      char *console_device;
1941
1999
 
1942
 
      state->should_force_details = true;
1943
 
 
1944
 
      console = strdup (remaining_command_line);
1945
 
 
1946
 
      end = strpbrk (console, " \n\t\v");
1947
 
 
1948
 
      if (end != NULL)
1949
 
        *end = '\0';
1950
 
 
1951
 
      console_length = strlen (console);
 
2000
      /* Advance past any leading whitespace */
 
2001
      remaining_file_contents += strspn (remaining_file_contents, " \n\t\v");
 
2002
 
 
2003
      if (*remaining_file_contents == '\0')
 
2004
        {
 
2005
          /* There's nothing left after the whitespace, we're done */
 
2006
          break;
 
2007
        }
 
2008
 
 
2009
      /* Find trailing whitespace and NUL terminate.  If strcspn
 
2010
       * doesn't find whitespace, it gives us the length of the string
 
2011
       * until the next NUL byte, which we'll just overwrite with
 
2012
       * another NUL byte anyway. */
 
2013
      console_length = strcspn (remaining_file_contents, " \n\t\v");
 
2014
      console = strndup (remaining_file_contents, console_length);
 
2015
 
 
2016
      /* If this console is anything besides tty0, then the user is sort
 
2017
       * of a weird case (uses a serial console or whatever) and they
 
2018
       * most likely don't want a graphical splash, so force details.
 
2019
       */
 
2020
      if (strcmp (console, "tty0") != 0)
 
2021
        state->should_force_details = true;
1952
2022
 
1953
2023
      asprintf (&console_device, "/dev/%s", console);
 
2024
 
1954
2025
      free (console);
1955
 
      console = NULL;
1956
2026
 
1957
2027
      ply_trace ("console %s found!", console_device);
1958
2028
      ply_hashtable_insert (consoles, console_device, console_device);
1959
 
      remaining_command_line += console_length;
 
2029
      num_consoles++;
 
2030
 
 
2031
      /* Move past the parsed console string, and the whitespace we
 
2032
       * may have found above.  If we found a NUL above and not whitespace,
 
2033
       * then we're going to jump past the end of the buffer and the loop
 
2034
       * will terminate
 
2035
       */
 
2036
      remaining_file_contents += console_length + 1;
1960
2037
    }
1961
2038
 
1962
 
  return true;
 
2039
  return num_consoles;
1963
2040
}
1964
2041
 
1965
 
static void
 
2042
static int
1966
2043
add_consoles_from_kernel_command_line (state_t         *state,
1967
2044
                                       ply_hashtable_t *consoles)
1968
2045
{
1969
2046
  const char *console_string;
1970
2047
  const char *remaining_command_line;
1971
2048
  char *console;
 
2049
  int num_consoles;
1972
2050
 
1973
2051
  remaining_command_line = state->kernel_command_line;
1974
2052
 
 
2053
  num_consoles = 0;
1975
2054
  console = NULL;
1976
2055
  while ((console_string = command_line_get_string_after_prefix (remaining_command_line,
1977
2056
                                                                 "console=")) != NULL)
2007
2086
 
2008
2087
      ply_trace ("console %s found!", console_device);
2009
2088
      ply_hashtable_insert (consoles, console_device, console_device);
 
2089
      num_consoles++;
2010
2090
      remaining_command_line += console_length;
2011
2091
    }
 
2092
 
 
2093
  return num_consoles;
2012
2094
}
2013
2095
 
2014
2096
static void
2018
2100
{
2019
2101
  char *console;
2020
2102
  ply_hashtable_t *consoles;
 
2103
  int num_consoles;
 
2104
  bool ignore_serial_consoles;
2021
2105
 
2022
2106
  ply_trace ("checking for consoles%s",
2023
2107
             should_add_displays? " and adding displays": "");
2024
2108
 
2025
2109
  consoles = ply_hashtable_new (ply_hashtable_string_hash,
2026
2110
                                ply_hashtable_string_compare);
2027
 
 
2028
 
  if (!add_consoles_from_file (state,
2029
 
                               consoles,
2030
 
                               "/sys/class/tty/console/active"))
2031
 
    {
2032
 
      ply_trace ("falling back to kernel command line");
2033
 
      add_consoles_from_kernel_command_line (state, consoles);
 
2111
  ignore_serial_consoles = command_line_has_argument (state->kernel_command_line, "plymouth.ignore-serial-consoles");
 
2112
 
 
2113
  num_consoles = 0;
 
2114
 
 
2115
  if (!ignore_serial_consoles)
 
2116
    {
 
2117
      num_consoles = add_consoles_from_file (state, consoles, "/sys/class/tty/console/active");
 
2118
 
 
2119
      if (num_consoles == 0)
 
2120
        {
 
2121
          ply_trace ("falling back to kernel command line");
 
2122
          num_consoles = add_consoles_from_kernel_command_line (state, consoles);
 
2123
        }
 
2124
    }
 
2125
  else
 
2126
    {
 
2127
      ply_trace ("ignoring all consoles but default console because of plymouth.ignore-serial-consoles");
2034
2128
    }
2035
2129
 
2036
2130
  console = ply_hashtable_remove (consoles, (void *) "/dev/tty0");
2037
2131
  if (console != NULL)
2038
2132
    {
2039
2133
      free (console);
2040
 
      ply_hashtable_insert (consoles, (void *) default_tty, (char *) default_tty);
 
2134
      console = strdup (default_tty);
 
2135
      ply_hashtable_insert (consoles, console, console);
2041
2136
    }
2042
2137
 
2043
2138
  console = ply_hashtable_remove (consoles, (void *) "/dev/tty");
2044
2139
  if (console != NULL)
2045
2140
    {
2046
2141
      free (console);
2047
 
      ply_hashtable_insert (consoles, (void *) default_tty, (void *) default_tty);
 
2142
      console = strdup (default_tty);
 
2143
      ply_hashtable_insert (consoles, console, console);
2048
2144
    }
2049
2145
 
2050
2146
  free (state->kernel_console_tty);
2055
2151
 
2056
2152
  if (should_add_displays)
2057
2153
    {
2058
 
      ply_hashtable_foreach (consoles,
2059
 
                             (ply_hashtable_foreach_func_t *)
2060
 
                             add_display_and_keyboard_for_console,
2061
 
                             state);
 
2154
      /* Do a full graphical splash if there's no weird serial console
 
2155
       * stuff going on, otherwise just prepare text splashes
 
2156
       */
 
2157
      if ((num_consoles == 0) ||
 
2158
          ((num_consoles == 1) &&
 
2159
           (ply_hashtable_lookup (consoles, (void *) default_tty) != NULL)))
 
2160
        add_default_displays_and_keyboard (state);
 
2161
      else
 
2162
        ply_hashtable_foreach (consoles,
 
2163
                               (ply_hashtable_foreach_func_t *)
 
2164
                               add_display_and_keyboard_for_console,
 
2165
                               state);
2062
2166
    }
2063
2167
 
2064
2168
  ply_hashtable_foreach (consoles, (ply_hashtable_foreach_func_t *) free, NULL);
2066
2170
 
2067
2171
  ply_trace ("After processing serial consoles there are now %d text displays",
2068
2172
             ply_list_get_length (state->text_displays));
2069
 
  if (should_add_displays && ply_list_get_length (state->text_displays) == 0)
2070
 
    add_default_displays_and_keyboard (state);
2071
2173
}
2072
2174
 
2073
2175
static bool
2338
2440
    {
2339
2441
      if (strcmp (mode_string, "shutdown") == 0)
2340
2442
        state.mode = PLY_MODE_SHUTDOWN;
 
2443
      else if (strcmp (mode_string, "updates") == 0)
 
2444
        state.mode = PLY_MODE_UPDATES;
2341
2445
      else
2342
2446
        state.mode = PLY_MODE_BOOT;
2343
2447
 
2400
2504
      return EX_OSERR;
2401
2505
    }
2402
2506
 
 
2507
  /* Make the first byte in argv be '@' so that we can survive systemd's killing
 
2508
   * spree when going from initrd to /, and so we stay alive all the way until
 
2509
   * the power is killed at shutdown.
 
2510
   * http://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons
 
2511
   */
 
2512
  argv[0][0] = '@';
 
2513
 
 
2514
  state.boot_server = start_boot_server (&state);
 
2515
 
 
2516
  if (state.boot_server == NULL)
 
2517
    {
 
2518
      ply_trace ("plymouthd is already running");
 
2519
 
 
2520
      if (daemon_handle != NULL)
 
2521
        ply_detach_daemon (daemon_handle, EX_OK);
 
2522
      return EX_OK;
 
2523
    }
 
2524
 
2403
2525
  state.boot_buffer = ply_buffer_new ();
2404
2526
 
2405
2527
  if (attach_to_session)
2414
2536
        }
2415
2537
    }
2416
2538
 
2417
 
  state.boot_server = start_boot_server (&state);
2418
 
 
2419
 
  if (state.boot_server == NULL)
2420
 
    {
2421
 
      ply_trace ("could not log bootup: %m");
2422
 
 
2423
 
      detach_from_running_session (&state);
2424
 
 
2425
 
      if (daemon_handle != NULL)
2426
 
        ply_detach_daemon (daemon_handle, EX_UNAVAILABLE);
2427
 
      return EX_UNAVAILABLE;
2428
 
    }
2429
 
 
2430
2539
  state.progress = ply_progress_new ();
2431
2540
 
2432
2541
  ply_progress_load_cache (state.progress,