Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Adding cli argument to configure thumbnail root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lutoma committed May 13, 2012
1 parent 3bb5aaf commit 5533583
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fastresize-init
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
19 changes: 10 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void handle_request(FCGX_Request* request, char* root, char* thumbnail_root);

0 comments on commit 5533583

Please sign in to comment.