path.c revision 3f6fd1ba65f962702753c4ad284b588e59689a23
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek This file is part of systemd.
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek Copyright 2014 Lennart Poettering
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek (at your option) any later version.
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekstatic const char *arg_suffix = NULL;
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekstatic const char* const path_table[_SD_PATH_MAX] = {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_TEMPORARY] = "temporary",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_TEMPORARY_LARGE] = "temporary-large",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_BINARIES] = "system-binaries",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_INCLUDE] = "system-include",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_LIBRARY_ARCH] = "system-library-arch",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_SHARED] = "system-shared",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_CONFIGURATION_FACTORY] = "system-configuration-factory",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_STATE_FACTORY] = "system-state-factory",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_CONFIGURATION] = "system-configuration",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_RUNTIME] = "system-runtime",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_RUNTIME_LOGS] = "system-runtime-logs",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_STATE_PRIVATE] = "system-state-private",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_STATE_LOGS] = "system-state-logs",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_STATE_CACHE] = "system-state-cache",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SYSTEM_STATE_SPOOL] = "system-state-spool",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_BINARIES] = "user-binaries",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_LIBRARY_PRIVATE] = "user-library-private",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_LIBRARY_ARCH] = "user-library-arch",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_SHARED] = "user-shared",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_CONFIGURATION] = "user-configuration",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_RUNTIME] = "user-runtime",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_STATE_CACHE] = "user-state-cache",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_DOCUMENTS] = "user-documents",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_MUSIC] = "user-music",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_PICTURES] = "user-pictures",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_VIDEOS] = "user-videos",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_DOWNLOAD] = "user-download",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_PUBLIC] = "user-public",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_TEMPLATES] = "user-templates",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_USER_DESKTOP] = "user-desktop",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_BINARIES] = "search-binaries",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_LIBRARY_PRIVATE] = "search-library-private",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_LIBRARY_ARCH] = "search-library-arch",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_SHARED] = "search-shared",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek [SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek for (i = 0; i < ELEMENTSOF(path_table); i++) {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek q = sd_path_home(i, arg_suffix, &p);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to query %s: %m", path_table[i]);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek printf("%s: %s\n", path_table[i], p);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekstatic int print_home(const char *n) {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek for (i = 0; i < ELEMENTSOF(path_table); i++) {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek r = sd_path_home(i, arg_suffix, &p);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to query %s: %m", n);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek log_error("Path %s not known.", n);
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekstatic void help(void) {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek printf("%s [OPTIONS...] [NAME...]\n\n"
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek "Show system and user paths.\n\n"
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek " -h --help Show this help\n"
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek " --version Show package version\n"
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek " --suffix=SUFFIX Suffix to append to paths\n",
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekstatic int parse_argv(int argc, char *argv[]) {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek static const struct option options[] = {
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek { "help", no_argument, NULL, 'h' },
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek { "version", no_argument, NULL, ARG_VERSION },
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek { "suffix", required_argument, NULL, ARG_SUFFIX },
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek assert_not_reached("Unhandled option");
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmekint main(int argc, char* argv[]) {
goto finish;
r = list_homes();