delta.c revision 7e8d5761ecd4e8bc8f93b1f21861cac2a39a78a1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "hashmap.h"
#include "util.h"
#include "path-util.h"
#include "log.h"
#include "pager.h"
#include "build.h"
static bool arg_no_pager = false;
static int equivalent(const char *a, const char *b) {
char *x, *y;
int r;
x = canonicalize_file_name(a);
if (!x)
return -errno;
y = canonicalize_file_name(b);
if (!y) {
free(x);
return -errno;
}
r = path_equal(x, y);
free(x);
free(y);
return r;
}
char *dest;
int k;
if (null_or_empty_path(top) > 0) {
goto finish;
}
if (k >= 0) {
else
goto finish;
}
putchar('\n');
if (pid < 0) {
log_error("Failed to fork off diff: %m");
return -errno;
} else if (pid == 0) {
log_error("Failed to execute diff: %m");
_exit(1);
}
putchar('\n');
return 0;
}
DIR *d;
int r = 0;
if (!d) {
return 0;
return -errno;
}
for (;;) {
int k;
char *p;
if (k != 0) {
r = -k;
goto finish;
}
if (!de)
break;
if (!dirent_is_file(de))
continue;
if (!p) {
r = -ENOMEM;
goto finish;
}
if (k >= 0) {
p = strdup(p);
if (!p) {
r = -ENOMEM;
goto finish;
}
} else if (k != -EEXIST) {
free(p);
r = k;
goto finish;
}
if (k < 0) {
free(p);
r = k;
goto finish;
}
}
closedir(d);
return r;
}
const char *p;
char *f;
int r = 0, k;
Iterator i;
int n_found = 0;
if (!top) {
r = -ENOMEM;
goto finish;
}
if (!bottom) {
r = -ENOMEM;
goto finish;
}
NULSTR_FOREACH(p, prefixes) {
char *t;
if (!t) {
r = -ENOMEM;
goto finish;
}
if (k < 0)
r = k;
log_debug("Looking at %s", t);
free(t);
}
HASHMAP_FOREACH(f, top, i) {
char *o;
assert(o);
if (path_equal(o, f))
continue;
k = found_override(f, o);
if (k < 0)
r = k;
n_found ++;
}
if (top)
if (bottom)
return r < 0 ? r : n_found;
}
const char *p;
if (!path_is_absolute(suffix))
/* Strip prefix from the suffix */
NULSTR_FOREACH(p, prefixes) {
if (startswith(suffix, p)) {
}
}
return -EINVAL;
}
static void help(void) {
printf("%s [OPTIONS...] [SUFFIX...]\n\n"
"Find overridden configuration files.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n",
}
enum {
ARG_NO_PAGER = 0x100,
};
};
int c;
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
return 0;
case ARG_NO_PAGER:
arg_no_pager = true;
break;
case '?':
return -EINVAL;
default:
log_error("Unknown option code %c", c);
return -EINVAL;
}
}
return 1;
}
const char prefixes[] =
"/etc\0"
"/run\0"
#ifdef HAVE_SPLIT_USR
"/lib\0"
#endif
;
const char suffixes[] =
"sysctl.d\0"
"tmpfiles.d\0"
"modules-load.d\0"
"binfmt.d\0"
"modprobe.d\0";
int r = 0, k;
int n_found = 0;
log_open();
if (r <= 0)
goto finish;
if (!arg_no_pager)
pager_open();
int i;
if (k < 0)
r = k;
else
n_found += k;
}
} else {
const char *n;
NULSTR_FOREACH(n, suffixes) {
k = process_suffix(prefixes, n);
if (k < 0)
r = k;
else
n_found += k;
}
}
if (r >= 0)
pager_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}