mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 13:51:38 +00:00
Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
670069d659 | ||
|
|
be74f893e6 | ||
|
|
7a5e4a9acd | ||
|
|
07a4c3d305 | ||
|
|
ab0e59628f | ||
|
|
af4a3f64f0 | ||
|
|
8c65e96479 | ||
|
|
7ea9a50b19 | ||
|
|
e16ab76926 | ||
|
|
090cb27a34 | ||
|
|
cbaf943fca | ||
|
|
32ae400e7d | ||
|
|
82f03f8e22 | ||
|
|
c1f45d9f3c | ||
|
|
bcff8fae39 | ||
|
|
66bab25bcd | ||
|
|
49ac392f01 | ||
|
|
71f4e789c4 | ||
|
|
f776162882 | ||
|
|
a2abd8d2a9 | ||
|
|
8844b0b0e1 | ||
|
|
ca63e1be25 | ||
|
|
078e9987d5 | ||
|
|
97431314b5 | ||
|
|
07e1f033e1 | ||
|
|
45f22398ca | ||
|
|
b538b457ce | ||
|
|
09affa9bf5 | ||
|
|
2a217476f7 | ||
|
|
4d6639148f | ||
|
|
83509e34c7 |
@@ -4,10 +4,12 @@ clr_debug_fuse
|
||||
clr_debug_daemon
|
||||
clr_debug_prepare
|
||||
.deps/
|
||||
.dirstamp
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
compile
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
@@ -18,3 +20,5 @@ install-sh
|
||||
missing
|
||||
stamp-h1
|
||||
*.tar.gz
|
||||
tags
|
||||
cscope.*
|
||||
|
||||
+6
-5
@@ -1,5 +1,9 @@
|
||||
EXTRA_DIST = COPYING clr_debug_fuse.service clr_debug_daemon.service debuginfo.conf
|
||||
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
|
||||
--with-systemdtmpfilesdir=$$dc_install_base/$(tmpfilesdir)
|
||||
|
||||
bin_PROGRAMS = clr_debug_fuse clr_debug_daemon clr_debug_prepare
|
||||
|
||||
clr_debug_fuse_SOURCES = src/fuse.c src/client.c
|
||||
@@ -14,9 +18,6 @@ clr_debug_fuse_LDADD = ${fuse_LIBS} $(glib_LIBS)
|
||||
clr_debug_daemon_LDADD = $(glib_LIBS) ${curl_LIBS}
|
||||
clr_debug_prepare_LDADD = $(glib_LIBS)
|
||||
|
||||
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service
|
||||
|
||||
systemdunitdir = @SYSTEMD_UNITDIR@
|
||||
systemdunit_DATA = clr_debug_fuse.service clr_debug_daemon.service
|
||||
|
||||
tmpwatchdir = /etc/tmpfiles.d
|
||||
tmpwatch_DATA = debuginfo.conf
|
||||
tmpfiles_DATA = debuginfo.conf
|
||||
|
||||
@@ -4,7 +4,6 @@ Description=Clear Linux debuginfo daemon
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/clr_debug_daemon
|
||||
ExecStopPost=umount /run/user/0/debug-lib ; umount /run/user/0/debug-src
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
+15
-10
@@ -2,8 +2,8 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.66])
|
||||
AC_INIT(clr-debug-info, 7, arjan@linux.intel.com)
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -W])
|
||||
AC_INIT(clr-debug-info, 30, arjan@linux.intel.com)
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_PROG_CC
|
||||
AC_LANG(C)
|
||||
@@ -13,14 +13,19 @@ PKG_CHECK_MODULES([curl], [libcurl])
|
||||
PKG_CHECK_MODULES([fuse], [fuse])
|
||||
PKG_CHECK_MODULES([SYSTEMD], [systemd])
|
||||
|
||||
AC_ARG_WITH([systemdunitdir], AC_HELP_STRING([--with-systemdunitdir=DIR],
|
||||
[path to systemd service directory]), [path_systemdunit=${withval}],
|
||||
[path_systemdunit="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"])
|
||||
if (test -n "${path_systemdunit}"); then
|
||||
SYSTEMD_UNITDIR="${path_systemdunit}"
|
||||
AC_SUBST(SYSTEMD_UNITDIR)
|
||||
AM_CONDITIONAL(SYSTEMD, test -n "${path_systemdunit}")
|
||||
fi
|
||||
dir=""
|
||||
AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
|
||||
[path to systemd system service dir @<:@default=/usr/lib/systemd/system@:>@]), [dir=${withval}],
|
||||
[dir="$($PKG_CONFIG --variable=systemdsystemunitdir systemd)"])
|
||||
test -z "${dir}" && dir=/usr/lib/systemd/system
|
||||
AC_SUBST(systemdsystemunitdir, [${dir}])
|
||||
|
||||
dir=""
|
||||
AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR],
|
||||
[path to systemd tmpfiles dir @<:@default=/usr/lib/tmpfiles.d@:>@]), [dir=${withval}],
|
||||
[dir="$($PKG_CONFIG --variable=tmpfilesdir systemd)"])
|
||||
test -z "${dir}" && dir=/usr/lib/tmpfiles.d
|
||||
AC_SUBST(tmpfilesdir, [${dir}])
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
+2
-2
@@ -8,5 +8,5 @@
|
||||
# See tmpfiles.d(5) for details
|
||||
|
||||
# Clear tmp directories separately, to make them easier to override
|
||||
d /usr/lib/.debug 755 root root 10d
|
||||
d /usr/src/.debug 755 root root 1d
|
||||
d /var/cache/debuginfo/lib 755 root root 10d
|
||||
d /var/cache/debuginfo/src 755 root root 1d
|
||||
|
||||
+12
-5
@@ -34,6 +34,7 @@ Original copyright notice follows:
|
||||
#include <malloc.h>
|
||||
#include <fuse.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@@ -608,18 +609,24 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
char * fake_argv[20];
|
||||
char *dir = "/usr/src/debug";
|
||||
char *shadowdir = "/usr/src/.debug";
|
||||
char *shadowdir = "/var/cache/debuginfo/src";
|
||||
umask(0);
|
||||
|
||||
/* give the system some time to boot before we go active; this is a background task */
|
||||
sleep(1);
|
||||
|
||||
system("modprobe fuse");
|
||||
if (access("/sys/module/fuse/", F_OK))
|
||||
system("modprobe fuse");
|
||||
signal(SIGPIPE,SIG_IGN);
|
||||
|
||||
system("mkdir -p /usr/lib/.debug &> /dev/null");
|
||||
system("mkdir -p /usr/src/.debug &> /dev/null");
|
||||
if (access("/var/cache/debuginfo/lib/", F_OK))
|
||||
system("mkdir -p /var/cache/debuginfo/lib &> /dev/null");
|
||||
if (access("/var/cache/debuginfo/src/", F_OK))
|
||||
system("mkdir -p /var/cache/debuginfo/src &> /dev/null");
|
||||
|
||||
if (fork() == 0) {
|
||||
dir = "/usr/lib/debug";
|
||||
shadowdir = "/usr/lib/.debug";
|
||||
shadowdir = "/var/cache/debuginfo/lib";
|
||||
prefix = "lib";
|
||||
|
||||
}
|
||||
|
||||
+13
-11
@@ -161,10 +161,11 @@ out:
|
||||
static void recurse_dir(char *base1, char *base2, char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
char *fullpath1, *newpath;
|
||||
char *fullpath1, *fullpath2, *newpath;
|
||||
struct dirent *entry;
|
||||
|
||||
fullpath1 = NULL;
|
||||
fullpath2 = NULL;
|
||||
|
||||
|
||||
if (asprintf(&fullpath1, "%s%s", base1, path) < 0)
|
||||
@@ -184,20 +185,21 @@ static void recurse_dir(char *base1, char *base2, char *path)
|
||||
continue;
|
||||
if (strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
if (entry->d_type == DT_DIR) {
|
||||
newpath = NULL;
|
||||
if (asprintf(&newpath, "%s/%s", path, entry->d_name) >= 0) {
|
||||
|
||||
newpath = NULL;
|
||||
fullpath2 = NULL;
|
||||
asprintf(&fullpath2, "%s/%s", fullpath1, entry->d_name);
|
||||
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);
|
||||
free(newpath);
|
||||
}
|
||||
} else {
|
||||
newpath = NULL;
|
||||
if (asprintf(&newpath, "%s/%s", path, entry->d_name) >= 0) {
|
||||
} else {
|
||||
do_one_file(base1, base2, newpath, 0);
|
||||
free(newpath);
|
||||
}
|
||||
free(newpath);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
+56
-14
@@ -36,11 +36,15 @@
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <glib.h>
|
||||
|
||||
GStaticMutex dupes_mutex = G_STATIC_MUTEX_INIT;
|
||||
static GMutex dupes_mutex;
|
||||
|
||||
char *urls[2] = {"https://debuginfo.clearlinux.org/debuginfo/", "https://debuginfo.clearlinux.org/debuginfo/" };
|
||||
int urlcounter = 1;
|
||||
|
||||
|
||||
static GHashTable *hash;
|
||||
@@ -49,7 +53,7 @@ static int avoid_dupes(const char *url)
|
||||
{
|
||||
int retval = 0;
|
||||
void *value;
|
||||
g_static_mutex_lock(&dupes_mutex);
|
||||
g_mutex_lock(&dupes_mutex);
|
||||
|
||||
if (hash == NULL)
|
||||
hash = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
@@ -67,7 +71,7 @@ static int avoid_dupes(const char *url)
|
||||
g_hash_table_replace(hash, strdup(url), data);
|
||||
}
|
||||
|
||||
g_static_mutex_unlock(&dupes_mutex);
|
||||
g_mutex_unlock(&dupes_mutex);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -118,13 +122,22 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
fflush(file);
|
||||
// printf("HTTP return code is %i\n", ret);
|
||||
|
||||
/* 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
|
||||
* already added the URL to the hash table. So, the first crash for a
|
||||
* boot may result in a 304 if the debuginfo had been downloaded in a
|
||||
* previous boot.
|
||||
*/
|
||||
if (ret != 200 && ret != 404 && ret != 304)
|
||||
urlcounter++;
|
||||
|
||||
if (ret == 200) {
|
||||
char *command = NULL;
|
||||
// printf("Filename is %s\n", filename);
|
||||
|
||||
memset(&statbuf, 0, sizeof(statbuf));
|
||||
stat(filename, &statbuf);
|
||||
if (statbuf.st_size > 0 && asprintf(&command, "tar -C /usr/%s/.debug --no-same-owner -xf %s", prefix, filename) >= 0) {
|
||||
if (statbuf.st_size > 0 && asprintf(&command, "tar -C /var/cache/debuginfo/%s --no-same-owner -xf %s", prefix, filename) >= 0) {
|
||||
system(command);
|
||||
free(command);
|
||||
}
|
||||
@@ -184,8 +197,16 @@ static void *server_thread(void *arg)
|
||||
*path = 0;
|
||||
path++;
|
||||
|
||||
/* GDB and elfutils both stat /usr/lib/debug directly when looking up
|
||||
* debuginfo, so avoid the download for "/.tar"; the associated cache
|
||||
* directories already exist by this point.
|
||||
*/
|
||||
if (strlen(path) == 1 && strcmp(path, "/") == 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strstr(path, "..") || strstr(prefix, "..")) {
|
||||
if (strstr(path, "..") || strstr(prefix, "..") || strstr(path, "'") || strstr(path, ";")) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -196,7 +217,7 @@ static void *server_thread(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
url = NULL;
|
||||
if (asprintf(&url, "http://localhost/debuginfo/%s%s.tar", prefix, path) < 0) {
|
||||
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -204,14 +225,28 @@ static void *server_thread(void *arg)
|
||||
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
|
||||
ret = curl_get_file(url, prefix, timestamp);
|
||||
|
||||
/* tell the other side we're done with the download */
|
||||
write(fd, "ok", 3);
|
||||
close(fd);
|
||||
switch (ret) {
|
||||
case 200:
|
||||
case 300:
|
||||
case 304:
|
||||
case 404:
|
||||
// ignore these error codes
|
||||
break;
|
||||
default:
|
||||
printf("Request for %s resulted in error %i\n", url, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
gettimeofday(&after, NULL);
|
||||
if (timedelta(before, after) > 0.6)
|
||||
printf("Request for %s took %5.2f seconds (%i - %i)\n", url,
|
||||
after.tv_sec - before.tv_sec + (1.0*after.tv_usec - before.tv_usec) / 1000000.0, ret, (int)timestamp);
|
||||
|
||||
/* tell the other side we're done with the download */
|
||||
write(fd, "ok", 3);
|
||||
close(fd);
|
||||
|
||||
|
||||
free(url);
|
||||
return NULL;
|
||||
}
|
||||
@@ -222,18 +257,19 @@ int main(int argc, char **argv)
|
||||
int sockfd;
|
||||
struct sockaddr_un sun;
|
||||
int ret;
|
||||
int curl_done = 0;
|
||||
|
||||
if (argc < -1)
|
||||
(void)argv;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
signal(SIGPIPE,SIG_IGN);
|
||||
|
||||
system("mkdir -p /usr/lib/.debug &> /dev/null");
|
||||
system("mkdir -p /usr/src/.debug &> /dev/null");
|
||||
|
||||
|
||||
if (access("/var/cache/debuginfo/lib/", F_OK))
|
||||
system("mkdir -p /var/cache/debuginfo/lib/ &> /dev/null");
|
||||
if (access("/var/cache/debuginfo/src/", F_OK))
|
||||
system("mkdir -p /var/cache/debuginfo/src/ &> /dev/null");
|
||||
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
return EXIT_FAILURE;
|
||||
@@ -258,8 +294,14 @@ int main(int argc, char **argv)
|
||||
int clientsock;
|
||||
pthread_t thread;
|
||||
|
||||
malloc_trim(0);
|
||||
clientsock = accept(sockfd, NULL, NULL);
|
||||
|
||||
if (!curl_done) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl_done = 1;
|
||||
}
|
||||
|
||||
pthread_create(&thread, NULL, server_thread, (void *)(unsigned long)clientsock);
|
||||
pthread_detach(thread);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user