#include "Evas.h"
#include "evas_cs.h"
+#include <signal.h>
// fixme:'s
//
-// sigint/term - catch and shut down cleanly (server)
-// sigpipe - catch and ignore (both)
-// cwd for loading files needs to be put into a full path (client)
// add ops to get/set cache size, check time and cache time (both)
// add ops to get internal state (both)
// preload - make it work (both)
}
}
+static exit_flag = 0;
+
+static void
+exit_handler(int x, siginfo_t *info, void *data)
+{
+ exit_flag = 1;
+}
+
+static void
+pipe_handler(int x, siginfo_t *info, void *data)
+{
+}
+
+static void
+signal_init(void)
+{
+ struct sigaction action, old_action;
+
+ action.sa_handler = NULL;
+ action.sa_sigaction = exit_handler;
+ action.sa_flags = SA_RESTART | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGINT, &action, &old_action);
+
+ action.sa_handler = NULL;
+ action.sa_sigaction = exit_handler;
+ action.sa_flags = SA_RESTART | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGTERM, &action, &old_action);
+
+ action.sa_handler = NULL;
+ action.sa_sigaction = exit_handler;
+ action.sa_flags = SA_RESTART | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGQUIT, &action, &old_action);
+
+ action.sa_handler = NULL;
+ action.sa_sigaction = pipe_handler;
+ action.sa_flags = SA_RESTART | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGPIPE, &action, &old_action);
+
+ // SIGUSR1
+ // SIGUSR2
+ // SIGHUP
+
+ // SIGCHLD
+
+ // SIGSEGV
+ // SIGILL
+ // SIGBUS
+ // SIGFPE
+ // SIGABRT
+}
+
+static void
+signal_shutdown(void)
+{
+}
+
int
main(int argc, char **argv)
{
evas_init();
img_init();
+ signal_init();
s = evas_cserve_server_add();
if (!s)
{
{
/* fixme: timeout 0 only her - future use timeouts for timed
* housekeping */
+ if (exit_flag) break;
evas_cserve_server_wait(s, t_next * 1000000);
+ if (exit_flag) break;
t = time(NULL);
t_next = t - last_check;
if ((t_next) > cache_item_timeout_check)
t_next = 1;
}
error:
+ printf("clean shutdown\n");
+ if (stat_mem)
+ {
+ stat_clean(stat_mem);
+ }
+ signal_shutdown();
img_shutdown();
if (stat_mem)
{
#include "evas_cs.h"
+#include <signal.h>
#ifdef EVAS_CSERVE
+static void
+pipe_handler(int x, siginfo_t *info, void *data)
+{
+}
+
+static void
+pipe_handle(int push)
+{
+ static struct sigaction old_action;
+ struct sigaction action;
+
+ if (push)
+ {
+ action.sa_handler = NULL;
+ action.sa_sigaction = pipe_handler;
+ action.sa_flags = SA_RESTART | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGPIPE, &action, &old_action);
+ }
+ else
+ {
+ sigaction(SIGPIPE, &old_action, &action);
+ }
+}
+
static Server *
server_connect(void)
{
int ints[2];
int num;
+ pipe_handle(1);
ints[0] = size;
ints[1] = opcode;
num = write(s->fd, ints, (sizeof(int) * 2));
- if (num < 0) return 0;
+ if (num < 0)
+ {
+ pipe_handle(0);
+ return 0;
+ }
num = write(s->fd, data, size);
- if (num < 0) return 0;
+ if (num < 0)
+ {
+ pipe_handle(0);
+ return 0;
+ }
+ pipe_handle(0);
return 1;
}
Op_Load msg;
Op_Load_Reply *rep;
unsigned char *buf;
+ char fbuf[PATH_MAX], wd[PATH_MAX];
int flen, klen;
int opcode;
int size;
msg.lopt.dpi = lopt->dpi;
msg.lopt.w = lopt->w;
msg.lopt.h = lopt->h;
+ if (file[0] != '/')
+ {
+ if (getcwd(wd, sizeof(wd)))
+ {
+ snprintf(fbuf, "%s/%s", wd, file);
+ file = fbuf;
+ }
+ }
+ if (!realpath(file, wd)) file = wd;
flen = strlen(file) + 1;
klen = strlen(key) + 1;
buf = malloc(sizeof(msg) + flen + klen);