mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 13:51:38 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f27d35886 | ||
|
|
286069732b | ||
|
|
15d3176382 | ||
|
|
d33715f6e9 | ||
|
|
a8dbe93c7e | ||
|
|
ac9e0cbefb | ||
|
|
888d469c28 | ||
|
|
e9e16fd560 | ||
|
|
f962d43af2 | ||
|
|
cfacaece11 | ||
|
|
96a1f7cffc | ||
|
|
26c614fbe2 | ||
|
|
7e694a71ab | ||
|
|
c618401317 | ||
|
|
c0321b2872 | ||
|
|
bff72b661b | ||
|
|
4c9b2ee263 | ||
|
|
8cf3382343 | ||
|
|
ccbb7bb31c | ||
|
|
aacde58ece | ||
|
|
a6a25cbfc1 | ||
|
|
a54f328ad7 | ||
|
|
27a9b3923a | ||
|
|
374a17ea95 | ||
|
|
80c2659731 | ||
|
|
6d46f4d404 | ||
|
|
81149b109b | ||
|
|
8d9d392ce5 | ||
|
|
4e8854f491 | ||
|
|
3951a29dcc | ||
|
|
f153d6079a | ||
|
|
95cd32d127 | ||
|
|
5d3868ad29 | ||
|
|
a6952576e6 | ||
|
|
05fd5593e2 | ||
|
|
54918c1c02 | ||
|
|
e715583dc5 | ||
|
|
a3f4a2071c | ||
|
|
7016c88df6 | ||
|
|
c569470df3 | ||
|
|
883a4b0e42 | ||
|
|
a63ceb51b5 | ||
|
|
b16557179c | ||
|
|
4d1ac0e90b | ||
|
|
ff8275f7a1 | ||
|
|
80ae1d110c | ||
|
|
bba42e469e | ||
|
|
13c7727a3a | ||
|
|
4632c932d3 | ||
|
|
7fcebafd08 | ||
|
|
718c01f65b | ||
|
|
584cbb5b4e | ||
|
|
85b8895e15 | ||
|
|
de08f0ebd5 | ||
|
|
b51f835219 | ||
|
|
905e8051b2 | ||
|
|
19652c9c87 | ||
|
|
a524875fd3 | ||
|
|
91efece071 | ||
|
|
37048557ec | ||
|
|
d2192337d0 | ||
|
|
0642cc1835 | ||
|
|
77fc03de73 | ||
|
|
97c6ab80a0 | ||
|
|
aeb73c71d3 | ||
|
|
a64fc31838 | ||
|
|
8d6503ed2f | ||
|
|
6fb3c6f193 | ||
|
|
3124367ce7 | ||
|
|
41e3538eb4 | ||
|
|
b199c54804 | ||
|
|
6009fe08f7 | ||
|
|
2cd799e5ec | ||
|
|
c3701ee088 | ||
|
|
8b995e1a20 | ||
|
|
c4e73a4c9e | ||
|
|
b5ab4c61e8 | ||
|
|
eb6b1b86a3 |
@@ -1,19 +0,0 @@
|
|||||||
name: C/C++ CI
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: install dependencies
|
|
||||||
run: sudo apt-get install libsystemd-dev libcurl4-openssl-dev libfuse-dev
|
|
||||||
- name: autogen
|
|
||||||
run: sh autogen.sh
|
|
||||||
- name: make
|
|
||||||
run: make
|
|
||||||
- name: make distcheck
|
|
||||||
run: make distcheck
|
|
||||||
+1
-11
@@ -2,15 +2,12 @@
|
|||||||
*.o
|
*.o
|
||||||
clr_debug_fuse
|
clr_debug_fuse
|
||||||
clr_debug_daemon
|
clr_debug_daemon
|
||||||
test-driver
|
clr_debug_prepare
|
||||||
testing_fuse
|
|
||||||
testing_daemon
|
|
||||||
.deps/
|
.deps/
|
||||||
.dirstamp
|
.dirstamp
|
||||||
Makefile
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
ar-lib
|
|
||||||
autom4te.cache/
|
autom4te.cache/
|
||||||
compile
|
compile
|
||||||
config.h
|
config.h
|
||||||
@@ -32,10 +29,3 @@ config.guess
|
|||||||
config.sub
|
config.sub
|
||||||
libtool
|
libtool
|
||||||
ltmain.sh
|
ltmain.sh
|
||||||
test-suite.log
|
|
||||||
testing_fuse.log
|
|
||||||
testing_fuse.trs
|
|
||||||
testing_daemon.log
|
|
||||||
testing_daemon.trs
|
|
||||||
clr_debug_daemon.socket
|
|
||||||
debuginfo.conf
|
|
||||||
+8
-17
@@ -1,4 +1,4 @@
|
|||||||
EXTRA_DIST = COPYING clr_debug_fuse.service clr_debug_daemon.service clr_debug_daemon.socket debuginfo.conf
|
EXTRA_DIST = COPYING clr_debug_fuse.service clr_debug_daemon.service debuginfo.conf
|
||||||
|
|
||||||
DISTCHECK_CONFIGURE_FLAGS = \
|
DISTCHECK_CONFIGURE_FLAGS = \
|
||||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
|
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
|
||||||
@@ -14,9 +14,7 @@ AM_CFLAGS = \
|
|||||||
|
|
||||||
AM_CPPFLAGS = $(AM_CFLAGS) ${curl_CFLAGS} ${fuse_CFLAGS}
|
AM_CPPFLAGS = $(AM_CFLAGS) ${curl_CFLAGS} ${fuse_CFLAGS}
|
||||||
|
|
||||||
bin_PROGRAMS = clr_debug_fuse clr_debug_daemon
|
bin_PROGRAMS = clr_debug_fuse clr_debug_daemon clr_debug_prepare
|
||||||
|
|
||||||
dist_bin_SCRIPTS = scripts/clr_debug_prepare
|
|
||||||
|
|
||||||
noinst_LTLIBRARIES = \
|
noinst_LTLIBRARIES = \
|
||||||
libnica.la
|
libnica.la
|
||||||
@@ -35,22 +33,15 @@ clr_debug_fuse_SOURCES = src/fuse.c src/client.c
|
|||||||
clr_debug_daemon_SOURCES = src/server.c
|
clr_debug_daemon_SOURCES = src/server.c
|
||||||
clr_debug_daemon_CFLAGS = \
|
clr_debug_daemon_CFLAGS = \
|
||||||
-pthread \
|
-pthread \
|
||||||
$(AM_CFLAGS) \
|
$(AM_CFLAGS)
|
||||||
$(LIBSYSTEMD_CFLAGS)
|
|
||||||
|
clr_debug_prepare_SOURCES = src/prepare.c
|
||||||
|
|
||||||
|
|
||||||
clr_debug_fuse_LDADD = ${fuse_LIBS} libnica.la
|
clr_debug_fuse_LDADD = ${fuse_LIBS} libnica.la
|
||||||
clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la ${LIBSYSTEMD_LIBS}
|
clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la
|
||||||
|
clr_debug_prepare_LDADD = libnica.la
|
||||||
|
|
||||||
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service clr_debug_daemon.socket
|
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service
|
||||||
|
|
||||||
tmpfiles_DATA = debuginfo.conf
|
tmpfiles_DATA = debuginfo.conf
|
||||||
|
|
||||||
# Functional Testing
|
|
||||||
noinst_PROGRAMS = testing_fuse testing_daemon
|
|
||||||
|
|
||||||
testing_fuse_SOURCES = tests/testing_fuse.c
|
|
||||||
testing_fuse_CFLAGS = $(AM_CFLAGS)
|
|
||||||
|
|
||||||
testing_daemon_SOURCES = tests/testing_daemon.c
|
|
||||||
testing_daemon_CFLAGS = $(AM_CFLAGS)
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Clear Linux debuginfo daemon
|
Description=Clear Linux debuginfo daemon
|
||||||
DefaultDependencies=no
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/bin/clr_debug_daemon
|
ExecStart=/usr/bin/clr_debug_daemon
|
||||||
|
DefaultDependencies=no
|
||||||
|
Nice=10
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Clear Linux OS debuginfo daemon
|
|
||||||
|
|
||||||
[Socket]
|
|
||||||
ListenStream=@SOCKET_PATH@
|
|
||||||
SocketMode=0600
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=sockets.target
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Clear Linux debuginfo fuse monitor
|
Description=Clear Linux debuginfo fuse monitor
|
||||||
After=clr_debug_daemon.socket
|
After=clr_debug_daemon.service
|
||||||
Requires=clr_debug_daemon.socket
|
|
||||||
DefaultDependencies=no
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/bin/clr_debug_fuse
|
ExecStart=/usr/bin/clr_debug_fuse
|
||||||
|
DefaultDependencies=no
|
||||||
|
Nice=10
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
+1
-23
@@ -2,19 +2,15 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ([2.66])
|
AC_PREREQ([2.66])
|
||||||
AC_INIT(clr-debug-info, 52, arjan@linux.intel.com)
|
AC_INIT(clr-debug-info, 38, arjan@linux.intel.com)
|
||||||
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AM_PROG_AR
|
|
||||||
AC_LANG(C)
|
AC_LANG(C)
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_FILES([clr_debug_daemon.socket])
|
|
||||||
AC_CONFIG_FILES([debuginfo.conf])
|
|
||||||
PKG_CHECK_MODULES([curl], [libcurl])
|
PKG_CHECK_MODULES([curl], [libcurl])
|
||||||
PKG_CHECK_MODULES([fuse], [fuse])
|
PKG_CHECK_MODULES([fuse], [fuse])
|
||||||
PKG_CHECK_MODULES([SYSTEMD], [systemd])
|
PKG_CHECK_MODULES([SYSTEMD], [systemd])
|
||||||
PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd])
|
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
dir=""
|
dir=""
|
||||||
@@ -38,22 +34,6 @@ else
|
|||||||
AC_MSG_WARN([C11 stdatomic support unavailable. Falling back to slow mutex])
|
AC_MSG_WARN([C11 stdatomic support unavailable. Falling back to slow mutex])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SOCKET_PATH=""
|
|
||||||
AC_ARG_WITH([socket-path], AS_HELP_STRING([--with-socket-path=SOCKET_PATH],
|
|
||||||
[path to create unix socket @<:@default=/run/clr-debug-info@:>@]), [SOCKET_PATH=${withval}],
|
|
||||||
[SOCKET_PATH="/run/clr-debug-info"])
|
|
||||||
test -z "${SOCKET_PATH}" && SOCKET_PATH=/run/clr-debug-info
|
|
||||||
AC_DEFINE_UNQUOTED([SOCKET_PATH], ["${SOCKET_PATH}"], [path to create unix socket @<:@default=/run/clr-debug-info@:>@])
|
|
||||||
AC_SUBST(SOCKET_PATH, [${SOCKET_PATH}])
|
|
||||||
|
|
||||||
CACHE_DIR=""
|
|
||||||
AC_ARG_WITH([cache-dir], AS_HELP_STRING([--with-cache-dir=CACHE_DIR],
|
|
||||||
[path to cache downloaded content @<:@default=/var/cache/debuginfo@:>@]), [CACHE_DIR="${withval}"],
|
|
||||||
[CACHE_DIR="/var/cache/debuginfo"])
|
|
||||||
test -z "${CACHE_DIR}" && CACHE_DIR=/var/cache/debuginfo
|
|
||||||
AC_DEFINE_UNQUOTED([CACHE_DIR], ["${CACHE_DIR}"], [path to cache downloaded content @<:@default=/var/cache/debuginfo@:>@])
|
|
||||||
AC_SUBST(CACHE_DIR, [${CACHE_DIR}])
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
@@ -73,8 +53,6 @@ AC_MSG_RESULT([
|
|||||||
|
|
||||||
systemd-unit-dir: ${systemdsystemunitdir}
|
systemd-unit-dir: ${systemdsystemunitdir}
|
||||||
tmpfiles.d: ${tmpfilesdir}
|
tmpfiles.d: ${tmpfilesdir}
|
||||||
socket_dir: ${SOCKET_PATH}
|
|
||||||
cache_dir: ${CACHE_DIR}
|
|
||||||
|
|
||||||
C11 stdatomic support: ${have_atomics}
|
C11 stdatomic support: ${have_atomics}
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -8,7 +8,5 @@
|
|||||||
# See tmpfiles.d(5) for details
|
# See tmpfiles.d(5) for details
|
||||||
|
|
||||||
# Clear tmp directories separately, to make them easier to override
|
# Clear tmp directories separately, to make them easier to override
|
||||||
# Unfortunatly tmpfiles doesn't change the ownership for things if they
|
d /var/cache/debuginfo/lib 755 root root 10d
|
||||||
# are not listed.
|
d /var/cache/debuginfo/src 755 root root 1d
|
||||||
d @CACHE_DIR@/lib 755 dbginfo dbginfo 10d
|
|
||||||
d @CACHE_DIR@/src 755 dbginfo dbginfo 1d
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[Service]
|
|
||||||
# Uncomment to use custom URLs, space separated
|
|
||||||
#Environment="CLR_DEBUGINFO_URLS=https://cdn-alt.download.clearlinux.org/debuginfo/ https://cdn.download.clearlinux.org/debuginfo/"
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Clear Linux -- automatic debuginfo preparation
|
|
||||||
#
|
|
||||||
# Copyright 2019 Intel Corporation
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify it under
|
|
||||||
# the terms of the GNU General Public License as published by the Free Software
|
|
||||||
# Foundation, version 3 or later of the License.
|
|
||||||
#
|
|
||||||
# This program 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 General Public License for more
|
|
||||||
# details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License along with
|
|
||||||
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
if [ $# -eq 1 ] || [ $# -gt 2 ]; then
|
|
||||||
echo "Usage: $0 [SOURCEDIR] [DESTDIR]"
|
|
||||||
echo "Generates automatic debuginfo tarballs in DESTDIR using content from SOURCEDIR."
|
|
||||||
echo "The default SOURCEDIR and DESTDIR are /var/www/html/debuginfo.raw and"
|
|
||||||
echo "/var/www/html/debuginfo, respectively."
|
|
||||||
exit 0
|
|
||||||
fi >&2
|
|
||||||
|
|
||||||
if [ $# -eq 2 ]; then
|
|
||||||
if [ ! -d "$1" ]; then
|
|
||||||
echo "ERROR: SOURCEDIR argument must be an existing directory"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi >&2
|
|
||||||
|
|
||||||
export SRC="${1:-/var/www/html/debuginfo.raw}"
|
|
||||||
export DEST="${2:-/var/www/html/debuginfo}"
|
|
||||||
|
|
||||||
srclist=$(mktemp -p .)
|
|
||||||
destlist=$(mktemp -p .)
|
|
||||||
trap "rm $srclist $destlist" EXIT
|
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# First, scan the state of the SRC tree, containing all content for debuginfo RPMs.
|
|
||||||
if ! find "$SRC" -mindepth 4 -printf "%p %T@ %y\n" | sed "s|$SRC||" | sort -k 1 > "$srclist"; then
|
|
||||||
echo "ERROR: expected content in $SRC"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Next, scan the state of the DEST tree, containing previously generated
|
|
||||||
# automatic debuginfo tarballs. Will be empty on first run.
|
|
||||||
mkdir -p "$DEST"
|
|
||||||
find "$DEST" -mindepth 2 -name '*.tar' -printf "%p %T@ %y\n" | sed "s|$DEST||;s|\.tar | |" | sort -k 1 > "$destlist"
|
|
||||||
|
|
||||||
|
|
||||||
process_one() {
|
|
||||||
srcname="$1"
|
|
||||||
destname="$2"
|
|
||||||
filetype="$3"
|
|
||||||
srcloc="$SRC/$srcname"
|
|
||||||
srcdir="$SRC/$(echo "$srcname" | sed -r 's@^(/usr/(lib|share|src)/debug(/src)?).*@\1@')"
|
|
||||||
tarcontent="$(echo "$srcname" | sed -r 's@^/usr/(lib|share|src)/debug(/src)?@.@')"
|
|
||||||
destdir="$DEST/$(dirname "$destname")"
|
|
||||||
dest="$DEST/$destname.tar"
|
|
||||||
|
|
||||||
echo "Creating $destname.tar ..."
|
|
||||||
|
|
||||||
mkdir -p "$destdir"
|
|
||||||
if [ "$filetype" = "f" ]; then
|
|
||||||
tar --no-recursion -C "$srcdir" --zstd -cf "$dest" "$tarcontent"
|
|
||||||
elif [ "$filetype" = "l" ]; then
|
|
||||||
# We "unsymlink" non-broken symlinks as an optimization by adding the
|
|
||||||
# symlink target to the dest tarball, transforming the name as appropriate.
|
|
||||||
if target=$(realpath -e "$srcloc" --relative-to="$srcdir" 2> /dev/null); then
|
|
||||||
tar --no-recursion -C "$srcdir" --zstd -cf "$dest" --transform='s|.*|'"$tarcontent"'|' "$target"
|
|
||||||
else
|
|
||||||
tar --no-recursion -C "$srcdir" --zstd -cf "$dest" "$tarcontent"
|
|
||||||
fi
|
|
||||||
elif [ "$filetype" = "d" ]; then
|
|
||||||
tar --no-recursion -C "$srcdir" --zstd -cf "$dest" "$tarcontent"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
export -f process_one
|
|
||||||
|
|
||||||
|
|
||||||
gawk '
|
|
||||||
BEGIN { OFS = "\t" }
|
|
||||||
LIST == "src" {
|
|
||||||
name = $1
|
|
||||||
srcname = name
|
|
||||||
ret = sub(/^\/usr\/lib\/debug/, "/lib", name)
|
|
||||||
if (ret == 0) {
|
|
||||||
ret = sub(/^\/usr\/src\/debug/, "/src", name)
|
|
||||||
if (ret == 0) {
|
|
||||||
ret = sub(/^\/usr\/share\/debug\/src/, "/src", name)
|
|
||||||
if (ret == 0) {
|
|
||||||
ret = sub(/^\/usr\/share\/debug/, "/lib", name)
|
|
||||||
if (ret == 0) {
|
|
||||||
print "Error: unexpected debuginfo file:", name
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
src[name]["srcname"] = srcname
|
|
||||||
src[name]["time"] = $2
|
|
||||||
src[name]["type"] = $3
|
|
||||||
src[name]["done"] = 0
|
|
||||||
}
|
|
||||||
LIST == "dest" {
|
|
||||||
dest_content = 1
|
|
||||||
name = $1
|
|
||||||
time = $2
|
|
||||||
type = $3
|
|
||||||
if (name in src) {
|
|
||||||
# No need to recreate directory tars if they exist
|
|
||||||
if (src[name]["type"] == "d") {
|
|
||||||
src[name]["done"] = 1
|
|
||||||
next
|
|
||||||
} else {
|
|
||||||
# Only regenerate content if timestamp is newer
|
|
||||||
if (time < src[name]["time"]) {
|
|
||||||
print src[name]["srcname"], name, src[name]["type"]
|
|
||||||
}
|
|
||||||
src[name]["done"] = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
PROCINFO["sorted_in"] = "@ind_str_asc"
|
|
||||||
if (dest_content == 0) {
|
|
||||||
for (s in src) {
|
|
||||||
print src[s]["srcname"], s, src[s]["type"]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (s in src) {
|
|
||||||
if (src[s]["done"] == 0) {
|
|
||||||
print src[s]["srcname"], s, src[s]["type"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
' LIST="src" "$srclist" LIST="dest" "$destlist" \
|
|
||||||
| parallel --colsep '\t' process_one
|
|
||||||
|
|
||||||
|
|
||||||
# vi: ft=sh et sw=2 sts=2
|
|
||||||
+7
-21
@@ -36,11 +36,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/* 0.75 seconds timeout */
|
/* 0.75 seconds timeout */
|
||||||
#define TIMEOUT 75000
|
#define TIMEOUT 750000
|
||||||
#define TIMEOUT2 1500
|
#define TIMEOUT2 15000
|
||||||
#define TIMEOUT3 500
|
#define TIMEOUT3 500
|
||||||
|
|
||||||
char *prefix = "src";
|
char *prefix = "src";
|
||||||
@@ -60,7 +58,7 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
|||||||
int shorttime = 0;
|
int shorttime = 0;
|
||||||
__nc_unused__ size_t wr = -1;
|
__nc_unused__ size_t wr = -1;
|
||||||
|
|
||||||
// printf("Trying to aquire %s\n", path);
|
// printf("Trying to aquire %s\n", path);
|
||||||
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sockfd < 0) {
|
if (sockfd < 0) {
|
||||||
@@ -68,13 +66,14 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sun.sun_family = AF_UNIX;
|
sun.sun_family = AF_UNIX;
|
||||||
strcpy(sun.sun_path, SOCKET_PATH);
|
strcpy(sun.sun_path, ":clr-debug-info");
|
||||||
|
sun.sun_path[0] = 0; /* anonymous unix socket */
|
||||||
|
|
||||||
ret = connect(sockfd,
|
ret = connect(sockfd,
|
||||||
(struct sockaddr *)&sun,
|
(struct sockaddr *)&sun,
|
||||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1);
|
offsetof(struct sockaddr_un, sun_path) + strlen(":clr-debug-info") + 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("Cannot connect to %s: %s\n", SOCKET_PATH, strerror(errno));
|
printf("Cannot connect %s\n", strerror(errno));
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,16 +120,3 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
|||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
||||||
*
|
|
||||||
* Local variables:
|
|
||||||
* c-basic-offset: 8
|
|
||||||
* tab-width: 8
|
|
||||||
* indent-tabs-mode: nil
|
|
||||||
* End:
|
|
||||||
*
|
|
||||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
|
||||||
* :indentSize=8:tabSize=8:noTabs=true:
|
|
||||||
*/
|
|
||||||
|
|||||||
+3
-26
@@ -75,16 +75,6 @@ static int xmp_getattr(const char *path, struct stat *stbuf)
|
|||||||
memset(stbuf, 0, sizeof(struct stat));
|
memset(stbuf, 0, sizeof(struct stat));
|
||||||
res = lstat(newpath, stbuf);
|
res = lstat(newpath, stbuf);
|
||||||
|
|
||||||
/*
|
|
||||||
* filter out things that never should get fetched
|
|
||||||
* this prevents us from asking curl to fetch us useless things
|
|
||||||
*/
|
|
||||||
if (strncmp(path, "/.Trash", strlen("/.Trash")) == 0) {
|
|
||||||
return -ENOENT;
|
|
||||||
} else if (strcmp(path, "/") == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get the file. if the st_mtime is set, this is just an async refresh, otherwise it's
|
* get the file. if the st_mtime is set, this is just an async refresh, otherwise it's
|
||||||
* a synchronous request.
|
* a synchronous request.
|
||||||
@@ -636,8 +626,8 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
|||||||
{
|
{
|
||||||
char *fake_argv[20];
|
char *fake_argv[20];
|
||||||
char *dir = "/usr/src/debug";
|
char *dir = "/usr/src/debug";
|
||||||
char *shadowdir = CACHE_DIR "/src";
|
char *shadowdir = "/var/cache/debuginfo/src";
|
||||||
const char *required_paths[] = { CACHE_DIR "/lib", CACHE_DIR "/src" };
|
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
||||||
|
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
@@ -663,7 +653,7 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
|||||||
|
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
dir = "/usr/lib/debug";
|
dir = "/usr/lib/debug";
|
||||||
shadowdir = CACHE_DIR "/lib";
|
shadowdir = "/var/cache/debuginfo/lib";
|
||||||
prefix = "lib";
|
prefix = "lib";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,16 +671,3 @@ int main(__nc_unused__ int argc, __nc_unused__ char *argv[])
|
|||||||
|
|
||||||
return fuse_main(9, fake_argv, &xmp_oper, NULL);
|
return fuse_main(9, fake_argv, &xmp_oper, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
||||||
*
|
|
||||||
* Local variables:
|
|
||||||
* c-basic-offset: 8
|
|
||||||
* tab-width: 8
|
|
||||||
* indent-tabs-mode: nil
|
|
||||||
* End:
|
|
||||||
*
|
|
||||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
|
||||||
* :indentSize=8:tabSize=8:noTabs=true:
|
|
||||||
*/
|
|
||||||
|
|||||||
+243
@@ -0,0 +1,243 @@
|
|||||||
|
/*
|
||||||
|
* Fenrus Linux -- automatic debug information installation
|
||||||
|
* Clear Linux -- automatic debug information installation
|
||||||
|
* Server side preparation logic
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Arjan van de Ven
|
||||||
|
* Copyright (C) 2014 Intel Corporation
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2 or later of the License.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Arjan van de Ven <arjanvandeven@gmail.com>
|
||||||
|
* Ikey Doherty <michael.i.doherty@intel.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "nica/files.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
this program takes a directory /var/www/html/debuginfo.raw,
|
||||||
|
in which all debuginfo rpms have previously been rpm2cpio'd, and
|
||||||
|
creates the content for /var/www/html/debuginfo
|
||||||
|
which contains tar'd up/compressed versions of all the files.
|
||||||
|
As part of this symlinks will be resolved server side
|
||||||
|
as much as possible.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void unsymlink(char *filename)
|
||||||
|
{
|
||||||
|
char *target;
|
||||||
|
__nc_unused__ int r;
|
||||||
|
|
||||||
|
target = canonicalize_file_name(filename);
|
||||||
|
// sleep(1);
|
||||||
|
// printf("Symlink %s points to %s\n", filename, target);
|
||||||
|
unlink(filename);
|
||||||
|
r = link(target, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wait_for_loadavg(void)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
char line[4096];
|
||||||
|
__nc_unused__ char *ret = NULL;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
double d;
|
||||||
|
file = fopen("/proc/loadavg", "r");
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
line[0] = 0;
|
||||||
|
ret = fgets(line, 4096, file);
|
||||||
|
fclose(file);
|
||||||
|
d = strtod(line, NULL);
|
||||||
|
if (d < 50) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sleep(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int tarcount;
|
||||||
|
|
||||||
|
static void do_one_file(char *base1, char *base2, char *path, int isdir)
|
||||||
|
{
|
||||||
|
char *dir2 = NULL;
|
||||||
|
autofree(char) * fullpath1, *fullpath2, *dir = NULL;
|
||||||
|
struct stat buf1, buf2;
|
||||||
|
int ret;
|
||||||
|
int sret;
|
||||||
|
|
||||||
|
if (asprintf(&fullpath1, "%s%s", base1, path) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (asprintf(&fullpath2, "%s%s.tar", base2, path) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = lstat(fullpath1, &buf1);
|
||||||
|
if (ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (S_ISLNK(buf1.st_mode)) {
|
||||||
|
// printf("%s is a symlink\n", fullpath1);
|
||||||
|
ret = stat(fullpath1, &buf2);
|
||||||
|
if (!ret) {
|
||||||
|
unsymlink(fullpath1);
|
||||||
|
}
|
||||||
|
ret = lstat(fullpath1, &buf1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = lstat(fullpath2, &buf2);
|
||||||
|
if (ret || buf1.st_mtime > buf2.st_mtime) {
|
||||||
|
char *command = NULL;
|
||||||
|
unlink(fullpath2);
|
||||||
|
|
||||||
|
dir = strdup(fullpath2);
|
||||||
|
|
||||||
|
dir2 = dirname(dir);
|
||||||
|
|
||||||
|
if (dir2) {
|
||||||
|
(void)nc_mkdir_p(dir2, 00755);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chdir(base1) != 0) {
|
||||||
|
fprintf(stderr, "Failed to chdir: %s\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isdir &&
|
||||||
|
asprintf(&command,
|
||||||
|
"tar --no-recursion -C %s -Jcf %s %s &",
|
||||||
|
base1,
|
||||||
|
fullpath2,
|
||||||
|
path) >= 0) {
|
||||||
|
// printf("Running -%s-\n", command);
|
||||||
|
printf("Processing %s\n", fullpath2);
|
||||||
|
tarcount++;
|
||||||
|
if (tarcount > 50) {
|
||||||
|
wait_for_loadavg();
|
||||||
|
tarcount = 0;
|
||||||
|
}
|
||||||
|
if ((sret = system(command)) != 0) {
|
||||||
|
fprintf(stderr, "Failure in command: [%d] %s\n", sret, command);
|
||||||
|
}
|
||||||
|
free(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isdir &&
|
||||||
|
asprintf(&command,
|
||||||
|
"tar --no-recursion -C %s -Jcf %s `find %s -type d` `find %s "
|
||||||
|
"-maxdepth 1 -type l` &",
|
||||||
|
base1,
|
||||||
|
fullpath2,
|
||||||
|
path,
|
||||||
|
path) >= 0) {
|
||||||
|
// printf("Running -%s-\n", command);
|
||||||
|
printf("Processing %s\n", fullpath2);
|
||||||
|
tarcount++;
|
||||||
|
if (tarcount > 50) {
|
||||||
|
wait_for_loadavg();
|
||||||
|
tarcount = 0;
|
||||||
|
}
|
||||||
|
if ((sret = system(command)) != 0) {
|
||||||
|
fprintf(stderr, "Failure in command: [%d] %s\n", sret, command);
|
||||||
|
}
|
||||||
|
free(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void recurse_dir(char *base1, char *base2, char *path)
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
char *fullpath1 = NULL;
|
||||||
|
struct dirent *entry;
|
||||||
|
|
||||||
|
if (asprintf(&fullpath1, "%s%s", base1, path) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = opendir(fullpath1);
|
||||||
|
|
||||||
|
if (!dir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
autofree(char) *fullpath2 = NULL;
|
||||||
|
autofree(char) *newpath = NULL;
|
||||||
|
|
||||||
|
entry = readdir(dir);
|
||||||
|
if (!entry) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcmp(entry->d_name, ".") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strcmp(entry->d_name, "..") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
newpath = NULL;
|
||||||
|
fullpath2 = NULL;
|
||||||
|
if (asprintf(&fullpath2, "%s/%s", fullpath1, entry->d_name) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (asprintf(&newpath, "%s/%s", path, entry->d_name) >= 0) {
|
||||||
|
struct stat sb;
|
||||||
|
stat(fullpath2, &sb);
|
||||||
|
|
||||||
|
if (entry->d_type == DT_DIR || S_ISDIR(sb.st_mode)) {
|
||||||
|
do_one_file(base1, base2, newpath, 1);
|
||||||
|
recurse_dir(base1, base2, newpath);
|
||||||
|
} else {
|
||||||
|
do_one_file(base1, base2, newpath, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc < 0)
|
||||||
|
(void)argv;
|
||||||
|
recurse_dir("/var/www/html/debuginfo.raw/usr/lib/debug/",
|
||||||
|
"/var/www/html/debuginfo/lib/",
|
||||||
|
".");
|
||||||
|
recurse_dir("/var/www/html/debuginfo.raw/usr/src/debug/",
|
||||||
|
"/var/www/html/debuginfo/src/",
|
||||||
|
".");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
+42
-236
@@ -2,7 +2,7 @@
|
|||||||
* Clear Linux -- automatic debug information installation
|
* Clear Linux -- automatic debug information installation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Arjan van de Ven
|
* Copyright (C) 2013 Arjan van de Ven
|
||||||
* Curl portions borrowed from the Fenrus Update code
|
* Curl portions borrowed from the Fenrus Update code
|
||||||
* which in part is (C) 2012 Intel Corporation
|
* which in part is (C) 2012 Intel Corporation
|
||||||
* Copyright (C) 2014 Intel Corporation
|
* Copyright (C) 2014 Intel Corporation
|
||||||
*
|
*
|
||||||
@@ -27,12 +27,9 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -50,23 +47,17 @@
|
|||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include "systemd/sd-daemon.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef HAVE_ATOMIC_SUPPORT
|
#ifdef HAVE_ATOMIC_SUPPORT
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TIMEOUT 600 /* 10 minutes */
|
|
||||||
|
|
||||||
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
char *urls_default[] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
char *urls[2] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
||||||
"https://cdn-alt.download.clearlinux.org/debuginfo/" };
|
"https://cdn.download.clearlinux.org/debuginfo/" };
|
||||||
int urls_size = 2;
|
|
||||||
int urlcounter = 1;
|
int urlcounter = 1;
|
||||||
char **urls = urls_default;
|
|
||||||
|
|
||||||
static NcHashmap *hash = NULL;
|
static NcHashmap *hash = NULL;
|
||||||
|
|
||||||
@@ -99,60 +90,6 @@ static int avoid_dupes(const char *url)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Read URLs from environment variable, space separated
|
|
||||||
*/
|
|
||||||
int configure_urls(void)
|
|
||||||
{
|
|
||||||
const char *env_var = getenv("CLR_DEBUGINFO_URLS");
|
|
||||||
const char *token = env_var;
|
|
||||||
int count = 0;
|
|
||||||
char **urls_new = NULL;
|
|
||||||
if (env_var) {
|
|
||||||
while (1) {
|
|
||||||
int token_len = strcspn(token, " \t\n");
|
|
||||||
if (token_len) {
|
|
||||||
count++;
|
|
||||||
urls_new = realloc(urls_new, count * sizeof(char *));
|
|
||||||
if (!urls_new) {
|
|
||||||
perror("realloc()");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *url = calloc(token_len + 1, sizeof(char));
|
|
||||||
if (!url) {
|
|
||||||
perror("calloc()");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
urls_new[count - 1] = strncpy(url, token, token_len);
|
|
||||||
token += token_len;
|
|
||||||
}
|
|
||||||
if (*token == '\0') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
token++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count) {
|
|
||||||
// Abandon defaults
|
|
||||||
urls = urls_new;
|
|
||||||
urls_size = count;
|
|
||||||
urlcounter = 0;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_urls(void)
|
|
||||||
{
|
|
||||||
if (urls != urls_default) {
|
|
||||||
for (int i = 0; i < urls_size; i++) {
|
|
||||||
free(urls[i]);
|
|
||||||
}
|
|
||||||
free(urls);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_ATOMIC_SUPPORT
|
#ifdef HAVE_ATOMIC_SUPPORT
|
||||||
|
|
||||||
static atomic_int current_connection_count = 0;
|
static atomic_int current_connection_count = 0;
|
||||||
@@ -225,11 +162,11 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
{
|
{
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
long ret;
|
long ret;
|
||||||
long changed;
|
|
||||||
int fd;
|
int fd;
|
||||||
autofree(char) *filename = NULL;
|
char filename[PATH_MAX];
|
||||||
CURL *curl = NULL;
|
CURL *curl = NULL;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
struct stat statbuf;
|
||||||
|
|
||||||
if (avoid_dupes(url)) {
|
if (avoid_dupes(url)) {
|
||||||
return 300;
|
return 300;
|
||||||
@@ -240,15 +177,12 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
return 301;
|
return 301;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fprintf(stderr, "Fetching %s, prefix %s, path %s\n", url, prefix, path);
|
strcpy(filename, "/tmp/clr-debug-info-XXXXXX");
|
||||||
if (asprintf(&filename, "/tmp/clr-debug-info-XXXXXX") < 0) {
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
return 418;
|
|
||||||
}
|
|
||||||
fd = mkstemp(filename);
|
fd = mkstemp(filename);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
return 418;
|
return 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = fdopen(fd, "w");
|
file = fdopen(fd, "w");
|
||||||
@@ -269,9 +203,6 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 30);
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 30);
|
||||||
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1024);
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1024);
|
||||||
|
|
||||||
/* request timestamp of files from server */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_FILETIME, 1);
|
|
||||||
|
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, timestamp);
|
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, timestamp);
|
||||||
@@ -286,7 +217,7 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret);
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret);
|
||||||
fflush(file);
|
fflush(file);
|
||||||
// printf("HTTP return code is %i\n", ret);
|
// printf("HTTP return code is %i\n", ret);
|
||||||
|
|
||||||
/* HTTP 304 is returned if (a) the cached debuginfo has the same
|
/* HTTP 304 is returned if (a) the cached debuginfo has the same
|
||||||
* timestamp or is newer than that on the server and (b) we haven't
|
* timestamp or is newer than that on the server and (b) we haven't
|
||||||
@@ -300,62 +231,20 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
|
|
||||||
if (ret == 200) {
|
if (ret == 200) {
|
||||||
autofree(char) *command = NULL;
|
autofree(char) *command = NULL;
|
||||||
struct stat statbuf;
|
// printf("Filename is %s\n", filename);
|
||||||
|
|
||||||
/* get timestamp, if any */
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_FILETIME, &changed);
|
|
||||||
if (changed >= 0) {
|
|
||||||
struct timespec times[2];
|
|
||||||
times[0].tv_sec = (time_t)changed;
|
|
||||||
times[0].tv_nsec = 0;
|
|
||||||
times[1].tv_sec = (time_t)changed;
|
|
||||||
times[1].tv_nsec = 0;
|
|
||||||
futimens(fd, times);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&statbuf, 0, sizeof(statbuf));
|
memset(&statbuf, 0, sizeof(statbuf));
|
||||||
stat(filename, &statbuf);
|
stat(filename, &statbuf);
|
||||||
if (statbuf.st_size <= 0) {
|
if (statbuf.st_size > 0 &&
|
||||||
ret = 418;
|
asprintf(&command,
|
||||||
goto out;
|
"tar -C /var/cache/debuginfo/%s --no-same-owner --no-same-permissions -xf %s",
|
||||||
}
|
|
||||||
|
|
||||||
/* test extraction first */
|
|
||||||
if (asprintf(&command,
|
|
||||||
"tar -C %s/%s --no-same-owner "
|
|
||||||
"--no-same-permissions -tf %s",
|
|
||||||
CACHE_DIR,
|
|
||||||
prefix,
|
prefix,
|
||||||
filename) < 0) {
|
filename) >= 0) {
|
||||||
ret = 418;
|
if (system(command) != 0) {
|
||||||
goto out;
|
fputs("Warning: tar extraction failed\n", stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system(command) != 0) {
|
|
||||||
ret = 418;
|
|
||||||
fprintf(stderr, "Error: tar validation failed\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(command); /* reuse */
|
|
||||||
if (asprintf(&command,
|
|
||||||
"tar -C %s/%s --no-same-owner "
|
|
||||||
"--no-same-permissions -xf %s",
|
|
||||||
CACHE_DIR,
|
|
||||||
prefix,
|
|
||||||
filename) < 0) {
|
|
||||||
ret = 418;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (system(command) != 0) {
|
|
||||||
ret = 418;
|
|
||||||
fprintf(stderr, "Error: tar extraction failed\n");
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@@ -425,11 +314,11 @@ static void *server_thread(void *arg)
|
|||||||
goto thread_end;
|
goto thread_end;
|
||||||
}
|
}
|
||||||
url = NULL;
|
url = NULL;
|
||||||
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % urls_size], prefix, path) < 0) {
|
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
|
||||||
goto thread_end;
|
goto thread_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
|
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
|
||||||
ret = curl_get_file(url, prefix, timestamp);
|
ret = curl_get_file(url, prefix, timestamp);
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
@@ -440,12 +329,12 @@ static void *server_thread(void *arg)
|
|||||||
// ignore these error codes
|
// ignore these error codes
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Request for %s resulted in error %i\n", url, ret);
|
printf("Request for %s resulted in error %i\n", url, ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&after, NULL);
|
gettimeofday(&after, NULL);
|
||||||
#if 0
|
#if 0
|
||||||
if (timedelta(before, after) > 0.6)
|
if (timedelta(before, after) > 0.6)
|
||||||
printf("Request for %s took %5.2f seconds (%i - %i)\n",
|
printf("Request for %s took %5.2f seconds (%i - %i)\n",
|
||||||
url,
|
url,
|
||||||
@@ -471,27 +360,7 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
|||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun;
|
||||||
int ret;
|
int ret;
|
||||||
int curl_done = 0;
|
int curl_done = 0;
|
||||||
uid_t dbg_user = 0;
|
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
||||||
gid_t dbg_group = 0;
|
|
||||||
struct passwd *passwdentry;
|
|
||||||
const char *required_paths[] = { CACHE_DIR "/lib", CACHE_DIR "/src" };
|
|
||||||
|
|
||||||
if (configure_urls()) {
|
|
||||||
fprintf(stderr, "Using urls from environment\n");
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Using compiled default urls\n");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < urls_size; i++) {
|
|
||||||
fprintf(stderr, "url: %s\n", urls[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
umask(0);
|
|
||||||
passwdentry = getpwnam("dbginfo");
|
|
||||||
if (passwdentry) {
|
|
||||||
dbg_user = passwdentry->pw_uid;
|
|
||||||
dbg_group = passwdentry->pw_gid;
|
|
||||||
}
|
|
||||||
endpwent();
|
|
||||||
|
|
||||||
if (prctl(PR_SET_DUMPABLE, 0) != 0) {
|
if (prctl(PR_SET_DUMPABLE, 0) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -507,94 +376,44 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
|||||||
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(required_paths); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(required_paths); i++) {
|
||||||
const char *req_path = required_paths[i];
|
const char *req_path = required_paths[i];
|
||||||
struct stat st = { .st_ino = 0 };
|
if (nc_file_exists(req_path)) {
|
||||||
if (lstat(req_path, &st) == 0) {
|
continue;
|
||||||
/* If the file already exists, check ownership
|
|
||||||
* and delete tree if incorrect. Essentially a
|
|
||||||
* one-off operation to transition from root owned to
|
|
||||||
* dbginfo owned */
|
|
||||||
if (st.st_uid == dbg_user) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "Removing old debug information %s\n", req_path);
|
|
||||||
nc_rm_rf(req_path);
|
|
||||||
}
|
}
|
||||||
if (!nc_mkdir_p(req_path, 00755)) {
|
if (!nc_mkdir_p(req_path, 00755)) {
|
||||||
fprintf(stderr, "Failed to mkdir: %s %s\n", strerror(errno), req_path);
|
fprintf(stderr, "Failed to mkdir: %s %s\n", strerror(errno), req_path);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (chown(req_path, dbg_user, dbg_group) != 0) {
|
|
||||||
fprintf(stderr, "Failed to chown: %s %s\n", strerror(errno), req_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
if (sd_listen_fds(0) == 1) {
|
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
/* systemd socket activation */
|
if (sockfd < 0) {
|
||||||
sockfd = SD_LISTEN_FDS_START + 0;
|
return EXIT_FAILURE;
|
||||||
} else if (sd_listen_fds(0) > 1) {
|
|
||||||
fprintf(stderr, "Too many file descriptors received.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else {
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
sun.sun_family = AF_UNIX;
|
|
||||||
strcpy(sun.sun_path, SOCKET_PATH);
|
|
||||||
|
|
||||||
ret = bind(sockfd,
|
|
||||||
(struct sockaddr *)&sun,
|
|
||||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1);
|
|
||||||
if (ret < 0) {
|
|
||||||
fprintf(stderr, "Failed to bind:%s \n", strerror(errno));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen(sockfd, 16) < 0) {
|
|
||||||
fprintf(stderr, "Failed to listen:%s \n", strerror(errno));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setgid(dbg_group)) {
|
sun.sun_family = AF_UNIX;
|
||||||
fprintf(stderr, "Unable to drop privileges setgid %s\n", strerror(errno));
|
strcpy(sun.sun_path, ":clr-debug-info");
|
||||||
exit(EXIT_FAILURE);
|
sun.sun_path[0] = 0; /* anonymous unix socket */
|
||||||
|
|
||||||
|
ret = bind(sockfd,
|
||||||
|
(struct sockaddr *)&sun,
|
||||||
|
offsetof(struct sockaddr_un, sun_path) + strlen(":clr-debug-info") + 1);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("Failed to bind:%s \n", strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (setgroups(1, &dbg_group)) {
|
|
||||||
fprintf(stderr, "Unable to drop privileges setgroups %s\n", strerror(errno));
|
if (listen(sockfd, 16) < 0) {
|
||||||
exit(EXIT_FAILURE);
|
printf("Failed to listen:%s \n", strerror(errno));
|
||||||
}
|
return EXIT_FAILURE;
|
||||||
if (setuid(dbg_user)) {
|
|
||||||
fprintf(stderr, "Unable to drop privileges setuid %s\n", strerror(errno));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
fd_set rfds;
|
|
||||||
struct timeval tv;
|
|
||||||
int ret;
|
|
||||||
int clientsock;
|
int clientsock;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
malloc_trim(0);
|
malloc_trim(0);
|
||||||
|
|
||||||
/* use select() to timeout and exit gracefully */
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(sockfd, &rfds);
|
|
||||||
tv.tv_sec = TIMEOUT;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
ret = select(sockfd + 1, &rfds, NULL, NULL, &tv);
|
|
||||||
if (ret == -1) {
|
|
||||||
perror("select()");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if (ret == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
clientsock = accept(sockfd, NULL, NULL);
|
clientsock = accept(sockfd, NULL, NULL);
|
||||||
|
|
||||||
/* Too many connections, wait for the next loop/retry */
|
/* Too many connections, wait for the next loop/retry */
|
||||||
@@ -620,18 +439,5 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
|||||||
nc_hashmap_free(hash);
|
nc_hashmap_free(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_urls();
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
||||||
*
|
|
||||||
* Local variables:
|
|
||||||
* c-basic-offset: 8
|
|
||||||
* tab-width: 8
|
|
||||||
* indent-tabs-mode: nil
|
|
||||||
* End:
|
|
||||||
*
|
|
||||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
|
||||||
* :indentSize=8:tabSize=8:noTabs=true:
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define BUFFER_LENGTH 16
|
|
||||||
|
|
||||||
int get_server_socket(void)
|
|
||||||
{
|
|
||||||
int sockfd;
|
|
||||||
struct sockaddr_un serveraddr;
|
|
||||||
fputs("Creating socket\n", stderr);
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0) {
|
|
||||||
fputs("Fail creating socket\n", stderr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memset(&serveraddr, 0, sizeof(serveraddr));
|
|
||||||
serveraddr.sun_family = AF_UNIX;
|
|
||||||
strcpy(serveraddr.sun_path, SOCKET_PATH);
|
|
||||||
|
|
||||||
fputs("Connecting to server\n", stderr);
|
|
||||||
if (connect(sockfd, (struct sockaddr*)&serveraddr,
|
|
||||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1) < 0) {
|
|
||||||
fprintf(stderr, "Fail connecting to server: %s\n", strerror(errno));
|
|
||||||
close(sockfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return sockfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int testing_daemon(void)
|
|
||||||
{
|
|
||||||
int sockfd;
|
|
||||||
char buffer[BUFFER_LENGTH];
|
|
||||||
|
|
||||||
if((sockfd = get_server_socket()) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs("Sending message to server\n", stderr);
|
|
||||||
memset(buffer, 0, sizeof(buffer));
|
|
||||||
strcpy(buffer, "0:lib:/lib");
|
|
||||||
if(send(sockfd, buffer, sizeof(buffer), 0) < 0) {
|
|
||||||
fputs("Fail sending message to socket service\n", stderr);
|
|
||||||
close(sockfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs("Receiving message from server\n", stderr);
|
|
||||||
memset(buffer, 0, sizeof(buffer));
|
|
||||||
if (recv(sockfd, &buffer[0],
|
|
||||||
BUFFER_LENGTH, 0) < 0) {
|
|
||||||
fputs("Failing receiving message from socket service\n", stderr);
|
|
||||||
close(sockfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sockfd);
|
|
||||||
return strcmp(buffer, "ok") && access(CACHE_DIR "/lib/lib", F_OK) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int res = 0;
|
|
||||||
pid_t p;
|
|
||||||
p = fork();
|
|
||||||
if (p == 0) {
|
|
||||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
|
||||||
return -1;
|
|
||||||
char *args[] = {"./clr_debug_daemon", NULL};
|
|
||||||
execvp("./clr_debug_daemon", args);
|
|
||||||
} else if (p > 0) {
|
|
||||||
sleep(1);
|
|
||||||
res = testing_daemon();
|
|
||||||
kill(p, SIGKILL);
|
|
||||||
} else {
|
|
||||||
fputs("error executing fork\n", stderr);
|
|
||||||
}
|
|
||||||
unlink(SOCKET_PATH);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
||||||
*
|
|
||||||
* Local variables:
|
|
||||||
* c-basic-offset: 8
|
|
||||||
* tab-width: 8
|
|
||||||
* indent-tabs-mode: nil
|
|
||||||
* End:
|
|
||||||
*
|
|
||||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
|
||||||
* :indentSize=8:tabSize=8:noTabs=true:
|
|
||||||
*/
|
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <grp.h>
|
|
||||||
#include <linux/capability.h>
|
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/prctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define TIMEOUT 600
|
|
||||||
#define MAX_CONNECTIONS 16
|
|
||||||
|
|
||||||
int check_file_request(int fd, char *expected_str)
|
|
||||||
{
|
|
||||||
char buf[PATH_MAX + 8];
|
|
||||||
int clientsock;
|
|
||||||
malloc_trim(0);
|
|
||||||
fputs("Accepting connection\n", stderr);
|
|
||||||
clientsock = accept(fd, NULL, NULL);
|
|
||||||
if (clientsock < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
fputs("Reading socket content\n", stderr);
|
|
||||||
if (read(clientsock, buf, PATH_MAX + 8) < 0)
|
|
||||||
return -1;
|
|
||||||
close(clientsock);
|
|
||||||
return strncmp(buf, expected_str, strlen(expected_str));
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_service_socket(void)
|
|
||||||
{
|
|
||||||
int sockfd;
|
|
||||||
struct sockaddr_un sun;
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
|
||||||
fputs("Creating socket\n", stderr);
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0) {
|
|
||||||
fputs("Fail creating socket\n", stderr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Socket path %s\n", SOCKET_PATH);
|
|
||||||
sun.sun_family = AF_UNIX;
|
|
||||||
strcpy(sun.sun_path, SOCKET_PATH);
|
|
||||||
|
|
||||||
fputs("Binding socket\n", stderr);
|
|
||||||
if (bind(sockfd, (struct sockaddr*)&sun,
|
|
||||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1) < 0) {
|
|
||||||
fprintf(stderr, "fail bind: %s\n", strerror(errno));
|
|
||||||
close(sockfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen(sockfd, 16) < 0) {
|
|
||||||
fputs("Fail listening socket \n", stderr);
|
|
||||||
close(sockfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return sockfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int testing_fuse(void)
|
|
||||||
{
|
|
||||||
int sockfd;
|
|
||||||
uid_t gdb_user = 0;
|
|
||||||
gid_t gdb_group = 0;
|
|
||||||
struct passwd *passwdentry;
|
|
||||||
pid_t p2;
|
|
||||||
int test_result = -1;
|
|
||||||
umask(0);
|
|
||||||
passwdentry = getpwnam("gdbinfo");
|
|
||||||
if (passwdentry) {
|
|
||||||
gdb_user = passwdentry->pw_uid;
|
|
||||||
gdb_group = passwdentry->pw_gid;
|
|
||||||
}
|
|
||||||
endpwent();
|
|
||||||
|
|
||||||
if (prctl(PR_SET_DUMPABLE, 0) != 0) {
|
|
||||||
fputs("fail prctl\n", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (geteuid() == 0) {
|
|
||||||
if (prctl(PR_CAPBSET_DROP, CAP_SYS_ADMIN) !=0) {
|
|
||||||
fprintf(stderr, "fail geteuid: %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((sockfd = get_service_socket()) < 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setgid(gdb_group)) {
|
|
||||||
fputs("fail setgid\n", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setgroups(1, &gdb_group)) {
|
|
||||||
fputs("fail setgroups\n", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setuid(gdb_user)) {
|
|
||||||
fputs("fail setuid\n", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
p2 = fork();
|
|
||||||
if (p2 > 0) {
|
|
||||||
test_result = check_file_request(sockfd, "0:lib:/tmp");
|
|
||||||
} else if (p2 == 0) {
|
|
||||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
|
||||||
exit(1);
|
|
||||||
char *args[] = {"/usr/bin/cat", "/usr/lib/debug/tmp", NULL};
|
|
||||||
execvp("/usr/bin/cat", args);
|
|
||||||
} else {
|
|
||||||
fputs("error executing fork\n", stderr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
wait(NULL);
|
|
||||||
close(sockfd);
|
|
||||||
return test_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int res = 0;
|
|
||||||
pid_t p;
|
|
||||||
p = fork();
|
|
||||||
if (p == 0) {
|
|
||||||
if (freopen("/dev/null", "w", stderr) == NULL)
|
|
||||||
return -1;
|
|
||||||
char *args[] = {"./clr_debug_fuse", NULL};
|
|
||||||
execvp("./clr_debug_fuse", args);
|
|
||||||
} else if (p > 0) {
|
|
||||||
sleep(1);
|
|
||||||
res = testing_fuse();
|
|
||||||
kill(p, SIGKILL);
|
|
||||||
} else {
|
|
||||||
fputs("error executing fork\n", stderr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
unlink(SOCKET_PATH);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
||||||
*
|
|
||||||
* Local variables:
|
|
||||||
* c-basic-offset: 8
|
|
||||||
* tab-width: 8
|
|
||||||
* indent-tabs-mode: nil
|
|
||||||
* End:
|
|
||||||
*
|
|
||||||
* vi: set shiftwidth=8 tabstop=8 expandtab:
|
|
||||||
* :indentSize=8:tabSize=8:noTabs=true:
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user