mirror of
https://github.com/clearlinux/clr-debug-info.git
synced 2026-09-06 13:51:38 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1f45d9f3c | ||
|
|
bcff8fae39 | ||
|
|
66bab25bcd | ||
|
|
49ac392f01 | ||
|
|
71f4e789c4 | ||
|
|
f776162882 | ||
|
|
a2abd8d2a9 | ||
|
|
8844b0b0e1 | ||
|
|
ca63e1be25 |
+24
-7
@@ -36,12 +36,16 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
GStaticMutex dupes_mutex = G_STATIC_MUTEX_INIT;
|
GStaticMutex dupes_mutex = G_STATIC_MUTEX_INIT;
|
||||||
|
|
||||||
|
char *urls[2] = {"https://debuginfo.clearlinux.org/debuginfo/", "http://debuginfo.fenrus.org/debuginfo/" };
|
||||||
|
int urlcounter = 1;
|
||||||
|
|
||||||
|
|
||||||
static GHashTable *hash;
|
static GHashTable *hash;
|
||||||
|
|
||||||
@@ -118,6 +122,9 @@ static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
|
|||||||
fflush(file);
|
fflush(file);
|
||||||
// printf("HTTP return code is %i\n", ret);
|
// printf("HTTP return code is %i\n", ret);
|
||||||
|
|
||||||
|
if (ret != 200 && ret != 404)
|
||||||
|
urlcounter++;
|
||||||
|
|
||||||
if (ret == 200) {
|
if (ret == 200) {
|
||||||
char *command = NULL;
|
char *command = NULL;
|
||||||
// printf("Filename is %s\n", filename);
|
// printf("Filename is %s\n", filename);
|
||||||
@@ -185,7 +192,7 @@ static void *server_thread(void *arg)
|
|||||||
path++;
|
path++;
|
||||||
|
|
||||||
|
|
||||||
if (strstr(path, "..") || strstr(prefix, "..")) {
|
if (strstr(path, "..") || strstr(prefix, "..") || strstr(path, "'") || strstr(path, ";")) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -196,7 +203,7 @@ static void *server_thread(void *arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
url = NULL;
|
url = NULL;
|
||||||
if (asprintf(&url, "http://debuginfo.clearlinux.org/debuginfo/%s%s.tar", prefix, path) < 0) {
|
if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -204,14 +211,19 @@ static void *server_thread(void *arg)
|
|||||||
// 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);
|
ret = curl_get_file(url, prefix, timestamp);
|
||||||
|
|
||||||
/* tell the other side we're done with the download */
|
if (ret != 200)
|
||||||
write(fd, "ok", 3);
|
printf("Request for %s resulted in error %i\n", url, ret);
|
||||||
close(fd);
|
|
||||||
|
|
||||||
gettimeofday(&after, NULL);
|
gettimeofday(&after, NULL);
|
||||||
if (timedelta(before, after) > 0.6)
|
if (timedelta(before, after) > 0.6)
|
||||||
printf("Request for %s took %5.2f seconds (%i - %i)\n", url,
|
printf("Request for %s took %5.2f seconds (%i - %i)\n", url,
|
||||||
after.tv_sec - before.tv_sec + (1.0*after.tv_usec - before.tv_usec) / 1000000.0, ret, (int)timestamp);
|
after.tv_sec - before.tv_sec + (1.0*after.tv_usec - before.tv_usec) / 1000000.0, ret, (int)timestamp);
|
||||||
|
|
||||||
|
/* tell the other side we're done with the download */
|
||||||
|
write(fd, "ok", 3);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
|
||||||
free(url);
|
free(url);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -222,11 +234,11 @@ int main(int argc, char **argv)
|
|||||||
int sockfd;
|
int sockfd;
|
||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun;
|
||||||
int ret;
|
int ret;
|
||||||
|
int curl_done = 0;
|
||||||
|
|
||||||
if (argc < -1)
|
if (argc < -1)
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
|
|
||||||
signal(SIGPIPE,SIG_IGN);
|
signal(SIGPIPE,SIG_IGN);
|
||||||
|
|
||||||
@@ -235,7 +247,6 @@ int main(int argc, char **argv)
|
|||||||
if (access("/var/cache/debuginfo/src/", F_OK))
|
if (access("/var/cache/debuginfo/src/", F_OK))
|
||||||
system("mkdir -p /var/cache/debuginfo/src/ &> /dev/null");
|
system("mkdir -p /var/cache/debuginfo/src/ &> /dev/null");
|
||||||
|
|
||||||
|
|
||||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sockfd < 0)
|
if (sockfd < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -260,8 +271,14 @@ int main(int argc, char **argv)
|
|||||||
int clientsock;
|
int clientsock;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
|
malloc_trim(0);
|
||||||
clientsock = accept(sockfd, NULL, NULL);
|
clientsock = accept(sockfd, NULL, NULL);
|
||||||
|
|
||||||
|
if (!curl_done) {
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
curl_done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_create(&thread, NULL, server_thread, (void *)(unsigned long)clientsock);
|
pthread_create(&thread, NULL, server_thread, (void *)(unsigned long)clientsock);
|
||||||
pthread_detach(thread);
|
pthread_detach(thread);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user