Compare commits

...
9 Commits
42 ... 45
Author SHA1 Message Date
Arjan van de Ven d108c0af64 add cdn-alt 2018-05-17 13:54:16 +00:00
Auke Kok 98e802b4cc Also install socket unit. 2018-04-24 13:04:33 -07:00
Auke Kok 612801b0c8 Make -daemon socket activated. 2018-04-23 15:15:33 -07:00
Arjan van de Ven 3c2ad26baa have tar follow symlinks 2017-12-23 00:49:24 +00:00
Arjan van de Ven d20d585e5c much shorter timeouts 2017-12-10 14:25:07 +00:00
Icarus Sparry 1f3a0f0be4 Extract tar file as dbginfo
Make /var/cache/debuginfo and its contents owned by dgbinfo. Create
the directories as this user, and switch to run as this user.

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2017-10-31 13:35:29 -07:00
Icarus Sparry d2d67bdb1d Change tmpfiles.d configuration
Use the dbginfo user for the directories.

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2017-10-31 09:47:39 -07:00
Auke Kok 60db7bab0f v43 2017-06-06 13:28:11 -07:00
Auke Kok ef6b11498a DefaultDependencies keyword is only valid in [Unit] context. 2017-06-06 13:27:20 -07:00
9 changed files with 97 additions and 34 deletions
+4 -3
View File
@@ -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 = \ DISTCHECK_CONFIGURE_FLAGS = \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \
@@ -33,7 +33,8 @@ 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_prepare_SOURCES = src/prepare.c
@@ -42,6 +43,6 @@ clr_debug_fuse_LDADD = ${fuse_LIBS} libnica.la
clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la clr_debug_daemon_LDADD = ${curl_LIBS} libnica.la
clr_debug_prepare_LDADD = libnica.la 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 tmpfiles_DATA = debuginfo.conf
+1 -1
View File
@@ -1,10 +1,10 @@
[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
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
+9
View File
@@ -0,0 +1,9 @@
[Unit]
Description=Clear Linux OS debuginfo daemon
[Socket]
ListenStream=/run/clr-debug-info
SocketMode=0600
[Install]
WantedBy=sockets.target
+1 -1
View File
@@ -1,11 +1,11 @@
[Unit] [Unit]
Description=Clear Linux debuginfo fuse monitor Description=Clear Linux debuginfo fuse monitor
After=clr_debug_daemon.service After=clr_debug_daemon.service
DefaultDependencies=no
[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
+3 -1
View File
@@ -2,15 +2,17 @@
# 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, 42, arjan@linux.intel.com) AC_INIT(clr-debug-info, 43, 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])
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=""
+4 -2
View File
@@ -8,5 +8,7 @@
# 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
d /var/cache/debuginfo/lib 755 root root 10d # Unfortunatly tmpfiles doesn't change the ownership for things if they
d /var/cache/debuginfo/src 755 root root 1d # are not listed.
d /var/cache/debuginfo/lib 755 dbginfo dbginfo 10d
d /var/cache/debuginfo/src 755 dbginfo dbginfo 1d
+4 -5
View File
@@ -37,8 +37,8 @@
#include <unistd.h> #include <unistd.h>
/* 0.75 seconds timeout */ /* 0.75 seconds timeout */
#define TIMEOUT 750000 #define TIMEOUT 75000
#define TIMEOUT2 15000 #define TIMEOUT2 1500
#define TIMEOUT3 500 #define TIMEOUT3 500
char *prefix = "src"; char *prefix = "src";
@@ -66,12 +66,11 @@ 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, ":clr-debug-info"); strcpy(sun.sun_path, "/run/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(":clr-debug-info") + 1); offsetof(struct sockaddr_un, sun_path) + strlen("/run/clr-debug-info") + 1);
if (ret < 0) { if (ret < 0) {
printf("Cannot connect %s\n", strerror(errno)); printf("Cannot connect %s\n", strerror(errno));
close(sockfd); close(sockfd);
+1 -1
View File
@@ -137,7 +137,7 @@ static void do_one_file(char *base1, char *base2, char *path, int isdir)
if (!isdir && if (!isdir &&
asprintf(&command, asprintf(&command,
"tar --no-recursion -C %s -Jcf %s %s &", "tar --no-recursion -h -C %s -Jcf %s %s &",
base1, base1,
fullpath2, fullpath2,
path) >= 0) { path) >= 0) {
+70 -20
View File
@@ -27,9 +27,11 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include <errno.h> #include <errno.h>
#include <grp.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>
@@ -47,6 +49,8 @@
#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
@@ -56,7 +60,7 @@
static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t dupes_mutex = PTHREAD_MUTEX_INITIALIZER;
char *urls[2] = { "https://cdn.download.clearlinux.org/debuginfo/", 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; int urlcounter = 1;
static NcHashmap *hash = NULL; static NcHashmap *hash = NULL;
@@ -252,7 +256,8 @@ 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 --no-same-permissions -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) {
@@ -349,7 +354,7 @@ static void *server_thread(void *arg)
} }
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,
@@ -375,8 +380,19 @@ 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;
gid_t dbg_group = 0;
struct passwd *passwdentry;
const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" }; const char *required_paths[] = { "/var/cache/debuginfo/lib", "/var/cache/debuginfo/src" };
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,
"Failed to disable PR_SET_DUMPABLE. Do NOT gdb attach this process: %s\n", "Failed to disable PR_SET_DUMPABLE. Do NOT gdb attach this process: %s\n",
@@ -391,36 +407,70 @@ 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];
if (nc_file_exists(req_path)) { struct stat st = { .st_ino = 0 };
continue; if (lstat(req_path, &st) == 0) {
/* 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);
sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sd_listen_fds(0) == 1) {
if (sockfd < 0) { /* systemd socket activation */
printf("Received socket from systemd socket activation\n");
sockfd = SD_LISTEN_FDS_START + 0;
} else if (sd_listen_fds(0) > 1) {
printf("Too many file descriptors received.\n");
exit(1);
} else {
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd < 0) {
return EXIT_FAILURE;
}
sun.sun_family = AF_UNIX;
strcpy(sun.sun_path, "/run/clr-debug-info");
ret = bind(sockfd,
(struct sockaddr *)&sun,
offsetof(struct sockaddr_un, sun_path) + strlen("/run/clr-debug-info") + 1);
if (ret < 0) {
printf("Failed to bind:%s \n", strerror(errno));
return EXIT_FAILURE;
}
if (listen(sockfd, 16) < 0) {
printf("Failed to listen:%s \n", strerror(errno));
return EXIT_FAILURE;
}
}
if (setgid(dbg_group)) {
fprintf(stderr, "Unable to drop privileges setgid %s\n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (setgroups(1, &dbg_group)) {
sun.sun_family = AF_UNIX; fprintf(stderr, "Unable to drop privileges setgroups %s\n", strerror(errno));
strcpy(sun.sun_path, ":clr-debug-info");
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; return EXIT_FAILURE;
} }
if (setuid(dbg_user)) {
if (listen(sockfd, 16) < 0) { fprintf(stderr, "Unable to drop privileges setuid %s\n", strerror(errno));
printf("Failed to listen:%s \n", strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }