From 5533583de84b29b63e5bf898a03a2367416a7c58 Mon Sep 17 00:00:00 2001 From: Lukas Martini Date: Sun, 13 May 2012 04:56:15 +0200 Subject: [PATCH] Adding cli argument to configure thumbnail root directory --- README.rst | 5 ++++- fastresize-init | 2 +- main.c | 19 ++++++++++--------- request.c | 4 ++-- request.h | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index d65f92d..7bfa524 100644 --- a/README.rst +++ b/README.rst @@ -28,11 +28,14 @@ Launching fastresize The syntax to launch fastresize is - fastresize [root] [listen_addr] [user] [group] [num_workers] + fastresize [root] [thumbnail_root] [listen_addr] [user] [group] [num_workers] root The directory assets should be served from. Don't forget the trailing slash. +thumbnail_root + The directory thumbnails should be saved at. Don't forget the trailing slash. + listen_addr The socket address to listen on, for example 127.0.0.1:9000 diff --git a/fastresize-init b/fastresize-init index 2285b72..a938988 100644 --- a/fastresize-init +++ b/fastresize-init @@ -16,7 +16,7 @@ SERVICE_NAME=fastresize USER=app GROUP=app PIDFILE=/var/run/fastresize.pid -DAEMON_OPTS="/var/www/asset/ 127.0.0.1:9000 nginx nginx 9" +DAEMON_OPTS="/var/www/asset/ /var/www/asset/ 127.0.0.1:9000 nginx nginx 9" if [ ! -x $DAEMON ]; then echo "ERROR: Can't execute $DAEMON." diff --git a/main.c b/main.c index 76423bb..3b37052 100644 --- a/main.c +++ b/main.c @@ -38,36 +38,37 @@ void usage(char* argv[]) { - fprintf(stderr, "Usage: %s [root] [listen_addr] [user] [group] [num_workers]\n", argv[0]); + fprintf(stderr, "Usage: %s [root] [thumbnail_root] [listen_addr] [user] [group] [num_workers]\n", argv[0]); syslog(LOG_ERR, "Invalid command line arguments\n"); exit(EXIT_FAILURE); } int main(int argc, char* argv[], char* envp[]) { - if(argc < 6) + if(argc < 7) usage(argv); char* root = argv[1]; - char* listen_addr = argv[2]; - int num_workers = atoi(argv[5]); + char* thumbnail_root = argv[2]; + char* listen_addr = argv[3]; + int num_workers = atoi(argv[6]); if(num_workers < 1) usage(argv); - struct passwd* pwd = getpwnam(argv[3]); + struct passwd* pwd = getpwnam(argv[4]); if (pwd == NULL) error_errno("getpwnam_r failed", EXIT_FAILURE); - struct group* grp = getgrnam(argv[4]); + struct group* grp = getgrnam(argv[5]); if (grp == NULL) error_errno("getgrnam_r failed", EXIT_FAILURE); int userid = pwd->pw_uid; int groupid = grp->gr_gid; - if(root[strlen(root) - 1] != '/') - error("Did you forget the ending slash in the root directory path?", EXIT_FAILURE); + if(root[strlen(root) - 1] != '/' || thumbnail_root[strlen(thumbnail_root) - 1] != '/') + error("Did you forget the ending slash in the (thumbnail) root directory path?", EXIT_FAILURE); // TODO Some more error checking @@ -133,7 +134,7 @@ int main(int argc, char* argv[], char* envp[]) } while(FCGX_Accept_r(&request) == 0) - handle_request(&request, root); + handle_request(&request, root, thumbnail_root); // Cleanup & exit MagickWandTerminus(); diff --git a/request.c b/request.c index 8a51728..1b6e776 100644 --- a/request.c +++ b/request.c @@ -28,7 +28,7 @@ #include "request.h" #include "resize.h" -void handle_request(FCGX_Request* request, char* root) +void handle_request(FCGX_Request* request, char* root, char* thumbnail_root) { char* basename = FCGX_GetParam("BASENAME", request->envp); char* extension = FCGX_GetParam("EXTENSION", request->envp); @@ -43,7 +43,7 @@ void handle_request(FCGX_Request* request, char* root) mode = "default"; // Build absolute file path - char* req_path = calloc(strlen(root) + strlen(req_file) + 1, sizeof(char)); + char* req_path = calloc(strlen(thumbnail_root) + strlen(req_file) + 1, sizeof(char)); sprintf(req_path, "%s%s", root, req_file); // Check if the requested file exists already diff --git a/request.h b/request.h index 585b8d3..ca2f517 100644 --- a/request.h +++ b/request.h @@ -30,4 +30,4 @@ static inline void http_error(FCGX_Request* request, int num) { #define http_error_c(num) { http_error(request, num); return; } #define http_sendfile(file) { FCGX_FPrintF(request->out, "X-Accel-Redirect: /asset-send/%s\r\n\r\n", file); } -void handle_request(FCGX_Request* request, char* root); \ No newline at end of file +void handle_request(FCGX_Request* request, char* root, char* thumbnail_root); \ No newline at end of file