static void cbWork(uv_work_t *req) {
	// We have this check in case we `Stop` before this thread starts,
	// otherwise the process will hang
	if(!isRunning) {
		return;
	}

	uv_signal_start(&int_signal, cbTerminate, SIGINT);
	uv_signal_start(&term_signal, cbTerminate, SIGTERM);

	runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort);

	gRunLoop = CFRunLoopGetCurrent();
	CFRunLoopAddSource(gRunLoop, runLoopSource, kCFRunLoopDefaultMode);

	// Creating `gRunLoop` can take some cycles so we also need this second
	// `isRunning` check here because it happens at a future time
	if(isRunning) {
		// Start the run loop. Now we'll receive notifications.
		CFRunLoopRun();
	}

	// The `CFRunLoopRun` is a blocking call so we also need this second
	// `isRunning` check here because it happens at a future time
	if(isRunning) {
		// We should never get here while running
		fprintf(stderr, "Unexpectedly back from CFRunLoopRun()!\n");
	}
}
static void loop_creating_worker(void* context) {
  (void) context;

  do {
    uv_loop_t *loop;
    uv_signal_t signal;
    int r;

    loop = malloc(sizeof(*loop));
    ASSERT(loop != NULL);
    ASSERT(0 == uv_loop_init(loop));

    r = uv_signal_init(loop, &signal);
    ASSERT(r == 0);

    r = uv_signal_start(&signal, signal_unexpected_cb, SIGTERM);
    ASSERT(r == 0);

    uv_close((uv_handle_t*) &signal, NULL);

    r = uv_run(loop, UV_RUN_DEFAULT);
    ASSERT(r == 0);

    uv_loop_close(loop);
    free(loop);

    increment_counter(&loop_creation_counter);
  } while (!stop);
}
Beispiel #3
0
skyray_process_watcher_t * skyray_process_watcher_new(skyray_reactor_t *reactor, zval *zprocess, zval *handler)
{
    zval object;
    skyray_process_watcher_t *intern;
    skyray_process_t *process = skyray_process_from_obj(Z_OBJ_P(zprocess));

    if (process->watcher) {
        zend_throw_exception_ex(skyray_ce_InvalidParamException, 0, "The process is already under watching, unable to watch again");
        return NULL;
    }

    object_init_ex(&object, skyray_ce_ProcessWatcher);
    zend_update_property(skyray_ce_ProcessWatcherHandler, handler, ZEND_STRL("watcher"), &object);

    intern = skyray_process_watcher_from_obj(Z_OBJ(object));
    intern->process = process;
    intern->handler = Z_OBJ_P(handler);
    zval_add_ref(handler);
    zval_add_ref(zprocess);

    process->watcher = intern;

    if (skyray_sigchld_count < 0) {
        uv_signal_init(&reactor->loop, &skyray_sigchld);
        skyray_sigchld_count = 0;
    }

    if (skyray_sigchld_count == 0) {
        uv_signal_start(&skyray_sigchld, signal_cb, SIGCHLD);
    }
    skyray_sigchld_count ++;

    return intern;
}
static void loop_creating_worker(void* context) {
  (void) context;

  do {
    uv_loop_t* loop;
    uv_signal_t signal;
    int r;

    loop = uv_loop_new();
    ASSERT(loop != NULL);

    r = uv_signal_init(loop, &signal);
    ASSERT(r == 0);

    r = uv_signal_start(&signal, signal_unexpected_cb, SIGTERM);
    ASSERT(r == 0);

    uv_close((uv_handle_t*) &signal, NULL);

    r = uv_run(loop);
    ASSERT(r == 0);

    uv_loop_delete(loop);

    increment_counter(&loop_creation_counter);
  } while (!stop);
}
Beispiel #5
0
/// Initializes job control resources
void job_init(void)
{
  uv_disable_stdio_inheritance();
  uv_timer_init(uv_default_loop(), &job_stop_timer);
  uv_signal_init(uv_default_loop(), &schld);
  uv_signal_start(&schld, chld_handler, SIGCHLD);
}
Beispiel #6
0
static int LuaIO_process_exec(lua_State* L) {
  const char* cmd;
  if (lua_type(L, 1) == LUA_TSTRING) {
    cmd = lua_tostring(L, 1);
  } else {
    return luaL_argerror(L, 2, "process.exec(cmd) error: cmd is required and must be [string]\n"); 
  }

  /*shell, -c, cmd, null*/
  char** args = LuaIO_malloc(sizeof(char*) * 4);
  args[0] = "/bin/sh";
  args[1] = "-c";
  args[2] = (char*)cmd;
  args[3] = NULL;

  if (!LuaIO_process_stdio_ptr) { 
    LuaIO_process_stdio[0].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[0].data.fd = 0;
    LuaIO_process_stdio[1].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[1].data.fd = 1;
    LuaIO_process_stdio[2].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[2].data.fd = 2;
    LuaIO_process_stdio_ptr = LuaIO_process_stdio;
  }

  uv_process_options_t* options = LuaIO_malloc(sizeof(uv_process_options_t));
  if (!options) {
    LuaIO_free(args);
    return luaL_error(L, "process.exec(cmd) error: no memory for uv_process_options_t options\n");
  }
  LuaIO_memzero(options, sizeof(uv_process_options_t));
  options->exit_cb = LuaIO_process_onexit;
  options->file = "/bin/sh";
  options->args = args;
  options->stdio_count = 3;
  options->stdio = LuaIO_process_stdio_ptr;

  uv_process_t* handle = LuaIO_malloc(sizeof(uv_process_t));
  if (!handle) {
    LuaIO_process_free_options(options);
    return luaL_error(L, "process.exec(cmd) error: no memory for uv_process_t handle\n");
  }
  LuaIO_memzero(handle, sizeof(uv_process_t));

  int ret = uv_spawn(uv_default_loop(), handle, options);
  if (ret < 0) {
    LuaIO_process_free_options(options);
    uv_close((uv_handle_t*)handle, NULL);
    return luaL_error(L, "process.exec(cmd) uv_spawn() error: %s\n", uv_strerror(ret));
  }

  if (!LuaIO_process_signal_ptr) {
    uv_signal_init(uv_default_loop(), &LuaIO_process_signal);
    LuaIO_process_signal_ptr = &LuaIO_process_signal;
    uv_signal_start(LuaIO_process_signal_ptr, LuaIO_process_signal_callback, SIGQUIT);
  }

  lua_pushinteger(L, handle->pid);
  return 1;
}
Beispiel #7
0
static PyObject *
Signal_func_start(Signal *self, PyObject *args)
{
    int r, signum;
    PyObject *tmp, *callback;

    tmp = NULL;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "Oi:start", &callback, &signum)) {
        return NULL;
    }

    if (!PyCallable_Check(callback)) {
        PyErr_SetString(PyExc_TypeError, "a callable is required");
        return NULL;
    }

    r = uv_signal_start((uv_signal_t *)UV_HANDLE(self), (uv_signal_cb)on_signal_callback, signum);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_SignalError);
        return NULL;
    }

    tmp = self->callback;
    Py_INCREF(callback);
    self->callback = callback;
    Py_XDECREF(tmp);

    Py_RETURN_NONE;
}
Beispiel #8
0
/* Starts a UvTcpServer running.  This function will block
 * the calling thread until the server is shutdown.
 *
 * Returns:
 * 		alib_error: Error occurred.
 * 		Anything else: Return code of 'uv_run()'.
 */
int UvTcpServer_start(UvTcpServer* server)
{
	int rcode;

	/* Check for bad arg. */
	if(!server)return(ALIB_BAD_ARG);

	/* Ensure the server is stopped before going on. */
	UvTcpServer_stop(server);

	/* Allocate the memory for the handle if need be. */
	if(!(server->handle = malloc(sizeof(uv_tcp_t))))
	{
		rcode = ALIB_MEM_ERR;
		goto f_error;
	}

	/* Initialize the handle. */
	if(uv_tcp_init(server->loop, server->handle))
	{
		rcode = ALIB_UNKNOWN_ERR;
		goto f_error;
	}

	/* Bind the port.  If this fails, most likely means
	 * port is already in use. */
	if(uv_tcp_bind(server->handle, (struct sockaddr*)&server->addr, 0))
	{
		rcode = ALIB_PORT_IN_USE;
		goto f_error;
	}

	/* Sets up the server to start listening. */
	server->handle->data = server;
	if(uv_listen((uv_stream_t*)server->handle, server->backlog_size, client_connection_cb))
	{
		rcode = ALIB_UNKNOWN_ERR;
		goto f_error;
	}

	/* Start listening for the signal interrupt. */
	if(uv_signal_start(&server->sig_handle, signal_interrupt_cb, SIGINT))
	{
		rcode = ALIB_UNKNOWN_ERR;
		goto f_error;
	}
	server->sig_handle.data = server;

	return(uv_run(server->loop, UV_RUN_DEFAULT));
f_error:
	/* Free resources as needed. */
	if(server->handle)
	{
		free(server->handle);
		server->handle = NULL;
	}

	return(rcode);
}
Beispiel #9
0
int App::exec()
{
    if (!m_options) {
        return 2;
    }

    uv_signal_start(&m_sigHUP,  App::onSignal, SIGHUP);
    uv_signal_start(&m_sigINT,  App::onSignal, SIGINT);
    uv_signal_start(&m_sigTERM, App::onSignal, SIGTERM);

    background();

    if (!CryptoNight::init(m_options->algorithm())) {
        LOG_ERR("\"%s\" hash self-test failed.", m_options->algoName());
        return 1;
    }

    Summary::print();
    m_options->oclInit();

#   ifndef XMRIG_NO_API
    Api::start();
#   endif

#   ifndef XMRIG_NO_HTTPD
    m_httpd = new Httpd(m_options->apiPort(), m_options->apiToken());
    m_httpd->start();
#   endif

    if (!Workers::start(m_options->threads())) {
        LOG_ERR("Failed to start threads");
        return 1;
    }

    m_network->connect();

    const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
    uv_loop_close(uv_default_loop());

    delete m_network;

    Options::release();
    Platform::release();

    return r;
}
Beispiel #10
0
 error start(int signum, SignalHandler callback)
 {
     callbacks::store(get()->data, internal::uv_cid_signal, callback);
     return error(uv_signal_start(get(),
                                  [](uv_signal_t* handle, int signum)
     {
         callbacks::invoke<decltype(callback)>(handle->data, internal::uv_cid_signal, signum);
     },
     signum));
 }
Beispiel #11
0
/* u3_unix_ef_move()
*/
void
u3_unix_ef_move(void)
{
    u3_unix* unx_u = &u3_Host.unx_u;
    u3_usig* sig_u;

    for ( sig_u = unx_u->sig_u; sig_u; sig_u = sig_u->nex_u ) {
        uv_signal_start(&sig_u->sil_u, _unix_sign_cb, sig_u->num_i);
    }
}
Beispiel #12
0
static void
signal_install(uv_loop_t *loop, uv_signal_cb cb, void *data) {
    signals[0].signum = SIGINT;
    signals[1].signum = SIGQUIT;
    for (int i = 0; i < 2; i++) {
        signals[i].sig.data = data;
        uv_signal_init(loop, &signals[i].sig);
        uv_signal_start(&signals[i].sig, cb, signals[i].signum);
    }
}
Beispiel #13
0
static void init(void *const unused) {
	int rc = async_random((byte_t *)&SLNSeed, sizeof(SLNSeed));
	if(rc < 0) {
		alogf("Random seed error\n");
		return;
	}

	uv_signal_init(async_loop, sigpipe);
	uv_signal_start(sigpipe, ignore, SIGPIPE);
	uv_unref((uv_handle_t *)sigpipe);

	str_t *tmp = strdup(path);
	strarg_t const reponame = basename(tmp); // TODO
	rc = SLNRepoCreate(path, reponame, &repo);
	FREE(&tmp);
	if(rc < 0) {
		alogf("Repository could not be opened: %s\n", sln_strerror(rc));
		return;
	}
	blog = BlogCreate(repo);
	if(!blog) {
		alogf("Blog server could not be initialized\n");
		return;
	}
	rc = RSSServerCreate(repo, &rss);
	if(rc < 0) {
		alogf("RSS server error: %s\n", sln_strerror(rc));
		return;
	}

	if(init_http() < 0 || init_https() < 0) {
		HTTPServerClose(server_raw);
		HTTPServerClose(server_tls);
		return;
	}

//	SLNRepoPullsStart(repo);

	uv_signal_init(async_loop, sigint);
	uv_signal_start(sigint, stop, SIGINT);
	uv_unref((uv_handle_t *)sigint);
}
Beispiel #14
0
void skyray_process_watcher_watch(skyray_process_watcher_t *self)
{
    if (self->process->watcher) {
        return;
    }

    if (skyray_sigchld_count == 0) {
        uv_signal_start(&skyray_sigchld, signal_cb, SIGCHLD);
    }
    skyray_sigchld_count ++;
}
Beispiel #15
0
/* u2_unix_io_init(): initialize unix sync.
*/
void 
u2_unix_io_init(void)
{
  u2_unix* unx_u = &u2_Host.unx_u;

  u2_unix_acquire(u2_Host.cpu_c);

  uv_timer_init(u2L, &unx_u->tim_u);
  unx_u->alm = u2_no;

  {
    u2_usig* sig_u;

    sig_u = malloc(sizeof(u2_usig));
    uv_signal_init(u2L, &sig_u->sil_u);
    uv_signal_start(&sig_u->sil_u, _unix_sign_cb, SIGTERM); 

    sig_u->nex_u = unx_u->sig_u;
    unx_u->sig_u = sig_u;
  }
  {
    u2_usig* sig_u;

    sig_u = malloc(sizeof(u2_usig));
    uv_signal_init(u2L, &sig_u->sil_u);
    uv_signal_start(&sig_u->sil_u, _unix_sign_cb, SIGINT); 

    sig_u->nex_u = unx_u->sig_u;
    unx_u->sig_u = sig_u;
  }
  {
    u2_usig* sig_u;

    sig_u = malloc(sizeof(u2_usig));
    uv_signal_init(u2L, &sig_u->sil_u);
    uv_signal_start(&sig_u->sil_u, _unix_sign_cb, SIGWINCH); 

    sig_u->nex_u = unx_u->sig_u;
    unx_u->sig_u = sig_u;
  }
}
Beispiel #16
0
int strus_run_server( unsigned short port, unsigned int nofThreads, strus_globalctx_t* glbctx)
{
	int res;
	struct sockaddr_in addr;
#define NOF_SIGNALS 7
	int signalar[ NOF_SIGNALS] = {SIGINT,SIGILL,SIGABRT,SIGFPE,SIGSEGV,SIGTERM,SIGHUP};
	uv_signal_t signal[ NOF_SIGNALS];
	int ii;

	if (g_glbctx)
	{
		log_error( "cannot run two server instances");
		return -1;
	}
	g_glbctx = glbctx;

	memset( &g_server, 0, sizeof(g_server));
	uv_tcp_init( uv_default_loop(), &g_server);

	for (ii=0; ii<NOF_SIGNALS; ++ii)
	{
		uv_signal_init( g_server.loop, &signal[ ii]);
		uv_signal_start( &signal[ ii], on_signal, signalar[ ii]);
	}
#if (UV_VERSION_NUM>10)
	uv_ip4_addr( "0.0.0.0", port, &addr);
	res = uv_tcp_bind( &g_server, (const struct sockaddr*) &addr, 0);
#else
	addr = uv_ip4_addr( "0.0.0.0", port);
	res = uv_tcp_bind( &g_server, addr);
#endif
	if (res < 0)
	{
		log_error_sys( "error in bind", res);
		return -1;
	}
	res = uv_listen( (uv_stream_t*)&g_server, 256, on_connected);
	if (res < 0)
	{
		log_error_sys( "error in listen", res);
		return -2;
	}
	res = uv_run( g_server.loop, UV_RUN_DEFAULT);
	if (res != 0)
	{
		log_error( "server event loop was aborted");
	}
#if (UV_VERSION_NUM>10)
	uv_loop_close( g_server.loop);
#endif
	g_glbctx = 0;
	return res;
}
int main()
{
    uv_loop_t* loop = malloc(sizeof(uv_loop_t));
    uv_loop_init(loop);

    uv_signal_t sigInt;
    uv_signal_init(loop, &sigInt);
    uv_signal_start(&sigInt, sigIntClbk, SIGINT);

    uv_signal_t sigTstp;
    uv_signal_init(loop, &sigTstp);
    uv_signal_start(&sigTstp, sigTstpClbk, SIGTSTP);

    uv_run(loop, UV_RUN_DEFAULT);

    uv_loop_close(loop);
    free(loop);

    //printf("Out...");
    return 0;
}
Beispiel #18
0
/* u2_save_io_init(): initialize autosave.
*/
void
u2_save_io_init(void)
{
  u2_save* sav_u = &u2_Host.sav_u;

  sav_u->ent_w = 0;
  sav_u->pid_w = 0;

  uv_timer_init(u2L, &sav_u->tim_u);
  uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000);

  uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD);
}
Beispiel #19
0
            inline void start( int signum, Functor f ) {
                typedef detail::Continuation<Functor, Signal> Cont;

                this->internal_data.continuation = std::make_shared<Cont>( f );

                uv_signal_start( this->handle(), []( uv_signal_t *h, int sn ) {
                    HandleData *d = static_cast<HandleData *>(h->data);

                    Signal *self = static_cast<Signal *>(d->self);

                    static_cast<Cont *>(d->continuation.get())->dispatch( self, sn );
                }, signum );
            }
Beispiel #20
0
static int lluv_signal_start(lua_State *L){
  lluv_handle_t *handle = lluv_check_signal(L, 1, LLUV_FLAG_OPEN);
  int signum = luaL_checkint(L, 2);
  int err;

  lluv_check_args_with_cb(L, 3);
  LLUV_START_CB(handle) = luaL_ref(L, LLUV_LUA_REGISTRY);

  err = uv_signal_start(LLUV_H(handle, uv_signal_t), lluv_on_signal_start, signum);

  if(err >= 0) lluv_handle_lock(L, handle, LLUV_LOCK_START);

  return lluv_return(L, handle, LLUV_START_CB(handle), err);
}
Beispiel #21
0
  int init() {
    int rc = 0;
#if UV_VERSION_MAJOR > 0
    rc = uv_loop_init(&loop_);
    if (rc != 0) return rc;
    is_loop_initialized_ = true;
#endif

#if !defined(_WIN32)
    rc = uv_signal_init(loop(), &sigpipe_);
    if (rc != 0) return rc;
    rc = uv_signal_start(&sigpipe_, on_signal, SIGPIPE);
#endif
    return rc;
  }
Beispiel #22
0
int main(int argc, char * argv[])
{
	uv_signal_t signals;
	uv_signal_init(uv_default_loop(), &signals);
	uv_signal_start(&signals, &_SignalFunc, SIGINT);
	int hInstance = 0; // TODO: getpid?
	sprintf( szAppClass, "Gate-Server%d", hInstance);
	if (!InitApplication( hInstance))		return (false);
    if (!InitInstance()) return (false);
	
	Initialize();
	EventLoop();

    return 0;
}
Beispiel #23
0
void Application::waitForShutdown(std::function<void(void*)> callback, void* opaque)
{ 
    auto cmd = new internal::ShutdownCmd;
    cmd->self = this;
    cmd->opaque = opaque;
    cmd->callback = callback;

    auto sig = new uv_signal_t;
    sig->data = cmd;
    uv_signal_init(loop, sig);
    uv_signal_start(sig, Application::onShutdownSignal, SIGINT);
        
    DebugLS(this) << "Wait for shutdown" << std::endl;
    run();
}
Beispiel #24
0
int App::exec()
{
    if (!m_controller->config()) {
        return 0;
    }

    uv_signal_start(&m_sigHUP,  App::onSignal, SIGHUP);
    uv_signal_start(&m_sigINT,  App::onSignal, SIGINT);
    uv_signal_start(&m_sigTERM, App::onSignal, SIGTERM);

    background();

    Summary::print(m_controller);

#   ifndef XMRIG_NO_API
    Api::start(m_controller);
#   endif

#   ifndef XMRIG_NO_HTTPD
    m_httpd = new Httpd(
                m_controller->config()->apiPort(),
                m_controller->config()->apiToken(),
                m_controller->config()->isApiIPv6(),
                m_controller->config()->isApiRestricted()
                );

    m_httpd->start();
#   endif

    m_controller->proxy()->connect();

    const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
    uv_loop_close(uv_default_loop());

    return r;
}
Beispiel #25
0
LWS_VISIBLE int
lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
	struct lws *wsi = wsi_from_fd(context, pt->lserv_fd);
	int status = 0, n;

	if (!loop) {
		loop = lws_malloc(sizeof(*loop));
		uv_loop_init(loop);
		pt->ev_loop_foreign = 0;
	} else
		pt->ev_loop_foreign = 1;

	pt->io_loop_uv = loop;

	if (pt->context->use_ev_sigint) {
		assert(ARRAY_SIZE(sigs) <= ARRAY_SIZE(pt->signals));
		for (n = 0; n < ARRAY_SIZE(sigs); n++) {
			uv_signal_init(loop, &pt->signals[n]);
			pt->signals[n].data = pt->context;
			uv_signal_start(&pt->signals[n], context->lws_uv_sigint_cb, sigs[n]);
		}
	}

	/*
	 * Initialize the accept wsi read watcher with the listening socket
	 * and register a callback for read operations
	 *
	 * We have to do it here because the uv loop(s) are not
	 * initialized until after context creation.
	 */
	if (wsi) {
		wsi->w_read.context = context;
		uv_poll_init(pt->io_loop_uv, &wsi->w_read.uv_watcher,
			     pt->lserv_fd);
		uv_poll_start(&wsi->w_read.uv_watcher, UV_READABLE,
			      lws_io_cb);
	}

	uv_timer_init(pt->io_loop_uv, &pt->uv_timeout_watcher);
	uv_timer_start(&pt->uv_timeout_watcher, lws_uv_timeout_cb, 1000, 1000);

	return status;
}
static void
foreign_event_loop_init_and_run_libuv(void)
{
	/* we create and start our "foreign loop" */

#if (UV_VERSION_MAJOR > 0) // Travis...
	uv_loop_init(&loop_uv);
#endif
	uv_signal_init(&loop_uv, &sighandler_uv);
	uv_signal_start(&sighandler_uv, signal_cb_uv, SIGINT);

	uv_timer_init(&loop_uv, &timer_outer_uv);
#if (UV_VERSION_MAJOR > 0) // Travis...
	uv_timer_start(&timer_outer_uv, timer_cb_uv, 0, 1000);
#else
	(void)timer_cb_uv;
#endif

	uv_run(&loop_uv, UV_RUN_DEFAULT);
}
Beispiel #27
0
            inline void start( int signum, Functor f ) {
                typedef detail::Continuation<Functor, Signal> Cont;

                this->internal_data->continuation = std::make_shared<Cont>( f );

                uv_signal_start( this->handle(), []( uv_signal_t *h, int sn ) {
                    std::weak_ptr<HandleData> *d = static_cast<std::weak_ptr<HandleData> *>(h->data);

                    if( d != nullptr ) {
                        if( auto data = d->lock()) {
                            if( auto self = data->self.lock()) {
                                data->cont<Cont>()->dispatch( self, sn );
                            }

                        } else {
                            HandleData::cleanup( h, d );
                        }
                    }
                }, signum );
            }
Beispiel #28
0
void signal_init(void)
{
  uv_signal_init(uv_default_loop(), &sint);
  uv_signal_init(uv_default_loop(), &spipe);
  uv_signal_init(uv_default_loop(), &shup);
  uv_signal_init(uv_default_loop(), &squit);
  uv_signal_init(uv_default_loop(), &sterm);
  uv_signal_init(uv_default_loop(), &swinch);
  uv_signal_start(&sint, signal_cb, SIGINT);
  uv_signal_start(&spipe, signal_cb, SIGPIPE);
  uv_signal_start(&shup, signal_cb, SIGHUP);
  uv_signal_start(&squit, signal_cb, SIGQUIT);
  uv_signal_start(&sterm, signal_cb, SIGTERM);
  uv_signal_start(&swinch, signal_cb, SIGWINCH);
#ifdef SIGPWR
  uv_signal_init(uv_default_loop(), &spwr);
  uv_signal_start(&spwr, signal_cb, SIGPWR);
#endif
}
Beispiel #29
0
static int luv_signal_start(lua_State* L) {
  uv_signal_t* handle = luv_check_signal(L, 1);
  int signum, ret;
  if (lua_isnumber(L, 2)) {
    signum = lua_tointeger(L, 2);
  }
  else if (lua_isstring(L, 2)) {
    signum = luv_sig_string_to_num(luaL_checkstring(L, 2));
    luaL_argcheck(L, signum, 2, "Invalid Signal name");
  }
  else {
    return luaL_argerror(L, 2, "Missing Signal name");
  }

  if (!lua_isnoneornil(L, 3)) {
    luv_check_callback(L, handle->data, LUV_SIGNAL, 3);
  }
  ret = uv_signal_start(handle, luv_signal_cb, signum);
  if (ret < 0) return luv_error(L, ret);
  lua_pushinteger(L, ret);
  return 1;
}
void SignalsHandler::AddSignal(int signum, std::string name)
{
	MS_TRACE();

	int err;

	uv_signal_t* uvHandle = new uv_signal_t;
	uvHandle->data = (void*)this;

	err = uv_signal_init(DepLibUV::GetLoop(), uvHandle);
	if (err)
	{
		delete uvHandle;
		MS_THROW_ERROR("uv_signal_init() failed for signal %s: %s", name.c_str(), uv_strerror(err));
	}

	err = uv_signal_start(uvHandle, (uv_signal_cb)on_signal, signum);
	if (err)
		MS_THROW_ERROR("uv_signal_start() failed for signal %s: %s", name.c_str(), uv_strerror(err));

	// Enter the UV handle into the vector.
	this->uvHandles.push_back(uvHandle);
}