GPtrArray* get_serial_array(GError **error) { GDBusProxy *udisks_proxy=0; GVariant *device_list; GPtrArray* rv=0; udisks_proxy = g_dbus_proxy_new_for_bus_sync ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL /* info */ , DBUS_COMMON_NAME_UDISKS, DBUS_OBJECT_PATH_UDISKS_ROOT, DBUS_INTERFACE_UDISKS, NULL /* cancellable */ , error ); if(udisks_proxy == NULL) { g_prefix_error (error, "Failed to create dBus proxy:"); goto udisks_proxy_create_error; } // Call ListNames method, wait for reply device_list = g_dbus_proxy_call_sync ( udisks_proxy, "EnumerateDevices", NULL /* paramatrs */, G_DBUS_CALL_FLAGS_NONE, -1 /* timeout_msec */, NULL /* cancellable */, error); if(device_list == NULL) { g_prefix_error (error, "Failed to call EnumerateDevices udisks method:"); goto enumerate_device_error; } // g_print("%s: \n", ); { GVariantIter *iter; gchar *device; g_variant_get (device_list, "(ao)", &iter); rv = g_ptr_array_new(); g_ptr_array_set_free_func(rv, g_free); while (g_variant_iter_loop (iter, "o", &device)) { GDBusProxy *device_proxy = 0; device_proxy = g_dbus_proxy_new_for_bus_sync ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL /* info */ , DBUS_COMMON_NAME_UDISKS, device, DBUS_INTERFACE_UDISKS_DEVICE, NULL /* cancellable */ , error ); if(device_proxy == NULL) { g_prefix_error (error, "Failed to create dBus devices proxy for %s device:", device); g_ptr_array_unref(rv); rv=0; goto devices_proxy_create_error; } if( dbus_get_bool_property(device_proxy, "DeviceIsDrive") && ! dbus_get_bool_property(device_proxy, "DeviceIsRemovable") ) { gchar* full_serial=0; gchar *vendor = dbus_get_string_property(device_proxy, "DriveVendor"); gchar *model = dbus_get_string_property(device_proxy, "DriveModel"); gchar *revision = dbus_get_string_property(device_proxy, "DriveRevision"); gchar *serial = dbus_get_string_property(device_proxy, "DriveSerial"); gchar *wwn = dbus_get_string_property(device_proxy, "DriveWwn"); full_serial = g_strdup_printf("%s-%s-%s-%s", model, revision, serial, wwn); g_ptr_array_add(rv, full_serial); g_free(vendor); g_free(model); g_free(revision); g_free(serial); g_free(wwn); } g_object_unref (device_proxy); } devices_proxy_create_error: g_variant_iter_free(iter); } g_variant_unref(device_list); enumerate_device_error: g_object_unref (udisks_proxy); udisks_proxy_create_error: return rv; }
int main (int argc, char **argv) { GstPlay *play; GPtrArray *playlist; gboolean print_version = FALSE; gboolean interactive = FALSE; /* FIXME: maybe enable by default? */ gboolean shuffle = FALSE; gboolean repeat = FALSE; gdouble volume = 1.0; gchar **filenames = NULL; gchar **uris; guint num, i; GError *err = NULL; GOptionContext *ctx; gchar *playlist_file = NULL; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version information and exit", NULL}, {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle, "Shuffle playlist", NULL}, {"interactive", 0, 0, G_OPTION_ARG_NONE, &interactive, "Interactive control via keyboard", NULL}, {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume, "Volume", NULL}, {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file, "Playlist file containing input media files", NULL}, {"loop", 0, 0, G_OPTION_ARG_NONE, &repeat, "Repeat all", NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; g_set_prgname ("gst-play"); ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); g_clear_error (&err); g_option_context_free (ctx); return 1; } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play"); if (print_version) { gchar *version_str; version_str = gst_version_string (); g_print ("%s version %s\n", g_get_prgname (), "1.0"); g_print ("%s\n", version_str); g_free (version_str); g_free (playlist_file); return 0; } playlist = g_ptr_array_new (); if (playlist_file != NULL) { gchar *playlist_contents = NULL; gchar **lines = NULL; if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) { lines = g_strsplit (playlist_contents, "\n", 0); num = g_strv_length (lines); for (i = 0; i < num; i++) { if (lines[i][0] != '\0') { GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]); add_to_playlist (playlist, lines[i]); } } g_strfreev (lines); g_free (playlist_contents); } else { g_printerr ("Could not read playlist: %s\n", err->message); g_clear_error (&err); } g_free (playlist_file); playlist_file = NULL; } if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) { g_printerr ("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...", "gst-play"); g_printerr ("\n\n"), g_printerr ("%s\n\n", "You must provide at least one filename or URI to play."); /* No input provided. Free array */ g_ptr_array_free (playlist, TRUE); return 1; } /* fill playlist */ if (filenames != NULL && *filenames != NULL) { num = g_strv_length (filenames); for (i = 0; i < num; ++i) { GST_LOG ("command line argument: %s", filenames[i]); add_to_playlist (playlist, filenames[i]); } g_strfreev (filenames); } num = playlist->len; g_ptr_array_add (playlist, NULL); uris = (gchar **) g_ptr_array_free (playlist, FALSE); if (shuffle) shuffle_uris (uris, num); /* prepare */ play = play_new (uris, volume); play->repeat = repeat; if (interactive) { if (gst_play_kb_set_key_handler (keyboard_cb, play)) { atexit (restore_terminal); } else { g_print ("Interactive keyboard handling in terminal not available.\n"); } } /* play */ do_play (play); /* clean up */ play_free (play); g_print ("\n"); return 0; }
/* ** Perform a reduce action and the shift that must immediately ** follow the reduce. */ static void yy_reduce( yyParser *yypParser, /* The parser */ int yyruleno /* Number of the rule by which to reduce */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ BbParseARG_FETCH; yymsp = &yypParser->yystack[yypParser->yyidx]; #ifndef NDEBUG if( yyTraceFILE && yyruleno>=0 && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){ fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, yyRuleName[yyruleno]); } #endif /* NDEBUG */ switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: ** case 0: ** #line <lineno> <grammarfile> ** { ... } // User supplied code ** #line <lineno> <thisfile> ** break; */ case 0: #line 28 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[-2].minor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, "add"); yy_destructor(2,&yymsp[-1].minor); } #line 592 "core/bb-p.c" break; case 1: #line 34 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[-2].minor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, "mul"); yy_destructor(4,&yymsp[-1].minor); } #line 602 "core/bb-p.c" break; case 2: #line 40 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[-2].minor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, "sub"); yy_destructor(3,&yymsp[-1].minor); } #line 612 "core/bb-p.c" break; case 3: #line 46 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, "neg"); yy_destructor(3,&yymsp[-1].minor); } #line 621 "core/bb-p.c" break; case 4: #line 51 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[-2].minor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, "div"); yy_destructor(5,&yymsp[-1].minor); } #line 631 "core/bb-p.c" break; case 5: #line 58 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_append_program (yygotominor.yy5, yymsp[-1].minor.yy5); yy_destructor(7,&yymsp[-2].minor); yy_destructor(8,&yymsp[0].minor); } #line 639 "core/bb-p.c" break; case 6: #line 61 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_append_program (yygotominor.yy5, yymsp[-2].minor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[0].minor.yy5); yy_destructor(1,&yymsp[-1].minor); } #line 647 "core/bb-p.c" break; case 7: #line 65 "core/bb-p.lemon" { GValue value; char *end; gdouble nvalue = strtod (yymsp[0].minor.yy0, &end); if (yymsp[0].minor.yy0 == end) g_error ("error parsing number from %s", yymsp[0].minor.yy0); memset (&value, 0, sizeof (value)); if (strcmp (end, "sec") == 0 || strcmp (end, "s") == 0) { g_value_init (&value, BB_TYPE_DURATION); bb_value_set_duration (&value, BB_DURATION_UNITS_SECONDS, nvalue); } else if (strcmp (end, "samp") == 0) { g_value_init (&value, BB_TYPE_DURATION); bb_value_set_duration (&value, BB_DURATION_UNITS_SAMPLES, nvalue); } else if (strcmp (end, "beat") == 0 || strcmp (end, "b") == 0) { g_value_init (&value, BB_TYPE_DURATION); bb_value_set_duration (&value, BB_DURATION_UNITS_BEATS, nvalue); } else if (strcmp (end, "%") == 0) { g_value_init (&value, BB_TYPE_DURATION); bb_value_set_duration (&value, BB_DURATION_UNITS_NOTE_LENGTHS, nvalue * 0.01); } else if (*end != 0) { g_error ("garbage after number (garbage is '%s'", end); } else { g_value_init (&value, G_TYPE_DOUBLE); g_value_set_double (&value, nvalue); } yygotominor.yy5 = bb_program_new (); bb_program_add_push (yygotominor.yy5, &value); } #line 688 "core/bb-p.c" break; case 8: #line 104 "core/bb-p.lemon" { /* find or allocate parameter */ guint i; for (i = 0; i < context->pspec_array->len; i++) { GParamSpec *p = g_ptr_array_index (context->pspec_array, i); if (bb_param_spec_names_equal (p->name, yymsp[0].minor.yy0)) break; } if (i == context->pspec_array->len) { for (i = 0; i < context->n_source_pspecs; i++) if (bb_param_spec_names_equal (yymsp[0].minor.yy0, context->source_pspecs[i]->name)) break; if (i == context->n_source_pspecs) { g_message ("warning: allocating double parameter named %s", yymsp[0].minor.yy0); g_ptr_array_add (context->pspec_array, g_param_spec_double (yymsp[0].minor.yy0,yymsp[0].minor.yy0,NULL, -1e9,1e9,0,G_PARAM_READWRITE)); } else g_ptr_array_add (context->pspec_array, context->source_pspecs[i]); i = context->pspec_array->len - 1; } yygotominor.yy5 = bb_program_new (); bb_program_add_push_param (yygotominor.yy5, i); } #line 718 "core/bb-p.c" break; case 9: #line 132 "core/bb-p.lemon" { BbBuiltinFunc f; yygotominor.yy5 = bb_program_new (); f = bb_builtin_lookup (yymsp[-3].minor.yy0); if (f != NULL) { bb_program_append_program (yygotominor.yy5, yymsp[-1].minor.yy5); bb_program_add_builtin (yygotominor.yy5, yymsp[-3].minor.yy0, f); } else { /* TODO: try resolving the function now */ bb_program_add_function_begin (yygotominor.yy5); bb_program_append_program (yygotominor.yy5, yymsp[-1].minor.yy5); bb_program_add_lazy_function (yygotominor.yy5, yymsp[-3].minor.yy0); } yy_destructor(7,&yymsp[-2].minor); yy_destructor(8,&yymsp[0].minor); } #line 740 "core/bb-p.c" break; case 10: #line 149 "core/bb-p.lemon" { BbBuiltinFunc f; yygotominor.yy5 = bb_program_new (); f = bb_builtin_lookup (yymsp[-2].minor.yy0); if (f != NULL) bb_program_add_builtin (yygotominor.yy5, yymsp[-2].minor.yy0, f); else { bb_program_add_function_begin (yygotominor.yy5); bb_program_add_lazy_function (yygotominor.yy5, yymsp[-2].minor.yy0); } yy_destructor(7,&yymsp[-1].minor); yy_destructor(8,&yymsp[0].minor); } #line 757 "core/bb-p.c" break; case 11: #line 163 "core/bb-p.lemon" { GType type = g_type_from_name (yymsp[-2].minor.yy0); guint v; GValue ev; if (type == 0 || !g_type_is_a (type, G_TYPE_ENUM)) g_error ("no enum named '%s'", yymsp[-2].minor.yy0); if (!bb_enum_value_lookup (type, yymsp[0].minor.yy0, &v)) g_error ("no value of %s named %s", yymsp[-2].minor.yy0, yymsp[0].minor.yy0); memset (&ev, 0, sizeof (ev)); g_value_init (&ev, type); g_value_set_enum (&ev, v); yygotominor.yy5 = bb_program_new (); bb_program_add_push (yygotominor.yy5, &ev); yy_destructor(6,&yymsp[-1].minor); } #line 775 "core/bb-p.c" break; case 12: #line 178 "core/bb-p.lemon" { yygotominor.yy5 = bb_program_new (); bb_program_add_push_special (yygotominor.yy5, BB_VM_SPECIAL_ARRAY_BEGIN); bb_program_append_program (yygotominor.yy5, yymsp[-1].minor.yy5); bb_program_add_builtin (yygotominor.yy5, "create_array", bb_builtin_create_array); yy_destructor(11,&yymsp[-2].minor); yy_destructor(12,&yymsp[0].minor); } #line 785 "core/bb-p.c" break; case 13: #line 184 "core/bb-p.lemon" { GValue v = BB_VALUE_INIT; yygotominor.yy5 = bb_program_new (); g_value_init (&v, G_TYPE_STRING); g_value_set_string (&v, yymsp[0].minor.yy0); bb_program_add_push (yygotominor.yy5, &v); } #line 794 "core/bb-p.c" break; case 14: #line 191 "core/bb-p.lemon" { if (context->program) { g_warning ("got two programs"); } else { context->program = bb_program_ref (yymsp[0].minor.yy5); } } #line 803 "core/bb-p.c" break; }; yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yypParser,yygoto); if( yyact < YYNSTATE ){ yy_shift(yypParser,yyact,yygoto,&yygotominor); }else if( yyact == YYNSTATE + YYNRULE + 1 ){ yy_accept(yypParser); } }
static GPtrArray * parse_pkgdb_collections_data (const gchar *data, gssize length, GError **error) { g_autoptr(JsonParser) parser = NULL; GPtrArray *distros = NULL; JsonArray *collections; JsonObject *root; gboolean ret; guint i; parser = json_parser_new (); ret = json_parser_load_from_data (parser, data, length, error); if (!ret) return NULL; root = json_node_get_object (json_parser_get_root (parser)); if (root == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "no root object"); return NULL; } collections = json_object_get_array_member (root, "collections"); if (collections == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "no collections object"); return NULL; } distros = g_ptr_array_new_with_free_func ((GDestroyNotify) distro_info_free); for (i = 0; i < json_array_get_length (collections); i++) { DistroInfo *distro_info; JsonObject *item; DistroStatus status; const gchar *name; const gchar *status_str; const gchar *version_str; gchar *endptr = NULL; guint64 version; item = json_array_get_object_element (collections, i); if (item == NULL) continue; name = json_object_get_string_member (item, "name"); if (name == NULL) continue; status_str = json_object_get_string_member (item, "status"); if (status_str == NULL) continue; if (g_strcmp0 (status_str, "Active") == 0) status = DISTRO_STATUS_ACTIVE; else if (g_strcmp0 (status_str, "Under Development") == 0) status = DISTRO_STATUS_DEVEL; else if (g_strcmp0 (status_str, "EOL") == 0) status = DISTRO_STATUS_EOL; else continue; version_str = json_object_get_string_member (item, "version"); if (version_str == NULL) continue; version = g_ascii_strtoull (version_str, &endptr, 10); if (endptr == version_str || version > G_MAXUINT) continue; distro_info = g_slice_new0 (DistroInfo); distro_info->name = g_strdup (name); distro_info->status = status; distro_info->version = (guint) version; g_ptr_array_add (distros, distro_info); } return distros; }
static void subprocess_wait_cb (GObject *object, GAsyncResult *res, gpointer user_data) { GSubprocess *subprocess = (GSubprocess *)object; g_autofree gchar *input_prefix = NULL; g_autoptr(IdeDiagnostics) local_diags = NULL; g_autoptr(GTask) task = user_data; g_autoptr(GPtrArray) array = NULL; g_autoptr(GDataInputStream) stderr_data_input = NULL; GInputStream *stderr_input = NULL; g_autoptr(IdeGettextDiagnostics) diags = NULL; g_autoptr(GError) error = NULL; TranslationUnit *unit; g_assert (G_IS_SUBPROCESS (subprocess)); g_assert (G_IS_TASK (task)); unit = g_task_get_task_data (task); g_assert (unit != NULL); if (!g_subprocess_wait_finish (subprocess, res, &error)) { g_task_return_error (task, g_steal_pointer (&error)); return; } array = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref); if (g_subprocess_get_exit_status (subprocess) == 0) goto out; stderr_input = g_subprocess_get_stderr_pipe (subprocess); stderr_data_input = g_data_input_stream_new (stderr_input); input_prefix = g_strdup_printf ("%s:", ide_unsaved_file_get_temp_path (unit->unsaved_file)); for (;;) { g_autofree gchar *line = NULL; gsize length; line = g_data_input_stream_read_line (stderr_data_input, &length, g_task_get_cancellable (task), &error); if (line == NULL) break; if (g_str_has_prefix (line, input_prefix)) { gchar *p = line + strlen (input_prefix); if (g_ascii_isdigit (*p)) { gulong line_number = strtoul (p, &p, 10); IdeSourceLocation *loc; IdeDiagnostic *diag; loc = ide_source_location_new (unit->file, line_number - 1, 0, 0); diag = ide_diagnostic_new (IDE_DIAGNOSTIC_WARNING, g_strstrip (p + 1), loc); g_ptr_array_add (array, diag); } } } out: local_diags = ide_diagnostics_new (g_steal_pointer (&array)); diags = g_object_new (IDE_TYPE_GETTEXT_DIAGNOSTICS, "diagnostics", local_diags, "sequence", ide_unsaved_file_get_sequence (unit->unsaved_file), NULL); g_task_return_pointer (task, g_steal_pointer (&diags), g_object_unref); }
static BraseroBurnResult brasero_readom_set_argv (BraseroProcess *process, GPtrArray *argv, GError **error) { BraseroBurnResult result = FALSE; BraseroTrackType *output = NULL; BraseroImageFormat format; BraseroJobAction action; BraseroReadom *readom; BraseroMedium *medium; BraseroDrive *drive; BraseroTrack *track; BraseroMedia media; gchar *outfile_arg; gchar *dev_str; readom = BRASERO_READOM (process); /* This is a kind of shortcut */ brasero_job_get_action (BRASERO_JOB (process), &action); if (action == BRASERO_JOB_ACTION_SIZE) return brasero_readom_get_size (readom, error); g_ptr_array_add (argv, g_strdup ("readom")); brasero_job_get_current_track (BRASERO_JOB (readom), &track); drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track)); if (!brasero_drive_get_device (drive)) return BRASERO_BURN_ERR; dev_str = g_strdup_printf ("dev=%s", brasero_drive_get_device (drive)); g_ptr_array_add (argv, dev_str); g_ptr_array_add (argv, g_strdup ("-nocorr")); medium = brasero_drive_get_medium (drive); media = brasero_medium_get_status (medium); output = brasero_track_type_new (); brasero_job_get_output_type (BRASERO_JOB (readom), output); format = brasero_track_type_get_image_format (output); brasero_track_type_free (output); if ((media & BRASERO_MEDIUM_DVD) && format != BRASERO_IMAGE_FORMAT_BIN) { g_set_error (error, BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, _("An internal error occurred")); return BRASERO_BURN_ERR; } if (format == BRASERO_IMAGE_FORMAT_CLONE) { /* NOTE: with this option the sector size is 2448 * because it is raw96 (2352+96) otherwise it is 2048 */ g_ptr_array_add (argv, g_strdup ("-clone")); } else if (format == BRASERO_IMAGE_FORMAT_BIN) { g_ptr_array_add (argv, g_strdup ("-noerror")); /* don't do it for clone since we need the entire disc */ result = brasero_readom_argv_set_iso_boundary (readom, argv, error); if (result != BRASERO_BURN_OK) return result; } else BRASERO_JOB_NOT_SUPPORTED (readom); if (brasero_job_get_fd_out (BRASERO_JOB (readom), NULL) != BRASERO_BURN_OK) { gchar *image; if (format != BRASERO_IMAGE_FORMAT_CLONE && format != BRASERO_IMAGE_FORMAT_BIN) BRASERO_JOB_NOT_SUPPORTED (readom); result = brasero_job_get_image_output (BRASERO_JOB (readom), &image, NULL); if (result != BRASERO_BURN_OK) return result; outfile_arg = g_strdup_printf ("-f=%s", image); g_ptr_array_add (argv, outfile_arg); g_free (image); } else if (format == BRASERO_IMAGE_FORMAT_BIN) { outfile_arg = g_strdup ("-f=-"); g_ptr_array_add (argv, outfile_arg); } else /* unfortunately raw images can't be piped out */ BRASERO_JOB_NOT_SUPPORTED (readom); brasero_job_set_use_average_rate (BRASERO_JOB (process), TRUE); return BRASERO_BURN_OK; }
void mcview_growbuf_read_until (mcview_t * view, off_t ofs) { ssize_t nread; byte *p; size_t bytesfree; gboolean short_read; assert (view->growbuf_in_use); if (view->growbuf_finished) return; short_read = FALSE; while (mcview_growbuf_filesize (view) < ofs || short_read) { if (view->growbuf_lastindex == VIEW_PAGE_SIZE) { /* Append a new block to the growing buffer */ byte *newblock = g_try_malloc (VIEW_PAGE_SIZE); if (newblock == NULL) return; g_ptr_array_add (view->growbuf_blockptr, newblock); view->growbuf_lastindex = 0; } p = g_ptr_array_index (view->growbuf_blockptr, view->growbuf_blockptr->len - 1) + view->growbuf_lastindex; bytesfree = VIEW_PAGE_SIZE - view->growbuf_lastindex; if (view->datasource == DS_STDIO_PIPE) { nread = fread (p, 1, bytesfree, view->ds_stdio_pipe); if (nread == 0) { view->growbuf_finished = TRUE; (void) pclose (view->ds_stdio_pipe); mcview_display (view); close_error_pipe (D_NORMAL, NULL); view->ds_stdio_pipe = NULL; return; } } else { assert (view->datasource == DS_VFS_PIPE); do { nread = mc_read (view->ds_vfs_pipe, p, bytesfree); } while (nread == -1 && errno == EINTR); if (nread == -1 || nread == 0) { view->growbuf_finished = TRUE; (void) mc_close (view->ds_vfs_pipe); view->ds_vfs_pipe = -1; return; } } short_read = ((size_t) nread < bytesfree); view->growbuf_lastindex += nread; } }
void Trace_AppendSignal (struct callback_ *cb, unsigned long long time) { // printf ("Trace_AppendSignal %lld\n", time); #ifdef DO_PATTERN_ANALYSIS int chan_num, int event_type; int chan_num = (((int) cb) - ((int) channel)) / sizeof (struct chan); int event_type = ((((int) cb) - ((int) channel)) % sizeof (struct chan)) / sizeof (struct callback_); char *typekw[4] = { "requp", "reqdown", "ackup", "ackdown" }; if (type >= 4) return; // fprintf (TraceFile, "signal %d %d\n", channum, type); if (channel[channum].traceType & TRACETYPE_HHH) { WriteAnimationInfo_time (time); fprintf (TraceFile, "signal %d %s (time %lld)\n", chan_num, typekw[event_type], time); PatternAnalysis_AppendSignal (chan_num, event_type, time); } #endif /* struct EventTraceItem *trace_item = g_new (struct EventTraceItem, 1); trace_item->chan_num = chan_num; trace_item->event_type = event_type; trace_item->time= time; */ int delay = time - first_uncommited_timestep; if (delay >= event_trace_time_span || event_trace_time_span == 0) { struct event_trace_time_slot *old_event_trace = event_trace; int old_event_trace_time_span = event_trace_time_span; int first_time_slot = (event_trace_time_span == 0) ? 0 : first_uncommited_timestep % event_trace_time_span; if ((event_trace == NULL) && (event_trace_time_span == 0)) event_trace_time_span = 64; //INIT_NUM_SLOTS while (event_trace_time_span < (delay + 1)) event_trace_time_span *= 2; event_trace = (struct event_trace_time_slot *) calloc (event_trace_time_span, sizeof (struct event_trace_time_slot)); if (old_event_trace != NULL) { int offset_first = (first_uncommited_timestep % event_trace_time_span) - (first_uncommited_timestep % old_event_trace_time_span); int offset_0 = (((first_uncommited_timestep / old_event_trace_time_span) + 1) * old_event_trace_time_span) % event_trace_time_span; /* copy things *below* first_time_slot */ memcpy (event_trace + offset_0, old_event_trace, first_time_slot * sizeof (struct event_trace_time_slot)); /* copy things from first_time_slot up to old_event_trace_time_span */ memcpy (&(event_trace[first_time_slot + offset_first]), &(old_event_trace[first_time_slot]), (old_event_trace_time_span - first_time_slot) * sizeof (struct event_trace_time_slot)); g_free (old_event_trace); } if (DebugFlag != 0) fprintf (stderr, "INFO: enlarging event_trace_time_span to %d at simulation time %lld\n", event_trace_time_span, time); } int slot = time % event_trace_time_span; if (!event_trace[slot].callbacks) event_trace[slot].callbacks = g_ptr_array_new (); g_ptr_array_add (event_trace[slot].callbacks, cb); }
static void add_group_to_array (struct group *gr, gpointer user_data) { g_ptr_array_add (user_data, g_strdup (gr->gr_name)); }
gboolean upload_results(AppData *app_data) { GError *error = NULL; SoupURI *result_uri = NULL; guint ret = 0; SoupSession *session; SoupMessage *server_msg; SoupRequest *request; gchar *form_data; GHashTable *data_table = g_hash_table_new (NULL, NULL); result_uri = soup_uri_new (app_data->server); if (result_uri == NULL) { g_set_error (&error, RESTRAINT_ERROR, RESTRAINT_PARSE_ERROR_BAD_SYNTAX, "Malformed server url: %s", app_data->server); goto cleanup; } session = soup_session_new_with_options("timeout", 3600, NULL); g_hash_table_insert (data_table, "path", app_data->test_name); g_hash_table_insert (data_table, "result", app_data->test_result); // if AVC_ERROR=+no_avc_check then disable the selinux check plugin // This is for legacy rhts tests.. please use --disable-plugin gchar *avc_error = getenv("AVC_ERROR"); if (g_strcmp0 (avc_error, "+no_avc_check") == 0) { g_ptr_array_add (app_data->disable_plugin, g_strdup ("10_avc_check")); } if (app_data->disable_plugin->pdata) { g_ptr_array_add (app_data->disable_plugin, NULL); g_hash_table_insert (data_table, "disable_plugin", g_strjoinv (" ", (gchar **)app_data->disable_plugin->pdata)); } if (app_data->no_plugins) g_hash_table_insert (data_table, "no_plugins", &app_data->no_plugins); if (app_data->score) g_hash_table_insert (data_table, "score", app_data->score); if (app_data->result_msg) g_hash_table_insert (data_table, "message", app_data->result_msg); request = (SoupRequest *)soup_session_request_http_uri (session, "POST", result_uri, &error); server_msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request)); g_object_unref(request); form_data = soup_form_encode_hash (data_table); soup_message_set_request (server_msg, "application/x-www-form-urlencoded", SOUP_MEMORY_TAKE, form_data, strlen (form_data)); g_print ("** %s %s Score:%s\n", app_data->test_name, app_data->test_result, app_data->score != NULL ? app_data->score : "N/A"); ret = soup_session_send_message (session, server_msg); if (SOUP_STATUS_IS_SUCCESSFUL (ret)) { gchar *location = g_strdup_printf ("%s/logs/", soup_message_headers_get_one (server_msg->response_headers, "Location")); soup_uri_free (result_uri); result_uri = soup_uri_new (location); g_free (location); if (app_data->outputfile != NULL && g_file_test (app_data->outputfile, G_FILE_TEST_EXISTS)) { g_print ("Uploading %s ", app_data->filename); if (upload_file (session, app_data->outputfile, app_data->filename, result_uri, &error)) { g_print ("done\n"); } else { g_print ("failed\n"); } } } else { g_warning ("Failed to submit result, status: %d Message: %s\n", ret, server_msg->reason_phrase); } g_object_unref(server_msg); soup_session_abort(session); g_object_unref(session); cleanup: g_hash_table_destroy(data_table); if (result_uri != NULL) { soup_uri_free (result_uri); } if (error) { g_printerr("%s [%s, %d]\n", error->message, g_quark_to_string(error->domain), error->code); g_clear_error(&error); return FALSE; } else { return TRUE; } }
static gboolean builder_options_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node) { if (strcmp (property_name, "arch") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_boxed (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_OBJECT) { JsonObject *object = json_node_get_object (property_node); g_autoptr(GHashTable) hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); g_autoptr(GList) members = NULL; GList *l; members = json_object_get_members (object); for (l = members; l != NULL; l = l->next) { const char *member_name = l->data; JsonNode *val; GObject *option; val = json_object_get_member (object, member_name); option = json_gobject_deserialize (BUILDER_TYPE_OPTIONS, val); if (option == NULL) return FALSE; g_hash_table_insert (hash, g_strdup (member_name), option); } g_value_set_boxed (value, hash); return TRUE; } return FALSE; } else if (strcmp (property_name, "env") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_boxed (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_OBJECT) { JsonObject *object = json_node_get_object (property_node); g_autoptr(GPtrArray) env = g_ptr_array_new_with_free_func (g_free); g_autoptr(GList) members = NULL; GList *l; members = json_object_get_members (object); for (l = members; l != NULL; l = l->next) { const char *member_name = l->data; JsonNode *val; const char *val_str; val = json_object_get_member (object, member_name); val_str = json_node_get_string (val); if (val_str == NULL) return FALSE; g_ptr_array_add (env, g_strdup_printf ("%s=%s", member_name, val_str)); } g_ptr_array_add (env, NULL); g_value_take_boxed (value, g_ptr_array_free (g_steal_pointer (&env), FALSE)); return TRUE; } return FALSE; } else { return json_serializable_default_deserialize_property (serializable, property_name, value, pspec, property_node); } }
/** * The function called by the parser when the text between tags is read. * This function is responsible for filling in the variables (e.g. team names) * when a file gets loaded. * @see The GLib manual (Simple XML parser). */ void xml_cup_read_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error) { #ifdef DEBUG printf("xml_cup_read_text\n"); #endif gchar buf[text_len + 1]; gint int_value; gfloat float_value; strncpy(buf, text, text_len); buf[text_len] = '\0'; int_value = (gint)g_ascii_strtod(buf, NULL); float_value = (gfloat)g_ascii_strtod(buf, NULL); if(state == STATE_NAME) misc_string_assign(&new_cup.name, buf); else if(state == STATE_SHORT_NAME) misc_string_assign(&new_cup.short_name, buf); else if(state == STATE_SYMBOL) misc_string_assign(&new_cup.symbol, buf); else if(state == STATE_SID) misc_string_assign(&new_cup.sid, buf); else if(state == STATE_GROUP) new_cup.group = int_value; else if(state == STATE_LAST_WEEK) new_cup.last_week = int_value; else if(state == STATE_PROPERTY) g_ptr_array_add(new_cup.properties, g_strdup(buf)); else if(state == STATE_ADD_WEEK) new_cup.add_week = int_value; else if(state == STATE_WEEK_GAP) new_cup.week_gap = int_value; else if(state == STATE_WEEK_BREAK) new_week_break.week_number = int_value; else if(state == STATE_SKIP_WEEKS_WITH) g_ptr_array_add(new_cup.skip_weeks_with, g_strdup(buf)); else if(state == STATE_YELLOW_RED) new_cup.yellow_red = int_value; else if(state == STATE_TALENT_DIFF) new_cup.talent_diff = (float_value / 10000); else if(state == STATE_CUP_ROUND_NAME) new_round.name = g_strdup(buf); else if(state == STATE_CUP_ROUND_NEW_TEAMS) new_round.new_teams = int_value; else if(state == STATE_CUP_ROUND_BYES) new_round.byes = int_value; else if(state == STATE_CUP_ROUND_HOME_AWAY) new_round.home_away = int_value; else if(state == STATE_CUP_ROUND_REPLAY) new_round.replay = int_value; else if(state == STATE_CUP_ROUND_NEUTRAL) new_round.neutral = int_value; else if(state == STATE_CUP_ROUND_DELAY) new_round.delay = int_value; else if(state == STATE_CUP_ROUND_RANDOMISE_TEAMS) new_round.randomise_teams = int_value; else if(state == STATE_CUP_ROUND_NUMBER_OF_GROUPS) new_round.round_robin_number_of_groups = int_value; else if(state == STATE_CUP_ROUND_NUMBER_OF_ADVANCE) new_round.round_robin_number_of_advance = int_value; else if(state == STATE_CUP_ROUND_NUMBER_OF_BEST_ADVANCE) new_round.round_robin_number_of_best_advance = int_value; else if(state == STATE_CUP_ROUND_ROUND_ROBINS) new_round.round_robins = int_value; else if(state == STATE_CUP_ROUND_BREAK) league_cup_fill_rr_breaks(new_round.rr_breaks, buf); else if(state == STATE_CUP_ROUND_WAIT) new_wait.cup_sid = g_strdup(buf); else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_START) g_array_append_val(new_round.two_match_weeks[0], int_value); else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK_END) g_array_append_val(new_round.two_match_weeks[1], int_value); else if(state == STATE_CUP_ROUND_TWO_MATCH_WEEK) new_round.two_match_week = int_value; else if(state == STATE_CHOOSE_TEAM_SID) misc_string_assign(&new_choose_team.sid, buf); else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS) new_choose_team.number_of_teams = int_value; else if(state == STATE_CHOOSE_TEAM_START_IDX) new_choose_team.start_idx = int_value; else if(state == STATE_CHOOSE_TEAM_END_IDX) new_choose_team.end_idx = int_value; else if(state == STATE_CHOOSE_TEAM_RANDOMLY) new_choose_team.randomly = int_value; else if(state == STATE_CHOOSE_TEAM_GENERATE) new_choose_team.generate = int_value; else if(state == STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK) new_choose_team.skip_group_check = int_value; else if(state == STATE_CHOOSE_TEAM_FROM_TABLE) new_choose_team.from_table = int_value; else if(state == STATE_CHOOSE_TEAM_PRELOAD) new_choose_team.preload = int_value; }
static void populate_cache (DzlTaskCache *cache, gconstpointer key, GTask *task, gpointer user_data) { IdeGettextDiagnosticProvider *self = user_data; g_autoptr(IdeUnsavedFile) unsaved_file = NULL; g_autoptr(GSubprocess) subprocess = NULL; GtkSourceLanguage *language; const gchar *language_id; const gchar *xgettext_lang; const gchar *temp_path; TranslationUnit *unit; IdeFile *file = (IdeFile *)key; GCancellable *cancellable; g_autoptr(GError) error = NULL; GPtrArray *args; g_assert (DZL_IS_TASK_CACHE (cache)); g_assert (IDE_IS_FILE (file)); g_assert (IDE_IS_GETTEXT_DIAGNOSTIC_PROVIDER (self)); cancellable = g_task_get_cancellable (task); if (NULL == (unsaved_file = get_unsaved_file (self, file))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Failed to locate file contents"); return; } if (NULL == (language = ide_file_get_language (file)) || NULL == (language_id = gtk_source_language_get_id (language)) || NULL == (xgettext_lang = id_to_xgettext_language (language_id))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Failed to determine language type"); return; } if (!ide_unsaved_file_persist (unsaved_file, cancellable, &error)) { g_task_return_error (task, g_steal_pointer (&error)); return; } temp_path = ide_unsaved_file_get_temp_path (unsaved_file); g_assert (temp_path != NULL); args = g_ptr_array_new (); g_ptr_array_add (args, "xgettext"); g_ptr_array_add (args, "--check=ellipsis-unicode"); g_ptr_array_add (args, "--check=quote-unicode"); g_ptr_array_add (args, "--check=space-ellipsis"); g_ptr_array_add (args, "-k_"); g_ptr_array_add (args, "-kN_"); g_ptr_array_add (args, "-L"); g_ptr_array_add (args, (gchar *)xgettext_lang); g_ptr_array_add (args, "-o"); g_ptr_array_add (args, "-"); g_ptr_array_add (args, (gchar *)temp_path); g_ptr_array_add (args, NULL); #ifdef IDE_ENABLE_TRACE { g_autofree gchar *str = NULL; str = g_strjoinv (" ", (gchar **)args->pdata); IDE_TRACE_MSG ("Launching '%s'", str); } #endif subprocess = g_subprocess_newv ((const gchar * const *)args->pdata, G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &error); g_ptr_array_free (args, TRUE); if (subprocess == NULL) { g_task_return_error (task, g_steal_pointer (&error)); return; } unit = g_slice_new0 (TranslationUnit); unit->file = g_object_ref (file); unit->unsaved_file = ide_unsaved_file_ref (unsaved_file); g_task_set_task_data (task, unit, (GDestroyNotify)translation_unit_free); g_subprocess_wait_async (subprocess, cancellable, subprocess_wait_cb, g_object_ref (task)); }
/** * as_validator_validate_tree: * @validator: An instance of #AsValidator. * @root_dir: The root directory of the filesystem tree that should be validated. * * Validate a full directory tree for issues in AppStream metadata. **/ gboolean as_validator_validate_tree (AsValidator *validator, const gchar *root_dir) { g_autofree gchar *metainfo_dir = NULL; g_autofree gchar *legacy_metainfo_dir = NULL; g_autofree gchar *apps_dir = NULL; g_autoptr(GPtrArray) mfiles = NULL; g_autoptr(GPtrArray) mfiles_legacy = NULL; g_autoptr(GPtrArray) dfiles = NULL; GHashTable *dfilenames = NULL; GHashTable *validated_cpts = NULL; guint i; gboolean ret = TRUE; g_autoptr(AsXMLData) xdt = NULL; struct MInfoCheckData ht_helper; /* cleanup */ as_validator_clear_issues (validator); metainfo_dir = g_build_filename (root_dir, "usr", "share", "metainfo", NULL); legacy_metainfo_dir = g_build_filename (root_dir, "usr", "share", "appdata", NULL); apps_dir = g_build_filename (root_dir, "usr", "share", "applications", NULL); /* check if we actually have a directory which could hold metadata */ if ((!g_file_test (metainfo_dir, G_FILE_TEST_IS_DIR)) && (!g_file_test (legacy_metainfo_dir, G_FILE_TEST_IS_DIR))) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_FILE_MISSING, "No AppStream metadata was found."); goto out; } /* check if we actually have a directory which could hold application information */ if (!g_file_test (apps_dir, G_FILE_TEST_IS_DIR)) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_PEDANTIC, /* pedantic because not everything which has metadata is an application */ AS_ISSUE_KIND_FILE_MISSING, "No XDG applications directory found."); } /* holds a filename -> component mapping */ validated_cpts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); /* set up XML parser */ xdt = as_xmldata_new (); as_xmldata_initialize (xdt, AS_CURRENT_FORMAT_VERSION, "C", NULL, NULL, NULL, 0); as_xmldata_set_format_style (xdt, AS_FORMAT_STYLE_METAINFO); /* validate all metainfo files */ mfiles = as_utils_find_files_matching (metainfo_dir, "*.xml", FALSE, NULL); mfiles_legacy = as_utils_find_files_matching (legacy_metainfo_dir, "*.xml", FALSE, NULL); /* in case we only have legacy files */ if (mfiles == NULL) mfiles = g_ptr_array_new_with_free_func (g_free); if (mfiles_legacy != NULL) { for (i = 0; i < mfiles_legacy->len; i++) { const gchar *fname; g_autofree gchar *fname_basename = NULL; /* process metainfo files in legacy paths */ fname = (const gchar*) g_ptr_array_index (mfiles_legacy, i); fname_basename = g_path_get_basename (fname); as_validator_set_current_fname (validator, fname_basename); as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_LEGACY, "The metainfo file is stored in a legacy path. Please place it in '/usr/share/metainfo'."); g_ptr_array_add (mfiles, g_strdup (fname)); } } for (i = 0; i < mfiles->len; i++) { const gchar *fname; g_autoptr(GFile) file = NULL; g_autoptr(GInputStream) file_stream = NULL; g_autoptr(GError) tmp_error = NULL; g_autoptr(GString) asdata = NULL; gssize len; const gsize buffer_size = 1024 * 24; g_autofree gchar *buffer = NULL; xmlNode *root; xmlDoc *doc; g_autofree gchar *fname_basename = NULL; fname = (const gchar*) g_ptr_array_index (mfiles, i); file = g_file_new_for_path (fname); if (!g_file_query_exists (file, NULL)) { g_warning ("File '%s' suddenly vanished.", fname); g_object_unref (file); continue; } fname_basename = g_path_get_basename (fname); as_validator_set_current_fname (validator, fname_basename); /* load a plaintext file */ file_stream = G_INPUT_STREAM (g_file_read (file, NULL, &tmp_error)); if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); continue; } asdata = g_string_new (""); buffer = g_malloc (buffer_size); while ((len = g_input_stream_read (file_stream, buffer, buffer_size, NULL, &tmp_error)) > 0) { g_string_append_len (asdata, buffer, len); } /* check if there was an error */ if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); continue; } /* now read the XML */ doc = as_validator_open_xml_document (validator, xdt, asdata->str); if (doc == NULL) { as_validator_clear_current_fname (validator); continue; } root = xmlDocGetRootElement (doc); if (g_strcmp0 ((gchar*) root->name, "component") == 0) { AsComponent *cpt; cpt = as_validator_validate_component_node (validator, xdt, root); if (cpt != NULL) g_hash_table_insert (validated_cpts, g_strdup (fname_basename), cpt); } else if (g_strcmp0 ((gchar*) root->name, "components") == 0) { as_validator_add_issue (validator, root, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "The metainfo file specifies multiple components. This is not allowed."); ret = FALSE; } else if (g_str_has_prefix ((gchar*) root->name, "application")) { as_validator_add_issue (validator, root, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_LEGACY, "The metainfo file uses an ancient version of the AppStream specification, which can not be validated. Please migrate it to version 0.6 (or higher)."); ret = FALSE; } as_validator_clear_current_fname (validator); xmlFreeDoc (doc); } /* check if we have matching .desktop files */ dfilenames = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); dfiles = as_utils_find_files_matching (apps_dir, "*.desktop", FALSE, NULL); if (dfiles != NULL) { for (i = 0; i < dfiles->len; i++) { const gchar *fname; fname = (const gchar*) g_ptr_array_index (dfiles, i); g_hash_table_add (dfilenames, g_path_get_basename (fname)); } } /* validate the component-id <-> filename relations and availability of other metadata */ ht_helper.validator = validator; ht_helper.desktop_fnames = dfilenames; ht_helper.apps_dir = apps_dir; g_hash_table_foreach (validated_cpts, (GHFunc) as_validator_analyze_component_metainfo_relation_cb, &ht_helper); out: if (dfilenames != NULL) g_hash_table_unref (dfilenames); if (validated_cpts != NULL) g_hash_table_unref (validated_cpts); return ret; }
/* See "man 5 passwd" We just make sure the name and uid/gid match, and that none are missing. don't care about GECOS/dir/shell. */ static gboolean rpmostree_check_passwd_groups (gboolean passwd, OstreeRepo *repo, GFile *yumroot, GFile *treefile_dirpath, JsonObject *treedata, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *direct = NULL; const char *chk_type = "previous"; const char *ref = NULL; const char *commit_filepath = passwd ? "usr/lib/passwd" : "usr/lib/group"; const char *json_conf_name = passwd ? "check-passwd" : "check-groups"; const char *json_conf_ign = passwd ? "ignore-removed-users" : "ignore-removed-groups"; gs_unref_object GFile *old_path = NULL; gs_unref_object GFile *new_path = g_file_resolve_relative_path (yumroot, commit_filepath); gs_unref_ptrarray GPtrArray *ignore_removed_ents = NULL; gboolean ignore_all_removed = FALSE; gs_free char *old_contents = NULL; gs_free char *new_contents = NULL; gs_unref_ptrarray GPtrArray *old_ents = NULL; gs_unref_ptrarray GPtrArray *new_ents = NULL; unsigned int oiter = 0; unsigned int niter = 0; if (json_object_has_member (treedata, json_conf_name)) { JsonObject *chk = json_object_get_object_member (treedata,json_conf_name); if (!chk) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s is not an object", json_conf_name); goto out; } chk_type = _rpmostree_jsonutil_object_require_string_member (chk, "type", error); if (!chk_type) goto out; if (g_str_equal (chk_type, "none")) { ret = TRUE; goto out; } else if (g_str_equal (chk_type, "file")) { direct = _rpmostree_jsonutil_object_require_string_member (chk, "filename", error); if (!direct) goto out; } else if (g_str_equal (chk_type, "data")) { JsonNode *ents_node = json_object_get_member (chk, "entries"); JsonObject *ents_obj = NULL; GList *ents; GList *iter; if (!ents_node) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No entries member for data in %s", json_conf_name); goto out; } ents_obj = json_node_get_object (ents_node); if (passwd) old_ents = g_ptr_array_new_with_free_func (conv_passwd_ent_free); else old_ents = g_ptr_array_new_with_free_func (conv_group_ent_free); ents = json_object_get_members (ents_obj); for (iter = ents; iter; iter = iter->next) if (passwd) { const char *name = iter->data; JsonNode *val = json_object_get_member (ents_obj, name); JsonNodeType child_type = json_node_get_node_type (val); gint64 uid = 0; gint64 gid = 0; struct conv_passwd_ent *convent = g_new (struct conv_passwd_ent, 1); if (child_type != JSON_NODE_ARRAY) { if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &uid, error)) goto out; gid = uid; } else { JsonArray *child_array = json_node_get_array (val); guint len = json_array_get_length (child_array); if (!len || (len > 2)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Array %s is only for uid and gid. Has length %u", name, len); goto out; } if (!_rpmostree_jsonutil_array_require_int_element (child_array, 0, &uid, error)) goto out; if (len == 1) gid = uid; else if (!_rpmostree_jsonutil_array_require_int_element (child_array, 1, &gid, error)) goto out; } convent->name = g_strdup (name); convent->uid = uid; convent->gid = gid; g_ptr_array_add (old_ents, convent); } else { const char *name = iter->data; gint64 gid = 0; struct conv_group_ent *convent = g_new (struct conv_group_ent, 1); if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &gid, error)) goto out; convent->name = g_strdup (name); convent->gid = gid; g_ptr_array_add (old_ents, convent); } }
static gboolean build_content_sizenames_recurse (OstreeRepo *repo, OstreeRepoCommitTraverseIter *iter, GHashTable *sizenames_map, GHashTable *include_only_objects, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; while (TRUE) { OstreeRepoCommitIterResult iterres = ostree_repo_commit_traverse_iter_next (iter, cancellable, error); if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_ERROR) goto out; else if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_END) break; else if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_FILE) { char *name; char *checksum; OstreeDeltaContentSizeNames *csizenames; ostree_repo_commit_traverse_iter_get_file (iter, &name, &checksum); if (include_only_objects && !g_hash_table_contains (include_only_objects, checksum)) continue; csizenames = g_hash_table_lookup (sizenames_map, checksum); if (!csizenames) { g_autoptr(GFileInfo) finfo = NULL; if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, cancellable, error)) goto out; if (g_file_info_get_file_type (finfo) != G_FILE_TYPE_REGULAR) continue; csizenames = g_new0 (OstreeDeltaContentSizeNames, 1); csizenames->checksum = g_strdup (checksum); csizenames->size = g_file_info_get_size (finfo); g_hash_table_replace (sizenames_map, csizenames->checksum, csizenames); } if (!csizenames->basenames) csizenames->basenames = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (csizenames->basenames, g_strdup (name)); } else if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_DIR) { char *name; char *content_checksum; char *meta_checksum; g_autoptr(GVariant) dirtree = NULL; ostree_cleanup_repo_commit_traverse_iter OstreeRepoCommitTraverseIter subiter = { 0, }; ostree_repo_commit_traverse_iter_get_dir (iter, &name, &content_checksum, &meta_checksum); if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, content_checksum, &dirtree, error)) goto out; if (!ostree_repo_commit_traverse_iter_init_dirtree (&subiter, repo, dirtree, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, error)) goto out; if (!build_content_sizenames_recurse (repo, &subiter, sizenames_map, include_only_objects, cancellable, error)) goto out; } else g_assert_not_reached (); } ret = TRUE; out: return ret; }
static BraseroBurnResult brasero_readom_argv_set_iso_boundary (BraseroReadom *readom, GPtrArray *argv, GError **error) { goffset nb_blocks; BraseroTrack *track; GValue *value = NULL; BraseroTrackType *output = NULL; brasero_job_get_current_track (BRASERO_JOB (readom), &track); output = brasero_track_type_new (); brasero_job_get_output_type (BRASERO_JOB (readom), output); brasero_track_tag_lookup (track, BRASERO_TRACK_MEDIUM_ADDRESS_START_TAG, &value); if (value) { guint64 start, end; /* we were given an address to start */ start = g_value_get_uint64 (value); /* get the length now */ value = NULL; brasero_track_tag_lookup (track, BRASERO_TRACK_MEDIUM_ADDRESS_END_TAG, &value); end = g_value_get_uint64 (value); BRASERO_JOB_LOG (readom, "reading from sector %lli to %lli", start, end); g_ptr_array_add (argv, g_strdup_printf ("-sectors=%"G_GINT64_FORMAT"-%"G_GINT64_FORMAT, start, end)); } /* 0 means all disc, -1 problem */ else if (brasero_track_disc_get_track_num (BRASERO_TRACK_DISC (track)) > 0) { goffset start; BraseroDrive *drive; BraseroMedium *medium; drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track)); medium = brasero_drive_get_medium (drive); brasero_medium_get_track_space (medium, brasero_track_disc_get_track_num (BRASERO_TRACK_DISC (track)), NULL, &nb_blocks); brasero_medium_get_track_address (medium, brasero_track_disc_get_track_num (BRASERO_TRACK_DISC (track)), NULL, &start); BRASERO_JOB_LOG (readom, "reading %i from sector %lli to %lli", brasero_track_disc_get_track_num (BRASERO_TRACK_DISC (track)), start, start + nb_blocks); g_ptr_array_add (argv, g_strdup_printf ("-sectors=%"G_GINT64_FORMAT"-%"G_GINT64_FORMAT, start, start + nb_blocks)); } /* if it's BIN output just read the last track */ else if (brasero_track_type_get_image_format (output) == BRASERO_IMAGE_FORMAT_BIN) { goffset start; BraseroDrive *drive; BraseroMedium *medium; drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track)); medium = brasero_drive_get_medium (drive); brasero_medium_get_last_data_track_space (medium, NULL, &nb_blocks); brasero_medium_get_last_data_track_address (medium, NULL, &start); BRASERO_JOB_LOG (readom, "reading last track from sector %"G_GINT64_FORMAT" to %"G_GINT64_FORMAT, start, start + nb_blocks); g_ptr_array_add (argv, g_strdup_printf ("-sectors=%"G_GINT64_FORMAT"-%"G_GINT64_FORMAT, start, start + nb_blocks)); } else { brasero_track_get_size (track, &nb_blocks, NULL); g_ptr_array_add (argv, g_strdup_printf ("-sectors=0-%"G_GINT64_FORMAT, nb_blocks)); } brasero_track_type_free (output); return BRASERO_BURN_OK; }
void mcview_growbuf_read_until (WView * view, off_t ofs) { gboolean short_read = FALSE; #ifdef HAVE_ASSERT_H assert (view->growbuf_in_use); #endif if (view->growbuf_finished) return; while (mcview_growbuf_filesize (view) < ofs || short_read) { ssize_t nread = 0; byte *p; size_t bytesfree; if (view->growbuf_lastindex == VIEW_PAGE_SIZE) { /* Append a new block to the growing buffer */ byte *newblock = g_try_malloc (VIEW_PAGE_SIZE); if (newblock == NULL) return; g_ptr_array_add (view->growbuf_blockptr, newblock); view->growbuf_lastindex = 0; } p = (byte *) g_ptr_array_index (view->growbuf_blockptr, view->growbuf_blockptr->len - 1) + view->growbuf_lastindex; bytesfree = VIEW_PAGE_SIZE - view->growbuf_lastindex; if (view->datasource == DS_STDIO_PIPE) { mc_pipe_t *sp = view->ds_stdio_pipe; GError *error = NULL; if (bytesfree > MC_PIPE_BUFSIZE) bytesfree = MC_PIPE_BUFSIZE; sp->out.len = bytesfree; sp->err.len = MC_PIPE_BUFSIZE; mc_pread (sp, &error); if (error != NULL) { mcview_show_error (view, error->message); g_error_free (error); mcview_growbuf_done (view); return; } if (view->pipe_first_err_msg && sp->err.len > 0) { /* ignore possible following errors */ /* reset this flag before call of mcview_show_error() to break * endless recursion: mcview_growbuf_read_until() -> mcview_show_error() -> * MSG_DRAW -> mcview_display() -> mcview_get_byte() -> mcview_growbuf_read_until() */ view->pipe_first_err_msg = FALSE; mcview_show_error (view, sp->err.buf); } if (sp->out.len > 0) { memmove (p, sp->out.buf, sp->out.len); nread = sp->out.len; } else if (sp->out.len == MC_PIPE_STREAM_EOF || sp->out.len == MC_PIPE_ERROR_READ) { if (sp->out.len == MC_PIPE_ERROR_READ) { char *err_msg; err_msg = g_strdup_printf (_("Failed to read data from child stdout:\n%s"), unix_error_string (sp->out.error)); mcview_show_error (view, err_msg); g_free (err_msg); } if (view->ds_stdio_pipe != NULL) { /* when switch from parse to raw mode and back, * do not close the already closed pipe after following loop: * mcview_growbuf_read_until() -> mcview_show_error() -> * MSG_DRAW -> mcview_display() -> mcview_get_byte() -> mcview_growbuf_read_until() */ mcview_growbuf_done (view); } mcview_display (view); return; } } else { #ifdef HAVE_ASSERT_H assert (view->datasource == DS_VFS_PIPE); #endif do { nread = mc_read (view->ds_vfs_pipe, p, bytesfree); } while (nread == -1 && errno == EINTR); if (nread <= 0) { mcview_growbuf_done (view); return; } } short_read = ((size_t) nread < bytesfree); view->growbuf_lastindex += nread; } }
static RejillaBurnResult rejilla_vcd_imager_set_argv (RejillaProcess *process, GPtrArray *argv, GError **error) { RejillaVcdImagerPrivate *priv; RejillaBurnResult result; RejillaJobAction action; RejillaMedia medium; gchar *output; gchar *image; gchar *toc; priv = REJILLA_VCD_IMAGER_PRIVATE (process); rejilla_job_get_action (REJILLA_JOB (process), &action); if (action != REJILLA_JOB_ACTION_IMAGE) REJILLA_JOB_NOT_SUPPORTED (process); g_ptr_array_add (argv, g_strdup ("vcdxbuild")); g_ptr_array_add (argv, g_strdup ("--progress")); g_ptr_array_add (argv, g_strdup ("-v")); /* specifies output */ image = toc = NULL; rejilla_job_get_image_output (REJILLA_JOB (process), &image, &toc); g_ptr_array_add (argv, g_strdup ("-c")); g_ptr_array_add (argv, toc); g_ptr_array_add (argv, g_strdup ("-b")); g_ptr_array_add (argv, image); /* get temporary file to write XML */ result = rejilla_job_get_tmp_file (REJILLA_JOB (process), NULL, &output, error); if (result != REJILLA_BURN_OK) return result; g_ptr_array_add (argv, output); rejilla_job_get_media (REJILLA_JOB (process), &medium); if (medium & REJILLA_MEDIUM_CD) { GValue *value = NULL; rejilla_job_tag_lookup (REJILLA_JOB (process), REJILLA_VCD_TYPE, &value); if (value) priv->svcd = (g_value_get_int (value) == REJILLA_SVCD); } result = rejilla_vcd_imager_generate_xml_file (process, output, error); if (result != REJILLA_BURN_OK) return result; rejilla_job_set_current_action (REJILLA_JOB (process), REJILLA_BURN_ACTION_CREATING_IMAGE, _("Creating file layout"), FALSE); return REJILLA_BURN_OK; }