mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 05:41:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b802948209 | ||
|
|
4495b923a9 | ||
|
|
8f7289f028 |
+1
-1
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.66])
|
||||
AC_INIT(clr-debug-info, 48, arjan@linux.intel.com)
|
||||
AC_INIT(clr-debug-info, 49, arjan@linux.intel.com)
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -W subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_PROG_CC
|
||||
|
||||
+50
-21
@@ -2,7 +2,7 @@
|
||||
* Clear Linux -- automatic debug information installation
|
||||
*
|
||||
* Copyright (C) 2013 Arjan van de Ven
|
||||
* Curl portions borrowed from the Fenrus Update code
|
||||
* Curl portions borrowed from the Fenrus Update code
|
||||
* which in part is (C) 2012 Intel Corporation
|
||||
* Copyright (C) 2014 Intel Corporation
|
||||
*
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <malloc.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <libgen.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
@@ -170,10 +171,9 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
long ret;
|
||||
long changed;
|
||||
int fd;
|
||||
char filename[PATH_MAX];
|
||||
autofree(char) *filename = NULL;
|
||||
CURL *curl = NULL;
|
||||
FILE *file;
|
||||
struct stat statbuf;
|
||||
|
||||
if (avoid_dupes(url)) {
|
||||
return 300;
|
||||
@@ -184,12 +184,15 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
return 301;
|
||||
}
|
||||
|
||||
strcpy(filename, "/tmp/clr-debug-info-XXXXXX");
|
||||
|
||||
// fprintf(stderr, "Fetching %s, prefix %s, path %s\n", url, prefix, path);
|
||||
if (asprintf(&filename, "/tmp/clr-debug-info-XXXXXX") < 0) {
|
||||
curl_easy_cleanup(curl);
|
||||
return 418;
|
||||
}
|
||||
fd = mkstemp(filename);
|
||||
if (fd < 0) {
|
||||
curl_easy_cleanup(curl);
|
||||
return 500;
|
||||
return 418;
|
||||
}
|
||||
|
||||
file = fdopen(fd, "w");
|
||||
@@ -227,7 +230,7 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret);
|
||||
fflush(file);
|
||||
// printf("HTTP return code is %i\n", ret);
|
||||
// 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
|
||||
@@ -240,6 +243,9 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
}
|
||||
|
||||
if (ret == 200) {
|
||||
autofree(char) *command = NULL;
|
||||
struct stat statbuf;
|
||||
|
||||
/* get timestamp, if any */
|
||||
curl_easy_getinfo(curl, CURLINFO_FILETIME, &changed);
|
||||
if (changed >= 0) {
|
||||
@@ -251,22 +257,45 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
||||
futimens(fd, times);
|
||||
}
|
||||
|
||||
autofree(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 /var/cache/debuginfo/%s --no-same-owner "
|
||||
"--no-same-permissions -xf %s",
|
||||
if (statbuf.st_size <= 0) {
|
||||
ret = 418;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* test extraction first */
|
||||
if (asprintf(&command, "tar -C /var/cache/debuginfo/%s --no-same-owner "
|
||||
"--no-same-permissions -tf %s",
|
||||
prefix,
|
||||
filename) >= 0) {
|
||||
if (system(command) != 0) {
|
||||
fputs("Warning: tar extraction failed\n", stderr);
|
||||
}
|
||||
filename) < 0) {
|
||||
ret = 418;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (system(command) != 0) {
|
||||
ret = 418;
|
||||
fprintf(stderr, "Error: tar validation failed\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
free(command); /* reuse */
|
||||
if (asprintf(&command, "tar -C /var/cache/debuginfo/%s --no-same-owner "
|
||||
"--no-same-permissions -xf %s",
|
||||
prefix,
|
||||
filename) < 0) {
|
||||
ret = 418;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (system(command) != 0) {
|
||||
ret = 418;
|
||||
fprintf(stderr, "Error: tar extraction failed\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
unlink(filename);
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(file);
|
||||
@@ -340,7 +369,7 @@ static void *server_thread(void *arg)
|
||||
goto thread_end;
|
||||
}
|
||||
|
||||
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
|
||||
// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
|
||||
ret = curl_get_file(url, prefix, timestamp);
|
||||
|
||||
switch (ret) {
|
||||
@@ -351,7 +380,7 @@ static void *server_thread(void *arg)
|
||||
// ignore these error codes
|
||||
break;
|
||||
default:
|
||||
printf("Request for %s resulted in error %i\n", url, ret);
|
||||
fprintf(stderr, "Request for %s resulted in error %i\n", url, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -437,7 +466,7 @@ int main(__nc_unused__ int argc, __nc_unused__ char **argv)
|
||||
/* systemd socket activation */
|
||||
sockfd = SD_LISTEN_FDS_START + 0;
|
||||
} else if (sd_listen_fds(0) > 1) {
|
||||
printf("Too many file descriptors received.\n");
|
||||
fprintf(stderr, "Too many file descriptors received.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
||||
Reference in New Issue
Block a user