dev-setup.c revision 2eec67acbb00593e414549a7e5b35eb7dd776b1b
3832N/A/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3832N/A
3832N/A/***
3832N/A This file is part of systemd.
3832N/A
3832N/A Copyright 2010-2012 Lennart Poettering
3832N/A
3832N/A systemd is free software; you can redistribute it and/or modify it
3832N/A under the terms of the GNU Lesser General Public License as published by
3832N/A the Free Software Foundation; either version 2.1 of the License, or
3832N/A (at your option) any later version.
3832N/A
3832N/A systemd is distributed in the hope that it will be useful, but
3832N/A WITHOUT ANY WARRANTY; without even the implied warranty of
3832N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3832N/A Lesser General Public License for more details.
3832N/A
3832N/A You should have received a copy of the GNU Lesser General Public License
3832N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
3832N/A***/
3832N/A
3832N/A#include <errno.h>
3832N/A#include <stdlib.h>
3832N/A#include <unistd.h>
4458N/A
6033N/A#include "dev-setup.h"
3832N/A#include "util.h"
3832N/A#include "label.h"
3832N/A
3832N/Aint dev_setup(const char *prefix) {
3832N/A const char *j, *k;
3832N/A
3832N/A static const char symlinks[] =
3832N/A "-/proc/kcore\0" "/dev/core\0"
3832N/A "/proc/self/fd\0" "/dev/fd\0"
3832N/A "/proc/self/fd/0\0" "/dev/stdin\0"
3832N/A "/proc/self/fd/1\0" "/dev/stdout\0"
4714N/A "/proc/self/fd/2\0" "/dev/stderr\0";
3832N/A
3832N/A NULSTR_FOREACH_PAIR(j, k, symlinks) {
3832N/A if (j[0] == '-') {
3832N/A j++;
3832N/A
3832N/A if (access(j, F_OK) < 0)
4714N/A continue;
4714N/A }
4714N/A
4714N/A if (prefix) {
4714N/A _cleanup_free_ char *link_name = NULL;
4714N/A
4714N/A link_name = strjoin(prefix, "/", k, NULL);
4714N/A if (!link_name)
4714N/A return -ENOMEM;
4714N/A
4714N/A symlink_label(j, link_name);
4714N/A } else
4714N/A symlink_label(j, k);
4714N/A }
4714N/A
4714N/A return 0;
4714N/A}
4714N/A