mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 05:41:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc376d5e8b | ||
|
|
c831ecb902 | ||
|
|
0978d429b2 | ||
|
|
6653992aba | ||
|
|
0af0308dd2 | ||
|
|
8ace503438 | ||
|
|
2c87f83adc | ||
|
|
67b9b3acc8 | ||
|
|
d108c0af64 | ||
|
|
98e802b4cc | ||
|
|
612801b0c8 | ||
|
|
3c2ad26baa |
@@ -8,6 +8,7 @@ clr_debug_prepare
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
ar-lib
|
||||
autom4te.cache/
|
||||
compile
|
||||
config.h
|
||||
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
EXTRA_DIST = COPYING clr_debug_fuse.service clr_debug_daemon.service debuginfo.conf
|
||||
EXTRA_DIST = COPYING clr_debug_fuse.service clr_debug_daemon.service clr_debug_daemon.socket debuginfo.conf
|
||||
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
|
||||
@@ -33,15 +33,16 @@ clr_debug_fuse_SOURCES = src/fuse.c src/client.c
|
||||
clr_debug_daemon_SOURCES = src/server.c
|
||||
clr_debug_daemon_CFLAGS = \
|
||||
-pthread \
|
||||
$(AM_CFLAGS)
|
||||
$(AM_CFLAGS) \
|
||||
$(LIBSYSTEMD_CFLAGS)
|
||||
|
||||
clr_debug_prepare_SOURCES = src/prepare.c
|
||||
|
||||
|
||||
clr_debug_fuse_LDADD = ${fuse_LIBS} libnica.la
|
||||
clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la
|
||||
clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la ${LIBSYSTEMD_LIBS}
|
||||
clr_debug_prepare_LDADD = libnica.la
|
||||
|
||||
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service
|
||||
systemdsystemunit_DATA = clr_debug_fuse.service clr_debug_daemon.service clr_debug_daemon.socket
|
||||
|
||||
tmpfiles_DATA = debuginfo.conf
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Clear Linux OS debuginfo daemon
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/clr-debug-info
|
||||
SocketMode=0600
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
@@ -1,6 +1,7 @@
|
||||
[Unit]
|
||||
Description=Clear Linux debuginfo fuse monitor
|
||||
After=clr_debug_daemon.service
|
||||
After=clr_debug_daemon.socket
|
||||
Requires=clr_debug_daemon.socket
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
|
||||
+5
-1
@@ -2,17 +2,21 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.66])
|
||||
AC_INIT(clr-debug-info, 43, arjan@linux.intel.com)
|
||||
AC_INIT(clr-debug-info, 48, arjan@linux.intel.com)
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_PROG_CC
|
||||
AM_PROG_AR
|
||||
AC_LANG(C)
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
PKG_CHECK_MODULES([curl], [libcurl])
|
||||
PKG_CHECK_MODULES([fuse], [fuse])
|
||||
PKG_CHECK_MODULES([SYSTEMD], [systemd])
|
||||
PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd])
|
||||
LT_INIT
|
||||
|
||||
AC_DEFINE([SOCKET_PATH], ["/run/clr-debug-info"], [path to communication socket])
|
||||
|
||||
dir=""
|
||||
AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
|
||||
[path to systemd system service dir @<:@default=/usr/lib/systemd/system@:>@]), [dir=${withval}],
|
||||
|
||||
+6
-5
@@ -36,6 +36,8 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* 0.75 seconds timeout */
|
||||
#define TIMEOUT 75000
|
||||
#define TIMEOUT2 1500
|
||||
@@ -58,7 +60,7 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
||||
int shorttime = 0;
|
||||
__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);
|
||||
if (sockfd < 0) {
|
||||
@@ -66,14 +68,13 @@ void try_to_get(const char *path, int pid, time_t timestamp)
|
||||
}
|
||||
|
||||
sun.sun_family = AF_UNIX;
|
||||
strcpy(sun.sun_path, ":clr-debug-info");
|
||||
sun.sun_path[0] = 0; /* anonymous unix socket */
|
||||
strcpy(sun.sun_path, SOCKET_PATH);
|
||||
|
||||
ret = connect(sockfd,
|
||||
(struct sockaddr *)&sun,
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(":clr-debug-info") + 1);
|
||||
offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_PATH) + 1);
|
||||
if (ret < 0) {
|
||||
printf("Cannot connect %s\n", strerror(errno));
|
||||
printf("Cannot connect to %s: %s\n", SOCKET_PATH, strerror(errno));
|
||||
close(sockfd);
|
||||
return;
|
||||
}
|
||||
|
||||
+10
@@ -75,6 +75,16 @@ static int xmp_getattr(const char *path, struct stat *stbuf)
|
||||
memset(stbuf, 0, sizeof(struct stat));
|
||||
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
|
||||
* a synchronous request.
|
||||
|
||||
+51
-24
@@ -49,16 +49,20 @@
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "systemd/sd-daemon.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_ATOMIC_SUPPORT
|
||||
#include <stdatomic.h>
|
||||
#endif
|
||||
|
||||
#define TIMEOUT 600 /* 10 minutes */
|
||||
|
||||
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
char *urls[2] = { "https://cdn.download.clearlinux.org/debuginfo/",
|
||||
"https://cdn.download.clearlinux.org/debuginfo/" };
|
||||
"https://cdn-alt.download.clearlinux.org/debuginfo/" };
|
||||
int urlcounter = 1;
|
||||
|
||||
static NcHashmap *hash = NULL;
|
||||
@@ -352,7 +356,7 @@ static void *server_thread(void *arg)
|
||||
}
|
||||
|
||||
gettimeofday(&after, NULL);
|
||||
#if 0
|
||||
#if 0
|
||||
if (timedelta(before, after) > 0.6)
|
||||
printf("Request for %s took %5.2f seconds (%i - %i)\n",
|
||||
url,
|
||||
@@ -429,46 +433,71 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (sd_listen_fds(0) == 1) {
|
||||
/* systemd socket activation */
|
||||
sockfd = SD_LISTEN_FDS_START + 0;
|
||||
} else if (sd_listen_fds(0) > 1) {
|
||||
printf("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, ":clr-debug-info");
|
||||
sun.sun_path[0] = 0; /* anonymous unix socket */
|
||||
sun.sun_family = AF_UNIX;
|
||||
strcpy(sun.sun_path, SOCKET_PATH);
|
||||
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
printf("Failed to listen:%s \n", strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
if (listen(sockfd, 16) < 0) {
|
||||
fprintf(stderr, "Failed to listen:%s \n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (setgid(dbg_group)) {
|
||||
fprintf(stderr, "Unable to drop privileges setgid %s\n", strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setgroups(1, &dbg_group)) {
|
||||
fprintf(stderr, "Unable to drop privileges setgroups %s\n", strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setuid(dbg_user)) {
|
||||
fprintf(stderr, "Unable to drop privileges setuid %s\n", strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
int clientsock;
|
||||
pthread_t thread;
|
||||
|
||||
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);
|
||||
|
||||
/* Too many connections, wait for the next loop/retry */
|
||||
@@ -493,6 +522,4 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
if (hash) {
|
||||
nc_hashmap_free(hash);
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user