| 869 | } |
| 870 | |
| 871 | static void |
| 872 | malloc_conf_init(void) { |
| 873 | unsigned i; |
| 874 | char buf[PATH_MAX + 1]; |
| 875 | const char *opts, *k, *v; |
| 876 | size_t klen, vlen; |
| 877 | |
| 878 | for (i = 0; i < 4; i++) { |
| 879 | /* Get runtime configuration. */ |
| 880 | switch (i) { |
| 881 | case 0: |
| 882 | opts = config_malloc_conf; |
| 883 | break; |
| 884 | case 1: |
| 885 | if (je_malloc_conf != NULL) { |
| 886 | /* |
| 887 | * Use options that were compiled into the |
| 888 | * program. |
| 889 | */ |
| 890 | opts = je_malloc_conf; |
| 891 | } else { |
| 892 | /* No configuration specified. */ |
| 893 | buf[0] = '\0'; |
| 894 | opts = buf; |
| 895 | } |
| 896 | break; |
| 897 | case 2: { |
| 898 | ssize_t linklen = 0; |
| 899 | #ifndef _WIN32 |
| 900 | int saved_errno = errno; |
| 901 | const char *linkname = |
| 902 | # ifdef JEMALLOC_PREFIX |
| 903 | "/etc/"JEMALLOC_PREFIX"malloc.conf" |
| 904 | # else |
| 905 | "/etc/malloc.conf" |
| 906 | # endif |
| 907 | ; |
| 908 | |
| 909 | /* |
| 910 | * Try to use the contents of the "/etc/malloc.conf" |
| 911 | * symbolic link's name. |
| 912 | */ |
| 913 | linklen = readlink(linkname, buf, sizeof(buf) - 1); |
| 914 | if (linklen == -1) { |
| 915 | /* No configuration specified. */ |
| 916 | linklen = 0; |
| 917 | /* Restore errno. */ |
| 918 | set_errno(saved_errno); |
| 919 | } |
| 920 | #endif |
| 921 | buf[linklen] = '\0'; |
| 922 | opts = buf; |
| 923 | break; |
| 924 | } case 3: { |
| 925 | const char *envname = |
| 926 | #ifdef JEMALLOC_PREFIX |
| 927 | JEMALLOC_CPREFIX"MALLOC_CONF" |
| 928 | #else |
no test coverage detected