static bool SAMLCheckAudience(const XMLCh *audience) { bool ret; /* * XXX This should be much better. Ideally it should check that it refers * to the hostname of a URL or matches some kind of URN. Also, this is * where the VC UUID can be used when running in a VM. * We should accept: * URL: <scheme_name>://<host_name>[/stuff] * URN: urn:vmware:vgauth:<vc_domain_name>:<vc_vm_uuid>:[vgauth_client_app_name] * Glib has a basic URL and we should use it. * TODO: Need a RpcIn call into the VMX to get the VC UUID, since it is not * currently exposed. (Could be NamespaceDB, but then need to make a separate * workflow for pushing the VC UUIDs out to VMs.) */ ret = strstr(SAMLStringWrapper(audience).c_str(), g_get_host_name()) != NULL; Debug("%s: audience check: token: '%s', host: '%s' ? %d\n", __FUNCTION__, SAMLStringWrapper(audience).c_str(), g_get_host_name(), ret); return ret; }
/** * 创建命令数据. * @param command 命令字 * @param attach 附加数据 */ void Command::CreateCommand(uint32_t command, const char *attach) { const gchar *env; char *ptr; snprintf(buf, MAX_UDPLEN, "%s", IPTUX_VERSION); size = strlen(buf); ptr = buf + size; snprintf(ptr, MAX_UDPLEN - size, ":%" PRIu32, packetn); packetn++; size += strlen(ptr); ptr = buf + size; env = g_get_user_name(); snprintf(ptr, MAX_UDPLEN - size, ":%s", env); size += strlen(ptr); ptr = buf + size; env = g_get_host_name(); snprintf(ptr, MAX_UDPLEN - size, ":%s", env); size += strlen(ptr); ptr = buf + size; if(command == IPMSG_GETFILEDATA) snprintf(ptr, MAX_UDPLEN - size, ":%d", command); else snprintf(ptr, MAX_UDPLEN - size, ":%" PRIu32, command); size += strlen(ptr); ptr = buf + size; snprintf(ptr, MAX_UDPLEN - size, ":%s", attach ? attach : ""); size += strlen(ptr) + 1; }
static gchar * gebrd_mpich2_initialize(GebrdMpiInterface * mpi) { GebrdMpich2 *self = (GebrdMpich2*) mpi; gchar *tmp = g_build_filename(g_get_home_dir(), ".gebr", "gebrd", g_get_host_name(), "mpd.hostsXXXXXX", NULL); gint n = 0; GString *hosts = g_string_new(NULL); for (GList *i = self->servers; i; i = i->next) { g_string_append(hosts, i->data); g_string_append_c(hosts, '\n'); n++; } self->tmp_file = "$_gebr_tmp"; gchar *ret_cmd = g_strdup_printf("( _gebr_tmp=`mktemp %s` && echo '%s' >> %s", tmp, hosts->str, self->tmp_file); g_string_free(hosts, TRUE); g_free(tmp); return ret_cmd; }
static void infd_xmpp_server_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) { InfdXmppServer* xmpp; InfdXmppServerPrivate* priv; xmpp = INFD_XMPP_SERVER(object); priv = INFD_XMPP_SERVER_PRIVATE(xmpp); switch(prop_id) { case PROP_TCP: infd_xmpp_server_set_tcp( xmpp, INFD_TCP_SERVER(g_value_get_object(value)) ); break; case PROP_LOCAL_HOSTNAME: g_free(priv->local_hostname); priv->local_hostname = g_value_dup_string(value); if(priv->local_hostname == NULL) priv->local_hostname = g_strdup(g_get_host_name()); break; case PROP_CREDENTIALS: if(priv->tls_creds != NULL) inf_certificate_credentials_unref(priv->tls_creds); priv->tls_creds = g_value_dup_boxed(value); break; case PROP_SASL_CONTEXT: if(priv->sasl_own_context != NULL) { inf_sasl_context_unref(priv->sasl_own_context); priv->sasl_own_context = NULL; } if(priv->sasl_context != NULL) inf_sasl_context_unref(priv->sasl_context); priv->sasl_context = g_value_dup_boxed(value); infd_xmpp_server_setup_own_sasl_context(xmpp); break; case PROP_SASL_MECHANISMS: g_free(priv->sasl_mechanisms); priv->sasl_mechanisms = g_value_dup_string(value); break; case PROP_SECURITY_POLICY: infd_xmpp_server_set_security_policy(xmpp, g_value_get_enum(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
gboolean gebr_comm_is_local_address(const gchar *addr) { if (g_strcmp0(g_get_host_name(), addr) == 0 || g_strcmp0(addr, "localhost") == 0 || g_strcmp0(addr, "127.0.0.1") == 0) return TRUE; return FALSE; }
static char * start_startup_notification (GdkDisplay * display, EggDesktopFile * desktop_file, const char *argv0, int screen, int workspace, guint32 launch_time) { static int sequence = 0; char *startup_id; char *description, *wmclass; char *screen_str, *workspace_str; if (g_key_file_has_key (desktop_file->key_file, EGG_DESKTOP_FILE_GROUP, EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY, NULL)) { if (!g_key_file_get_boolean (desktop_file->key_file, EGG_DESKTOP_FILE_GROUP, EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY, NULL)) return NULL; wmclass = NULL; } else { wmclass = g_key_file_get_string (desktop_file->key_file, EGG_DESKTOP_FILE_GROUP, EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS, NULL); if (!wmclass) return NULL; } if (launch_time == (guint32) - 1) launch_time = gdk_x11_display_get_user_time (display); startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long) getpid (), g_get_host_name (), argv0, sequence++, (unsigned long) launch_time); description = g_strdup_printf (_("Starting %s"), desktop_file->name); screen_str = g_strdup_printf ("%d", screen); workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", desktop_file->name, "SCREEN", screen_str, "BIN", argv0, "ICON", desktop_file->icon, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", wmclass, NULL); g_free (description); g_free (wmclass); g_free (screen_str); g_free (workspace_str); return startup_id; }
/** * Retrieve some basic information about system. */ void appInfo() { GError *err; // get some system data appPid = getpid(); appPath = g_file_read_link("/proc/self/exe", &err); appHomeDir = g_get_home_dir(); appUserName = g_get_user_name(); appRealName = g_get_real_name(); appHostName = g_get_host_name(); }
/** * Inits the main structure. * @note With sqlite version > 3.7.7 we should use URI filename. * @param opt : a filled options_t * structure that contains all options * by default, read into the file or selected in the command line. * @returns a main_struct_t * pointer to the main structure */ static main_struct_t *init_main_structure(options_t *opt) { main_struct_t *main_struct = NULL; gchar *db_uri = NULL; gchar *conn = NULL; if (opt != NULL) { print_debug(_("Please wait while initializing main structure...\n")); main_struct = (main_struct_t *) g_malloc0(sizeof(main_struct_t)); create_directory(opt->dircache); db_uri = g_build_filename(opt->dircache, opt->dbname , NULL); main_struct->database = open_database(db_uri); db_uri = free_variable(db_uri); main_struct->opt = opt; main_struct->hostname = g_get_host_name(); if (opt != NULL && opt->ip != NULL) { conn = make_connexion_string(opt->ip, opt->port); main_struct->comm = init_comm_struct(conn); main_struct->reconnected = init_comm_struct(conn); free_variable(conn); } else { /* This should never happen because we have default values */ main_struct->comm = NULL; } main_struct->signal_fd = start_signals(); main_struct->fanotify_fd = start_fanotify(opt); /* inits the queue that will wait for events on files */ main_struct->save_queue = g_async_queue_new(); main_struct->dir_queue = g_async_queue_new(); main_struct->regex_exclude_list = make_regex_exclude_list(opt->exclude_list); /* Thread initialization */ main_struct->save_one_file = g_thread_new("save_one_file", save_one_file_threaded, main_struct); main_struct->carve_all_directories = g_thread_new("carve_all_directories", carve_all_directories, main_struct); main_struct->reconn_thread = g_thread_new("reconnected", reconnected, main_struct); print_debug(_("Main structure initialized !\n")); } return main_struct; }
static void ide_local_device_init (IdeLocalDevice *self) { IdeLocalDevicePrivate *priv = ide_local_device_get_instance_private (self); priv->system_type = get_system_type (); priv->config = g_key_file_new (); g_key_file_set_string (priv->config, "autoconf", "--host", priv->system_type); ide_device_set_display_name (IDE_DEVICE (self), g_get_host_name ()); ide_device_set_id (IDE_DEVICE (self), "local"); }
/* Generates a unique string for a window role */ static gchar * gen_role (void) { GTimeVal result; static gint serial; g_get_current_time (&result); return g_strdup_printf ("gedit-window-%ld-%ld-%d-%s", result.tv_sec, result.tv_usec, serial++, g_get_host_name ()); }
void git_upgrade () // Upgrades the git system. { // Go through the projects that have their git repository enabled. extern Settings * settings; vector <ustring> projects = projects_get_all (); for (unsigned int i = 0; i < projects.size(); i++) { ProjectConfiguration * projectconfig = settings->projectconfig (projects[i]); ustring git_directory = gw_build_filename (project_data_directory_project (projects[i]), ".git"); if (projectconfig->git_use_remote_repository_get()) { // At times there's a stale index.lock file that prevents any collaboration. // This is to be removed. ustring index_lock = gw_build_filename (git_directory, "index.lock"); if (g_file_test (index_lock.c_str(), G_FILE_TEST_IS_REGULAR)) { gw_message (_("Cleaning out index lock ") + index_lock); unix_unlink (index_lock.c_str()); } // Get the data directory for the project ustring datadirectory = tiny_project_data_directory_project(projects[i]); // On most machines git can determine the user's name from the system services. // On the XO machine, it can't. It is set here manually. // On more recent versions of git, like version 1.8.3 and younger, // although git may determine the user's name from the system, // it still requires it to be set manually. ustring command; command = "git config user.email \""; command.append(g_get_user_name()); command.append("@"); command.append(g_get_host_name()); command.append("\""); maintenance_register_shell_command (datadirectory, command); command = "git config user.name \""; command.append(g_get_real_name()); command.append("\""); maintenance_register_shell_command (datadirectory, command); // (Re)initialize the repository. This can be done repeatedly without harm. // Note that this is done on shutdown. maintenance_register_shell_command (datadirectory, "git init"); } else { if (g_file_test (git_directory.c_str(), G_FILE_TEST_IS_DIR)) { gw_message (_("Cleaning out folder ") + git_directory); ProgressWindow progresswindow (_("Tidying up project ") + projects[i], false); progresswindow.set_fraction (0.5); unix_rmdir (git_directory); } } } }
static EventdPluginContext * _eventd_evp_init(EventdCoreContext *core, EventdCoreInterface *core_interface) { EventdPluginContext *service; service = g_new0(EventdPluginContext, 1); service->core = core; service->core_interface= core_interface; service->avahi_name = g_strdup_printf(PACKAGE_NAME " %s", g_get_host_name()); service->events = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); return service; }
int main(int argc, char *argv[]) { static Settings settings = { .num_images = -1, .width = 1024, .height = 1024, .do_profile = FALSE }; static GOptionEntry entries[] = { { "num-images", 'n', 0, G_OPTION_ARG_INT, &settings.num_images, "Number of images", "N" }, { "width", 'w', 0, G_OPTION_ARG_INT, &settings.width, "Width of imags", "W" }, { "height", 'h', 0, G_OPTION_ARG_INT, &settings.height, "Height of images", "H" }, { "enable-profiling", 'n', 0, G_OPTION_ARG_NONE, &settings.do_profile, "Enable profiling", NULL }, { NULL } }; GOptionContext *context; opencl_desc *ocl; Benchmark *benchmark; GError *error = NULL; context = g_option_context_new (" - test multi GPU performance"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Option parsing failed: %s\n", error->message); return 1; } g_print("## %s@%s\n", g_get_user_name(), g_get_host_name()); g_thread_init (NULL); ocl = ocl_new (settings.do_profile); benchmark = setup_benchmark (ocl, &settings); measure_benchmark ("Single GPU", execute_single_gpu, benchmark); measure_benchmark ("Single Threaded, Multi GPU", execute_multi_gpu_single_thread, benchmark); measure_benchmark ("Multi Threaded, Multi GPU", execute_multi_gpu_multi_thread, benchmark); teardown_benchmark(benchmark); ocl_free(ocl); return 0; }
gretl_bundle *get_sysinfo_bundle (int *err) { if (sysinfo_bundle == NULL) { gretl_bundle *b = gretl_bundle_new(); if (b == NULL) { *err = E_ALLOC; } else { int ival = 0; #if HAVE_MPI ival = check_for_mpiexec(); #endif gretl_bundle_set_scalar(b, "mpi", (double) ival); ival = gretl_max_mpi_processes(); gretl_bundle_set_scalar(b, "mpimax", (double) ival); ival = gretl_n_processors(); gretl_bundle_set_scalar(b, "nproc", (double) ival); ival = 0; #ifdef _OPENMP ival = 1; #endif gretl_bundle_set_scalar(b, "omp", (double) ival); ival = sizeof(void*) == 8 ? 64 : 32; gretl_bundle_set_scalar(b, "wordlen", (double) ival); gretl_bundle_set_scalar(b, "omp_num_threads", get_omp_n_threads()); #if defined(G_OS_WIN32) gretl_bundle_set_string(b, "os", "windows"); #elif defined(OS_OSX) gretl_bundle_set_string(b, "os", "osx"); #elif defined(linux) gretl_bundle_set_string(b, "os", "linux"); #else gretl_bundle_set_string(b, "os", "other"); #endif gretl_bundle_set_string(b, "hostname", g_get_host_name()); gretl_bundle_set_string(b, "blas", blas_variant_string()); } sysinfo_bundle = b; } return sysinfo_bundle; }
char* _mux_maildir_get_target_path (const char *path, const char *target_dir, MuxMaildirMoveFlags move_flags, MuxMaildirFlags target_flags, GError **err) { char *basename, *flagstr, *target; /* perhaps we want to rename to some random base? */ if (move_flags & MUX_MAILDIR_MOVE_FLAG_RENAME) { char date[9]; /* YYYYMMDD */ time_t now; const char *host; now = time(NULL); strftime (date, sizeof(date), "%Y%m%d", localtime(&now)); host = g_get_host_name (); basename = g_strdup_printf ( "%s-%08x-%s", date, g_random_int (), host ? host : "localhost"); } else { basename = mux_maildir_path_parse ( path, NULL, TRUE/*require mdir*/, err); if (!basename) return NULL; } flagstr = mux_maildir_flags_to_str (target_flags, FALSE /* no N */); if (target_flags & MUX_MAILDIR_FLAG_NEW) target = g_strdup_printf ( "%s/new/%s", target_dir, basename); else target = g_strdup_printf ( "%s/cur/%s%c2,%s", target_dir, basename, (move_flags & MUX_MAILDIR_MOVE_FLAG_USE_BANG) ? '!' : ':', flagstr); g_free (basename); g_free (flagstr); return target; }
static void gconf_save_device (GConfClient *client, const char *device) { const char *hostname; if (device == NULL) { return; } hostname = g_get_host_name (); if (hostname != NULL) { gboolean res; char *key; key = g_strdup_printf ("/apps/nautilus-cd-burner/%s/last_device", hostname); res = gconf_client_set_string (client, key, device, NULL); } }
static char * gconf_load_device (GConfClient *client) { const char *hostname; char *device; device = NULL; hostname = g_get_host_name (); if (hostname != NULL) { char *key; key = g_strdup_printf ("/apps/nautilus-cd-burner/%s/last_device", hostname); device = gconf_client_get_string (client, key, NULL); g_free (key); } return device; }
static void infd_xmpp_server_init(GTypeInstance* instance, gpointer g_class) { InfdXmppServer* xmpp; InfdXmppServerPrivate* priv; xmpp = INFD_XMPP_SERVER(instance); priv = INFD_XMPP_SERVER_PRIVATE(xmpp); priv->tcp = NULL; priv->status = INFD_XMPP_SERVER_CLOSED; priv->local_hostname = g_strdup(g_get_host_name()); priv->security_policy = INF_XMPP_CONNECTION_SECURITY_ONLY_UNSECURED; priv->tls_creds = NULL; priv->sasl_context = NULL; priv->sasl_own_context = NULL; priv->sasl_mechanisms = NULL; }
static char * get_share_name (void) { static char *name = NULL; const char *host_name; char *str; if (name == NULL) { host_name = g_get_host_name (); if (strcmp (host_name, "localhost") == 0) { /* Translators: The %s will get filled in with the user name of the user, to form a genitive. If this is difficult to translate correctly so that it will work correctly in your language, you may use something equivalent to "Public files of %s", or leave out the %s altogether. In the latter case, please put "%.0s" somewhere in the string, which will match the user name string passed by the C code, but not put the user name in the final string. This is to avoid the warning that msgfmt might otherwise generate. */ name = g_strdup_printf (_("%s's public files"), g_get_user_name ()); } else { /* Translators: This is similar to the string before, only it has the hostname in it too. */ name = g_strdup_printf (_("%s's public files on %s"), g_get_user_name (), host_name); } } /* And truncate */ if (strlen (name) < AVAHI_LABEL_MAX) return name; str = truncate_name (name); g_free (name); name = str; return name; }
static gchar * get_dbid (void) { static gchar *dbid; if (!dbid) { GString *name; // Creates a service name 14 characters long concatenating the hostname // hash hex value with itself. // Idea taken from stereo. name = g_string_new (NULL); g_string_printf (name, "%.8x", g_str_hash (g_get_host_name ())); g_string_ascii_up (name); g_string_append_len (name, name->str, 4); dbid = name->str; g_string_free (name, FALSE); } return dbid; }
int main(int argc, char *argv[]) { printf("Host name\t: %s\n", g_get_host_name()); // 取得使用者真實姓名 printf("Real name\t: %s\n", g_get_real_name()); // 取得使用者帳號名稱 printf("User name\t: %s\n", g_get_user_name()); // 取得目前所在路徑 printf("Current dir\t: %s\n", g_get_current_dir()); // 取得使用者家目錄 printf("Home dir\t: %s\n", g_get_home_dir()); // 取得暫存目錄 printf("Temp dir\t: %s\n", g_get_tmp_dir()); // 取得PATH環境變數 printf("PATH\t\t: %s\n", g_getenv("PATH")); // 設定CLASSPATH環境變數,FALSE表示若已設定則不覆寫 g_setenv("CLASSPATH", "D:\\Temp", FALSE); // 取得CLASSPATH環境變數 printf("CLASSPATH\t: %s\n", g_getenv("CLASSPATH")); // 取消CLASSPATH環境變數 g_unsetenv("CLASSPATH"); printf("CLASSPATH\t: %s\n", g_getenv("CLASSPATH")); return 0; }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; context = g_option_context_new("GêBR Maestro"); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print("option parsing failed: %s\n", error->message); exit(EXIT_FAILURE); } g_type_init(); g_thread_init(NULL); if (show_version) { fprintf(stdout, "%s (%s)\n", GEBR_VERSION NANOVERSION, gebr_version()); exit(EXIT_SUCCESS); } GebrMaestroSettings *ms = gebrm_app_create_configuration(); const gchar *nfsid = gebrm_app_get_nfsid(ms); const gchar *local_addr = g_get_host_name(); gchar *curr_version = NULL; curr_version = g_strdup_printf("%s (%s)\n", GEBR_VERSION NANOVERSION, gebr_version()); gboolean valid; valid = verify_singleton_lock(curr_version); const gchar *gebrd_location = g_find_program_in_path("gebrd"); if (nfsid) { gebr_maestro_settings_append_address(ms, nfsid, local_addr); gebr_maestro_settings_add_node(ms, nfsid, gebrd_location ? g_get_host_name() : ""); } gebr_maestro_settings_free(ms); // Singleton lock is valid and suggest the correct maestro if (valid) { g_free(curr_version); exit(0); } if (!interactive) fork_and_exit_main(); struct sigaction sa; sa.sa_handler = gebrm_remove_lock_and_quit; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGTERM, &sa, NULL) || sigaction(SIGINT, &sa, NULL) || sigaction(SIGQUIT, &sa, NULL) || sigaction(SIGSEGV, &sa, NULL)) perror("sigaction"); gebr_geoxml_init(); gebrm_app_create_folder_for_addr(local_addr); const gchar *path = gebrm_app_get_log_file_for_address(local_addr); gebr_log_set_default(path); GebrmApp *app = gebrm_app_singleton_get(); if (!gebrm_app_run(app, output_fd, curr_version)) exit(EXIT_FAILURE); g_free(curr_version); g_object_unref(app); gebr_geoxml_finalize(); return EXIT_SUCCESS; }
static InfXmppConnection* inf_test_certificate_validate_setup_client(InfIo* io, const gchar* ca_file, const gchar* remote_hostname, GError** error) { InfIpAddress* addr; InfTcpConnection* conn; InfXmppConnection* xmpp; InfCertificateCredentials* creds; GPtrArray* cas; int res; guint i; creds = inf_certificate_credentials_new(); if(ca_file != NULL) { cas = inf_cert_util_read_certificate(ca_file, NULL, error); if(cas == NULL) { inf_certificate_credentials_unref(creds); return NULL; } res = gnutls_certificate_set_x509_trust( inf_certificate_credentials_get(creds), (gnutls_x509_crt_t*)cas->pdata, cas->len ); for(i = 0; i < cas->len; ++i) gnutls_x509_crt_deinit(cas->pdata[i]); g_ptr_array_free(cas, TRUE); } addr = inf_ip_address_new_loopback4(); conn = inf_tcp_connection_new(io, addr, 6524); inf_ip_address_free(addr); xmpp = inf_xmpp_connection_new( conn, INF_XMPP_CONNECTION_CLIENT, g_get_host_name(), remote_hostname, INF_XMPP_CONNECTION_SECURITY_ONLY_TLS, creds, NULL, NULL ); inf_certificate_credentials_unref(creds); if(inf_tcp_connection_open(conn, error) == FALSE) { g_object_unref(conn); g_object_unref(xmpp); return NULL; } g_object_unref(conn); return xmpp; }
char * mpl_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; #if 0 GdkAppLaunchContextPrivate *priv; #endif GdkDisplay *display; GdkScreen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; #if 0 GIcon *icon; #endif guint32 timestamp; char *startup_id; #if 0 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv; if (priv->screen) { screen = priv->screen; display = gdk_screen_get_display (priv->screen); } else if (priv->display) { display = priv->display; screen = gdk_display_get_default_screen (display); } else { display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); } #else display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); #endif files_count = g_list_length (files); if (files_count == 0) description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); else if (files_count == 1) description = g_strdup_printf (_("Opening %s"), get_display_name (files->data)); else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; #if 0 if (priv->icon_name) icon_name = g_strdup (priv->icon_name); else { icon = NULL; if (priv->icon != NULL) icon = g_object_ref (priv->icon); else if (files_count == 1) icon = get_icon (files->data); if (icon == NULL) { icon = g_app_info_get_icon (info); g_object_ref (icon); } if (icon) icon_name = gicon_to_string (icon); g_object_unref (icon); } #endif binary_name = g_app_info_get_executable (info); #if 0 timestamp = priv->timestamp; if (timestamp == GDK_CURRENT_TIME) #endif timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen)); #if 0 if (priv->workspace > -1) workspace_str = g_strdup_printf ("%d", priv->workspace); else #endif workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); add_startup_timeout (screen, startup_id); return startup_id; }
static VALUE rg_s_host_name(G_GNUC_UNUSED VALUE self) { return CSTR2RVAL(g_get_host_name()); }
int main() { g_get_host_name(); return EXIT_SUCCESS; }
/* (Unix domain) socket support to replace the old FIFO code * (taken from Sylpheed, thanks) * Returns the created socket, -1 if an error occurred or -2 if another socket exists and files * were sent to it. */ gint socket_init(gint argc, gchar **argv) { gint sock; #ifdef G_OS_WIN32 HANDLE hmutex; HWND hwnd; socket_init_win32(); hmutex = CreateMutexA(NULL, FALSE, "Geany"); if (! hmutex) { geany_debug("cannot create Mutex\n"); return -1; } if (GetLastError() != ERROR_ALREADY_EXISTS) { /* To support multiple instances with different configuration directories (as we do on * non-Windows systems) we would need to use different port number s but it might be * difficult to get a port number which is unique for a configuration directory (path) * and which is unused. This port number has to be guessed by the first and new instance * and the only data is the configuration directory path. * For now we use one port number, that is we support only one instance at all. */ sock = socket_fd_open_inet(REMOTE_CMD_PORT); if (sock < 0) return -1; return sock; } sock = socket_fd_connect_inet(REMOTE_CMD_PORT); if (sock < 0) return -1; #else gchar *display_name = NULL; const gchar *hostname = g_get_host_name(); GdkDisplay *display = gdk_display_get_default(); gchar *p; /* On OS X with quartz backend gdk_display_get_name() returns hostname * using [NSHost currentHost] (it could return more or less whatever string * as display name is a X11 specific thing). This call can lead to network * query and block for several seconds so better skip it. */ #ifndef GDK_WINDOWING_QUARTZ if (display != NULL) display_name = g_strdup(gdk_display_get_name(display)); #endif if (display_name == NULL) display_name = g_strdup("NODISPLAY"); /* these lines are taken from dcopc.c in kdelibs */ if ((p = strrchr(display_name, '.')) > strrchr(display_name, ':') && p != NULL) *p = '\0'; /* remove characters that may not be acceptable in a filename */ for (p = display_name; *p; p++) { if (*p == ':' || *p == '/') *p = '_'; } if (socket_info.file_name == NULL) socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s", app->configdir, G_DIR_SEPARATOR, hostname, display_name); g_free(display_name); /* check whether the real user id is the same as this of the socket file */ check_socket_permissions(); sock = socket_fd_connect_unix(socket_info.file_name); if (sock < 0) { remove_socket_link_full(); /* deletes the socket file and the symlink */ return socket_fd_open_unix(socket_info.file_name); } #endif /* remote command mode, here we have another running instance and want to use it */ /* now we send the command line args */ if (argc > 1) { #ifdef G_OS_WIN32 /* first we send a request to retrieve the window handle and focus the window */ socket_fd_write_all(sock, "window\n", 7); if (socket_fd_read(sock, (gchar *)&hwnd, sizeof(hwnd)) == sizeof(hwnd)) SetForegroundWindow(hwnd); #endif send_open_command(sock, argc, argv); } if (cl_options.list_documents) { socket_get_document_list(sock); } socket_fd_close(sock); return -2; }
static gnutls_x509_crt_t* infinoted_startup_load_certificate(InfinotedLog* log, gboolean create_self_signed_certificate, gnutls_x509_privkey_t key, const gchar* certificate_file, const gchar* certificate_chain_file, guint* n_certificates, GError** error) { InfCertUtilDescription desc; gnutls_x509_crt_t* result; gnutls_x509_crt_t cert; GPtrArray* certs; GPtrArray* chain_certs; gboolean res; if(create_self_signed_certificate == TRUE) { if(infinoted_util_create_dirname(certificate_file, error) == FALSE) return NULL; infinoted_log_info(log, _("Generating self-signed certificate...")); desc.validity = 365 * 24 * 3600; desc.dn_common_name = g_get_host_name(); desc.san_dnsname = g_get_host_name(); cert = inf_cert_util_create_self_signed_certificate(key, &desc, error); if(cert == NULL) return NULL; res = inf_cert_util_write_certificate(&cert, 1, certificate_file, error); if(res == FALSE) { gnutls_x509_crt_deinit(cert); return NULL; } else { result = g_malloc(sizeof(gnutls_x509_crt_t)); *result = cert; *n_certificates = 1; } } else { certs = inf_cert_util_read_certificate(certificate_file, NULL, error); if(certs == NULL) return NULL; if(certificate_chain_file != NULL) { chain_certs = inf_cert_util_read_certificate(certificate_chain_file, certs, error); if(chain_certs == NULL) { result = (gnutls_x509_crt_t*)g_ptr_array_free(certs, FALSE); infinoted_startup_free_certificate_array(result, *n_certificates); return NULL; } } *n_certificates = certs->len; result = (gnutls_x509_crt_t*)g_ptr_array_free(certs, FALSE); } return result; }
int owl_variable_tty_set(owl_variable *v, const char *newval) { owl_zephyr_set_locationinfo(g_get_host_name(), newval); return owl_variable_string_set_default(v, newval); }
int vino_upnp_add_port (VinoUpnp *upnp, int port) { char *ext_port, *int_port, *desc; int err, local_port; char int_client_tmp[16], int_port_tmp[6]; g_return_val_if_fail (VINO_IS_UPNP (upnp), -1); if (!update_upnp_status (upnp)) return -1; vino_upnp_remove_port (upnp); local_port = port; do { ext_port = g_strdup_printf ("%d", local_port); dprintf (UPNP, "UPnP: Trying to forward port %d...: ", local_port); UPNP_GetSpecificPortMappingEntry (upnp->priv->urls->controlURL, upnp->priv->data->servicetype, ext_port, "TCP", int_client_tmp, int_port_tmp); if ( (strcmp (int_client_tmp, upnp->priv->lanaddr) == 0) && (strcmp (int_port_tmp, ext_port) == 0) ) { dprintf (UPNP, "UPnP: Found a previous redirect\n"); break; } else if (int_client_tmp[0]) { dprintf (UPNP, "Failed, this port is already forwarded to %s:%s\n", int_client_tmp, int_port_tmp); g_free (ext_port); } else { dprintf (UPNP, "OK, this port is free on the router\n"); break; } local_port++; } while (local_port < INT_MAX); if (local_port == INT_MAX) { dprintf (UPNP, "UPnP: Not forwarding any port, tried so much\n"); return -1; } int_port = g_strdup_printf ("%d", port); desc = g_strdup_printf ("VNC: %s@%s", g_get_user_name (), g_get_host_name ()); err = UPNP_AddPortMapping (upnp->priv->urls->controlURL, upnp->priv->data->servicetype, ext_port, int_port, upnp->priv->lanaddr, desc, "TCP"); if (err == 0) { upnp->priv->port = local_port; upnp->priv->internal_port = port; dprintf (UPNP, "UPnP: Successfuly forwarded port %d\n", local_port); } else dprintf (UPNP, "Failed to forward port %d, with status %d\n", local_port, err); g_free (ext_port); g_free (int_port); g_free (desc); return upnp->priv->port; }