mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 05:41:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be8a99da53 | ||
|
|
c9304402e2 | ||
|
|
6e202f13f7 | ||
|
|
6735f8f6ed | ||
|
|
8b3777ab99 | ||
|
|
84350939ef | ||
|
|
72b1120a40 | ||
|
|
d3d5fab301 | ||
|
|
e377433a9d | ||
|
|
afa92c77b1 | ||
|
|
a01ce4c329 | ||
|
|
1eaaac582c | ||
|
|
935dbee3c7 | ||
|
|
0065ef2670 | ||
|
|
b5b4030f7c | ||
|
|
de9e0ce5c5 | ||
|
|
9e400bd149 | ||
|
|
f5a65358af | ||
|
|
c82a007960 |
@@ -4,6 +4,7 @@ Description=Clear Linux debuginfo daemon
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/bin/clr_debug_daemon
|
ExecStart=/usr/bin/clr_debug_daemon
|
||||||
|
DefaultDependencies=no
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ After=clr_debug_daemon.service
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/bin/clr_debug_fuse
|
ExecStart=/usr/bin/clr_debug_fuse
|
||||||
|
DefaultDependencies=no
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
+28
-1
@@ -2,7 +2,7 @@
|
|||||||
# 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, 31, 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
|
||||||
@@ -27,5 +27,32 @@ AC_ARG_WITH([systemdtmpfilesdir], AS_HELP_STRING([--with-systemdtmpfilesdir=DIR]
|
|||||||
test -z "${dir}" && dir=/usr/lib/tmpfiles.d
|
test -z "${dir}" && dir=/usr/lib/tmpfiles.d
|
||||||
AC_SUBST(tmpfilesdir, [${dir}])
|
AC_SUBST(tmpfilesdir, [${dir}])
|
||||||
|
|
||||||
|
AC_CHECK_HEADER([stdatomic.h], [have_atomics="yes"], [have_atomics="no"])
|
||||||
|
if test x$have_atomics = "xyes"; then
|
||||||
|
AC_DEFINE([HAVE_ATOMIC_SUPPORT], [1], [stdatomic supported by compiler])
|
||||||
|
else
|
||||||
|
AC_MSG_WARN([C11 stdatomic support unavailable. Falling back to slow mutex])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
AC_MSG_RESULT([
|
||||||
|
clr-debuginfo $VERSION
|
||||||
|
|
||||||
|
prefix: ${prefix}
|
||||||
|
libdir: ${libdir}
|
||||||
|
sysconfdir: ${sysconfdir}
|
||||||
|
exec_prefix: ${exec_prefix}
|
||||||
|
bindir: ${bindir}
|
||||||
|
datarootdir: ${datarootdir}
|
||||||
|
|
||||||
|
compiler: ${CC}
|
||||||
|
cflags: ${CFLAGS}
|
||||||
|
ldflags: ${LDFLAGS}
|
||||||
|
|
||||||
|
systemd-unit-dir: ${systemdsystemunitdir}
|
||||||
|
tmpfiles.d: ${tmpfilesdir}
|
||||||
|
|
||||||
|
C11 stdatomic support: ${have_atomics}
|
||||||
|
])
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
|||||||
if (ret == 0 && cred.pid == pid) {
|
if (ret == 0 && cred.pid == pid) {
|
||||||
printf("Recursion\n");
|
printf("Recursion\n");
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = NULL;
|
command = NULL;
|
||||||
|
|||||||
+1
-1
@@ -113,7 +113,7 @@ bool nc_copy_file(const char *src, const char *dst, mode_t mode, bool remove_tar
|
|||||||
while (true) {
|
while (true) {
|
||||||
if ((r = read(src_fd, &buffer, sizeof(buffer))) < 0) {
|
if ((r = read(src_fd, &buffer, sizeof(buffer))) < 0) {
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
goto end;
|
||||||
}
|
}
|
||||||
if (write(dest_fd, buffer, sizeof(buffer)) != r) {
|
if (write(dest_fd, buffer, sizeof(buffer)) != r) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
+7
-5
@@ -123,8 +123,8 @@ static inline unsigned nc_hashmap_get_hash(NcHashmap *self, const void *key)
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nc_hashmap_insert_bucket(NcHashmap *self, NcHashmapEntry *buckets, int n_buckets,
|
static int nc_hashmap_insert_bucket(NcHashmap *self, NcHashmapEntry *buckets, int n_buckets,
|
||||||
unsigned hash, const void *key, void *value)
|
unsigned hash, const void *key, void *value)
|
||||||
{
|
{
|
||||||
NcHashmapEntry *row = &(buckets[hash % n_buckets]);
|
NcHashmapEntry *row = &(buckets[hash % n_buckets]);
|
||||||
NcHashmapEntry *head = NULL;
|
NcHashmapEntry *head = NULL;
|
||||||
@@ -458,10 +458,12 @@ bool nc_hashmap_iter_next(NcHashmapIter *citer, void **key, void **value)
|
|||||||
}
|
}
|
||||||
item = &(map->buckets[iter->bucket]);
|
item = &(map->buckets[iter->bucket]);
|
||||||
}
|
}
|
||||||
if (item && item->occ) {
|
if (item) {
|
||||||
goto success;
|
if (item->occ) {
|
||||||
|
goto success;
|
||||||
|
}
|
||||||
|
item = item->next;
|
||||||
}
|
}
|
||||||
item = item->next;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
+82
-8
@@ -27,14 +27,15 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <linux/capability.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdatomic.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -46,18 +47,22 @@
|
|||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_ATOMIC_SUPPORT
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
char *urls[2] = { "https://debuginfo.clearlinux.org/debuginfo/",
|
char *urls[2] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
||||||
"https://debuginfo.clearlinux.org/debuginfo/" };
|
"https://cdn.download.clearlinux.org/debuginfo/" };
|
||||||
int urlcounter = 1;
|
int urlcounter = 1;
|
||||||
|
|
||||||
static NcHashmap *hash = NULL;
|
static NcHashmap *hash = NULL;
|
||||||
|
|
||||||
#define MAX_CONNECTIONS 16
|
#define MAX_CONNECTIONS 16
|
||||||
|
|
||||||
static atomic_int current_connection_count = 0;
|
|
||||||
|
|
||||||
static int avoid_dupes(const char *url)
|
static int avoid_dupes(const char *url)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
@@ -85,6 +90,10 @@ static int avoid_dupes(const char *url)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_ATOMIC_SUPPORT
|
||||||
|
|
||||||
|
static atomic_int current_connection_count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current connection count atomically
|
* Get the current connection count atomically
|
||||||
*/
|
*/
|
||||||
@@ -108,6 +117,46 @@ __nc_inline__ static inline void dec_connection_count(void)
|
|||||||
{
|
{
|
||||||
atomic_fetch_sub(¤t_connection_count, 1);
|
atomic_fetch_sub(¤t_connection_count, 1);
|
||||||
}
|
}
|
||||||
|
#else /* HAVE_ATOMIC_SUPPORT */
|
||||||
|
|
||||||
|
static int current_connection_count = 0;
|
||||||
|
|
||||||
|
/* No stdatomic compiler support, fallback to pthread mutex (slower) */
|
||||||
|
pthread_mutex_t con_count_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current connection count via mutex
|
||||||
|
*/
|
||||||
|
__nc_inline__ static inline int get_current_connection_count(void)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
pthread_mutex_lock(&con_count_mutex);
|
||||||
|
r = current_connection_count;
|
||||||
|
pthread_mutex_unlock(&con_count_mutex);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increment the connection counter via mutex
|
||||||
|
*/
|
||||||
|
__nc_inline__ static inline void inc_connection_count(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&con_count_mutex);
|
||||||
|
current_connection_count++;
|
||||||
|
pthread_mutex_unlock(&con_count_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrement the connection counter via mutex
|
||||||
|
*/
|
||||||
|
__nc_inline__ static inline void dec_connection_count(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&con_count_mutex);
|
||||||
|
current_connection_count--;
|
||||||
|
pthread_mutex_unlock(&con_count_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !(HAVE_ATOMIC_SUPPORT) */
|
||||||
|
|
||||||
static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||||
{
|
{
|
||||||
@@ -140,6 +189,19 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some sane timeout values to prevent stalls
|
||||||
|
*
|
||||||
|
* Connect timeout is for first connection to the server.
|
||||||
|
* The low speed timeout is for slow downloads. Since many
|
||||||
|
* files are several mB large, we want to prevent them from
|
||||||
|
* taking forever. (1kB/sec avg over 30secs).
|
||||||
|
*/
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 30);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1024);
|
||||||
|
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
||||||
@@ -175,7 +237,7 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
stat(filename, &statbuf);
|
stat(filename, &statbuf);
|
||||||
if (statbuf.st_size > 0 &&
|
if (statbuf.st_size > 0 &&
|
||||||
asprintf(&command,
|
asprintf(&command,
|
||||||
"tar -C /var/cache/debuginfo/%s --no-same-owner -xf %s",
|
"tar -C /var/cache/debuginfo/%s --no-same-owner --no-same-permissions -xf %s",
|
||||||
prefix,
|
prefix,
|
||||||
filename) >= 0) {
|
filename) >= 0) {
|
||||||
if (system(command) != 0) {
|
if (system(command) != 0) {
|
||||||
@@ -220,7 +282,6 @@ static void *server_thread(void *arg)
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto thread_end;
|
goto thread_end;
|
||||||
}
|
}
|
||||||
prefix = buf;
|
|
||||||
c = strchr(buf, ':');
|
c = strchr(buf, ':');
|
||||||
if (!c) {
|
if (!c) {
|
||||||
goto thread_end;
|
goto thread_end;
|
||||||
@@ -273,6 +334,7 @@ static void *server_thread(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&after, NULL);
|
gettimeofday(&after, NULL);
|
||||||
|
#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,
|
||||||
@@ -280,7 +342,7 @@ static void *server_thread(void *arg)
|
|||||||
(1.0 * after.tv_usec - before.tv_usec) / 1000000.0,
|
(1.0 * after.tv_usec - before.tv_usec) / 1000000.0,
|
||||||
ret,
|
ret,
|
||||||
(int)timestamp);
|
(int)timestamp);
|
||||||
|
#endif
|
||||||
/* tell the other side we're done with the download */
|
/* tell the other side we're done with the download */
|
||||||
wr = write(fd, "ok", 3);
|
wr = write(fd, "ok", 3);
|
||||||
|
|
||||||
@@ -300,6 +362,18 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
|||||||
int curl_done = 0;
|
int curl_done = 0;
|
||||||
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
|
||||||
|
|
||||||
|
if (prctl(PR_SET_DUMPABLE, 0) != 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Failed to disable PR_SET_DUMPABLE. Do NOT gdb attach this process: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geteuid() == 0) {
|
||||||
|
if (prctl(PR_CAPBSET_DROP, CAP_SYS_ADMIN) != 0) {
|
||||||
|
fprintf(stderr, "Failed to drop caps: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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];
|
||||||
if (nc_file_exists(req_path)) {
|
if (nc_file_exists(req_path)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user