コード例 #1
0
ファイル: spt_setup.c プロジェクト: aasted/py-setproctitle
/* Initialize the module internal functions.
 *
 * The function reproduces the initialization performed by PostgreSQL
 * to be able to call the functions in pg_status.c
 *
 * The function should be called only once in the process lifetime.
 * so is called at module initialization. After the function is called,
 * set_ps_display() can be used.
 */
void
spt_setup(void)
{
#ifndef WIN32
    int argc = 0;
    char **argv = NULL;

    if (!get_argc_argv(&argc, &argv)) {
        spt_debug("setup failed");
        goto exit;
    }

    save_ps_display_args(argc, argv);

    /* Set up the first title to fully initialize the code */
    char *init_title = join_argv(argc, argv);
    init_ps_display(init_title);
    free(init_title);
#else
    /* On Windows save_ps_display_args is a no-op
     * This is a good news, because Py_GetArgcArgv seems not usable.
     */
    LPTSTR init_title = GetCommandLine();
    init_ps_display(init_title);
#endif

exit:
    /* clear the exception. Propagating it to the module init would make a
     * fatal error. What we want instead is just to create a no-op module. */
    PyErr_Clear();
}
コード例 #2
0
/* Initialize the module internal functions.
 *
 * The function reproduces the initialization performed by PostgreSQL
 * to be able to call the functions in pg_status.c
 *
 * Return 0 in case of success, else -1. In case of failure with an error that
 * shouldn't be ignored, also set a Python exception.
 *
 * The function should be called only once in the process lifetime.
 * so is called at module initialization. After the function is called,
 * set_ps_display() can be used.
 */
int
spt_setup(void)
{
    int rv = -1;

#ifndef WIN32
    int argc = 0;
    char **argv = NULL;
    char *init_title;

    if (0 > get_argc_argv(&argc, &argv)) {
        spt_debug("get_argc_argv failed");
        goto exit;
    }

    save_ps_display_args(argc, argv);

    /* Set up the first title to fully initialize the code */
    if (!(init_title = join_argv(argc, argv))) { goto exit; }
    init_ps_display(init_title);
    free(init_title);

#else
    /* On Windows save_ps_display_args is a no-op
     * This is a good news, because Py_GetArgcArgv seems not usable.
     */
    LPTSTR init_title = GetCommandLine();
    init_ps_display(init_title);
#endif

    rv = 0;

exit:
    return rv;
}
コード例 #3
0
ファイル: cmd_wl.c プロジェクト: AndreyMostovov/asf
cmd_state_t
cmd_delpass(int argc, char* argv[], void* ctx)
{
        const char *usage = "usage: dpass <ssid>\n";
        struct wl_network_t net;
        char desired_ssid[WL_SSID_MAX_LENGTH];
        int len = 0;

        if (argc != 2) {
                printk(usage);
                return CMD_DONE;
        }

        memset(&net, 0, sizeof net);
        memset(net.bssid.octet, 0xFF, sizeof net.bssid.octet);

        len = join_argv(desired_ssid, sizeof desired_ssid, argc - 1, argv + 1);
        if (0 == len) {
                return CMD_DONE;
        }
        memcpy(net.ssid.ssid, desired_ssid, len);
        net.ssid.len = len;
        net.enc_type = ENC_TYPE_AUTO;
        if (wl_clear_passphrase(&net) != WL_SUCCESS) {
                printk("%s : Failed to delete passphrase\n", __func__);
        }

        return CMD_DONE;
}
コード例 #4
0
ファイル: spt_setup.c プロジェクト: simplegeo/setproctitle
/* Initialize the module internal functions.
 *
 * The function reproduces the initialization performed by PostgreSQL
 * to be able to call the functions in pg_status.c
 *
 * The function should be called only once in the process lifetime.
 * so is called at module initialization. After the function is called,
 * set_ps_display() can be used.
 */
void
spt_setup(void)
{
#ifndef WIN32
    int argc = 0;
    char **argv = NULL;

    if (!get_argc_argv(&argc, &argv)) {
        spt_debug("setup failed");
        return;
    }

    save_ps_display_args(argc, argv);

    /* Set up the first title to fully initialize the code */
    char *init_title = join_argv(argc, argv);
    init_ps_display(init_title);
    free(init_title);
#else
    /* On Windows save_ps_display_args is a no-op
     * This is a good news, because Py_GetArgcArgv seems not usable.
     */
    LPTSTR init_title = GetCommandLine();
    init_ps_display(init_title);
#endif

}
コード例 #5
0
ファイル: testbed_api_hosts.c プロジェクト: tg-x/gnunet
/**
 * Checks whether a host can be used to start testbed service
 *
 * @param host the host to check
 * @param config the configuration handle to lookup the path of the testbed
 *          helper
 * @param cb the callback to call to inform about habitability of the given host
 * @param cb_cls the closure for the callback
 * @return NULL upon any error or a handle which can be passed to
 *           GNUNET_TESTBED_is_host_habitable_cancel()
 */
struct GNUNET_TESTBED_HostHabitableCheckHandle *
GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
                                  const struct GNUNET_CONFIGURATION_Handle
                                  *config,
                                  GNUNET_TESTBED_HostHabitableCallback cb,
                                  void *cb_cls)
{
  struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
  char **rsh_args;
  char **rsh_suffix_args;
  char *stat_args[3];
  const char *hostname;
  char *port;

  h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle);
  h->cb = cb;
  h->cb_cls = cb_cls;
  h->host = host;
  hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_get_value_filename (config, "testbed",
                                             "HELPER_BINARY_PATH",
                                             &stat_args[1]))
    stat_args[1] =
        GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
  GNUNET_asprintf (&port, "%u", host->port);
  rsh_args = gen_rsh_args (port, hostname, host->username);
  GNUNET_free (port);
  port = NULL;
  stat_args[0] = "stat";
  stat_args[2] = NULL;
  rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
  GNUNET_free (stat_args[1]);
  h->helper_argv = join_argv ((const char **) rsh_args,
                              (const char **) rsh_suffix_args);
  free_argv (rsh_suffix_args);
  free_argv (rsh_args);
  h->auxp =
      GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL,
                                   NULL, NULL, h->helper_argv[0], h->helper_argv);
  if (NULL == h->auxp)
  {
    GNUNET_break (0);           /* Cannot exec SSH? */
    GNUNET_free (h);
    return NULL;
  }
  h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
  h->habitability_check_task =
      GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
  return h;
}
コード例 #6
0
ファイル: cmd_wl.c プロジェクト: AndreyMostovov/asf
cmd_state_t
cmd_connect(int argc, char* argv[], void* ctx)
{
        struct wl_ssid_t ssid;
        char desired_ssid[WL_SSID_MAX_LENGTH];
        int len = 0;

        if (argc < 2) {
                printk("usage: connect <ssid>\n");
                return CMD_DONE;
        }

        len = join_argv(desired_ssid, sizeof desired_ssid, argc - 1, argv + 1);
        if (0 == len) {
                return CMD_DONE;
        }

        memcpy(ssid.ssid, desired_ssid, len);
        ssid.len = len;
        wl_cm_set_network(&ssid, NULL);
        return CMD_DONE;
}
コード例 #7
0
ファイル: setproctitle.c プロジェクト: vijvijay/rapidapp
void
initsetproctitle(void)
{
    PyObject *m, *d;

    /* Create the module and add the functions */
    m = Py_InitModule3("setproctitle", spt_methods,
        setproctitle_module_documentation);

    /* Add version string to the module*/
    d = PyModule_GetDict(m);
    spt_version = PyString_FromString(xstr(SPT_VERSION));
    PyDict_SetItemString(d, "__version__", spt_version);

    /* Initialize the process title */
#ifndef WIN32
    int argc;
    char **argv;
    Py_GetArgcArgv(&argc, &argv);
    argv = fix_argv(argc, argv);
    save_ps_display_args(argc, argv);

    /* Set up the first title to fully initialize the code */
    char *init_title = join_argv(argc, argv);
    init_ps_display(init_title);
    free(init_title);
#else
    /* On Windows save_ps_display_args is a no-op
     * This is a good news, because Py_GetArgcArgv seems not usable.
     */
    LPTSTR init_title = GetCommandLine();
    init_ps_display(init_title);
#endif


    /* Check for errors */
    if (PyErr_Occurred())
        Py_FatalError("can't initialize module setproctitle");
}
コード例 #8
0
ファイル: cmd_wl.c プロジェクト: AndreyMostovov/asf
cmd_state_t
cmd_setpass(int argc, char* argv[], void* ctx)
{
        const char *usage = "usage: wpass <ssid> <passphrase>\n";
        struct wl_network_t net;
        char desired_ssid[WL_SSID_MAX_LENGTH];
        int len = 0;

        if (argc < 3) {
                printk(usage);
                return CMD_DONE;
        }
        /* Not really kosher, an ssid may legally contain 0-bytes but
         * the console interface does not deal with that.
         */
        memset(&net, 0, sizeof net);
        memset(net.bssid.octet, 0xFF, sizeof net.bssid.octet);

        len = join_argv(desired_ssid, sizeof desired_ssid, argc - 2, argv + 1);
        if (0 == len) {
                return CMD_DONE;
        }

        memcpy(net.ssid.ssid, desired_ssid, len);
        net.ssid.len = len;
        net.enc_type = ENC_TYPE_AUTO;
        if (wl_set_passphrase(&net,
                              argv[argc - 1],
                              strlen(argv[argc - 1]),
                              ENC_TYPE_AUTO,
                              AUTH_MODE_AUTO)
            != WL_SUCCESS) {
                printk("%s : Failed to add passphrase\n", __func__);
        }

        return CMD_DONE;
}
コード例 #9
0
ファイル: testbed_api_hosts.c プロジェクト: tg-x/gnunet
/**
 * Starts a controller process at the given host.  The given host's configration
 * is used as a Template configuration to use for the remote controller; the
 * remote controller will be started with a slightly modified configuration
 * (port numbers, unix domain sockets and service home values are changed as per
 * TESTING library on the remote host).  The modified configuration replaces the
 * host's existing configuration before signalling success through the
 * GNUNET_TESTBED_ControllerStatusCallback()
 *
 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
 *          HOST(all connections form this ip are permitted by the testbed) when
 *          starting testbed controller at host. This can either be a single ip
 *          address or a network address in CIDR notation.
 * @param host the host where the controller has to be started.  CANNOT be NULL.
 * @param cb function called when the controller is successfully started or
 *          dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
 *          called if cb is called with GNUNET_SYSERR as status. Will never be
 *          called in the same task as 'GNUNET_TESTBED_controller_start'
 *          (synchronous errors will be signalled by returning NULL). This
 *          parameter cannot be NULL.
 * @param cls closure for above callbacks
 * @return the controller process handle, NULL on errors
 */
struct GNUNET_TESTBED_ControllerProc *
GNUNET_TESTBED_controller_start (const char *trusted_ip,
                                 struct GNUNET_TESTBED_Host *host,
                                 GNUNET_TESTBED_ControllerStatusCallback cb,
                                 void *cls)
{
  struct GNUNET_TESTBED_ControllerProc *cp;
  struct GNUNET_TESTBED_HelperInit *msg;
  const struct GNUNET_CONFIGURATION_Handle *cfg;
  const char *hostname;
  static char *const binary_argv[] = {
    HELPER_TESTBED_BINARY, NULL
  };

  GNUNET_assert (NULL != host);
  GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
  hostname = NULL;
  API_VIOLATION (GNUNET_NO == host->locked,
                 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
  host->locked = GNUNET_YES;
  API_VIOLATION (GNUNET_NO == host->controller_started,
                 "Attempting to start a controller on a host which is already started a controller");
  cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
  if (0 == GNUNET_TESTBED_host_get_id_ (host))
  {
    cp->helper =
        GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv,
                             &helper_mst, &helper_exp_cb, cp);
  }
  else
  {
    char *helper_binary_path_args[2];
    char **rsh_args;
    char **rsh_suffix_args;
    const char *username;
    char *port;
    char *argstr;
    char *aux;
    unsigned int cnt;

    username = host->username;
    hostname = host->hostname;
    GNUNET_asprintf (&port, "%u", host->port);
    LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
    if (GNUNET_OK !=
        GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed",
                                               "HELPER_BINARY_PATH",
                                               &helper_binary_path_args[0]))
      helper_binary_path_args[0] =
          GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
    helper_binary_path_args[1] = NULL;
    rsh_args = gen_rsh_args (port, hostname, username);
    rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
    cp->helper_argv =
        join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
    free_argv (rsh_args);
    free_argv (rsh_suffix_args);
    GNUNET_free (port);
    argstr = GNUNET_strdup ("");
    for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++)
    {
      aux = argstr;
      GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
      GNUNET_free (aux);
    }
    LOG_DEBUG ("Helper cmd str: %s\n", argstr);
    GNUNET_free (argstr);
    cp->helper =
        GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
                             &helper_exp_cb, cp);
    GNUNET_free (helper_binary_path_args[0]);
  }
  if (NULL == cp->helper)
  {
    if (NULL != cp->helper_argv)
      free_argv (cp->helper_argv);
    GNUNET_free (cp);
    return NULL;
  }
  cp->host = host;
  cp->cb = cb;
  cp->cls = cls;
  msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
  cp->msg = &msg->header;
  cp->shandle =
      GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
  if (NULL == cp->shandle)
  {
    GNUNET_free (msg);
    GNUNET_TESTBED_controller_stop (cp);
    return NULL;
  }
  return cp;
}