aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/local-def.h1
-rw-r--r--src/http-svc.c28
-rw-r--r--src/main.c38
3 files changed, 26 insertions, 41 deletions
diff --git a/include/local-def.h b/include/local-def.h
index 70d7762c..5deca987 100644
--- a/include/local-def.h
+++ b/include/local-def.h
@@ -179,6 +179,7 @@ typedef struct {
int forceexit; // when autoconfig from script force exit before starting server
AFB_plugin **plugins; // pointer to REST/API plugins
magic_t magic; // Mime type file magic lib
+ sigjmp_buf restartCkpt; // context save for restart set/longjmp
} AFB_session;
diff --git a/src/http-svc.c b/src/http-svc.c
index a5bd4b80..034753f4 100644
--- a/src/http-svc.c
+++ b/src/http-svc.c
@@ -100,15 +100,9 @@ STATIC int servFile (struct MHD_Connection *connection, AFB_session *session, co
goto abortRequest;
}
- if (! S_ISREG (sbuf.st_mode)) { // only standard file any other one including symbolic links are refused.
- close (staticfile->fd); // nothing useful to do with this file
- fprintf (stderr, "Fail file: [%s] is not a regular file\n", staticfile->path);
- const char *errorstr = "<html><body>Alsa-Json-Gateway Invalid file type</body></html>";
- response = MHD_create_response_from_buffer (strlen (errorstr),
- (void *) errorstr, MHD_RESPMEM_PERSISTENT);
- MHD_queue_response (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, response);
- goto sendRequest;
- }
+
+
+
// if url is a directory let's add index.html and redirect client
if (S_ISDIR (sbuf.st_mode)) {
@@ -129,7 +123,15 @@ STATIC int servFile (struct MHD_Connection *connection, AFB_session *session, co
fprintf(stderr, "No Index.html in direcory [%s]\n", staticfile->path);
goto abortRequest;
}
- }
+ } else if (! S_ISREG (sbuf.st_mode)) { // only standard file any other one including symbolic links are refused.
+ close (staticfile->fd); // nothing useful to do with this file
+ fprintf (stderr, "Fail file: [%s] is not a regular file\n", staticfile->path);
+ const char *errorstr = "<html><body>Application Framework Binder Invalid file type</body></html>";
+ response = MHD_create_response_from_buffer (strlen (errorstr),
+ (void *) errorstr, MHD_RESPMEM_PERSISTENT);
+ MHD_queue_response (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, response);
+ goto sendRequest;
+ }
// https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=fr
// ftp://ftp.heanet.ie/disk1/www.gnu.org/software/libmicrohttpd/doxygen/dc/d0c/microhttpd_8h.html
@@ -196,14 +198,14 @@ STATIC int requestFile(struct MHD_Connection *connection, AFB_session *session,
char *requestdir, *requesturl;
// default search for file is rootdir base
- requestdir = session->config->rootdir;
- requesturl=url;
+ requestdir= session->config->rootdir;
+ requesturl=(char*)url;
// Check for optional aliases
for (idx=0; session->config->aliasdir[idx].url != NULL; idx++) {
if (0 == strncmp(url, session->config->aliasdir[idx].url, session->config->aliasdir[idx].len)) {
requestdir = session->config->aliasdir[idx].path;
- requesturl=&url[session->config->aliasdir[idx].len];
+ requesturl=(char*)&url[session->config->aliasdir[idx].len];
break;
}
}
diff --git a/src/main.c b/src/main.c
index b681bd09..6d8ffdef 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,8 +30,7 @@
#include <signal.h>
#include <getopt.h>
-static sigjmp_buf exitpoint; // context save for set/longjmp
-static sigjmp_buf restartpoint; // context save for set/longjmp
+static sigjmp_buf exitPoint; // context save for set/longjmp
/*----------------------------------------------------------
| printversion
@@ -115,21 +114,10 @@ static AFB_aliasdir aliasdir[MAX_ALIAS];
static int aliascount=0;
/*----------------------------------------------------------
- | signalQuit
- | return to intitial exitpoint on order to close backend
- | before exiting.
- +--------------------------------------------------------- */
-void signalQuit (int signum)
-{
- if (verbose) printf ("INF:signalQuit received signal to quit\n");
- longjmp (exitpoint, signum);
-}
-
-/*----------------------------------------------------------
| timeout signalQuit
|
+--------------------------------------------------------- */
-void signalFail (int signum) {
+void signalQuit (int signum) {
sigset_t sigset;
@@ -138,9 +126,9 @@ void signalFail (int signum) {
sigaddset (&sigset, SIGABRT);
sigprocmask (SIG_UNBLOCK, &sigset, 0);
- fprintf (stderr, "%s ERR:getAllBlock acquisition timeout\n",configTime());
- syslog (LOG_ERR, "Daemon fail and restart [please report bug]");
- longjmp (restartpoint, signum);
+ fprintf (stderr, "%s ERR:Received signal quit\n",configTime());
+ syslog (LOG_ERR, "Daemon got kill3 & quit [please report bug]");
+ longjmp (exitPoint, signum);
}
@@ -236,7 +224,7 @@ static void closeSession (AFB_session *session) {
static void listenLoop (AFB_session *session) {
AFB_error err;
- if (signal (SIGABRT, signalFail) == SIG_ERR) {
+ if (signal (SIGABRT, signalQuit) == SIG_ERR) {
fprintf (stderr, "%s ERR: main fail to install Signal handler\n", configTime());
return;
}
@@ -269,7 +257,7 @@ int main(int argc, char *argv[]) {
AFB_config cliconfig; // temp structure to store CLI option before file config upload
// ------------- Build session handler & init config -------
- session = configInit ();
+ session = configInit ();
memset(&cliconfig,0,sizeof(cliconfig));
memset(&aliasdir ,0,sizeof(aliasdir));
cliconfig.aliasdir = aliasdir;
@@ -344,9 +332,7 @@ int main(int argc, char *argv[]) {
aliascount++;
} else {
fprintf(stderr, "Too many aliases [max:%s] %s ignored\n", optarg, MAX_ALIAS-1);
- }
-
-
+ }
break;
case SET_SMACK:
@@ -483,8 +469,8 @@ int main(int argc, char *argv[]) {
return (-1);
}
- // save exitpoint context when returning from longjmp closeSession and exit
- status = setjmp (exitpoint); // return !+ when coming from longjmp
+ // save exitPoint context when returning from longjmp closeSession and exit
+ status = setjmp (exitPoint); // return !+ when coming from longjmp
if (status != 0) {
if (verbose) printf ("INF:main returning from longjump after signal [%d]\n", status);
closeSession (session);
@@ -494,11 +480,7 @@ int main(int argc, char *argv[]) {
// let's run this program with a low priority
status=nice (20);
-
// ------------------ Finaly Process Commands -----------------------------
-
-
-
// if --save then store config on disk upfront
if (session->configsave) configStoreFile (session);
if (session->forceexit) exit (0);