From d243a4f3fba71b6ecb05eccb5cd9d04a5b3c6fc7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 23 Mar 2016 18:36:12 +0000 Subject: [PATCH] cgi-fcgi-interp: wip garbage collection --- cprogs/cgi-fcgi-interp.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cprogs/cgi-fcgi-interp.c b/cprogs/cgi-fcgi-interp.c index 4403586..2732774 100644 --- a/cprogs/cgi-fcgi-interp.c +++ b/cprogs/cgi-fcgi-interp.c @@ -164,6 +164,7 @@ static const struct cmdinfo cmdinfos[]= { static uid_t us; static const char *run_base, *script, *socket_path; +static struct stat sock_stab; static bool find_run_base_var_run(void) { struct stat stab; @@ -307,6 +308,8 @@ static void find_socket_path(void) { ((tvp)->tv_sec cmp (uvp)->tv_sec)) #endif /*timespeccmp*/ + + static bool stab_isnewer(const struct stat *a, const struct stat *b) { #ifdef st_mtime return timespeccmp(&a->st_mtim, &b->st_mtim, >); @@ -316,7 +319,7 @@ static bool stab_isnewer(const struct stat *a, const struct stat *b) { } static bool check_garbage(void) { - struct stat sock_stab, script_stab; + struct stat script_stab; int r; r = lstat(script, &script_stab); @@ -343,6 +346,15 @@ static bool check_garbage(void) { return 0; } +static void tidy_garbage(void) { + const char *this_garbage = + m_asprintf("%s/%lu.%lu", run_base, + (unsigned long)sock_stab.st_ino, + (unsigned long)getpid()); + + printf("this_garb: %s\n", this_garbage); +} + static void shbang_opts(const char *const **argv_io, const struct cmdinfo *cmdinfos) { myopt(argv_io, cmdinfos); @@ -393,13 +405,18 @@ int main(int argc, const char *const *argv) { find_socket_path(); - check_garbage(); + bool havegarbage = check_garbage(); if (debugmode) { printf("socket: %s\n",socket_path); printf("interp: %s\n",interp); printf("script: %s\n",script); + printf("garbage: %d\n",havegarbage); + exit(0); } + if (havegarbage) + tidy_garbage(); + exit(0); } -- 2.30.2