int main(int argc __attribute__((unused)), char *argv[]) { uint pagen; uchar long_tr_id[6]; PAGECACHE pagecache; LSN lsn, first_lsn, theor_lsn; LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; MY_INIT(argv[0]); plan(2); bzero(&pagecache, sizeof(pagecache)); /* Don't give an error if we can't create dir, as it may already exist from a previously aborted run */ maria_data_root= create_tmpdir(argv[0]); if (maria_log_remove(0)) exit(1); bzero(long_tr_id, 6); #ifndef DBUG_OFF #if defined(__WIN__) default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace"; #else default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace"; #endif if (argc > 1) { DBUG_SET(default_dbug_option); DBUG_SET_INITIAL(default_dbug_option); } #endif if (ma_control_file_open(TRUE, TRUE)) { fprintf(stderr, "Can't init control file (%d)\n", errno); exit(1); } if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, PCACHE_PAGE, 0)) == 0) { fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno); exit(1); } if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS, 0, &translog_example_table_init, 0)) { fprintf(stderr, "Can't init loghandler (%d)\n", errno); exit(1); } /* Suppressing of automatic record writing */ dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; theor_lsn= translog_first_theoretical_lsn(); if (theor_lsn == 1) { fprintf(stderr, "Error reading the first log file."); translog_destroy(); exit(1); } if (theor_lsn == LSN_IMPOSSIBLE) { fprintf(stderr, "There is no first log file."); translog_destroy(); exit(1); } first_lsn= translog_first_lsn_in_log(); if (first_lsn != LSN_IMPOSSIBLE) { fprintf(stderr, "Incorrect first lsn response (%lu,0x%lx).", LSN_IN_PARTS(first_lsn)); translog_destroy(); exit(1); } ok(1, "Empty log response"); int4store(long_tr_id, 0); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #%lu\n", (ulong) 0); translog_destroy(); exit(1); } theor_lsn= translog_first_theoretical_lsn(); if (theor_lsn == 1) { fprintf(stderr, "Error reading the first log file\n"); translog_destroy(); exit(1); } if (theor_lsn == LSN_IMPOSSIBLE) { fprintf(stderr, "There is no first log file\n"); translog_destroy(); exit(1); } first_lsn= translog_first_lsn_in_log(); if (first_lsn != theor_lsn) { fprintf(stderr, "Incorrect first lsn: (%lu,0x%lx) " " theoretical first: (%lu,0x%lx)\n", LSN_IN_PARTS(first_lsn), LSN_IN_PARTS(theor_lsn)); translog_destroy(); exit(1); } ok(1, "Full log response"); translog_destroy(); end_pagecache(&pagecache, 1); ma_control_file_end(); if (maria_log_remove(maria_data_root)) exit(1); exit(0); }
int main(int argc __attribute__((unused)), char *argv[]) { ulong i; uint pagen; uchar long_tr_id[6]; PAGECACHE pagecache; LSN lsn; LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; uchar *long_buffer= malloc(LONG_BUFFER_SIZE); MY_INIT(argv[0]); plan(2); bzero(&pagecache, sizeof(pagecache)); bzero(long_buffer, LONG_BUFFER_SIZE); maria_data_root= create_tmpdir(argv[0]); if (maria_log_remove(0)) exit(1); bzero(long_tr_id, 6); #ifndef DBUG_OFF #if defined(__WIN__) default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace"; #else default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace"; #endif if (argc > 1) { DBUG_SET(default_dbug_option); DBUG_SET_INITIAL(default_dbug_option); } #endif if (ma_control_file_open(TRUE, TRUE)) { fprintf(stderr, "Can't init control file (%d)\n", errno); exit(1); } if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, PCACHE_PAGE, 0)) == 0) { fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno); exit(1); } if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS, 0, &translog_example_table_init, 0)) { fprintf(stderr, "Can't init loghandler (%d)\n", errno); exit(1); } /* Suppressing of automatic record writing */ dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; /* write more then 1 file */ int4store(long_tr_id, 0); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #0\n"); translog_destroy(); exit(1); } for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++) { if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #0\n"); translog_destroy(); exit(1); } } translog_destroy(); end_pagecache(&pagecache, 1); ma_control_file_end(); { char file_name[FN_REFLEN]; for (i= 1; i <= 2; i++) { translog_filename_by_fileno(i, file_name); if (my_access(file_name, W_OK)) { fprintf(stderr, "No file '%s'\n", file_name); exit(1); } if (my_delete(file_name, MYF(MY_WME)) != 0) { fprintf(stderr, "Error %d during removing file'%s'\n", errno, file_name); exit(1); } } } if (ma_control_file_open(TRUE, TRUE)) { fprintf(stderr, "Can't init control file (%d)\n", errno); exit(1); } if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, PCACHE_PAGE, 0)) == 0) { fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno); exit(1); } if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS, 0, &translog_example_table_init, 1)) { fprintf(stderr, "Can't init loghandler (%d)\n", errno); exit(1); } /* Suppressing of automatic record writing */ dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; ok(1, "Log init OK"); int4store(long_tr_id, 0); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #0\n"); translog_destroy(); exit(1); } translog_destroy(); end_pagecache(&pagecache, 1); ma_control_file_end(); if (!translog_is_file(3)) { fprintf(stderr, "No file #3\n"); exit(1); } ok(1, "New log is OK"); if (maria_log_remove(maria_data_root)) exit(1); exit(0); }
int main(int argc __attribute__((unused)), char *argv[]) { ulong i; uint pagen; uchar long_tr_id[6]; PAGECACHE pagecache; LSN lsn; LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; uchar *long_buffer= malloc(LONG_BUFFER_SIZE); MY_INIT(argv[0]); plan(4); bzero(&pagecache, sizeof(pagecache)); bzero(long_buffer, LONG_BUFFER_SIZE); maria_data_root= create_tmpdir(argv[0]); if (maria_log_remove(0)) exit(1); bzero(long_tr_id, 6); #ifndef DBUG_OFF #if defined(__WIN__) default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace"; #else default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace"; #endif if (argc > 1) { DBUG_SET(default_dbug_option); DBUG_SET_INITIAL(default_dbug_option); } #endif if (ma_control_file_open(TRUE, TRUE)) { fprintf(stderr, "Can't init control file (%d)\n", errno); exit(1); } if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, PCACHE_PAGE, 0, 0)) == 0) { fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno); exit(1); } if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS, 0, &translog_example_table_init, 0)) { fprintf(stderr, "Can't init loghandler (%d)\n", errno); exit(1); } /* Suppressing of automatic record writing */ dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; /* write more then 1 file */ int4store(long_tr_id, 0); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #%lu\n", (ulong) 0); translog_destroy(); exit(1); } translog_purge(lsn); if (!translog_is_file(1)) { fprintf(stderr, "First file was removed after first record\n"); translog_destroy(); exit(1); } ok(1, "First is not removed"); for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++) { if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #%lu\n", (ulong) 0); translog_destroy(); exit(1); } } translog_purge(lsn); if (translog_is_file(1)) { fprintf(stderr, "First file was not removed.\n"); translog_destroy(); exit(1); } ok(1, "First file is removed"); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_buffer; parts[TRANSLOG_INTERNAL_PARTS + 0].length= LONG_BUFFER_SIZE; if (translog_write_record(&lsn, LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, LONG_BUFFER_SIZE, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write variable record\n"); translog_destroy(); exit(1); } translog_purge(lsn); if (!translog_is_file(2) || !translog_is_file(3)) { fprintf(stderr, "Second file (%d) or third file (%d) is not present.\n", translog_is_file(2), translog_is_file(3)); translog_destroy(); exit(1); } ok(1, "Second and third files are not removed"); int4store(long_tr_id, 0); parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write last record\n"); translog_destroy(); exit(1); } translog_purge(lsn); if (translog_is_file(2)) { fprintf(stderr, "Second file is not removed\n"); translog_destroy(); exit(1); } ok(1, "Second file is removed"); translog_destroy(); end_pagecache(&pagecache, 1); ma_control_file_end(); if (maria_log_remove(maria_data_root)) exit(1); my_uuid_end(); my_free_open_file_info(); my_end(0); exit(0); }
int main(int argc __attribute__((unused)), char *argv[]) { uint pagen; int rc= 1; uchar long_tr_id[6]; PAGECACHE pagecache; LSN first_lsn; TRANSLOG_HEADER_BUFFER rec; LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; translog_size_t len; MY_INIT(argv[0]); plan(1); bzero(&pagecache, sizeof(pagecache)); maria_data_root= create_tmpdir(argv[0]); if (maria_log_remove(0)) exit(1); bzero(long_tr_id, 6); #ifndef DBUG_OFF #if defined(__WIN__) default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace"; #else default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace"; #endif if (argc > 1) { DBUG_SET(default_dbug_option); DBUG_SET_INITIAL(default_dbug_option); } #endif if (ma_control_file_open(TRUE, TRUE)) { fprintf(stderr, "Can't init control file (%d)\n", errno); exit(1); } if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, PCACHE_PAGE, 0)) == 0) { fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno); exit(1); } if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, LOG_FLAGS, 0, &translog_example_table_init, 0)) { fprintf(stderr, "Can't init loghandler (%d)\n", errno); exit(1); } /* Suppressing of automatic record writing */ dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; int4store(long_tr_id, 0); long_tr_id[5]= 0xff; parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; if (translog_write_record(&first_lsn, LOGREC_FIXED_RECORD_0LSN_EXAMPLE, &dummy_transaction_object, NULL, 6, TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL)) { fprintf(stderr, "Can't write record #%lu\n", (ulong) 0); translog_destroy(); exit(1); } len= translog_read_record_header(first_lsn, &rec); if (len == 0) { fprintf(stderr, "translog_read_record_header failed (%d)\n", errno); goto err; } if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 || rec.record_length != 6 || uint4korr(rec.header) != 0 || ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF || first_lsn != rec.lsn) { fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE " "data read(0)\n" "type: %u (%d) strid: %u (%d) len: %u (%d) i: %u (%d), " "4: %u (%d) 5: %u (%d) " "lsn(%lu,0x%lx) (%d)\n", (uint) rec.type, (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE), (uint) rec.short_trid, (rec.short_trid != 0), (uint) rec.record_length, (rec.record_length != 6), (uint) uint4korr(rec.header), (uint4korr(rec.header) != 0), (uint) rec.header[4], (((uchar)rec.header[4]) != 0), (uint) rec.header[5], (((uchar)rec.header[5]) != 0xFF), LSN_IN_PARTS(rec.lsn), (first_lsn != rec.lsn)); goto err; } ok(1, "read OK"); rc= 0; err: translog_destroy(); end_pagecache(&pagecache, 1); ma_control_file_end(); if (maria_log_remove(maria_data_root)) exit(1); exit(rc); }
int main(gint argc, gchar **argv) { const gchar *self = *argv++; if (argc < 2) { g_message("%s command [arguments...]", self); return 1; } g_autofree const gchar *prefix = create_tmpdir(); pid_t cpid = fork(); if (cpid < 0) fail("fork", errno); else if (cpid == 0) { uid_t uid = getuid(); gid_t gid = getgid(); if (unshare(CLONE_NEWNS | CLONE_NEWUSER) < 0) { int unshare_errno = errno; g_message("Requires Linux version >= 3.19 built with CONFIG_USER_NS"); if (g_file_test("/proc/sys/kernel/unprivileged_userns_clone", G_FILE_TEST_EXISTS)) g_message("Run: sudo sysctl -w kernel.unprivileged_userns_clone=1"); fail("unshare", unshare_errno); } spit("/proc/self/setgroups", "deny"); spit("/proc/self/uid_map", "%d %d 1", uid, uid); spit("/proc/self/gid_map", "%d %d 1", gid, gid); // If there is a /host directory, assume this is nested chrootenv and use it as host instead. gboolean nested_host = g_file_test("/host", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); g_autofree const gchar *host = nested_host ? "/host" : "/"; bind(host, prefix); // Replace /host by an actual (inner) /host. if (nested_host) { fail_if(g_mkdir("/real-host", 0755)); fail_if(mount("/host/host", "/real-host", NULL, MS_BIND | MS_REC, NULL)); // For some reason umount("/host") returns EBUSY even immediately after // pivot_root. We detach it at least to keep `/proc/mounts` from blowing // up in nested cases. fail_if(umount2("/host", MNT_DETACH)); fail_if(mount("/real-host", "/host", NULL, MS_MOVE, NULL)); fail_if(rmdir("/real-host")); } fail_if(chdir("/")); fail_if(execvp(*argv, argv)); } else { int status; fail_if(waitpid(cpid, &status, 0) != cpid); fail_if(rmdir(prefix)); if (WIFEXITED(status)) return WEXITSTATUS(status); else if (WIFSIGNALED(status)) kill(getpid(), WTERMSIG(status)); return 1; } }
/******************************************************* Function: ld_compile *******************************************************/ string ld_compile (bfd *abfd) { string input_path; string output_path; int argc; string *argv; int child_pid; int statptr; string file_name = (string)abfd->filename; if (tmpdir == 0) if (create_tmpdir (FALSE) != 0) { fprintf(stderr,"create_tmpdir() failed for %s\n",abfd->filename); exit(1); } if ((input_path = create_unique_file (file_name, 'B')) == 0) { fprintf(stderr,"create_unique_file() failed for %s\n",abfd->filename); exit(1); } if (abfd->arelt_data) { if (extract_archive_member (abfd, input_path) != 0) { fprintf(stderr,"extract_archive_member() failed for %s\n",abfd->filename); exit(1); } } else { UNLINK (input_path); if (make_link (file_name, input_path) != 0) { fprintf(stderr,"make_link() failed for %s\n",abfd->filename); exit(1); } } if ((output_path = create_unique_file (file_name, 'o')) == 0) { fprintf(stderr,"create_unique_file() failed for %s\n",abfd->filename); exit(1); } add_to_tmp_file_list (output_path); add_to_tmp_file_list (input_path); argv = get_command_line (abfd, input_path, output_path, &argc); if (ld_ipa_opt[LD_IPA_VERBOSE].flag || ld_ipa_opt[LD_IPA_SHOW].flag) fprintf(stderr,"Compiling %s\n",abfd->filename); child_pid = do_compile (argv); (void) waitpid (child_pid, &statptr, 0); if (statptr != 0 && WEXITSTATUS(statptr) != 0) { fprintf(stderr,"Compile of %s failed!\n",abfd->filename); exit(1); } active_pid = 0; FREE (argv); UNLINK (input_path); remove_from_tmp_file_list (input_path); FREE (input_path); return output_path; } /* ld_compile */