/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { /* check for root as process owner */ check_root(); /* capture signals */ tst_sig(FORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); /* Pause if that option was specified */ TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); /* get an IPC resource key */ shmkey = getipckey(); /* create a shared memory segment with read and write permissions */ if ((shm_id_1 = shmget(shmkey, huge_pages_shm_to_be_allocated, SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "Failed to create shared memory " "segment in setup"); } /* get the userid for a non root user */ ltp_uid = getuserid(ltp_user); }
int main(){ int T; int in[3]; int ans[3]; scanf("%d", &T); while(T-- && scanf("%d%d%d", &in[0], &in[1], &in[2]) == 3){ para[0] = -in[0]; para[1] = (in[0]*in[0]-in[2])/2; para[2] = -in[1]; // printf("[0]%lf [1]%lf [2]%lf\n", para[0], para[1], para[2]); /*if(para[0]*para[0]-4*para[1] > 0){ printf("%lf ", para[0]*para[0]-4*para[1]); puts("para No solution."); continue; }*/ int count = 0; for(int i = -100; i <= 100 && count < 3; i++) if(check_root(i)) ans[count++] = i; if(count < 3){ puts("No solution."); continue; } for(int i = 0; i < 3; i++){ printf("%d", ans[i]); if(i != 2) putchar(' '); } puts(""); } return 0; }
void man_valid_post(struct man *man) { struct man_node *n; v_check *cp; n = man->last; if (n->flags & MAN_VALID) return; n->flags |= MAN_VALID; switch (n->type) { case MAN_TEXT: check_text(man, n); break; case MAN_ROOT: check_root(man, n); break; case MAN_EQN: /* FALLTHROUGH */ case MAN_TBL: break; default: cp = man_valids + n->tok; if (*cp) (*cp)(man, n); break; } }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { /* check for root as user id of process */ check_root(); tst_sig(FORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); msgkey = getipckey(); /* now we have a key, so let's create a message queue */ if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { tst_brkm(TBROK, cleanup, "Can't create message queue #1"); } /* get the user ID for a non root user */ ltp_uid = getuserid(ltp_user); }
int main(int argc, char **argv) { int ret = EXIT_FAILURE; banner(); //verbose++; if (!parse_options(argc, argv)) return ret; check_root(); if (dump) { efivar_bootloader_dump(); printf("\n"); return EXIT_SUCCESS; } init_log(); /* insure current_version is set */ if (current_version == -1) current_version = read_version_from_subvol_file(""); ret = do_update_bootloader_pref(); close_log(ret, current_version, 0, log_bootloader_pref); return ret; }
/* this function is intended to encapsulate the basic swupd * initializations for the majority of commands, that is: * - Make sure root is the user running the code * - Initialize log facility * - Get the lock * - initialize mounted directories * - Initialize curl */ int swupd_init(int *lock_fd) { int ret = 0; check_root(); *lock_fd = p_lockfile(); if (*lock_fd < 0) { ret = ELOCK_FILE; goto out_fds; } get_mounted_directories(); if (swupd_curl_init() != 0) { ret = ECURL_INIT; goto out_close_lock; } return ret; out_close_lock: v_lockfile(*lock_fd); out_fds: dump_file_descriptor_leaks(); return ret; }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { /* check for root as user id of process */ check_root(); tst_sig(FORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); /* get an IPC resource key */ semkey = getipckey(); /* create a semaphore set without read or alter permissions */ if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); } /* get the userid for a non root user */ ltp_uid = getuserid(ltp_user); }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { /* check for root as process owner */ check_root(); tst_sig(FORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); /* get an IPC resource key */ shmkey = getipckey(); /* create a shared memory segment with read and write permissions */ if ((shm_id_1 = shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW)) == -1) { tst_brkm(TBROK, cleanup, "couldn't create shared memory " "segment in setup()"); } /* get the userid for a non root user */ ltp_uid = getuserid(ltp_user); }
int man_valid_post(struct man *man) { v_check *cp; if (MAN_VALID & man->last->flags) return(1); man->last->flags |= MAN_VALID; switch (man->last->type) { case (MAN_TEXT): check_text(man, man->last); return(1); case (MAN_ROOT): return(check_root(man, man->last)); case (MAN_EQN): /* FALLTHROUGH */ case (MAN_TBL): return(1); default: break; } if (NULL == (cp = man_valids[man->last->tok].posts)) return(1); for ( ; *cp; cp++) if ( ! (*cp)(man, man->last)) return(0); return(1); }
int main(int argc, char **argv) { banner(); check_root(); if (!parse_options(argc, argv)) return EXIT_FAILURE; return bundle_add(); }
/* this function is intended to encapsulate the basic swupd * initializations for the majority of commands, that is: * - Make sure root is the user running the code * - Initialize globals * - initialize mounted directories * - Create necessary directories * - Get the lock * - Initialize curl * - Initialize signature checking */ int swupd_init(void) { int ret = 0; check_root(); record_fds(); /* Check that our system time is reasonably valid before continuing, * or the certificate verification will fail with invalid time */ if (timecheck) { if (!verify_time()) { ret = EBADTIME; goto out_fds; } } if (!init_globals()) { ret = EINIT_GLOBALS; goto out_fds; } get_mounted_directories(); if (create_required_dirs()) { ret = EREQUIRED_DIRS; goto out_fds; } if (p_lockfile() < 0) { ret = ELOCK_FILE; goto out_fds; } if (swupd_curl_init() != 0) { ret = ECURL_INIT; goto out_close_lock; } /* If --nosigcheck, we do not attempt any signature checking */ if (sigcheck && !initialize_signature()) { ret = ESIGNATURE; terminate_signature(); goto out_close_lock; } return ret; out_close_lock: v_lockfile(); out_fds: dump_file_descriptor_leaks(); return ret; }
errcode_t o2fsck_pass3(o2fsck_state *ost) { o2fsck_dir_parent *dp; errcode_t ret = 0; ocfs2_filesys *fs = ost->ost_fs; struct o2fsck_resource_track rt; printf("Pass 3: Checking directory connectivity\n"); o2fsck_init_resource_track(&rt, fs->fs_io); /* these could probably share more code. We might need to treat the * other required directories like root here */ check_root(ost); check_lostfound(ost); dp = o2fsck_dir_parent_lookup(&ost->ost_dir_parents, ost->ost_fs->fs_root_blkno); if (dp == NULL) { ret = OCFS2_ET_INTERNAL_FAILURE; com_err(whoami, ret, "root inode %"PRIu64" wasn't marked as " "a directory in pass1", ost->ost_fs->fs_root_blkno); goto out; } dp->dp_connected = 1; dp = o2fsck_dir_parent_lookup(&ost->ost_dir_parents, ost->ost_fs->fs_sysdir_blkno); if (dp == NULL) { ret = OCFS2_ET_INTERNAL_FAILURE; com_err(whoami, ret, "system dir inode %"PRIu64" wasn't " "marked as a directory in pass1", ost->ost_fs->fs_sysdir_blkno); goto out; } dp->dp_connected = 1; for(dp = o2fsck_dir_parent_first(&ost->ost_dir_parents) ; dp; dp = o2fsck_dir_parent_next(dp)) { /* XXX hmm, make sure dir->ino is in the dir map? */ ret = connect_directory(ost, dp); if (ret) goto out; } o2fsck_compute_resource_track(&rt, fs->fs_io); o2fsck_print_resource_track("Pass 3", ost, &rt, fs->fs_io); o2fsck_add_resource_track(&ost->ost_rt, &rt); out: return ret; }
void check_tree(ast_t* tree, errors_t* errors) { #ifdef NDEBUG // Keep compiler happy in release builds. (void)tree; (void)errors; #else // Only check tree in debug builds. assert(tree != NULL); check_res_t r = check_root(tree, errors); assert(r != CHK_ERROR); // Ignore CHK_NOT_FOUND, that means we weren't given a whole tree. #endif }
static int clean_init(void) { int ret = 0; check_root(); if (!init_globals()) { return SWUPD_INIT_GLOBALS_FAILED; } if (p_lockfile() < 0) { free_globals(); return SWUPD_LOCK_FILE_FAILED; } return ret; }
static void test_check_root(void) { int32_t rtrn = 0; uid_t uid = getuid(); rtrn = check_root(); if(uid != 0) { TEST_ASSERT(rtrn != 0); } else { TEST_ASSERT(rtrn == 0); } return; }
/* this function is intended to encapsulate the basic swupd * initializations for the majority of commands, that is: * - Make sure root is the user running the code * - Initialize log facility * - Get the lock * - initialize mounted directories * - Initialize curl */ int swupd_init(int *lock_fd) { int ret = 0; check_root(); if (!init_globals()) { ret = EINIT_GLOBALS; goto out_fds; } get_mounted_directories(); if (create_required_dirs()) { ret = EREQUIRED_DIRS; goto out_fds; } *lock_fd = p_lockfile(); if (*lock_fd < 0) { ret = ELOCK_FILE; goto out_fds; } if (swupd_curl_init() != 0) { ret = ECURL_INIT; goto out_close_lock; } if (!initialize_signature()) { ret = ESIGNATURE; terminate_signature(); goto out_close_lock; } return ret; out_close_lock: v_lockfile(*lock_fd); out_fds: dump_file_descriptor_leaks(); return ret; }
void man_node_validate(struct roff_man *man) { struct roff_node *n; v_check *cp; n = man->last; man->last = man->last->child; while (man->last != NULL) { man_node_validate(man); if (man->last == n) man->last = man->last->child; else man->last = man->last->next; } man->last = n; man->next = ROFF_NEXT_SIBLING; switch (n->type) { case ROFFT_TEXT: check_text(man, n); break; case ROFFT_ROOT: check_root(man, n); break; case ROFFT_EQN: case ROFFT_TBL: break; default: cp = man_valids + n->tok; if (*cp) (*cp)(man, n); if (man->last == n) man_state(man, n); break; } }
/* * Any Postgres server process begins execution here. */ int main(int argc, char *argv[]) { progname = get_progname(argv[0]); /* * Platform-specific startup hacks */ startup_hacks(progname); /* * Remember the physical location of the initially given argv[] array for * possible use by ps display. On some platforms, the argv[] storage must * be overwritten in order to set the process title for ps. In such cases * save_ps_display_args makes and returns a new copy of the argv[] array. * * save_ps_display_args may also move the environment strings to make * extra room. Therefore this should be done as early as possible during * startup, to avoid entanglements with code that might save a getenv() * result pointer. */ argv = save_ps_display_args(argc, argv); /* * If supported on the current platform, set up a handler to be called if * the backend/postmaster crashes with a fatal signal or exception. */ #if defined(WIN32) && defined(HAVE_MINIDUMP_TYPE) pgwin32_install_crashdump_handler(); #endif /* * Set up locale information from environment. Note that LC_CTYPE and * LC_COLLATE will be overridden later from pg_control if we are in an * already-initialized database. We set them here so that they will be * available to fill pg_control during initdb. LC_MESSAGES will get set * later during GUC option processing, but we set it here to allow startup * error messages to be localized. */ set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); #ifdef WIN32 /* * Windows uses codepages rather than the environment, so we work around * that by querying the environment explicitly first for LC_COLLATE and * LC_CTYPE. We have to do this because initdb passes those values in the * environment. If there is nothing there we fall back on the codepage. */ { char *env_locale; if ((env_locale = getenv("LC_COLLATE")) != NULL) pg_perm_setlocale(LC_COLLATE, env_locale); else pg_perm_setlocale(LC_COLLATE, ""); if ((env_locale = getenv("LC_CTYPE")) != NULL) pg_perm_setlocale(LC_CTYPE, env_locale); else pg_perm_setlocale(LC_CTYPE, ""); } #else pg_perm_setlocale(LC_COLLATE, ""); pg_perm_setlocale(LC_CTYPE, ""); #endif #ifdef LC_MESSAGES pg_perm_setlocale(LC_MESSAGES, ""); #endif /* * We keep these set to "C" always, except transiently in pg_locale.c; see * that file for explanations. */ pg_perm_setlocale(LC_MONETARY, "C"); pg_perm_setlocale(LC_NUMERIC, "C"); pg_perm_setlocale(LC_TIME, "C"); /* * Now that we have absorbed as much as we wish to from the locale * environment, remove any LC_ALL setting, so that the environment * variables installed by pg_perm_setlocale have force. */ unsetenv("LC_ALL"); /* * Catch standard options before doing much else */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(progname); exit(0); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { puts("postgres (PostgreSQL) " PG_VERSION); exit(0); } } /* * Make sure we are not running as root. */ check_root(progname); /* * Dispatch to one of various subprograms depending on first argument. */ #ifdef EXEC_BACKEND if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0) exit(SubPostmasterMain(argc, argv)); #endif #ifdef WIN32 /* * Start our win32 signal implementation * * SubPostmasterMain() will do this for itself, but the remaining modes * need it here */ pgwin32_signal_initialize(); #endif if (argc > 1 && strcmp(argv[1], "--boot") == 0) AuxiliaryProcessMain(argc, argv); /* does not return */ if (argc > 1 && strcmp(argv[1], "--describe-config") == 0) exit(GucInfoMain()); if (argc > 1 && strcmp(argv[1], "--single") == 0) exit(PostgresMain(argc, argv, get_current_username(progname))); exit(PostmasterMain(argc, argv)); }
/* * Any Postgres server process begins execution here. */ int main(int argc, char *argv[]) { bool do_check_root = true; progname = get_progname(argv[0]); /* * Platform-specific startup hacks */ startup_hacks(progname); /* * Remember the physical location of the initially given argv[] array for * possible use by ps display. On some platforms, the argv[] storage must * be overwritten in order to set the process title for ps. In such cases * save_ps_display_args makes and returns a new copy of the argv[] array. * * save_ps_display_args may also move the environment strings to make * extra room. Therefore this should be done as early as possible during * startup, to avoid entanglements with code that might save a getenv() * result pointer. */ argv = save_ps_display_args(argc, argv); /* * If supported on the current platform, set up a handler to be called if * the backend/postmaster crashes with a fatal signal or exception. */ #if defined(WIN32) && defined(HAVE_MINIDUMP_TYPE) pgwin32_install_crashdump_handler(); #endif /* * Fire up essential subsystems: error and memory management * * Code after this point is allowed to use elog/ereport, though * localization of messages may not work right away, and messages won't go * anywhere but stderr until GUC settings get loaded. */ MemoryContextInit(); /* * Set up locale information from environment. Note that LC_CTYPE and * LC_COLLATE will be overridden later from pg_control if we are in an * already-initialized database. We set them here so that they will be * available to fill pg_control during initdb. LC_MESSAGES will get set * later during GUC option processing, but we set it here to allow startup * error messages to be localized. */ set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); #ifdef WIN32 /* * Windows uses codepages rather than the environment, so we work around * that by querying the environment explicitly first for LC_COLLATE and * LC_CTYPE. We have to do this because initdb passes those values in the * environment. If there is nothing there we fall back on the codepage. */ { char *env_locale; if ((env_locale = getenv("LC_COLLATE")) != NULL) init_locale("LC_COLLATE", LC_COLLATE, env_locale); else init_locale("LC_COLLATE", LC_COLLATE, ""); if ((env_locale = getenv("LC_CTYPE")) != NULL) init_locale("LC_CTYPE", LC_CTYPE, env_locale); else init_locale("LC_CTYPE", LC_CTYPE, ""); } #else init_locale("LC_COLLATE", LC_COLLATE, ""); init_locale("LC_CTYPE", LC_CTYPE, ""); #endif #ifdef LC_MESSAGES init_locale("LC_MESSAGES", LC_MESSAGES, ""); #endif /* * We keep these set to "C" always, except transiently in pg_locale.c; see * that file for explanations. */ init_locale("LC_MONETARY", LC_MONETARY, "C"); init_locale("LC_NUMERIC", LC_NUMERIC, "C"); init_locale("LC_TIME", LC_TIME, "C"); /* * Now that we have absorbed as much as we wish to from the locale * environment, remove any LC_ALL setting, so that the environment * variables installed by pg_perm_setlocale have force. */ unsetenv("LC_ALL"); check_strxfrm_bug(); /* * Catch standard options before doing much else, in particular before we * insist on not being root. */ if (argc > 1) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(progname); exit(0); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { puts("postgres (PostgreSQL) " PG_VERSION); exit(0); } /* * In addition to the above, we allow "--describe-config" and "-C var" * to be called by root. This is reasonably safe since these are * read-only activities. The -C case is important because pg_ctl may * try to invoke it while still holding administrator privileges on * Windows. Note that while -C can normally be in any argv position, * if you want to bypass the root check you must put it first. This * reduces the risk that we might misinterpret some other mode's -C * switch as being the postmaster/postgres one. */ if (strcmp(argv[1], "--describe-config") == 0) do_check_root = false; else if (argc > 2 && strcmp(argv[1], "-C") == 0) do_check_root = false; } /* * Make sure we are not running as root, unless it's safe for the selected * option. */ if (do_check_root) check_root(progname); /* * Dispatch to one of various subprograms depending on first argument. */ #ifdef EXEC_BACKEND if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0) SubPostmasterMain(argc, argv); /* does not return */ #endif #ifdef WIN32 /* * Start our win32 signal implementation * * SubPostmasterMain() will do this for itself, but the remaining modes * need it here */ pgwin32_signal_initialize(); #endif if (argc > 1 && strcmp(argv[1], "--boot") == 0) AuxiliaryProcessMain(argc, argv); /* does not return */ else if (argc > 1 && strcmp(argv[1], "--describe-config") == 0) GucInfoMain(); /* does not return */ else if (argc > 1 && strcmp(argv[1], "--single") == 0) PostgresMain(argc, argv, NULL, /* no dbname */ strdup(get_user_name_or_exit(progname))); /* does not return */ else PostmasterMain(argc, argv); /* does not return */ abort(); /* should not get here */ }
void e2fsck_pass3(e2fsck_t ctx) { ext2_filsys fs = ctx->fs; struct dir_info_iter *iter; #ifdef RESOURCE_TRACK struct resource_track rtrack; #endif struct problem_context pctx; struct dir_info *dir; unsigned long maxdirs, count; init_resource_track(&rtrack, ctx->fs->io); clear_problem_context(&pctx); #ifdef MTRACE mtrace_print("Pass 3"); #endif if (!(ctx->options & E2F_OPT_PREEN)) fix_problem(ctx, PR_3_PASS_HEADER, &pctx); /* * Allocate some bitmaps to do loop detection. */ pctx.errcode = e2fsck_allocate_inode_bitmap(fs, _("inode done bitmap"), EXT2FS_BMAP64_AUTODIR, "inode_done_map", &inode_done_map); if (pctx.errcode) { pctx.num = 2; fix_problem(ctx, PR_3_ALLOCATE_IBITMAP_ERROR, &pctx); ctx->flags |= E2F_FLAG_ABORT; goto abort_exit; } print_resource_track(ctx, _("Peak memory"), &ctx->global_rtrack, NULL); check_root(ctx); if (ctx->flags & E2F_FLAG_SIGNAL_MASK) goto abort_exit; ext2fs_mark_inode_bitmap2(inode_done_map, EXT2_ROOT_INO); maxdirs = e2fsck_get_num_dirinfo(ctx); count = 1; if (ctx->progress) if ((ctx->progress)(ctx, 3, 0, maxdirs)) goto abort_exit; iter = e2fsck_dir_info_iter_begin(ctx); while ((dir = e2fsck_dir_info_iter(ctx, iter)) != 0) { if (ctx->flags & E2F_FLAG_SIGNAL_MASK) goto abort_exit; if (ctx->progress && (ctx->progress)(ctx, 3, count++, maxdirs)) goto abort_exit; if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, dir->ino)) if (check_directory(ctx, dir->ino, &pctx)) goto abort_exit; } e2fsck_dir_info_iter_end(ctx, iter); /* * Force the creation of /lost+found if not present */ if ((ctx->flags & E2F_OPT_READONLY) == 0) e2fsck_get_lost_and_found(ctx, 1); /* * If there are any directories that need to be indexed or * optimized, do it here. */ e2fsck_rehash_directories(ctx); abort_exit: e2fsck_free_dir_info(ctx); if (inode_loop_detect) { ext2fs_free_inode_bitmap(inode_loop_detect); inode_loop_detect = 0; } if (inode_done_map) { ext2fs_free_inode_bitmap(inode_done_map); inode_done_map = 0; } print_resource_track(ctx, _("Pass 3"), &rtrack, ctx->fs->io); }
/* Validate the subtree rooted at man->last. */ void man_validate(struct roff_man *man) { struct roff_node *n; const v_check *cp; /* * Translate obsolete macros such that later code * does not need to look for them. */ n = man->last; switch (n->tok) { case MAN_LP: case MAN_P: n->tok = MAN_PP; break; default: break; } /* * Iterate over all children, recursing into each one * in turn, depth-first. */ man->last = man->last->child; while (man->last != NULL) { man_validate(man); if (man->last == n) man->last = man->last->child; else man->last = man->last->next; } /* Finally validate the macro itself. */ man->last = n; man->next = ROFF_NEXT_SIBLING; switch (n->type) { case ROFFT_TEXT: check_text(man, n); break; case ROFFT_ROOT: check_root(man, n); break; case ROFFT_COMMENT: case ROFFT_EQN: case ROFFT_TBL: break; default: if (n->tok < ROFF_MAX) { roff_validate(man); break; } assert(n->tok >= MAN_TH && n->tok < MAN_MAX); cp = man_valids + (n->tok - MAN_TH); if (*cp) (*cp)(man, n); if (man->last == n) n->flags |= NODE_VALID; break; } }