コード例 #1
0
ファイル: omnius.c プロジェクト: zvxr-tech/omnius
/*
 * Run once on startup.
 */
int
startup(char **argv, int *msg_in, int *msg_out)
{
    key_t msg_in_key, msg_out_key;
    printf("Configuring...");

    /* Setup logging */
    g_logfile = stdout;

    /* register interrupt handler */
    if (setup_sigint() != EXIT_SUCCESS)
        return OMNIUS_RET_SIGNAL;

    /* clear the pid lookup table, because we interpret null=0 as empty. */
    memset(g_pid_lookup, 0, sizeof(g_pid_lookup));

    /*
     * Populate the message action dispatch table
     * These are the routines to call depending on the message mtype.
     */
    g_dispatch[MTYPE_NIL] 		= omnius_nil;
    g_dispatch[MTYPE_LOAD] 		= omnius_load;
    g_dispatch[MTYPE_UNLOAD] 	= omnius_unload;
    g_dispatch[MTYPE_ALLOC] 	= omnius_alloc;
    g_dispatch[MTYPE_DEALLOC] 	= omnius_dealloc;
    g_dispatch[MTYPE_READ] 		= omnius_read;
    g_dispatch[MTYPE_WRITE] 	= omnius_write;
    g_dispatch[MTYPE_VIEW]	 	= omnius_view_internal; /* omnius_view; */
    g_dispatch[MTYPE_TERMINATE] = omnius_nil;

    printf("Starting OMNIUS in %s...\n", g_bit_mode_str);
    /* Parse command arguments */
    if(*msg_in)
        msg_in_key = *msg_in;
    else
        msg_in_key = (int) strtol(argv[1], NULL, 16);

    if(*msg_out)
        msg_out_key = *msg_out;
    else
        msg_out_key = (int) strtol(argv[2], NULL, 16);

    if (msg_out_key == msg_in_key)
        return OMNIUS_RET_ARGS;

    /* connect to the outgoing msg queue, then incoming queue */
    if (((*msg_out = ipc_connect((key_t) msg_out_key)) < 0) ||
        ((*msg_in = ipc_connect((key_t) msg_in_key)) < 0))
        return OMNIUS_RET_MSG;

    printf("Loaded!\n");
    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: client.c プロジェクト: kpjjpk/so-tp1
void __connect() {
	if (ipc_connect(__get_id(), SRV_ID) == OK) {
		printf("Clt: connected to srv\n");
	} else {
		printf("Clt: could not connect to srv [ERROR]\n");
	}
}
コード例 #3
0
// IPC Auto Connect
eEsifError ipc_autoconnect(UInt32 max_retries)
{
	eEsifError rc = ESIF_OK;
	UInt32 connect_retries = 0;

	ESIF_TRACE_ENTRY_INFO();

	if (g_ipc_handle != ESIF_INVALID_HANDLE) {
		return rc;
	}

	// Attempt to connect to LF indefinitely until ESIF exits (unless the LF version is unsupported)
	while (!g_quit) {
		rc = ipc_connect();
		if (rc == ESIF_OK || rc == ESIF_E_NOT_SUPPORTED) {
			break;
		}

		if (max_retries > 0 && ++connect_retries >= max_retries) {
			ESIF_TRACE_ERROR("Unable to do an IPC connect\n");
			break;
		}

		esif_ccb_sleep(1);
	}
	ESIF_TRACE_EXIT_INFO_W_STATUS(rc);
	return rc;
}
コード例 #4
0
ファイル: ipc.c プロジェクト: AlanApter/steamlink-sdk
struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
					bool notifications,
					ipc_disconnect_cb cb, void *cb_data)
{
	struct ipc *ipc;

	ipc = g_new0(struct ipc, 1);

	ipc->services = g_new0(struct service_handler, max_service_id + 1);
	ipc->service_max = max_service_id;

	ipc->path = path;
	ipc->size = size;

	ipc->notifications = notifications;

	ipc->cmd_io = ipc_connect(path, size, cmd_connect_cb, ipc);
	if (!ipc->cmd_io) {
		g_free(ipc->services);
		g_free(ipc);
		return NULL;
	}

	ipc->disconnect_cb = cb;
	ipc->disconnect_cb_data = cb_data;

	return ipc;
}
コード例 #5
0
ファイル: ipc.c プロジェクト: AlanApter/steamlink-sdk
static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
							gpointer user_data)
{
	struct ipc *ipc = user_data;

	DBG("");

	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
		error("IPC: command socket connect failed");
		ipc_disconnect(ipc, false);

		return FALSE;
	}

	if (ipc->notifications) {
		ipc->notif_io = ipc_connect(ipc->path, ipc->size,
							notif_connect_cb, ipc);
		if (!ipc->notif_io)
			ipc_disconnect(ipc, false);

		return FALSE;
	}

	cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;

	ipc->cmd_watch = g_io_add_watch(ipc->cmd_io, cond, cmd_watch_cb, ipc);

	info("IPC: successfully connected (without notifications)");

	return FALSE;
}
コード例 #6
0
ファイル: pico_dev_ipc.c プロジェクト: danielinux/picotcp
struct pico_device *pico_ipc_create(const char *sock_path, const char *name, const uint8_t *mac)
{
    struct pico_device_ipc *ipc = PICO_ZALLOC(sizeof(struct pico_device_ipc));

    if (!ipc)
        return NULL;

    ipc->dev.mtu = IPC_MTU;

    if( 0 != pico_device_init((struct pico_device *)ipc, name, mac)) {
        dbg("Ipc init failed.\n");
        pico_ipc_destroy((struct pico_device *)ipc);
        return NULL;
    }

    ipc->dev.overhead = 0;
    ipc->fd = ipc_connect(sock_path);
    if (ipc->fd < 0) {
        dbg("Ipc creation failed.\n");
        pico_ipc_destroy((struct pico_device *)ipc);
        return NULL;
    }

    ipc->dev.send = pico_ipc_send;
    ipc->dev.poll = pico_ipc_poll;
    ipc->dev.destroy = pico_ipc_destroy;
    dbg("Device %s created.\n", ipc->dev.name);
    return (struct pico_device *)ipc;
}
コード例 #7
0
ファイル: proxy.c プロジェクト: android/platform_system_core
int main(int argc, char* argv[]) {
    int rc;

    /* drop privileges */
    if (drop_privs() < 0) return EXIT_FAILURE;

    /* parse arguments */
    parse_args(argc, argv);

    /* initialize secure storage directory */
    rc = storage_init(ss_data_root);
    if (rc < 0) return EXIT_FAILURE;

    /* open rpmb device */
    rc = rpmb_open(rpmb_devname, dev_type);
    if (rc < 0) return EXIT_FAILURE;

    /* connect to Trusty secure storage server */
    rc = ipc_connect(trusty_devname, ss_srv_name);
    if (rc < 0) return EXIT_FAILURE;

    /* enter main loop */
    rc = proxy_loop();
    ALOGE("exiting proxy loop with status (%d)\n", rc);

    ipc_disconnect();
    rpmb_close();

    return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}
コード例 #8
0
static int control_vol_init(snd_pcm_extplug_t *ext)
{ 
  int ret;
  
#ifdef DEBUG
  printf("control_vol plugin: Start to init\n");
#endif
 
  if((ret = ipc_connect()) == -1)
    ERROR(message);
  
  if(volume_control_data->volume_command_data->new_volume > 1.0f || 
    volume_control_data->volume_command_data->new_volume < 0.0f)
    ERROR(message);
  
  volume_control_data->current_volume = volume_control_data->volume_command_data->new_volume;
  volume_control_data->target_volume = volume_control_data->current_volume;
  volume_control_data->start_volume = volume_control_data->current_volume;
  
#ifdef DEBUG
  printf("control_vol plugin: Initialized\n");
#endif
  
  return 0;
}
コード例 #9
0
ファイル: ipc.c プロジェクト: livebox/livebox2
/* For writing data to a specific port - use it in the external process. */
int ipc_connect_buf_write(u16 port, void *data, int data_len)
{
    int fd, rc;

    if ((fd = ipc_connect(port)) < 0)
	return -1;
    rc = ipc_write(fd, data, data_len);
    ipc_client_close(fd, rc);
    return rc;
}
コード例 #10
0
ファイル: esif_uf.c プロジェクト: hoangt/dptf
eEsifError esif_uf_init()
{
	eEsifError rc = ESIF_OK;
	ESIF_TRACE_ENTRY_INFO();

#ifdef ESIF_ATTR_SHELL_LOCK
	esif_ccb_mutex_init(&g_shellLock);
#endif

	ESIF_TRACE_DEBUG("Init Upper Framework (UF)");

	esif_ccb_mempool_init_tracking();

	// Get Home directory
	CMD_OUT("Home: %s\n", esif_pathlist_get(ESIF_PATHTYPE_HOME));


	/* OS Agnostic */
	EsifLogMgrInit();

	esif_link_list_init();
	esif_ht_init();
	esif_ccb_tmrm_init();

	EsifCfgMgrInit();
	EsifEventMgr_Init();
	EsifCnjMgrInit();
	EsifUpPm_Init();
	EsifDspMgrInit();
	EsifActMgrInit();

	/* Web Server optionally started by shell scripts in esif_init */

	/* OS Specific */
	rc = esif_uf_os_init();
	if (ESIF_OK != rc) {
		goto exit;
	}

	/* Start App Manager after all dependent components started
	 * This does not actually start any apps.
	 */
	EsifAppMgrInit();

#ifdef ESIF_FEAT_OPT_ACTION_SYSFS
	SysfsRegisterParticipants();
#else
	ipc_connect();
	sync_lf_participants();
#endif

exit: 
	ESIF_TRACE_EXIT_INFO_W_STATUS(rc);
	return rc;
}
コード例 #11
0
ファイル: psa_crypto_spm.c プロジェクト: 0xc0170/mbed
static psa_status_t ipc_oneshot(uint32_t sid, psa_invec *in_vec, size_t in_vec_size,
                                psa_outvec *out_vec, size_t out_vec_size)
{
    psa_handle_t handle = PSA_NULL_HANDLE;
    psa_status_t status = ipc_connect(sid, &handle);
    if (status != PSA_SUCCESS) {
        return status;
    }
    status = ipc_call(&handle, in_vec, in_vec_size, out_vec, out_vec_size, true);
    return (status);
}
コード例 #12
0
ファイル: psa_crypto_spm.c プロジェクト: 0xc0170/mbed
psa_status_t psa_mac_abort(psa_mac_operation_t *operation)
{
    if (operation->handle <= PSA_NULL_HANDLE) {
        return (PSA_SUCCESS);
    }

    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = PSA_MAC_ABORT,
        .handle = 0,
        .alg    = 0
    };

    psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) };

    psa_status_t status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, true);
    return (status);
}

static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
                                  psa_key_handle_t key_handle,
                                  psa_algorithm_t alg,
                                  psa_sec_function_t func)
{
    if (operation->handle != PSA_NULL_HANDLE) {
        return (PSA_ERROR_BAD_STATE);
    }

    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = func,
        .handle = key_handle,
        .alg    = alg
    };

    psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) };

    psa_status_t status = ipc_connect(PSA_MAC_ID, &operation->handle);
    if (status != PSA_SUCCESS) {
        return (status);
    }
    status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
    if (status != PSA_SUCCESS) {
        ipc_close(&operation->handle);
    }
    return (status);
}

psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
                                psa_key_handle_t key_handle,
                                psa_algorithm_t alg)
{
    psa_status_t status = psa_mac_setup(operation, key_handle, alg, PSA_MAC_SIGN_SETUP);
    return (status);
}
コード例 #13
0
ファイル: ipcclient.cpp プロジェクト: jpalider/supla-core
bool ipc_client::auth(void) {
  if (!ipc_connect() || ipc_sauth_key == NULL) return false;

  snprintf(buffer, IPC_BUFFER_SIZE, "SAUTH:");
  memcpy(&buffer[6], ipc_sauth_key, IPC_SAUTH_KEY_SIZE);

  buffer[6 + IPC_SAUTH_KEY_SIZE] = '\n';

  send(sfd, buffer, strnlen(buffer, IPC_BUFFER_SIZE - 1), 0);

  if (read() && strcmp(buffer, "AUTH_OK\n") == 0) return true;

  return false;
}
コード例 #14
0
ファイル: esif_uf_ipc.c プロジェクト: qbbian/dptf
// IPC Auto Connect
void ipc_autoconnect ()
{
	if (g_ipc_handle != ESIF_INVALID_HANDLE) {
		return;
	}

	while (!g_quit) {
		ipc_connect();
		if (g_ipc_handle != ESIF_INVALID_HANDLE) {
			break;
		}
		esif_ccb_sleep(1);
	}
}
コード例 #15
0
ファイル: ipcclient.cpp プロジェクト: jpalider/supla-core
bool ipc_client::get_value(const char *cmd, int user_id, int device_id,
                           int channel_id) {
  if (!ipc_connect()) return false;

  snprintf(buffer, IPC_BUFFER_SIZE, "%s:%i,%i,%i\n", cmd, user_id, device_id,
           channel_id);
  send(sfd, buffer, strnlen(buffer, IPC_BUFFER_SIZE - 1), 0);

  if (read() &&
      memcmp(buffer, ipc_result_value, strnlen(ipc_result_value, 255)) == 0) {
    return true;
  }

  return false;
}
コード例 #16
0
ファイル: http_post.c プロジェクト: rainfly123/blog
static int http_post_mp4(char *file, char *obdid, char *token, char *eventid, char *cameraid, 
                          char *ip, int port, char *address)
{
    int bound_len = strlen(BOUNDARY_S) + strlen(FILE_NAME) + strlen(file) + \
                   strlen(FILE_TYPE_MP4) + strlen(BOUNDARY_E) - 2;

    struct stat stat;
    int len;
    char *data;
    ssize_t val;
    char md5[48];

    file_md5(file, md5, sizeof(md5));
    int fd = open(file, O_RDONLY);
    if (fd < 0) {
        return -1;
    }
    fstat(fd, &stat);
    data = (char *) malloc(512 + stat.st_size);
    memset(data, 0, (512 + stat.st_size));
    len = sprintf(data, METHOD, address, obdid, eventid, token, md5, cameraid);
    len += sprintf(data + len, USER_AGENT);
    len += sprintf(data + len, CON_LEN, bound_len + (int)stat.st_size);
    len += sprintf(data + len, CON_TYPE);
    len += sprintf(data + len, BOUNDARY_S);
    len += sprintf(data + len, FILE_NAME, file);
    len += sprintf(data + len, FILE_TYPE_MP4);

    val = read(fd, (void *)(data + len), stat.st_size);
    close(fd);
    if (val < 0){
        free(data);
        return -1;
    }
    len += val; 
    len += sprintf(data + len , "%s", BOUNDARY_E); 
    int skt;
    int res;
    skt = ipc_connect(ip, port);
    if (skt < 0)
        return -1;
    res = ipc_send(skt, (char *)data, len);
    close(skt);
    free(data);
    return res;
}
コード例 #17
0
ファイル: ipcclient.cpp プロジェクト: jpalider/supla-core
char ipc_client::is_connected(int user_id, int device_id) {
  if (ipc_connect()) {
    snprintf(buffer, IPC_BUFFER_SIZE, "%s:%i,%i\n", cmd_is_iodev_connected,
             user_id, device_id);
    // supla_log(LOG_DEBUG, "%s", buffer);
    send(sfd, buffer, strnlen(buffer, IPC_BUFFER_SIZE - 1), 0);

    if (read()) {
      if (memcmp(buffer, ipc_result_connected,
                 strnlen(ipc_result_connected, 255)) == 0)
        return IPC_RESULT_CONNECTED;

      if (memcmp(buffer, ipc_result_disconnected,
                 strnlen(ipc_result_disconnected, 255)) == 0)
        return IPC_RESULT_DISCONNECTED;
    }
  }

  return IPC_RESULT_SERVER_UNREACHABLE;
}
コード例 #18
0
ファイル: main.c プロジェクト: Jwomers/migen
static PLI_INT32 connect_calltf(PLI_BYTE8 *user)
{
	struct migensim_softc *sc = (struct migensim_softc *)user;
	vpiHandle sys;
	vpiHandle argv;
	vpiHandle item;
	s_vpi_value value;
	
	sys = vpi_handle(vpiSysTfCall, 0);
	argv = vpi_iterate(vpiArgument, sys);
	item = vpi_scan(argv);
	value.format = vpiStringVal;
	vpi_get_value(item, &value);
	
	sc->ipc = ipc_connect(value.value.str, h_go, h_write, h_read, sc);
	if(sc->ipc == NULL) {
		perror("ipc_connect");
		vpi_control(vpiFinish, 1);
		return 0;
	}
	
	return 0;
}
コード例 #19
0
static int fading_init(snd_pcm_extplug_t *ext)
{ 
  int ret;
  
#ifdef DEBUG
  printf("fading: Start to init\n");
#endif
 
  if((ret = ipc_connect()) == -1)
    ERROR(message);
  
  fading_data->fading_state = _fade_start;
  
  fading_data->current_volume = 1.0f;
  fading_data->start_volume = 1.0f;
  fading_data->volume_to_restore = 1.0f;
  
#ifdef DEBUG
  printf("fading: Initialized\n");
#endif
  
  return 0;
}
コード例 #20
0
ファイル: iscsid_req.c プロジェクト: cleech/open-iscsi
static int iscsid_connect(int *fd, int start_iscsid)
{
	return ipc_connect(fd, iscsid_namespace, start_iscsid);
}
コード例 #21
0
ファイル: util-process.c プロジェクト: JackieXie168/como
/*
 * -- start_child 
 * 
 * fork a child with the given function and process name.
 * If 'procname' is NULL then don't fork, as this is the supervisor.
 * The last argument is an optional fd to be passed to the program.
 */
pid_t
start_child(ipc_peer_full_t * child, mainloop_fn mainloop,
	    memmap_t * shmemmap, FILE *client_stream, como_node_t * node)
{
    pid_t pid;
    int i, p[2];
    char c;

    ipc_peer_t * who = (ipc_peer_t *) child;

    /* find a slot for the child */
    for (i = 0; i < MAX_CHILDREN; i++) {
	if (s_child_info[i].who == NULL)
	    break;
    }
    if (i == MAX_CHILDREN) { 
	warn("cannot create child, no more slots\n");
	return -1; 
    } 

    /*
     * set a pipe which will be used to tell child it may start.
     * this avoids a race condition when the child exists before
     * SU has registered it.
     */
    pipe(p);

    /* ok, fork a regular process and return pid to the caller. */
    debug("start_child -- forking\n");
    pid = fork();

    if (pid < 0) { /* fork() fails */
	warn("fork() failed: %s\n", strerror(errno));
        close(p[0]);
        close(p[1]);
        return -1;
    }
    else if (pid == 0) {	/* child */
	int supervisor_fd;

        debug("child: waiting for start signal\n");
        close(p[1]);                  /* not going to write to the pipe */
        como_read(p[0], &c, 1);       /* wait for start signal */
        close(p[0]);                  /* done with the pipe */
        debug("child: starting\n");

#ifdef ENABLE_PROFILING
	enable_profiling();
#endif
	signal(SIGHUP, SIG_IGN);        /* ignore SIGHUP */

	/* initialize the s_child_info array */ 
	bzero(s_child_info, sizeof(s_child_info)); 

	/* XXX TODO: close unneeded sockets */
	// fclose(stdout); // XXX
	// fclose(stderr); // XXX

        /* ipc_finish will close all FDs. We must retain a copy of client_fd */
	ipc_finish(FALSE);
	ipc_init(child, NULL, NULL);
	
	/* connect to SUPERVISOR */
        supervisor_fd = ipc_connect(COMO_SU);
        assert(supervisor_fd != -1);

	setproctitle("%s", ipc_peer_get_name(who));

	notice("starting process %s pid %d\n",
	       ipc_peer_get_name(who), getpid());

	mainloop((ipc_peer_t *) COMO_SU, shmemmap, client_stream, node);
	exit(0);
    }

    /* parent */
    close(p[0]); /* will not read from pipe */

    s_child_info[i].who = child; /* register the child info */
    s_child_info[i].pid = pid;
    s_children++;

    como_write(p[1], &c, 1); /* child process can start now */
    close(p[1]);             /* done with the pipe */
    
    return pid;
}
コード例 #22
0
ファイル: main.c プロジェクト: gabri94/olsrd
int
main(int argc, char *argv[])
{
  struct hostent *hp;
  struct in_addr in;

#ifdef _WIN32
  WSADATA WsaData;
#endif /* _WIN32 */
  GtkWidget *main_window;

#ifdef _WIN32
  if (WSAStartup(0x0202, &WsaData)) {
    fprintf(stderr, "Could not initialize WinSock.\n");
    exit(EXIT_FAILURE);
  }
#endif /* _WIN32 */

  /* Get IP */
  if ((hp = gethostbyname(argc > 1 ? argv[1] : "localhost")) == 0) {
    fprintf(stderr, "Not a valid host \"%s\"\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  in.s_addr = ((struct in_addr *)(void *)(hp->h_addr))->s_addr;
  printf("Address: %s\n", inet_ntoa(in));

  /* fill in the socket structure with host information */
  memset(&pin, 0, sizeof(pin));
  pin.sin_family = AF_INET;
  pin.sin_addr.s_addr = ((struct in_addr *)(void *)(hp->h_addr))->s_addr;
  pin.sin_port = htons(IPC_PORT);

  gtk_init(&argc, &argv);

  init_nodes();

  freeze_packets = 1;
  display_dec = 1;

  /* "Failsafe" values */
  ipversion = AF_INET;
  ipsize = sizeof(struct in_addr);

  main_window = create_main_window();
  gtk_widget_show(main_window);

  printf("Done building GUI\n");

  memset(&main_addr, 0, sizeof(union olsr_ip_addr));
  memset(&null_addr, 0, sizeof(union olsr_ip_addr));

  /* Terminate signal */
  signal(SIGINT, shutdown_);

  /* Init node timeout */
  nodes_timeout = NEIGHB_HOLD_TIME_NW;
  init_timer((olsr_u32_t) (nodes_timeout * 1000), &hold_time_nodes);

  ipc_connect(&pin);

  add_timeouts();

  gtk_main();
  return 0;
}
コード例 #23
0
ファイル: main.c プロジェクト: stfnm/i3
/*
 * Creates the config file and tells i3 to reload.
 *
 */
static void finish() {
    printf("creating \"%s\"...\n", config_path);

    if (!(dpy = XOpenDisplay(NULL)))
        errx(1, "Could not connect to X11");

    FILE *kc_config = fopen(SYSCONFDIR "/i3/config.keycodes", "r");
    if (kc_config == NULL)
        err(1, "Could not open input file \"%s\"", SYSCONFDIR "/i3/config.keycodes");

    FILE *ks_config = fopen(config_path, "w");
    if (ks_config == NULL)
        err(1, "Could not open output config file \"%s\"", config_path);
    free(config_path);

    char *line = NULL;
    size_t len = 0;
#ifndef USE_FGETLN
    ssize_t read;
#endif
    bool head_of_file = true;

    /* write a header about auto-generation to the output file */
    fputs("# This file has been auto-generated by i3-config-wizard(1).\n", ks_config);
    fputs("# It will not be overwritten, so edit it as you like.\n", ks_config);
    fputs("#\n", ks_config);
    fputs("# Should you change your keyboard layout somewhen, delete\n", ks_config);
    fputs("# this file and re-run i3-config-wizard(1).\n", ks_config);
    fputs("#\n", ks_config);

#ifdef USE_FGETLN
    char *buf = NULL;
    while ((buf = fgetln(kc_config, &len)) != NULL) {
        /* fgetln does not return null-terminated strings */
        FREE(line);
        sasprintf(&line, "%.*s", len, buf);
#else
    size_t linecap = 0;
    while ((read = getline(&line, &linecap, kc_config)) != -1) {
        len = strlen(line);
#endif
        /* skip the warning block at the beginning of the input file */
        if (head_of_file &&
            strncmp("# WARNING", line, strlen("# WARNING")) == 0)
            continue;

        head_of_file = false;

        /* Skip leading whitespace */
        char *walk = line;
        while (isspace(*walk) && walk < (line + len)) {
            /* Pre-output the skipped whitespaces to keep proper indentation */
            fputc(*walk, ks_config);
            walk++;
        }

        /* Set the modifier the user chose */
        if (strncmp(walk, "set $mod ", strlen("set $mod ")) == 0) {
            if (modifier == MOD_Mod1)
                fputs("set $mod Mod1\n", ks_config);
            else fputs("set $mod Mod4\n", ks_config);
            continue;
        }

        /* Check for 'bindcode'. If it’s not a bindcode line, we
         * just copy it to the output file */
        if (strncmp(walk, "bindcode", strlen("bindcode")) != 0) {
            fputs(walk, ks_config);
            continue;
        }
        char *result = rewrite_binding(walk);
        fputs(result, ks_config);
        free(result);
    }

    /* sync to do our best in order to have the file really stored on disk */
    fflush(ks_config);
    fsync(fileno(ks_config));

#ifndef USE_FGETLN
    free(line);
#endif

    fclose(kc_config);
    fclose(ks_config);

    /* tell i3 to reload the config file */
    int sockfd = ipc_connect(socket_path);
    ipc_send_message(sockfd, strlen("reload"), 0, (uint8_t*)"reload");
    close(sockfd);

    exit(0);
}

int main(int argc, char *argv[]) {
    config_path = resolve_tilde("~/.i3/config");
    socket_path = getenv("I3SOCK");
    char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
    char *patternbold = "-misc-fixed-bold-r-normal--13-120-75-75-C-70-iso10646-1";
    int o, option_index = 0;

    static struct option long_options[] = {
        {"socket", required_argument, 0, 's'},
        {"version", no_argument, 0, 'v'},
        {"limit", required_argument, 0, 'l'},
        {"prompt", required_argument, 0, 'P'},
        {"prefix", required_argument, 0, 'p'},
        {"font", required_argument, 0, 'f'},
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    char *options_string = "s:vh";

    while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
        switch (o) {
            case 's':
                FREE(socket_path);
                socket_path = strdup(optarg);
                break;
            case 'v':
                printf("i3-config-wizard " I3_VERSION "\n");
                return 0;
            case 'h':
                printf("i3-config-wizard " I3_VERSION "\n");
                printf("i3-config-wizard [-s <socket>] [-v]\n");
                return 0;
        }
    }

    /* Check if the destination config file does not exist but the path is
     * writable. If not, exit now, this program is not useful in that case. */
    struct stat stbuf;
    if (stat(config_path, &stbuf) == 0) {
        printf("The config file \"%s\" already exists. Exiting.\n", config_path);
        return 0;
    }

    /* Create ~/.i3 if it does not yet exist */
    char *config_dir = resolve_tilde("~/.i3");
    if (stat(config_dir, &stbuf) != 0)
        if (mkdir(config_dir, 0755) == -1)
            err(1, "mkdir(%s) failed", config_dir);
    free(config_dir);

    int fd;
    if ((fd = open(config_path, O_CREAT | O_RDWR, 0644)) == -1) {
        printf("Cannot open file \"%s\" for writing: %s. Exiting.\n", config_path, strerror(errno));
        return 0;
    }
    close(fd);
    unlink(config_path);

    if (socket_path == NULL)
        socket_path = root_atom_contents("I3_SOCKET_PATH");

    if (socket_path == NULL)
        socket_path = "/tmp/i3-ipc.sock";

    int screens;
    if ((conn = xcb_connect(NULL, &screens)) == NULL ||
        xcb_connection_has_error(conn))
        errx(1, "Cannot open display\n");

    xcb_get_modifier_mapping_cookie_t modmap_cookie;
    modmap_cookie = xcb_get_modifier_mapping(conn);
    symbols = xcb_key_symbols_alloc(conn);

    /* Place requests for the atoms we need as soon as possible */
    #define xmacro(atom) \
        xcb_intern_atom_cookie_t atom ## _cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
    #include "atoms.xmacro"
    #undef xmacro

    root_screen = xcb_aux_get_screen(conn, screens);
    root = root_screen->root;

    if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL)))
        errx(EXIT_FAILURE, "Could not get modifier mapping\n");

    xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);

    font = load_font(pattern, true);
    bold_font = load_font(patternbold, true);

    /* Open an input window */
    win = xcb_generate_id(conn);
    xcb_create_window(
        conn,
        XCB_COPY_FROM_PARENT,
        win, /* the window id */
        root, /* parent == root */
        490, 297, 300, 205, /* dimensions */
        0, /* X11 border = 0, we draw our own */
        XCB_WINDOW_CLASS_INPUT_OUTPUT,
        XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
        XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
        (uint32_t[]){
            0, /* back pixel: black */
            XCB_EVENT_MASK_EXPOSURE |
            XCB_EVENT_MASK_BUTTON_PRESS
        });

    /* Map the window (make it visible) */
    xcb_map_window(conn, win);

    /* Setup NetWM atoms */
    #define xmacro(name) \
        do { \
            xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name ## _cookie, NULL); \
            if (!reply) \
                errx(EXIT_FAILURE, "Could not get atom " # name "\n"); \
            \
            A_ ## name = reply->atom; \
            free(reply); \
        } while (0);
    #include "atoms.xmacro"
    #undef xmacro

    /* Set dock mode */
    xcb_change_property(conn,
        XCB_PROP_MODE_REPLACE,
        win,
        A__NET_WM_WINDOW_TYPE,
        A_ATOM,
        32,
        1,
        (unsigned char*) &A__NET_WM_WINDOW_TYPE_DIALOG);

    /* Set window title */
    xcb_change_property(conn,
        XCB_PROP_MODE_REPLACE,
        win,
        A__NET_WM_NAME,
        A_UTF8_STRING,
        8,
        strlen("i3: first configuration"),
        "i3: first configuration");

    /* Create pixmap */
    pixmap = xcb_generate_id(conn);
    pixmap_gc = xcb_generate_id(conn);
    xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, 500);
    xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);

    /* Grab the keyboard to get all input */
    xcb_flush(conn);

    /* Try (repeatedly, if necessary) to grab the keyboard. We might not
     * get the keyboard at the first attempt because of the keybinding
     * still being active when started via a wm’s keybinding. */
    xcb_grab_keyboard_cookie_t cookie;
    xcb_grab_keyboard_reply_t *reply = NULL;

    int count = 0;
    while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) {
        cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
        reply = xcb_grab_keyboard_reply(conn, cookie, NULL);
        usleep(1000);
    }

    if (reply->status != XCB_GRAB_STATUS_SUCCESS) {
        fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status);
        exit(-1);
    }

    xcb_flush(conn);

    xcb_generic_event_t *event;
    while ((event = xcb_wait_for_event(conn)) != NULL) {
        if (event->response_type == 0) {
            fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence);
            continue;
        }

        /* Strip off the highest bit (set if the event is generated) */
        int type = (event->response_type & 0x7F);

        switch (type) {
            case XCB_KEY_PRESS:
                handle_key_press(NULL, conn, (xcb_key_press_event_t*)event);
                break;

            /* TODO: handle mappingnotify */

            case XCB_BUTTON_PRESS:
                handle_button_press((xcb_button_press_event_t*)event);
                break;

            case XCB_EXPOSE:
                handle_expose();
                break;
        }

        free(event);
    }

    return 0;
}
コード例 #24
0
ファイル: callbacks.c プロジェクト: TKr/Wive-ng-rt8186
/*
 *Connect button callback
 */
void 
connect_callback( GtkWidget *widget,
		  gpointer   data )
{
  ipc_connect();
}
コード例 #25
0
ファイル: main.c プロジェクト: fernandoataoldotcom/i3
int main(int argc, char *argv[]) {
    format = sstrdup("%s");
    char *socket_path = NULL;
    char *pattern = sstrdup("pango:monospace 8");
    int o, option_index = 0;

    static struct option long_options[] = {
        {"socket", required_argument, 0, 's'},
        {"version", no_argument, 0, 'v'},
        {"limit", required_argument, 0, 'l'},
        {"prompt", required_argument, 0, 'P'},
        {"prefix", required_argument, 0, 'p'},
        {"format", required_argument, 0, 'F'},
        {"font", required_argument, 0, 'f'},
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}};

    char *options_string = "s:p:P:f:l:F:vh";

    while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
        switch (o) {
            case 's':
                FREE(socket_path);
                socket_path = sstrdup(optarg);
                break;
            case 'v':
                printf("i3-input " I3_VERSION);
                return 0;
            case 'p':
                /* This option is deprecated, but will still work in i3 v4.1, 4.2 and 4.3 */
                fprintf(stderr, "i3-input: WARNING: the -p option is DEPRECATED in favor of the -F (format) option\n");
                FREE(format);
                sasprintf(&format, "%s%%s", optarg);
                break;
            case 'l':
                limit = atoi(optarg);
                break;
            case 'P':
                i3string_free(prompt);
                prompt = i3string_from_utf8(optarg);
                break;
            case 'f':
                FREE(pattern);
                pattern = sstrdup(optarg);
                break;
            case 'F':
                FREE(format);
                format = sstrdup(optarg);
                break;
            case 'h':
                printf("i3-input " I3_VERSION "\n");
                printf("i3-input [-s <socket>] [-F <format>] [-l <limit>] [-P <prompt>] [-f <font>] [-v]\n");
                printf("\n");
                printf("Example:\n");
                printf("    i3-input -F 'workspace \"%%s\"' -P 'Switch to workspace: '\n");
                return 0;
        }
    }

    printf("using format \"%s\"\n", format);

    int screen;
    conn = xcb_connect(NULL, &screen);
    if (!conn || xcb_connection_has_error(conn))
        die("Cannot open display\n");

    sockfd = ipc_connect(socket_path);

    root_screen = xcb_aux_get_screen(conn, screen);
    root = root_screen->root;

    symbols = xcb_key_symbols_alloc(conn);

    init_dpi();
    font = load_font(pattern, true);
    set_font(&font);

    if (prompt != NULL)
        prompt_offset = predict_text_width(prompt);

    const xcb_rectangle_t win_pos = get_window_position();

    /* Open an input window */
    win = xcb_generate_id(conn);
    xcb_create_window(
        conn,
        XCB_COPY_FROM_PARENT,
        win,                                                 /* the window id */
        root,                                                /* parent == root */
        win_pos.x, win_pos.y, win_pos.width, win_pos.height, /* dimensions */
        0,                                                   /* X11 border = 0, we draw our own */
        XCB_WINDOW_CLASS_INPUT_OUTPUT,
        XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
        XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
        (uint32_t[]){
            0, /* back pixel: black */
            1, /* override redirect: don’t manage this window */
            XCB_EVENT_MASK_EXPOSURE});

    /* Map the window (make it visible) */
    xcb_map_window(conn, win);

    /* Initialize the drawable surface */
    draw_util_surface_init(conn, &surface, win, get_visualtype(root_screen), win_pos.width, win_pos.height);

    /* Grab the keyboard to get all input */
    xcb_flush(conn);

    /* Try (repeatedly, if necessary) to grab the keyboard. We might not
     * get the keyboard at the first attempt because of the keybinding
     * still being active when started via a wm’s keybinding. */
    xcb_grab_keyboard_cookie_t cookie;
    xcb_grab_keyboard_reply_t *reply = NULL;

    int count = 0;
    while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) {
        cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
        reply = xcb_grab_keyboard_reply(conn, cookie, NULL);
        usleep(1000);
    }

    if (reply->status != XCB_GRAB_STATUS_SUCCESS) {
        fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status);
        exit(-1);
    }

    xcb_flush(conn);

    xcb_generic_event_t *event;
    while ((event = xcb_wait_for_event(conn)) != NULL) {
        if (event->response_type == 0) {
            fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence);
            continue;
        }

        /* Strip off the highest bit (set if the event is generated) */
        int type = (event->response_type & 0x7F);

        switch (type) {
            case XCB_KEY_PRESS:
                handle_key_press(NULL, conn, (xcb_key_press_event_t *)event);
                break;

            case XCB_KEY_RELEASE:
                handle_key_release(NULL, conn, (xcb_key_release_event_t *)event);
                break;

            case XCB_EXPOSE:
                if (((xcb_expose_event_t *)event)->count == 0) {
                    handle_expose(NULL, conn, (xcb_expose_event_t *)event);
                }

                break;
        }

        free(event);
    }

    draw_util_surface_free(conn, &surface);
    return 0;
}
コード例 #26
0
ファイル: ipcTestSignals.c プロジェクト: kpjjpk/so-tp1
int main(int argc, char **argv) {
	int i = 0, client_id;
	char buf[200];
	boolean failed = false;
	FILE * file;
	string messages[] = {"hello", "world!", NULL};

	switch (fork()) {
		case -1:
			__fatal("Fork error");
			break;
		case 0: /* child */
			usleep(1000);
			client_id=getpid();
			while ( messages[i]!=NULL && !failed ) {
				printf("\nEntro hijo\n");
				ipc_connect(client_id, SRV_ID);
				printf("\nChild: about to send (\"%s\")\n", messages[i]);
				ipc_send(client_id, SRV_ID, messages[i], strlen(messages[i]));
				printf("Child: msg sent\n");
				ipc_recv(client_id, buf, SRV_RESP_LEN);
				printf("Child: response received (%.*s)\n", SRV_RESP_LEN, buf);
				failed = !strneq(OK_MSG, buf, SRV_RESP_LEN);
				if (failed) {
					printf("Child: Error\n");
				} else {
				  	printf("Child: ok response received\n");
				}
				ipc_disconnect(client_id, SRV_ID);
				i++;
			}
			ipc_close(client_id);
			printf("Child: out %s\n",failed? "[ERROR]":"[OK]");
			break;
		default: /* parent */
			printf("\nPadre:\n");			
			printf("Server id in Test%d\n", getpid());
			ipc_init(SRV_ID);
			printf("\nEntro padre\n");
			while ( messages[i]!=NULL ) {
				ipc_connect(SRV_ID, INVALID);
				printf("Parent: about to read\n");
				ipc_recv(SRV_ID, buf, strlen(messages[i]));
				// I can't omit this because usually the server receives the id at the beginning
				file=__open("client", "r", CLIENT_PATH);
				if(file==NULL){
					printf("%s\n","Error opening client id file in parent");
				}
				while(fscanf(file, "%d\n", &client_id) != EOF) {;}
				printf("Client id %d\n", client_id);
				printf("Parent: read (\"%.*s\") --(expecting: \"%s\")\n", (int)strlen(messages[i]), buf, messages[i]);
				if (strneq(messages[i], buf, strlen(messages[i]))) {
					printf("Parent: [OK]\n");
					ipc_send(SRV_ID, client_id, OK_MSG, SRV_RESP_LEN);
				} else {
					printf("Parent: [ERROR]\n");
					ipc_send(SRV_ID, client_id, NOT_OK_MSG, SRV_RESP_LEN);
				}
				ipc_disconnect(SRV_ID, INVALID);
				fclose(file);
				file = NULL;
				i++;
			}
			usleep(1000);
			ipc_close(SRV_ID);
			printf("Parent: out\n");
			break;
	}
	return 0;
}
コード例 #27
0
ファイル: iscsid_req.c プロジェクト: Nimain/open-iscsi
static int iscsid_connect(int *fd, int start_iscsid)
{
	return ipc_connect(fd, ISCSIADM_NAMESPACE, start_iscsid);
}
コード例 #28
0
ファイル: iscsid_req.c プロジェクト: Nimain/open-iscsi
static int uip_connect(int *fd)
{
	return ipc_connect(fd, ISCSID_UIP_NAMESPACE, 0);
}