mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
dll: fuse: Cygwin signal handling support
This commit is contained in:
parent
e227ae5751
commit
958f694b6f
@ -126,7 +126,8 @@ static inline int fuse_set_signal_handlers(struct fuse_session *se)
|
|||||||
|
|
||||||
static inline void fuse_remove_signal_handlers(struct fuse_session *se)
|
static inline void fuse_remove_signal_handlers(struct fuse_session *se)
|
||||||
{
|
{
|
||||||
fsp_fuse_remove_signal_handlers(se);
|
(void)se;
|
||||||
|
fsp_fuse_set_signal_handlers(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef FUSE_WINFSP_FUSE_H_INCLUDED
|
#ifndef FUSE_WINFSP_FUSE_H_INCLUDED
|
||||||
#define FUSE_WINFSP_FUSE_H_INCLUDED
|
#define FUSE_WINFSP_FUSE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#if !defined(WINFSP_DLL_INTERNAL)
|
#if !defined(WINFSP_DLL_INTERNAL)
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -158,7 +159,6 @@ struct fuse_flock
|
|||||||
MemAlloc, MemFree, \
|
MemAlloc, MemFree, \
|
||||||
fsp_fuse_daemonize, \
|
fsp_fuse_daemonize, \
|
||||||
fsp_fuse_set_signal_handlers, \
|
fsp_fuse_set_signal_handlers, \
|
||||||
fsp_fuse_remove_signal_handlers,\
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define FSP_FUSE_ENV_INIT \
|
#define FSP_FUSE_ENV_INIT \
|
||||||
@ -167,13 +167,12 @@ struct fuse_flock
|
|||||||
malloc, free, \
|
malloc, free, \
|
||||||
fsp_fuse_daemonize, \
|
fsp_fuse_daemonize, \
|
||||||
fsp_fuse_set_signal_handlers, \
|
fsp_fuse_set_signal_handlers, \
|
||||||
fsp_fuse_remove_signal_handlers,\
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__CYGWIN__)
|
#elif defined(__CYGWIN__)
|
||||||
|
|
||||||
#include <errno.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -207,7 +206,6 @@ struct fuse_flock
|
|||||||
malloc, free, \
|
malloc, free, \
|
||||||
fsp_fuse_daemonize, \
|
fsp_fuse_daemonize, \
|
||||||
fsp_fuse_set_signal_handlers, \
|
fsp_fuse_set_signal_handlers, \
|
||||||
fsp_fuse_remove_signal_handlers,\
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -226,9 +224,11 @@ struct fsp_fuse_env
|
|||||||
void (*memfree)(void *);
|
void (*memfree)(void *);
|
||||||
int (*daemonize)(int);
|
int (*daemonize)(int);
|
||||||
int (*set_signal_handlers)(void *);
|
int (*set_signal_handlers)(void *);
|
||||||
void (*remove_signal_handlers)(void *);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_signal_handler(int sig);
|
||||||
|
FSP_FUSE_API void fsp_fuse_set_signal_arg(void *se);
|
||||||
|
|
||||||
static inline int fsp_fuse_daemonize(int foreground)
|
static inline int fsp_fuse_daemonize(int foreground)
|
||||||
{
|
{
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
@ -250,13 +250,31 @@ static inline int fsp_fuse_daemonize(int foreground)
|
|||||||
|
|
||||||
static inline int fsp_fuse_set_signal_handlers(void *se)
|
static inline int fsp_fuse_set_signal_handlers(void *se)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
(void)se;
|
(void)se;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
#elif defined(__CYGWIN__)
|
||||||
|
|
||||||
static inline void fsp_fuse_remove_signal_handlers(void *se)
|
#define FSP_FUSE_SET_SIGNAL_HANDLER(sig, newha)\
|
||||||
{
|
newsa.sa_handler = se ? (newha) : SIG_DFL;\
|
||||||
(void)se;
|
if (-1 == sigaction((sig), 0, &oldsa) ||\
|
||||||
|
(oldsa.sa_handler == (se ? SIG_DFL : (newha)) && -1 == sigaction((sig), &newsa, 0)))\
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
struct sigaction oldsa, newsa = { 0 };
|
||||||
|
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGHUP, fsp_fuse_signal_handler);
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGINT, fsp_fuse_signal_handler);
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGTERM, fsp_fuse_signal_handler);
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGTERM, SIG_IGN);
|
||||||
|
|
||||||
|
fsp_fuse_set_signal_arg(se);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#undef FSP_FUSE_SET_SIGNAL_HANDLER
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct fsp_fuse_env *fsp_fuse_env(void)
|
static inline struct fsp_fuse_env *fsp_fuse_env(void)
|
||||||
|
@ -661,3 +661,18 @@ FSP_FUSE_API int32_t fsp_fuse_ntstatus_from_errno(struct fsp_fuse_env *env,
|
|||||||
return STATUS_ACCESS_DENIED;
|
return STATUS_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cygwin signal support */
|
||||||
|
|
||||||
|
static struct fuse *fsp_fuse_signal_arg;
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_signal_handler(int sig)
|
||||||
|
{
|
||||||
|
if (0 != fsp_fuse_signal_arg && 0 != fsp_fuse_signal_arg->Service)
|
||||||
|
FspServiceStop(fsp_fuse_signal_arg->Service);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_set_signal_arg(void *se)
|
||||||
|
{
|
||||||
|
fsp_fuse_signal_arg = se;
|
||||||
|
}
|
||||||
|
@ -153,7 +153,7 @@ FSP_FUSE_API int fsp_fuse_main_real(struct fsp_fuse_env *env,
|
|||||||
if (-1 == result)
|
if (-1 == result)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
result = env->set_signal_handlers(f/* !!!: REVISIT */);
|
result = env->set_signal_handlers(f);
|
||||||
if (-1 == result)
|
if (-1 == result)
|
||||||
goto exit;
|
goto exit;
|
||||||
signal_handlers = 1;
|
signal_handlers = 1;
|
||||||
@ -162,7 +162,7 @@ FSP_FUSE_API int fsp_fuse_main_real(struct fsp_fuse_env *env,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (signal_handlers)
|
if (signal_handlers)
|
||||||
env->remove_signal_handlers(f/* !!!: REVISIT */);
|
env->set_signal_handlers(0);
|
||||||
|
|
||||||
if (0 != f)
|
if (0 != f)
|
||||||
fsp_fuse_destroy(env, f);
|
fsp_fuse_destroy(env, f);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user