while (fgets(path, sizeof(path), fp) != NULL) { if (strstr(path, unique_field)) {
fclose(fp); /* strscpy is not available, use snprintf */
snprintf(out_dir, dir_len, "%s", buf.gl_pathv[i]);
ret = 0; goto out;
}
}
fclose(fp);
}
out:
globfree(&buf);
return ret;
}
staticbool event_exists(void)
{ int fd = open(enable_file, O_RDWR);
if (fd < 0) returnfalse;
close(fd);
returntrue;
}
staticint change_event(bool enable)
{ int fd = open(enable_file, O_RDWR); int ret;
if (fd < 0) return -1;
if (enable)
ret = write(fd, "1", 1); else
ret = write(fd, "0", 1);
close(fd);
if (ret == 1)
ret = 0; else
ret = -1;
return ret;
}
staticint event_delete(void)
{ int fd = open(data_file, O_RDWR); int ret;
if (fd < 0) return -1;
ret = ioctl(fd, DIAG_IOCSDEL, "__abi_event");
close(fd);
return ret;
}
staticint reg_enable_multi(void *enable, int size, int bit, int flags, char *args)
{ struct user_reg reg = {0}; char full_args[512] = {0}; int fd = open(data_file, O_RDWR); int len; int ret;
if (fd < 0) return -1;
len = snprintf(full_args, sizeof(full_args), "__abi_event %s", args);
if (len > sizeof(full_args)) {
ret = -E2BIG; goto out;
}
/* Should not be found in the same dir */
ASSERT_NE(0, strcmp(first_dir, second_dir));
/* First dir should still exist */
ASSERT_EQ(0, stat(first_dir, &buf));
/* Disabling first register should remove first dir */
ASSERT_EQ(0, reg_disable(&self->check, 0));
ASSERT_EQ(0, wait_for_delete(first_dir));
/* Second dir should still exist */
ASSERT_EQ(0, stat(second_dir, &buf));
/* Disabling second register should remove second dir */
ASSERT_EQ(0, reg_disable(&self->check, 1)); /* Ensure bit 1 and 2 are tied together, should not delete yet */
ASSERT_EQ(0, stat(second_dir, &buf));
ASSERT_EQ(0, reg_disable(&self->check, 2));
ASSERT_EQ(0, wait_for_delete(second_dir));
}
TEST_F(user, forks) { int i;
/* Ensure COW pages get updated after fork */
ASSERT_EQ(0, reg_enable(&self->check, sizeof(int), 0));
ASSERT_EQ(0, self->check);
if (fork() == 0) { /* Force COW */
self->check = 0;
/* Up to 1 sec for enablement */ for (i = 0; i < 10; ++i) {
usleep(100000);
if (self->check) exit(0);
}
exit(1);
}
/* Allow generous time for COW, then enable */
usleep(100000);
ASSERT_EQ(0, change_event(true));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.