diff --git a/src/client.c b/src/client.c
index 31ddfb2..6182650 100644
--- a/src/client.c
+++ b/src/client.c
@@ -7,12 +7,12 @@
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 or later of the License.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
@@ -23,16 +23,16 @@
#define _GNU_SOURCE
+#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
+#include
+#include
+#include
#include
+#include
/* 0.75 seconds timeout */
#define TIMEOUT 750000
@@ -45,71 +45,72 @@ time_t deadtime;
void try_to_get(const char *path, int pid, time_t timestamp)
{
- int sockfd;
- struct sockaddr_un sun;
- int ret;
- socklen_t len;
- char *command;
- fd_set rfds;
- struct timeval tv;
- struct ucred cred;
- int shorttime = 0;
-
-// printf("Trying to aquire %s\n", path);
-
- sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sockfd < 0)
- return;
-
- sun.sun_family = AF_UNIX;
- strcpy(sun.sun_path, ":clr-debug-info");
- sun.sun_path[0] = 0; /* anonymous unix socket */
+ int sockfd;
+ struct sockaddr_un sun;
+ int ret;
+ socklen_t len;
+ char *command;
+ fd_set rfds;
+ struct timeval tv;
+ struct ucred cred;
+ int shorttime = 0;
- ret = connect(sockfd, (struct sockaddr *)&sun, offsetof(struct sockaddr_un, sun_path) + strlen(":clr-debug-info") + 1);
- if (ret < 0) {
- printf("Cannot connect %s\n", strerror(errno));
- close(sockfd);
- return;
- }
+ // printf("Trying to aquire %s\n", path);
- len = sizeof(cred);
- memset(&cred, 0, sizeof(cred));
- ret = getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &len);
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ return;
- if (ret == 0 && cred.pid == pid) {
- printf("Recursion\n");
- close(sockfd);
- }
+ sun.sun_family = AF_UNIX;
+ strcpy(sun.sun_path, ":clr-debug-info");
+ sun.sun_path[0] = 0; /* anonymous unix socket */
- command = NULL;
- if (asprintf(&command, "%llu:%s:%s", (unsigned long long)timestamp, prefix, path) < 0) {
- close(sockfd);
- return;
- }
- write(sockfd, command, strlen(command )+1);
+ ret = connect(sockfd,
+ (struct sockaddr *)&sun,
+ offsetof(struct sockaddr_un, sun_path) + strlen(":clr-debug-info") + 1);
+ if (ret < 0) {
+ printf("Cannot connect %s\n", strerror(errno));
+ close(sockfd);
+ return;
+ }
- FD_ZERO(&rfds);
- FD_SET(sockfd, &rfds);
+ len = sizeof(cred);
+ memset(&cred, 0, sizeof(cred));
+ ret = getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &len);
- /* Wait up to 0.5 seconds. */
- tv.tv_sec = 0;
- tv.tv_usec = TIMEOUT;
-
- /* if we had a timeout recently, must go quicker to avoid sequential delays */
- if (deadtime > time(NULL)) {
- tv.tv_usec = TIMEOUT2;
- shorttime = 1;
- }
+ if (ret == 0 && cred.pid == pid) {
+ printf("Recursion\n");
+ close(sockfd);
+ }
- ret = 1;
-
+ command = NULL;
+ if (asprintf(&command, "%llu:%s:%s", (unsigned long long)timestamp, prefix, path) < 0) {
+ close(sockfd);
+ return;
+ }
+ write(sockfd, command, strlen(command) + 1);
- if (!timestamp)
- ret = select(sockfd+1, &rfds, NULL, &rfds, &tv);
- if (ret == 0 && !shorttime) {
- printf("timeout for %s\n", path);
- deadtime = time(NULL) + 4;
- }
+ FD_ZERO(&rfds);
+ FD_SET(sockfd, &rfds);
- close(sockfd);
+ /* Wait up to 0.5 seconds. */
+ tv.tv_sec = 0;
+ tv.tv_usec = TIMEOUT;
+
+ /* if we had a timeout recently, must go quicker to avoid sequential delays */
+ if (deadtime > time(NULL)) {
+ tv.tv_usec = TIMEOUT2;
+ shorttime = 1;
+ }
+
+ ret = 1;
+
+ if (!timestamp)
+ ret = select(sockfd + 1, &rfds, NULL, &rfds, &tv);
+ if (ret == 0 && !shorttime) {
+ printf("timeout for %s\n", path);
+ deadtime = time(NULL) + 4;
+ }
+
+ close(sockfd);
}
diff --git a/src/fuse.c b/src/fuse.c
index 8f4805f..0e63025 100644
--- a/src/fuse.c
+++ b/src/fuse.c
@@ -3,8 +3,8 @@
This is a lightly modified version of the fuse example "fusexmp.c",
the original copyright notice is retained below.
-The modifications to the example are
- (C) 2013 Arjan van de Ven
+The modifications to the example are
+ (C) 2013 Arjan van de Ven
Original copyright notice follows:
@@ -31,575 +31,566 @@ Original copyright notice follows:
#define _XOPEN_SOURCE 700
#endif
-#include
+#include
+#include
+#include
#include
+#include
+#include
#include
#include
#include
-#include
-#include
#include
-#include
-#include
-#include
#include
+#include
#ifdef HAVE_SETXATTR
#include
#endif
-
extern void try_to_get(const char *path, int pid, time_t timestamp);
-
-
static int xmp_getattr(const char *path, struct stat *stbuf)
{
- int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- memset(stbuf, 0, sizeof(struct stat));
- res = lstat(newpath, stbuf);
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
-
- /*
- * get the file. if the st_mtime is set, this is just an async refresh, otherwise it's
- * a synchronous request.
- */
- try_to_get(path, fuse_get_context()->pid, stbuf->st_mtime);
+ memset(stbuf, 0, sizeof(struct stat));
+ res = lstat(newpath, stbuf);
- res = lstat(newpath, stbuf);
- free(newpath);
+ /*
+ * get the file. if the st_mtime is set, this is just an async refresh, otherwise it's
+ * a synchronous request.
+ */
+ try_to_get(path, fuse_get_context()->pid, stbuf->st_mtime);
- if (res == -1)
- return -errno;
+ res = lstat(newpath, stbuf);
+ free(newpath);
- return 0;
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_access(const char *path, int mask)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- res = access(newpath, mask);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = access(newpath, mask);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_readlink(const char *path, char *buf, size_t size)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- res = readlink(newpath, buf, size - 1);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- buf[res] = '\0';
- return 0;
+ res = readlink(newpath, buf, size - 1);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ buf[res] = '\0';
+ return 0;
}
-
-static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
- off_t offset, struct fuse_file_info *fi)
+static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset,
+ struct fuse_file_info *fi)
{
- DIR *dp;
- struct dirent *de;
- char *newpath;
-
- (void) offset;
- (void) fi;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
-
- dp = opendir(newpath);
- if (dp == NULL) {
- free(newpath);
- return -errno;
- }
+ DIR *dp;
+ struct dirent *de;
+ char *newpath;
- while ((de = readdir(dp)) != NULL) {
- struct stat st;
- memset(&st, 0, sizeof(st));
- st.st_ino = de->d_ino;
- st.st_mode = de->d_type << 12;
- if (filler(buf, de->d_name, &st, 0))
- break;
- }
+ (void)offset;
+ (void)fi;
- closedir(dp);
- free(newpath);
- return 0;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
+
+ dp = opendir(newpath);
+ if (dp == NULL) {
+ free(newpath);
+ return -errno;
+ }
+
+ while ((de = readdir(dp)) != NULL) {
+ struct stat st;
+ memset(&st, 0, sizeof(st));
+ st.st_ino = de->d_ino;
+ st.st_mode = de->d_type << 12;
+ if (filler(buf, de->d_name, &st, 0))
+ break;
+ }
+
+ closedir(dp);
+ free(newpath);
+ return 0;
}
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- /* On Linux this could just be 'mknod(path, mode, rdev)' but this
- is more portable */
- if (S_ISREG(mode)) {
- res = open(newpath, O_CREAT | O_EXCL | O_WRONLY, mode);
- if (res >= 0)
- res = close(res);
- } else if (S_ISFIFO(mode))
- res = mkfifo(newpath, mode);
- else
- res = mknod(newpath, mode, rdev);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ /* On Linux this could just be 'mknod(path, mode, rdev)' but this
+ is more portable */
+ if (S_ISREG(mode)) {
+ res = open(newpath, O_CREAT | O_EXCL | O_WRONLY, mode);
+ if (res >= 0)
+ res = close(res);
+ } else if (S_ISFIFO(mode))
+ res = mkfifo(newpath, mode);
+ else
+ res = mknod(newpath, mode, rdev);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_mkdir(const char *path, mode_t mode)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- res = mkdir(newpath, mode);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = mkdir(newpath, mode);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_unlink(const char *path)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- res = unlink(newpath);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = unlink(newpath);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_rmdir(const char *path)
{
- int res;
+ int res;
- char *newpath = NULL;
-
- newpath = NULL;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- res = rmdir(newpath);
- free(newpath);
- if (res == -1)
- return -errno;
+ newpath = NULL;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = rmdir(newpath);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_symlink(const char *from, const char *to)
{
- int res;
+ int res;
- char *newfrom = NULL, *newto = NULL;
-
- if (asprintf(&newfrom, ".%s", from) < 0)
- return -ENOMEM;
- if (asprintf(&newto, ".%s", to) < 0) {
- free(newfrom);
- return -ENOMEM;
- }
+ char *newfrom = NULL, *newto = NULL;
- res = symlink(newfrom, newto);
- free(newfrom);
- free(newto);
- if (res == -1)
- return -errno;
+ if (asprintf(&newfrom, ".%s", from) < 0)
+ return -ENOMEM;
+ if (asprintf(&newto, ".%s", to) < 0) {
+ free(newfrom);
+ return -ENOMEM;
+ }
- return 0;
+ res = symlink(newfrom, newto);
+ free(newfrom);
+ free(newto);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_rename(const char *from, const char *to)
{
- int res;
+ int res;
- char *newfrom = NULL, *newto = NULL;
-
- if (asprintf(&newfrom, ".%s", from) < 0)
- return -ENOMEM;
- if (asprintf(&newto, ".%s", to) < 0) {
- free(newfrom);
- return -ENOMEM;
- }
+ char *newfrom = NULL, *newto = NULL;
- res = rename(newfrom, newto);
- free(newfrom);
- free(newto);
- if (res == -1)
- return -errno;
+ if (asprintf(&newfrom, ".%s", from) < 0)
+ return -ENOMEM;
+ if (asprintf(&newto, ".%s", to) < 0) {
+ free(newfrom);
+ return -ENOMEM;
+ }
- return 0;
+ res = rename(newfrom, newto);
+ free(newfrom);
+ free(newto);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_link(const char *from, const char *to)
{
- int res;
+ int res;
- char *newfrom = NULL, *newto = NULL;
-
- if (asprintf(&newfrom, ".%s", from) < 0)
- return -ENOMEM;
- if (asprintf(&newto, ".%s", to) < 0) {
- free(newfrom);
- return -ENOMEM;
- }
+ char *newfrom = NULL, *newto = NULL;
- res = link(newfrom, newto);
- free(newfrom);
- free(newto);
-
- if (res == -1)
- return -errno;
+ if (asprintf(&newfrom, ".%s", from) < 0)
+ return -ENOMEM;
+ if (asprintf(&newto, ".%s", to) < 0) {
+ free(newfrom);
+ return -ENOMEM;
+ }
- return 0;
+ res = link(newfrom, newto);
+ free(newfrom);
+ free(newto);
+
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_chmod(const char *path, mode_t mode)
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- res = chmod(newpath, mode);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = chmod(newpath, mode);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- res = lchown(newpath, uid, gid);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = lchown(newpath, uid, gid);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_truncate(const char *path, off_t size)
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- res = truncate(newpath, size);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = truncate(newpath, size);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
#ifdef HAVE_UTIMENSAT
static int xmp_utimens(const char *path, const struct timespec ts[2])
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- /* don't use utime/utimes since they follow symlinks */
- res = utimensat(0, newpath, ts, AT_SYMLINK_NOFOLLOW);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ /* don't use utime/utimes since they follow symlinks */
+ res = utimensat(0, newpath, ts, AT_SYMLINK_NOFOLLOW);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
#endif
static int xmp_open(const char *path, struct fuse_file_info *fi)
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- res = open(newpath, fi->flags);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- close(res);
- return 0;
+ res = open(newpath, fi->flags);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ close(res);
+ return 0;
}
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
- struct fuse_file_info *fi)
+ struct fuse_file_info *fi)
{
- int fd;
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int fd;
+ int res;
+ char *newpath = NULL;
- (void) fi;
- fd = open(newpath, O_RDONLY);
- free(newpath);
- if (fd == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- res = pread(fd, buf, size, offset);
- if (res == -1)
- res = -errno;
+ (void)fi;
+ fd = open(newpath, O_RDONLY);
+ free(newpath);
+ if (fd == -1)
+ return -errno;
- close(fd);
- return res;
+ res = pread(fd, buf, size, offset);
+ if (res == -1)
+ res = -errno;
+
+ close(fd);
+ return res;
}
-static int xmp_write(const char *path, const char *buf, size_t size,
- off_t offset, struct fuse_file_info *fi)
+static int xmp_write(const char *path, const char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi)
{
- int fd;
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int fd;
+ int res;
+ char *newpath = NULL;
- (void) fi;
- fd = open(newpath, O_WRONLY);
- free(newpath);
- if (fd == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- res = pwrite(fd, buf, size, offset);
- if (res == -1)
- res = -errno;
+ (void)fi;
+ fd = open(newpath, O_WRONLY);
+ free(newpath);
+ if (fd == -1)
+ return -errno;
- close(fd);
- return res;
+ res = pwrite(fd, buf, size, offset);
+ if (res == -1)
+ res = -errno;
+
+ close(fd);
+ return res;
}
static int xmp_statfs(const char *path, struct statvfs *stbuf)
{
- int res;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ int res;
+ char *newpath = NULL;
- res = statvfs(newpath, stbuf);
- free(newpath);
- if (res == -1)
- return -errno;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- return 0;
+ res = statvfs(newpath, stbuf);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_release(const char *path, struct fuse_file_info *fi)
{
- /* Just a stub. This method is optional and can safely be left
- unimplemented */
+ /* Just a stub. This method is optional and can safely be left
+ unimplemented */
- (void) path;
- (void) fi;
- return 0;
+ (void)path;
+ (void)fi;
+ return 0;
}
-static int xmp_fsync(const char *path, int isdatasync,
- struct fuse_file_info *fi)
+static int xmp_fsync(const char *path, int isdatasync, struct fuse_file_info *fi)
{
- /* Just a stub. This method is optional and can safely be left
- unimplemented */
+ /* Just a stub. This method is optional and can safely be left
+ unimplemented */
- (void) path;
- (void) isdatasync;
- (void) fi;
- return 0;
+ (void)path;
+ (void)isdatasync;
+ (void)fi;
+ return 0;
}
#ifdef HAVE_POSIX_FALLOCATE
-static int xmp_fallocate(const char *path, int mode,
- off_t offset, off_t length, struct fuse_file_info *fi)
+static int xmp_fallocate(const char *path, int mode, off_t offset, off_t length,
+ struct fuse_file_info *fi)
{
- int fd;
- int res;
- char *newpath = NULL;
-
+ int fd;
+ int res;
+ char *newpath = NULL;
- (void) fi;
+ (void)fi;
- if (mode)
- return -EOPNOTSUPP;
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ if (mode)
+ return -EOPNOTSUPP;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
- fd = open(newpath, O_WRONLY);
- free(newpath);
- if (fd == -1)
- return -errno;
+ fd = open(newpath, O_WRONLY);
+ free(newpath);
+ if (fd == -1)
+ return -errno;
- res = -posix_fallocate(fd, offset, length);
+ res = -posix_fallocate(fd, offset, length);
- close(fd);
- return res;
+ close(fd);
+ return res;
}
#endif
#ifdef HAVE_SETXATTR
/* xattr operations are optional and can safely be left unimplemented */
-static int xmp_setxattr(const char *path, const char *name, const char *value,
- size_t size, int flags)
+static int xmp_setxattr(const char *path, const char *name, const char *value, size_t size,
+ int flags)
{
+ char *newpath = NULL;
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
- int res = lsetxattr(newpath, name, value, size, flags);
- free(newpath);
- if (res == -1)
- return -errno;
- return 0;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
+ int res = lsetxattr(newpath, name, value, size, flags);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+ return 0;
}
-static int xmp_getxattr(const char *path, const char *name, char *value,
- size_t size)
+static int xmp_getxattr(const char *path, const char *name, char *value, size_t size)
{
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
- int res = lgetxattr(newpath, name, value, size);
- free(newpath);
- if (res == -1)
- return -errno;
- return res;
+ char *newpath = NULL;
+
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
+ int res = lgetxattr(newpath, name, value, size);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+ return res;
}
static int xmp_listxattr(const char *path, char *list, size_t size)
{
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
+ char *newpath = NULL;
- int res = llistxattr(newpath, list, size);
- free(newpath);
- if (res == -1)
- return -errno;
- return res;
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
+
+ int res = llistxattr(newpath, list, size);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+ return res;
}
static int xmp_removexattr(const char *path, const char *name)
{
- char *newpath = NULL;
-
- if (asprintf(&newpath, ".%s", path) < 0)
- return -ENOMEM;
- int res = lremovexattr(newpath, name);
- free(newpath);
- if (res == -1)
- return -errno;
- return 0;
+ char *newpath = NULL;
+
+ if (asprintf(&newpath, ".%s", path) < 0)
+ return -ENOMEM;
+ int res = lremovexattr(newpath, name);
+ free(newpath);
+ if (res == -1)
+ return -errno;
+ return 0;
}
#endif /* HAVE_SETXATTR */
int save_dir;
-static void* xmp_init(struct fuse_conn_info *conn)
+static void *xmp_init(struct fuse_conn_info *conn)
{
- fchdir(save_dir);
- close(save_dir);
-
- return NULL;
+ fchdir(save_dir);
+ close(save_dir);
+
+ return NULL;
}
static struct fuse_operations xmp_oper = {
- .init = xmp_init,
- .getattr = xmp_getattr,
- .access = xmp_access,
- .readlink = xmp_readlink,
- .readdir = xmp_readdir,
- .mknod = xmp_mknod,
- .mkdir = xmp_mkdir,
- .symlink = xmp_symlink,
- .unlink = xmp_unlink,
- .rmdir = xmp_rmdir,
- .rename = xmp_rename,
- .link = xmp_link,
- .chmod = xmp_chmod,
- .chown = xmp_chown,
- .truncate = xmp_truncate,
+ .init = xmp_init,
+ .getattr = xmp_getattr,
+ .access = xmp_access,
+ .readlink = xmp_readlink,
+ .readdir = xmp_readdir,
+ .mknod = xmp_mknod,
+ .mkdir = xmp_mkdir,
+ .symlink = xmp_symlink,
+ .unlink = xmp_unlink,
+ .rmdir = xmp_rmdir,
+ .rename = xmp_rename,
+ .link = xmp_link,
+ .chmod = xmp_chmod,
+ .chown = xmp_chown,
+ .truncate = xmp_truncate,
#ifdef HAVE_UTIMENSAT
- .utimens = xmp_utimens,
+ .utimens = xmp_utimens,
#endif
- .open = xmp_open,
- .read = xmp_read,
- .write = xmp_write,
- .statfs = xmp_statfs,
- .release = xmp_release,
- .fsync = xmp_fsync,
+ .open = xmp_open,
+ .read = xmp_read,
+ .write = xmp_write,
+ .statfs = xmp_statfs,
+ .release = xmp_release,
+ .fsync = xmp_fsync,
#ifdef HAVE_POSIX_FALLOCATE
- .fallocate = xmp_fallocate,
+ .fallocate = xmp_fallocate,
#endif
#ifdef HAVE_SETXATTR
- .setxattr = xmp_setxattr,
- .getxattr = xmp_getxattr,
- .listxattr = xmp_listxattr,
- .removexattr = xmp_removexattr,
+ .setxattr = xmp_setxattr,
+ .getxattr = xmp_getxattr,
+ .listxattr = xmp_listxattr,
+ .removexattr = xmp_removexattr,
#endif
};
@@ -607,41 +598,40 @@ extern char *prefix;
int main(int argc, char *argv[])
{
- char * fake_argv[20];
- char *dir = "/usr/src/debug";
- char *shadowdir = "/var/cache/debuginfo/src";
- umask(0);
-
- /* give the system some time to boot before we go active; this is a background task */
- sleep(1);
+ char *fake_argv[20];
+ char *dir = "/usr/src/debug";
+ char *shadowdir = "/var/cache/debuginfo/src";
+ umask(0);
- if (access("/sys/module/fuse/", F_OK))
- system("modprobe fuse");
- signal(SIGPIPE,SIG_IGN);
-
- if (access("/var/cache/debuginfo/lib/", F_OK))
- system("mkdir -p /var/cache/debuginfo/lib &> /dev/null");
- if (access("/var/cache/debuginfo/src/", F_OK))
- system("mkdir -p /var/cache/debuginfo/src &> /dev/null");
+ /* give the system some time to boot before we go active; this is a background task */
+ sleep(1);
- if (fork() == 0) {
- dir = "/usr/lib/debug";
- shadowdir = "/var/cache/debuginfo/lib";
- prefix = "lib";
+ if (access("/sys/module/fuse/", F_OK))
+ system("modprobe fuse");
+ signal(SIGPIPE, SIG_IGN);
- }
+ if (access("/var/cache/debuginfo/lib/", F_OK))
+ system("mkdir -p /var/cache/debuginfo/lib &> /dev/null");
+ if (access("/var/cache/debuginfo/src/", F_OK))
+ system("mkdir -p /var/cache/debuginfo/src &> /dev/null");
- save_dir = open(shadowdir, O_RDONLY);
+ if (fork() == 0) {
+ dir = "/usr/lib/debug";
+ shadowdir = "/var/cache/debuginfo/lib";
+ prefix = "lib";
+ }
- fake_argv[0] = "clr_debug_fuse";
- fake_argv[1] = "-f";
- fake_argv[2] = "-o";
- fake_argv[3] = "nonempty";
- fake_argv[4] = "-o";
- fake_argv[5] = "allow_other";
- fake_argv[6] = "-o";
- fake_argv[7] = "default_permissions";
- fake_argv[8] = dir;
-
- return fuse_main(9, fake_argv, &xmp_oper, NULL);
+ save_dir = open(shadowdir, O_RDONLY);
+
+ fake_argv[0] = "clr_debug_fuse";
+ fake_argv[1] = "-f";
+ fake_argv[2] = "-o";
+ fake_argv[3] = "nonempty";
+ fake_argv[4] = "-o";
+ fake_argv[5] = "allow_other";
+ fake_argv[6] = "-o";
+ fake_argv[7] = "default_permissions";
+ fake_argv[8] = dir;
+
+ return fuse_main(9, fake_argv, &xmp_oper, NULL);
}
diff --git a/src/prepare.c b/src/prepare.c
index bff31f6..fc31eba 100644
--- a/src/prepare.c
+++ b/src/prepare.c
@@ -9,12 +9,12 @@
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 or later of the License.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
@@ -24,194 +24,205 @@
*/
#define _GNU_SOURCE
+#include
+#include
+#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
-#include
-#include
+#include
#include
-#include
+#include
+#include
+#include
+#include
#include
-/*
+/*
this program takes a directory /var/www/html/debuginfo.raw,
in which all debuginfo rpms have previously been rpm2cpio'd, and
creates the content for /var/www/html/debuginfo
which contains tar'd up/compressed versions of all the files.
-As part of this symlinks will be resolved server side
+As part of this symlinks will be resolved server side
as much as possible.
*/
static void unsymlink(char *filename)
{
- char *target;
+ char *target;
- target = canonicalize_file_name(filename);
-// sleep(1);
-// printf("Symlink %s points to %s\n", filename, target);
- unlink(filename);
- link(target, filename);
+ target = canonicalize_file_name(filename);
+ // sleep(1);
+ // printf("Symlink %s points to %s\n", filename, target);
+ unlink(filename);
+ link(target, filename);
}
-
static void wait_for_loadavg(void)
{
- FILE *file;
- char line[4096];
- while (1) {
- double d;
- file = fopen("/proc/loadavg", "r");
- if (!file)
- return;
- line[0] = 0;
- fgets(line, 4096, file);
- fclose(file);
- d = strtod(line, NULL);
- if (d < 50)
- return;
- sleep(5);
-
- }
+ FILE *file;
+ char line[4096];
+ while (1) {
+ double d;
+ file = fopen("/proc/loadavg", "r");
+ if (!file)
+ return;
+ line[0] = 0;
+ fgets(line, 4096, file);
+ fclose(file);
+ d = strtod(line, NULL);
+ if (d < 50)
+ return;
+ sleep(5);
+ }
}
int tarcount;
static void do_one_file(char *base1, char *base2, char *path, int isdir)
{
- char *fullpath1 = NULL, *fullpath2 = NULL, *dir, *dir2;
- struct stat buf1, buf2;
- int ret;
+ char *fullpath1 = NULL, *fullpath2 = NULL, *dir, *dir2;
+ struct stat buf1, buf2;
+ int ret;
- if (asprintf(&fullpath1, "%s%s", base1, path) < 0)
- return;
- if (asprintf(&fullpath2, "%s%s.tar", base2, path) < 0) {
- free(fullpath1);
- return;
- }
+ if (asprintf(&fullpath1, "%s%s", base1, path) < 0)
+ return;
+ if (asprintf(&fullpath2, "%s%s.tar", base2, path) < 0) {
+ free(fullpath1);
+ return;
+ }
- ret = lstat(fullpath1, &buf1);
- if (ret)
- goto out;
+ ret = lstat(fullpath1, &buf1);
+ if (ret)
+ goto out;
- if (S_ISLNK(buf1.st_mode)) {
-// printf("%s is a symlink\n", fullpath1);
- ret = stat(fullpath1, &buf2);
- if (!ret)
- unsymlink(fullpath1);
- ret = lstat(fullpath1, &buf1);
- }
+ if (S_ISLNK(buf1.st_mode)) {
+ // printf("%s is a symlink\n", fullpath1);
+ ret = stat(fullpath1, &buf2);
+ if (!ret)
+ unsymlink(fullpath1);
+ ret = lstat(fullpath1, &buf1);
+ }
- ret = lstat(fullpath2, &buf2);
- if (ret || buf1.st_mtime > buf2.st_mtime) {
- char *command = NULL;
- unlink(fullpath2);
+ ret = lstat(fullpath2, &buf2);
+ if (ret || buf1.st_mtime > buf2.st_mtime) {
+ char *command = NULL;
+ unlink(fullpath2);
- dir = strdup(fullpath2);
+ dir = strdup(fullpath2);
- dir2 = dirname(dir);
+ dir2 = dirname(dir);
- if (asprintf(&command, "mkdir -p %s", dir2) >= 0) {
-// printf("Running -%s-\n", command);
- system(command);
- free(command);
- }
+ if (asprintf(&command, "mkdir -p %s", dir2) >= 0) {
+ // printf("Running -%s-\n", command);
+ system(command);
+ free(command);
+ }
- free(dir);
- chdir(base1);
- if (!isdir && asprintf(&command, "tar --no-recursion -C %s -Jcf %s %s &", base1, fullpath2, path) >= 0) {
-// printf("Running -%s-\n", command);
- printf("Processing %s\n", fullpath2);
- tarcount++;
- if (tarcount > 50) {
- wait_for_loadavg();
- tarcount = 0;
- }
- system(command);
- free(command);
- }
+ free(dir);
+ chdir(base1);
+ if (!isdir &&
+ asprintf(&command,
+ "tar --no-recursion -C %s -Jcf %s %s &",
+ base1,
+ fullpath2,
+ path) >= 0) {
+ // printf("Running -%s-\n", command);
+ printf("Processing %s\n", fullpath2);
+ tarcount++;
+ if (tarcount > 50) {
+ wait_for_loadavg();
+ tarcount = 0;
+ }
+ system(command);
+ free(command);
+ }
- if (isdir && asprintf(&command, "tar --no-recursion -C %s -Jcf %s `find %s -type d` `find %s -maxdepth 1 -type l` &", base1, fullpath2, path, path) >= 0) {
-// printf("Running -%s-\n", command);
- printf("Processing %s\n", fullpath2);
- tarcount++;
- if (tarcount > 50) {
- wait_for_loadavg();
- tarcount = 0;
- }
- system(command);
- free(command);
- }
-
- }
+ if (isdir &&
+ asprintf(&command,
+ "tar --no-recursion -C %s -Jcf %s `find %s -type d` `find %s "
+ "-maxdepth 1 -type l` &",
+ base1,
+ fullpath2,
+ path,
+ path) >= 0) {
+ // printf("Running -%s-\n", command);
+ printf("Processing %s\n", fullpath2);
+ tarcount++;
+ if (tarcount > 50) {
+ wait_for_loadavg();
+ tarcount = 0;
+ }
+ system(command);
+ free(command);
+ }
+ }
out:
- free(fullpath1);
- free(fullpath2);
+ free(fullpath1);
+ free(fullpath2);
}
-
static void recurse_dir(char *base1, char *base2, char *path)
{
- DIR *dir;
- char *fullpath1, *fullpath2, *newpath;
- struct dirent *entry;
+ DIR *dir;
+ char *fullpath1, *fullpath2, *newpath;
+ struct dirent *entry;
- fullpath1 = NULL;
- fullpath2 = NULL;
+ fullpath1 = NULL;
+ fullpath2 = NULL;
+ if (asprintf(&fullpath1, "%s%s", base1, path) < 0)
+ return;
- if (asprintf(&fullpath1, "%s%s", base1, path) < 0)
- return;
+ dir = opendir(fullpath1);
- dir = opendir(fullpath1);
+ if (!dir) {
+ free(fullpath1);
+ return;
+ }
+ while (1) {
+ entry = readdir(dir);
+ if (!entry)
+ break;
+ if (strcmp(entry->d_name, ".") == 0)
+ continue;
+ if (strcmp(entry->d_name, "..") == 0)
+ continue;
- if (!dir) {
- free(fullpath1);
- return;
- }
- while (1) {
- entry = readdir(dir);
- if (!entry)
- break;
- if (strcmp(entry->d_name, ".") == 0)
- continue;
- if (strcmp(entry->d_name, "..") == 0)
- continue;
-
- newpath = NULL;
- fullpath2 = NULL;
- asprintf(&fullpath2, "%s/%s", fullpath1, entry->d_name);
- if (asprintf(&newpath, "%s/%s", path, entry->d_name) >= 0) {
- struct stat sb;
- stat(fullpath2, &sb);
-
- if (entry->d_type == DT_DIR || S_ISDIR(sb.st_mode)) {
- do_one_file(base1, base2, newpath, 1);
- recurse_dir(base1, base2, newpath);
- } else {
- do_one_file(base1, base2, newpath, 0);
- }
- free(newpath);
- }
- }
- closedir(dir);
- free(fullpath1);
+ newpath = NULL;
+ fullpath2 = NULL;
+ asprintf(&fullpath2, "%s/%s", fullpath1, entry->d_name);
+ if (asprintf(&newpath, "%s/%s", path, entry->d_name) >= 0) {
+ struct stat sb;
+ stat(fullpath2, &sb);
+
+ if (entry->d_type == DT_DIR || S_ISDIR(sb.st_mode)) {
+ do_one_file(base1, base2, newpath, 1);
+ recurse_dir(base1, base2, newpath);
+ } else {
+ do_one_file(base1, base2, newpath, 0);
+ }
+ free(newpath);
+ }
+ }
+ closedir(dir);
+ free(fullpath1);
}
int main(int argc, char **argv)
{
- if (argc < 0)
- (void)argv;
- recurse_dir("/var/www/html/debuginfo.raw/usr/lib/debug/", "/var/www/html/debuginfo/lib/", ".");
- recurse_dir("/var/www/html/debuginfo.raw/usr/src/debug/", "/var/www/html/debuginfo/src/", ".");
+ if (argc < 0)
+ (void)argv;
+ recurse_dir("/var/www/html/debuginfo.raw/usr/lib/debug/",
+ "/var/www/html/debuginfo/lib/",
+ ".");
+ recurse_dir("/var/www/html/debuginfo.raw/usr/src/debug/",
+ "/var/www/html/debuginfo/src/",
+ ".");
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/src/server.c b/src/server.c
index be1e052..8bb9dce 100644
--- a/src/server.c
+++ b/src/server.c
@@ -9,12 +9,12 @@
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 or later of the License.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
@@ -24,288 +24,288 @@
*/
#define _GNU_SOURCE
-
+
+#include
+#include
+#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
#include
-#include
+#include
#include
-#include
+#include
+#include
+#include
#include
#include
static GMutex dupes_mutex;
-char *urls[2] = {"https://debuginfo.clearlinux.org/debuginfo/", "https://debuginfo.clearlinux.org/debuginfo/" };
+char *urls[2] = { "https://debuginfo.clearlinux.org/debuginfo/",
+ "https://debuginfo.clearlinux.org/debuginfo/" };
int urlcounter = 1;
-
static GHashTable *hash;
static int avoid_dupes(const char *url)
{
- int retval = 0;
- void *value;
- g_mutex_lock(&dupes_mutex);
+ int retval = 0;
+ void *value;
+ g_mutex_lock(&dupes_mutex);
- if (hash == NULL)
- hash = g_hash_table_new(g_str_hash, g_str_equal);
+ if (hash == NULL)
+ hash = g_hash_table_new(g_str_hash, g_str_equal);
- if (g_hash_table_lookup_extended(hash, url, NULL, &value)) {
- unsigned long tm;
- tm = (unsigned long)value;
- if (time(NULL) - tm < 600) {
- retval = 1;
- }
- } else {
- unsigned long tm;
- tm = time(NULL);
- void *data = (void *)(unsigned long)tm;
- g_hash_table_replace(hash, strdup(url), data);
- }
+ if (g_hash_table_lookup_extended(hash, url, NULL, &value)) {
+ unsigned long tm;
+ tm = (unsigned long)value;
+ if (time(NULL) - tm < 600) {
+ retval = 1;
+ }
+ } else {
+ unsigned long tm;
+ tm = time(NULL);
+ void *data = (void *)(unsigned long)tm;
+ g_hash_table_replace(hash, strdup(url), data);
+ }
- g_mutex_unlock(&dupes_mutex);
- return retval;
+ g_mutex_unlock(&dupes_mutex);
+ return retval;
}
static int curl_get_file(const char *url, const char *prefix, time_t timestamp)
{
- CURLcode code;
+ CURLcode code;
long ret;
- int fd;
- char filename[PATH_MAX];
- CURL *curl = NULL;
- FILE *file;
- struct stat statbuf;
+ int fd;
+ char filename[PATH_MAX];
+ CURL *curl = NULL;
+ FILE *file;
+ struct stat statbuf;
- if (avoid_dupes(url))
- return 300;
+ if (avoid_dupes(url))
+ return 300;
+ curl = curl_easy_init();
+ if (curl == NULL)
+ return 301;
- curl = curl_easy_init();
- if (curl == NULL)
- return 301;
+ strcpy(filename, "/tmp/clr-debug-info-XXXXXX");
+ fd = mkstemp(filename);
+ if (fd < 0) {
+ curl_easy_cleanup(curl);
+ return 500;
+ }
- strcpy(filename, "/tmp/clr-debug-info-XXXXXX");
-
- fd = mkstemp(filename);
- if (fd < 0) {
- curl_easy_cleanup(curl);
- return 500;
- }
+ file = fdopen(fd, "w");
- file = fdopen(fd, "w");
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
+ if (timestamp) {
+ curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+ curl_easy_setopt(curl, CURLOPT_TIMEVALUE, timestamp);
+ }
- if (timestamp) {
- curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- curl_easy_setopt(curl, CURLOPT_TIMEVALUE, timestamp);
- }
+ code = curl_easy_perform(curl);
- code = curl_easy_perform(curl);
+ /* can't trust the file if we get an error back */
+ if (code != 0)
+ unlink(filename);
- /* can't trust the file if we get an error back */
- if (code != 0)
- unlink(filename);
-
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret);
- fflush(file);
-// printf("HTTP return code is %i\n", ret);
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ret);
+ fflush(file);
+ // 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
- * already added the URL to the hash table. So, the first crash for a
- * boot may result in a 304 if the debuginfo had been downloaded in a
- * previous boot.
- */
- if (ret != 200 && ret != 404 && ret != 304)
- urlcounter++;
+ /* 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
+ * already added the URL to the hash table. So, the first crash for a
+ * boot may result in a 304 if the debuginfo had been downloaded in a
+ * previous boot.
+ */
+ if (ret != 200 && ret != 404 && ret != 304)
+ urlcounter++;
- if (ret == 200) {
- char *command = NULL;
-// printf("Filename is %s\n", filename);
+ if (ret == 200) {
+ 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 -xf %s", prefix, filename) >= 0) {
- system(command);
- free(command);
- }
- }
- unlink(filename);
- curl_easy_cleanup(curl);
- fclose(file);
- return ret;
+ memset(&statbuf, 0, sizeof(statbuf));
+ stat(filename, &statbuf);
+ if (statbuf.st_size > 0 &&
+ asprintf(&command,
+ "tar -C /var/cache/debuginfo/%s --no-same-owner -xf %s",
+ prefix,
+ filename) >= 0) {
+ system(command);
+ free(command);
+ }
+ }
+ unlink(filename);
+ curl_easy_cleanup(curl);
+ fclose(file);
+ return ret;
}
double timedelta(struct timeval before, struct timeval after)
{
- double d;
- d = 1.0 * (after.tv_sec - before.tv_sec) + (1.0 * after.tv_usec - before.tv_usec)/1000000.0;
- return d;
+ double d;
+ d = 1.0 * (after.tv_sec - before.tv_sec) +
+ (1.0 * after.tv_usec - before.tv_usec) / 1000000.0;
+ return d;
}
-
-
static void *server_thread(void *arg)
{
- int fd;
- char buf[PATH_MAX+8];
- int ret;
- char *prefix, *path, *url, *c;
- time_t timestamp;
- struct timeval before, after;
+ int fd;
+ char buf[PATH_MAX + 8];
+ int ret;
+ char *prefix, *path, *url, *c;
+ time_t timestamp;
+ struct timeval before, after;
- fd = (unsigned long)arg;
- if (fd < 0)
- return NULL;
-
- gettimeofday(&before, NULL);
+ fd = (unsigned long)arg;
+ if (fd < 0)
+ return NULL;
+ gettimeofday(&before, NULL);
- memset(buf, 0, sizeof(buf));
- ret = read(fd, buf, PATH_MAX+8);
- if (ret < 0) {
- close(fd);
- return NULL;
- }
- prefix = buf;
- c = strchr(buf, ':');
- if (!c) {
- close(fd);
- return NULL;
- }
- *c = 0;
- timestamp = strtoull(buf, NULL, 10);
- c++;
- prefix = c;
- path = strchr(c, ':');
- if (!path) {
- close(fd);
- return NULL;
- }
- *path = 0;
- path++;
+ memset(buf, 0, sizeof(buf));
+ ret = read(fd, buf, PATH_MAX + 8);
+ if (ret < 0) {
+ close(fd);
+ return NULL;
+ }
+ prefix = buf;
+ c = strchr(buf, ':');
+ if (!c) {
+ close(fd);
+ return NULL;
+ }
+ *c = 0;
+ timestamp = strtoull(buf, NULL, 10);
+ c++;
+ prefix = c;
+ path = strchr(c, ':');
+ if (!path) {
+ close(fd);
+ return NULL;
+ }
+ *path = 0;
+ path++;
- /* GDB and elfutils both stat /usr/lib/debug directly when looking up
- * debuginfo, so avoid the download for "/.tar"; the associated cache
- * directories already exist by this point.
- */
- if (strlen(path) == 1 && strcmp(path, "/") == 0) {
- close(fd);
- return NULL;
- }
+ /* GDB and elfutils both stat /usr/lib/debug directly when looking up
+ * debuginfo, so avoid the download for "/.tar"; the associated cache
+ * directories already exist by this point.
+ */
+ if (strlen(path) == 1 && strcmp(path, "/") == 0) {
+ close(fd);
+ return NULL;
+ }
- if (strstr(path, "..") || strstr(prefix, "..") || strstr(path, "'") || strstr(path, ";")) {
- close(fd);
- return NULL;
- }
+ if (strstr(path, "..") || strstr(prefix, "..") || strstr(path, "'") || strstr(path, ";")) {
+ close(fd);
+ return NULL;
+ }
- if (strcmp(prefix, "lib") !=0 && strcmp(prefix, "src") != 0) {
- /* invalid prefix */
- close(fd);
- return NULL;
- }
- url = NULL;
- if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
- close(fd);
- return NULL;
- }
+ if (strcmp(prefix, "lib") != 0 && strcmp(prefix, "src") != 0) {
+ /* invalid prefix */
+ close(fd);
+ return NULL;
+ }
+ url = NULL;
+ if (asprintf(&url, "%s%s%s.tar", urls[urlcounter % 2], prefix, path) < 0) {
+ close(fd);
+ return NULL;
+ }
-// printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
- ret = curl_get_file(url, prefix, timestamp);
+ // printf("Getting url %s %i:%06i\n", url, before.tv_sec, before.tv_usec);
+ ret = curl_get_file(url, prefix, timestamp);
- switch (ret) {
- case 200:
- case 300:
- case 304:
- case 404:
- // ignore these error codes
- break;
- default:
- printf("Request for %s resulted in error %i\n", url, ret);
- break;
- }
+ switch (ret) {
+ case 200:
+ case 300:
+ case 304:
+ case 404:
+ // ignore these error codes
+ break;
+ default:
+ printf("Request for %s resulted in error %i\n", url, ret);
+ break;
+ }
- gettimeofday(&after, NULL);
- if (timedelta(before, after) > 0.6)
- 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);
+ gettimeofday(&after, NULL);
+ if (timedelta(before, after) > 0.6)
+ 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);
- /* tell the other side we're done with the download */
- write(fd, "ok", 3);
- close(fd);
+ /* tell the other side we're done with the download */
+ write(fd, "ok", 3);
+ close(fd);
-
- free(url);
- return NULL;
+ free(url);
+ return NULL;
}
-
int main(int argc, char **argv)
{
- int sockfd;
- struct sockaddr_un sun;
- int ret;
- int curl_done = 0;
+ int sockfd;
+ struct sockaddr_un sun;
+ int ret;
+ int curl_done = 0;
- if (argc < -1)
- (void)argv;
+ if (argc < -1)
+ (void)argv;
+ signal(SIGPIPE, SIG_IGN);
- signal(SIGPIPE,SIG_IGN);
+ if (access("/var/cache/debuginfo/lib/", F_OK))
+ system("mkdir -p /var/cache/debuginfo/lib/ &> /dev/null");
+ if (access("/var/cache/debuginfo/src/", F_OK))
+ system("mkdir -p /var/cache/debuginfo/src/ &> /dev/null");
- if (access("/var/cache/debuginfo/lib/", F_OK))
- system("mkdir -p /var/cache/debuginfo/lib/ &> /dev/null");
- if (access("/var/cache/debuginfo/src/", F_OK))
- system("mkdir -p /var/cache/debuginfo/src/ &> /dev/null");
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ return EXIT_FAILURE;
- sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sockfd < 0)
- return 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, ":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;
+ }
- 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;
- }
+ if (listen(sockfd, 16) < 0) {
+ printf("Failed to listen:%s \n", strerror(errno));
+ return EXIT_FAILURE;
+ }
- if (listen(sockfd, 16) < 0) {
- printf("Failed to listen:%s \n", strerror(errno));
- return EXIT_FAILURE;
- }
+ while (1) {
+ int clientsock;
+ pthread_t thread;
+ malloc_trim(0);
+ clientsock = accept(sockfd, NULL, NULL);
- while (1) {
- int clientsock;
- pthread_t thread;
-
- malloc_trim(0);
- 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_detach(thread);
- }
- close(sockfd);
+ if (!curl_done) {
+ curl_global_init(CURL_GLOBAL_ALL);
+ curl_done = 1;
+ }
+ pthread_create(&thread, NULL, server_thread, (void *)(unsigned long)clientsock);
+ pthread_detach(thread);
+ }
+ close(sockfd);
}
-