コード例 #1
0
ファイル: fs_perms.c プロジェクト: sanyaade-research-hub/ltp
/*
 * Create file and set permissions, user id, group id.
 *
 * If flag is non zero, the file contains #!/PATH/sh shebang otherwise it's
 * empty.
 */
static void testsetup(const char *file_name, int flag, mode_t mode,
                      int user_id, int group_id)
{
    FILE *file;

    file = fopen(file_name, "w");

    if (file == NULL)
        tst_brkm(TBROK | TERRNO, cleanup,
                 "Could not create test file %s.", file_name);

    /* create file with shebang */
    if (flag) {
        char buf[PATH_MAX];

        if (tst_get_path("sh", buf, PATH_MAX))
            tst_brkm(TBROK, cleanup,
                     "Could not find path to sh in $PATH.");

        if (fprintf(file, "#!%s\n", buf) < 0)
            tst_brkm(TBROK, cleanup, "Calling fprintf failed.");
    }

    if (fclose(file))
        tst_brkm(TBROK | TERRNO, cleanup, "Calling fclose failed.");

    if (chmod(file_name, mode))
        tst_brkm(TBROK | TERRNO, cleanup,
                 "Could not chmod test file %s.", file_name);

    if (chown(file_name, user_id, group_id))
        tst_brkm(TBROK | TERRNO, cleanup,
                 "Could not chown test file %s.", file_name);
}
コード例 #2
0
ファイル: execv01.c プロジェクト: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	pid_t pid;
	char *const args[] = { "execv01_child", "canary", NULL};
	char path[2048];

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	if (tst_get_path("execv01_child", path, sizeof(path)))
		tst_brkm(TCONF, NULL, "Couldn't find execv01_child in $PATH");

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		switch (pid = FORK_OR_VFORK()) {
		case 0:
			execv(path, args);
			tst_brkm(TFAIL | TERRNO, NULL,
			         "Failed to execute execv01_child");
		case -1:
			tst_brkm(TBROK, NULL, "fork failed");
		default:
			tst_record_childstatus(NULL, pid);
		}
	}

	tst_exit();
}
コード例 #3
0
ファイル: execve04.c プロジェクト: 1587/ltp
void setup(void)
{
	char path[PATH_MAX];

	if (tst_get_path(TEST_APP, path, sizeof(path))) {
		tst_brkm(TBROK, NULL,
		         "Couldn't found "TEST_APP" binary in $PATH");
	}

	tst_tmpdir();

	TST_CHECKPOINT_INIT(tst_rmdir);

	SAFE_CP(tst_rmdir, path, ".");
}
コード例 #4
0
ファイル: execve02.c プロジェクト: 1587/ltp
static void setup(void)
{
	char path[PATH_MAX];
	struct passwd *pwd;

	tst_require_root();

	if (tst_get_path(TEST_APP, path, sizeof(path))) {
		tst_brkm(TBROK, NULL,
		         "Couldn't found "TEST_APP" binary in $PATH");
	}

	tst_tmpdir();

	SAFE_CP(tst_rmdir, path, ".");
	SAFE_CHMOD(cleanup, TEST_APP, 0700);

	pwd = SAFE_GETPWNAM(tst_rmdir, USER_NAME);
	nobody_uid = pwd->pw_uid;
}