Ejemplo n.º 1
0
int
main (int argc, char *argv[])
{
    int fd;
    const char *file = "test-flock.txt";

    /* Open a non-empty file for testing. */
    fd = open (file, O_RDWR | O_CREAT | O_TRUNC, 0644);
    ASSERT (fd >= 0);
    ASSERT (write (fd, "hello", 5) == 5);

#if defined __linux__
    /* Invalid operation codes are rejected by the Linux implementation and by
       the gnulib replacement,  but not by the MacOS X implementation.  */
    ASSERT (flock (fd, LOCK_SH | LOCK_EX) == -1);
    ASSERT (errno == EINVAL);
    ASSERT (flock (fd, LOCK_SH | LOCK_UN) == -1);
    ASSERT (errno == EINVAL);
    ASSERT (flock (fd, LOCK_EX | LOCK_UN) == -1);
    ASSERT (errno == EINVAL);
    ASSERT (flock (fd, 0) == -1);
    ASSERT (errno == EINVAL);
#endif

    test_shared (file, fd);
    test_exclusive (file, fd);

    /* Close and remove the test file. */
    ASSERT (close (fd) == 0);
    ASSERT (unlink (file) == 0);

    return 0;
}
Ejemplo n.º 2
0
static void proc_mutex(CuTest *tc)
{
#if APR_HAS_FORK
    apr_status_t rv;
    const char *shmname = "tpm.shm";
    apr_shm_t *shm;

    /* Use anonymous shm if available. */
    rv = apr_shm_create(&shm, sizeof(int), NULL, p);
    if (rv == APR_ENOTIMPL) {
        apr_file_remove(shmname, p);
        rv = apr_shm_create(&shm, sizeof(int), shmname, p);
    }

    apr_assert_success(tc, "create shm segment", rv);

    x = apr_shm_baseaddr_get(shm);
    test_exclusive(tc, NULL);
#else
    CuNotImpl(tc, "APR lacks fork() support");
#endif
}