LCOV - code coverage report
Current view: top level - core - locale-setup.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 0 34 0.0 %
Date: 2015-07-29 18:47:03 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
       2             : 
       3             : /***
       4             :   This file is part of systemd.
       5             : 
       6             :   Copyright 2010 Lennart Poettering
       7             : 
       8             :   systemd is free software; you can redistribute it and/or modify it
       9             :   under the terms of the GNU Lesser General Public License as published by
      10             :   the Free Software Foundation; either version 2.1 of the License, or
      11             :   (at your option) any later version.
      12             : 
      13             :   systemd is distributed in the hope that it will be useful, but
      14             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      16             :   Lesser General Public License for more details.
      17             : 
      18             :   You should have received a copy of the GNU Lesser General Public License
      19             :   along with systemd; If not, see <http://www.gnu.org/licenses/>.
      20             : ***/
      21             : 
      22             : #include <stdlib.h>
      23             : #include <errno.h>
      24             : 
      25             : #include "locale-setup.h"
      26             : #include "util.h"
      27             : #include "virt.h"
      28             : #include "fileio.h"
      29             : #include "strv.h"
      30             : #include "env-util.h"
      31             : #include "locale-util.h"
      32             : 
      33           0 : int locale_setup(char ***environment) {
      34             :         char **add;
      35           0 :         char *variables[_VARIABLE_LC_MAX] = {};
      36           0 :         int r = 0, i;
      37             : 
      38           0 :         if (detect_container(NULL) <= 0) {
      39           0 :                 r = parse_env_file("/proc/cmdline", WHITESPACE,
      40             :                                    "locale.LANG",              &variables[VARIABLE_LANG],
      41             :                                    "locale.LANGUAGE",          &variables[VARIABLE_LANGUAGE],
      42             :                                    "locale.LC_CTYPE",          &variables[VARIABLE_LC_CTYPE],
      43             :                                    "locale.LC_NUMERIC",        &variables[VARIABLE_LC_NUMERIC],
      44             :                                    "locale.LC_TIME",           &variables[VARIABLE_LC_TIME],
      45             :                                    "locale.LC_COLLATE",        &variables[VARIABLE_LC_COLLATE],
      46             :                                    "locale.LC_MONETARY",       &variables[VARIABLE_LC_MONETARY],
      47             :                                    "locale.LC_MESSAGES",       &variables[VARIABLE_LC_MESSAGES],
      48             :                                    "locale.LC_PAPER",          &variables[VARIABLE_LC_PAPER],
      49             :                                    "locale.LC_NAME",           &variables[VARIABLE_LC_NAME],
      50             :                                    "locale.LC_ADDRESS",        &variables[VARIABLE_LC_ADDRESS],
      51             :                                    "locale.LC_TELEPHONE",      &variables[VARIABLE_LC_TELEPHONE],
      52             :                                    "locale.LC_MEASUREMENT",    &variables[VARIABLE_LC_MEASUREMENT],
      53             :                                    "locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
      54             :                                    NULL);
      55             : 
      56           0 :                 if (r < 0 && r != -ENOENT)
      57           0 :                         log_warning_errno(r, "Failed to read /proc/cmdline: %m");
      58             :         }
      59             : 
      60             :         /* Hmm, nothing set on the kernel cmd line? Then let's
      61             :          * try /etc/locale.conf */
      62           0 :         if (r <= 0) {
      63           0 :                 r = parse_env_file("/etc/locale.conf", NEWLINE,
      64             :                                    "LANG",              &variables[VARIABLE_LANG],
      65             :                                    "LANGUAGE",          &variables[VARIABLE_LANGUAGE],
      66             :                                    "LC_CTYPE",          &variables[VARIABLE_LC_CTYPE],
      67             :                                    "LC_NUMERIC",        &variables[VARIABLE_LC_NUMERIC],
      68             :                                    "LC_TIME",           &variables[VARIABLE_LC_TIME],
      69             :                                    "LC_COLLATE",        &variables[VARIABLE_LC_COLLATE],
      70             :                                    "LC_MONETARY",       &variables[VARIABLE_LC_MONETARY],
      71             :                                    "LC_MESSAGES",       &variables[VARIABLE_LC_MESSAGES],
      72             :                                    "LC_PAPER",          &variables[VARIABLE_LC_PAPER],
      73             :                                    "LC_NAME",           &variables[VARIABLE_LC_NAME],
      74             :                                    "LC_ADDRESS",        &variables[VARIABLE_LC_ADDRESS],
      75             :                                    "LC_TELEPHONE",      &variables[VARIABLE_LC_TELEPHONE],
      76             :                                    "LC_MEASUREMENT",    &variables[VARIABLE_LC_MEASUREMENT],
      77             :                                    "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
      78             :                                    NULL);
      79             : 
      80           0 :                 if (r < 0 && r != -ENOENT)
      81           0 :                         log_warning_errno(r, "Failed to read /etc/locale.conf: %m");
      82             :         }
      83             : 
      84           0 :         add = NULL;
      85           0 :         for (i = 0; i < _VARIABLE_LC_MAX; i++) {
      86             :                 char *s;
      87             : 
      88           0 :                 if (!variables[i])
      89           0 :                         continue;
      90             : 
      91           0 :                 s = strjoin(locale_variable_to_string(i), "=", variables[i], NULL);
      92           0 :                 if (!s) {
      93           0 :                         r = -ENOMEM;
      94           0 :                         goto finish;
      95             :                 }
      96             : 
      97           0 :                 if (strv_consume(&add, s) < 0) {
      98           0 :                         r = -ENOMEM;
      99           0 :                         goto finish;
     100             :                 }
     101             :         }
     102             : 
     103           0 :         if (!strv_isempty(add)) {
     104             :                 char **e;
     105             : 
     106           0 :                 e = strv_env_merge(2, *environment, add);
     107           0 :                 if (!e) {
     108           0 :                         r = -ENOMEM;
     109           0 :                         goto finish;
     110             :                 }
     111             : 
     112           0 :                 strv_free(*environment);
     113           0 :                 *environment = e;
     114             :         }
     115             : 
     116           0 :         r = 0;
     117             : 
     118             : finish:
     119           0 :         strv_free(add);
     120             : 
     121           0 :         for (i = 0; i < _VARIABLE_LC_MAX; i++)
     122           0 :                 free(variables[i]);
     123             : 
     124           0 :         return r;
     125             : }

Generated by: LCOV version 1.11