mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 22:01:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eaaac582c | ||
|
|
935dbee3c7 | ||
|
|
0065ef2670 | ||
|
|
b5b4030f7c | ||
|
|
de9e0ce5c5 | ||
|
|
9e400bd149 | ||
|
|
f5a65358af | ||
|
|
c82a007960 |
+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, 32, 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}
|
||||||
|
])
|
||||||
|
|||||||
+70
-6
@@ -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,8 @@ 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);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1);
|
||||||
|
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
||||||
@@ -273,6 +324,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 +332,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 +352,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