static void setter_thread_body(void* arg) {
  int i;

  for (i = 0; i < NUM_ITERATIONS; i++) {
    ASSERT(0 == uv_set_process_title(titles[0]));
    ASSERT(0 == uv_set_process_title(titles[1]));
    ASSERT(0 == uv_set_process_title(titles[2]));
    ASSERT(0 == uv_set_process_title(titles[3]));
  }
}
Пример #2
0
static int luv_set_process_title(lua_State* L) {
  const char* title = luaL_checkstring(L, 1);
  int ret = uv_set_process_title(title);
  if (ret < 0) return luv_error(L, ret);
  lua_pushinteger(L, ret);
  return 1;
}
Пример #3
0
static PyObject *
Util_func_set_process_title(PyObject *obj, PyObject *args)
{
    char *title;
    uv_err_t err;

    UNUSED_ARG(obj);

    if (!PyArg_ParseTuple(args, "s:set_process_title", &title)) {
        return NULL;
    }

    if (!setup_args_called) {
        setup_args();
    }

    err = uv_set_process_title(title);
    if (err.code == UV_OK) {
        Py_RETURN_NONE;
    } else {
        PyObject *exc_data = Py_BuildValue("(is)", err.code, uv_strerror(err));
        if (exc_data != NULL) {
            PyErr_SetObject(PyExc_UVError, exc_data);
            Py_DECREF(exc_data);
        }
        return NULL;
    }
}
Пример #4
0
int luv_set_process_title(lua_State* L) {
  const char* title = luaL_checkstring(L, 1);
  uv_err_t err = uv_set_process_title(title);
  if (err.code) {
    return luaL_error(L, "uv_set_process_title: %s: %s", uv_err_name(err), uv_strerror(err));
  }
  return 0;
}
Пример #5
0
static void set_title(const char* title) {
  char buffer[512];
  int err;

  err = uv_get_process_title(buffer, sizeof(buffer));
  ASSERT(err == 0);

  err = uv_set_process_title(title);
  ASSERT(err == 0);

  err = uv_get_process_title(buffer, sizeof(buffer));
  ASSERT(err == 0);

  ASSERT(strcmp(buffer, title) == 0);
}
Пример #6
0
int main(int argc, const char *argv[]) {
  database db;
  db_init(&db);
  
  uv_loop_t *loop = uv_default_loop();
  uv_tcp_t server = {};
  net_listen(&server, &db, loop, 8766);
  
  uv_timer_t t;
  uv_timer_init(loop, &t);
//  uv_timer_start(&t, timer_cb, 0, 1000);
  
  printf("Listening on port 8766\n");
  
  uv_set_process_title("shared");
  uv_run(loop);
  
  db_free(&db);
}
Пример #7
0
int codatunnel_fork(int argc, char **argv,
                    const char *tcp_bindaddr,
                    const char *udp_bindaddr,
                    const char *bind_service,
		    int onlytcp)
{
    /*
       Create the Coda tunnel process.  Returns 0 on success, -1 on error.
       Invoked before RPC2_Init() by the Coda client or server.

       tcp_bindaddr is the IP address to be used to bind the TCP listen
       socket to.  This parameter should be NULL on the client as it is
       is expected to initiate new TCP connections.  On the server this
       can be set to "" (empty string) to bind to the wildcard address.

       udp_bindaddr is the IP address to be used to bind the UDP listen
       socket for communicating with legacy clients and servers that are
       not using codatunnel.  This can be set to "" (empty string) to
       bind to the wildcard address.

       bind_service is the port number to use; on the Coda client, this
       may be the value of the variable "masquerade_port" or NULL to
       bind to any available port.  On Coda servers, this is usually
       specified as "codasrv" which is specified as an IANA reserved
       port number in /etc/services.

       onlytcp is a flag.  If non-zero it suppresses use of UDP as fallback.
    */
    int rc, sockfd[2];

    DEBUG("codatunnel_fork(\"%s:%s\", \"%s:%s\", %d)\n",
          tcp_bindaddr, bind_service, udp_bindaddr, bind_service, onlytcp);

    /* codatunnel is enabled when the daemon process is forked */
    codatunnel_enable_codatunnel = 1;


    /* Create socketpair for host-facing UDP communication */
    rc = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockfd);
    if (rc < 0) {
        perror("codatunnel_fork: socketpair() failed: ");
        return -1;
    }

    DEBUG("hfsocket_fdpair after socketpair() is: [%d, %d]\n", sockfd[0], sockfd[1]);
    codatunnel_vside_sockfd = sockfd[0];


    /* fork, and then invoke codatunneld */
    rc = fork();
    if (rc < 0) {
        perror("codatunnel_fork: fork() failed: ");
        return -1;
    }

    if (rc > 0) { /* I am the parent. */
        DEBUG("Parent: fork succeeded, child pid is %d\n", rc);
        close(sockfd[1]);
        return 0;  /* this is the only success return */
    }

    /* If I get here, I must be the newborn child */
    DEBUG("Child: codatunneld fork succeeded\n");
    close(sockfd[0]); /* codatunnel_vside_sockfd */


    /* if possible, rename child's command line for "ps ax" */
    if (argc) {
        uv_setup_args(argc, argv);
        uv_set_process_title("codatunneld");
    }

    /* launch the tunnel and never return */
    codatunneld(sockfd[1], tcp_bindaddr, udp_bindaddr, bind_service, onlytcp);
    __builtin_unreachable(); /* should never reach here */
}
Пример #8
0
int main(int argc, char *argv[])
{
	char **newargv = uv_setup_args(argc, argv);
	char *server_listen = SERVER_LISTEN;
	int server_port = SERVER_PORT;
	uint8_t *password = (uint8_t *)PASSWORD;
	uint8_t crypt_method = CRYPTO_METHOD;
	char *pid_path = PID_FILE;

	char opt;
	while((opt = getopt(argc, newargv, "l:p:k:f:m:")) != -1) { // not portable to windows
		switch(opt) {
			case 'l':
			    server_listen = optarg;
			    break;
			case 'p':
			    server_port = atoi(optarg);
			    break;
			case 'k':
			    password = (uint8_t *)optarg;
			    break;
			case 'f':
			    pid_path = optarg;
			    break;
			case 'm':
			    if (!strcmp("rc4", optarg))
			    	crypt_method = METHOD_RC4;
			    else if (!strcmp("shadow", optarg))
			    	crypt_method = METHOD_SHADOWCRYPT;
			    break;
			default:
				fprintf(stderr, USAGE, newargv[0]);
				abort();
		}
	}

	FILE *pid_file = fopen(pid_path, "wb");
	if (!pid_file)
		FATAL("fopen failed, %s", strerror(errno));
	fprintf(pid_file, "%d", getpid());
	fclose(pid_file);

	char *process_title = malloc(PROCESS_TITLE_LENGTH); // we do not like waste memory
	if (!process_title)
		FATAL("malloc() failed!");
	snprintf(process_title, PROCESS_TITLE_LENGTH, PROCESS_TITLE, server_port);
	uv_set_process_title(process_title);
	free(process_title);

	LOGI(WELCOME_MESSAGE);

	if (crypt_method == METHOD_SHADOWCRYPT)
		LOGI("Using shadowcrypt crypto");
	else if (crypt_method == METHOD_RC4)
		LOGI("Using RC4 crypto");
	else
		FATAL("Crypto unknown!");

	make_encryptor(NULL, &crypto, crypt_method, password);

	LOGI("Crypto ready");
	
	int n;
	uv_loop_t *loop = uv_default_loop();
	uv_tcp_t listener;

	struct sockaddr_in6 addr = uv_ip6_addr(server_listen, server_port);

	n = uv_tcp_init(loop, &listener);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_tcp_bind6(&listener, addr);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_listen((uv_stream_t*)(void *)&listener, 5, connect_cb);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);
	LOGI("Listening on %s:%d", server_listen, server_port);

	#ifndef NDEBUG
	setup_signal_handler(loop);
	#endif /* !NDEBUG */

	return uv_run(loop);
}
Пример #9
0
int main(int argc, char *argv[])
{
	char *server_listen = SERVER_LISTEN;
	int server_port = SERVER_PORT;
	uint8_t *password = (uint8_t *)PASSWORD;
	char *pid_path = PID_FILE;

	char opt;
	while((opt = getopt(argc, argv, "l:p:k:f:")) != -1) { // not portable to windows
		switch(opt) {
			case 'l':
			    server_listen = optarg;
			    break;
			case 'p':
			    server_port = atoi(optarg);
			    break;
			case 'k':
				password = malloc(strlen(optarg + 1));
				strcpy((char *)password, optarg);
			    break;
			case 'f':
			    pid_path = optarg;
			    break;
			default:
				fprintf(stderr, USAGE, argv[0]);
				abort();
		}
	}

	FILE *pid_file = fopen(pid_path, "wb");
	if (!pid_file)
		FATAL("fopen failed, %s", strerror(errno));
	fprintf(pid_file, "%d", getpid());
	fclose(pid_file);

	char *process_title = malloc(PROCESS_TITLE_LENGTH); // we do not like waste memory
	if (!process_title)
		FATAL("malloc() failed!");
	snprintf(process_title, PROCESS_TITLE_LENGTH, PROCESS_TITLE, server_port);
	uv_setup_args(argc, argv);
	uv_set_process_title(process_title);
	free(process_title);

	LOGI(WELCOME_MESSAGE);
	make_tables(password, encrypt_table, decrypt_table);
	LOGI("Encrypt and decrypt table generated");
	
	int n;
	uv_loop_t *loop = uv_default_loop();
	uv_tcp_t listener;

	struct sockaddr_in addr = uv_ip4_addr(server_listen, server_port);

	n = uv_tcp_init(loop, &listener);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_tcp_bind(&listener, addr);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_listen((uv_stream_t*)(void *)&listener, 5, connect_cb);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);
	LOGI("Listening on %s:%d", server_listen, server_port);

	#ifndef NDEBUG
	setup_signal_handler(loop);
	#endif /* !NDEBUG */

	return uv_run(loop);
}