diff options
-rw-r--r-- | cgitrc.5.txt | 3 | ||||
-rw-r--r-- | filter.c | 14 | ||||
-rw-r--r-- | filters/email-gravatar.lua | 1 |
3 files changed, 12 insertions, 6 deletions
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index d8f7d0e..170e825 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -590,7 +590,8 @@ specification with the relevant string; available values are: | |||
590 | This is called whenever cgit writes data to the webpage. | 590 | This is called whenever cgit writes data to the webpage. |
591 | 'filter_close()':: | 591 | 'filter_close()':: |
592 | This is called when the current filtering operation is | 592 | This is called when the current filtering operation is |
593 | completed. | 593 | completed. It must return an integer value. Usually 0 |
594 | indicates success. | ||
594 | 595 | ||
595 | Additionally, cgit exposes to the Lua the following built-in functions: | 596 | Additionally, cgit exposes to the Lua the following built-in functions: |
596 | 597 | ||
diff --git a/filter.c b/filter.c index 4d4acaf..0cce7bb 100644 --- a/filter.c +++ b/filter.c | |||
@@ -106,7 +106,7 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap) | |||
106 | static int close_exec_filter(struct cgit_filter *base) | 106 | static int close_exec_filter(struct cgit_filter *base) |
107 | { | 107 | { |
108 | struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; | 108 | struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; |
109 | int i, exit_status; | 109 | int i, exit_status = 0; |
110 | 110 | ||
111 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), | 111 | chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), |
112 | "Unable to restore STDOUT"); | 112 | "Unable to restore STDOUT"); |
@@ -114,14 +114,14 @@ static int close_exec_filter(struct cgit_filter *base) | |||
114 | if (filter->pid < 0) | 114 | if (filter->pid < 0) |
115 | goto done; | 115 | goto done; |
116 | waitpid(filter->pid, &exit_status, 0); | 116 | waitpid(filter->pid, &exit_status, 0); |
117 | if (WIFEXITED(exit_status) && !WEXITSTATUS(exit_status)) | 117 | if (WIFEXITED(exit_status)) |
118 | goto done; | 118 | goto done; |
119 | die("Subprocess %s exited abnormally", filter->cmd); | 119 | die("Subprocess %s exited abnormally", filter->cmd); |
120 | 120 | ||
121 | done: | 121 | done: |
122 | for (i = 0; i < filter->base.argument_count; i++) | 122 | for (i = 0; i < filter->base.argument_count; i++) |
123 | filter->argv[i + 1] = NULL; | 123 | filter->argv[i + 1] = NULL; |
124 | return 0; | 124 | return WEXITSTATUS(exit_status); |
125 | 125 | ||
126 | } | 126 | } |
127 | 127 | ||
@@ -315,10 +315,14 @@ static int close_lua_filter(struct cgit_filter *base) | |||
315 | int ret = 0; | 315 | int ret = 0; |
316 | 316 | ||
317 | lua_getglobal(filter->lua_state, "filter_close"); | 317 | lua_getglobal(filter->lua_state, "filter_close"); |
318 | if (lua_pcall(filter->lua_state, 0, 0, 0)) { | 318 | if (lua_pcall(filter->lua_state, 0, 1, 0)) { |
319 | error_lua_filter(filter); | 319 | error_lua_filter(filter); |
320 | ret = 1; | 320 | ret = -1; |
321 | } else { | ||
322 | ret = lua_tonumber(filter->lua_state, -1); | ||
323 | lua_pop(filter->lua_state, 1); | ||
321 | } | 324 | } |
325 | |||
322 | unhook_write(); | 326 | unhook_write(); |
323 | return ret; | 327 | return ret; |
324 | } | 328 | } |
diff --git a/filters/email-gravatar.lua b/filters/email-gravatar.lua index 22f0641..c80b63e 100644 --- a/filters/email-gravatar.lua +++ b/filters/email-gravatar.lua | |||
@@ -16,6 +16,7 @@ end | |||
16 | 16 | ||
17 | function filter_close() | 17 | function filter_close() |
18 | html("<img src='//www.gravatar.com/avatar/" .. md5 .. "?s=13&d=retro' style='height:10pt;width:10pt' alt='Gravatar' /> " .. buffer) | 18 | html("<img src='//www.gravatar.com/avatar/" .. md5 .. "?s=13&d=retro' style='height:10pt;width:10pt' alt='Gravatar' /> " .. buffer) |
19 | return 0 | ||
19 | end | 20 | end |
20 | 21 | ||
21 | function filter_write(str) | 22 | function filter_write(str) |