Fix permission management for IPC and also for EXT2.

This commit is contained in:
Enrico Fraccaroli (Galfurian)
2023-05-23 13:40:02 -04:00
parent e7c0334ac0
commit 3ae9258347
12 changed files with 394 additions and 400 deletions
+1 -1
View File
@@ -87,8 +87,8 @@ set(TESTS
t_gid.c
# Test semaphores.
t_semget.c
t_sem1.c
t_semflg.c
t_semop.c
# Test scheduling feedback tests.
t_schedfb.c
)
+6 -15
View File
@@ -1,4 +1,8 @@
//test
/// @file t_semflg.c
/// @brief Tests some of the IPC flags.
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "sys/errno.h"
#include "sys/sem.h"
@@ -7,20 +11,7 @@
#include "fcntl.h"
#include "stdio.h"
/*
Testing IPC_NOWAIT flag.
*/
void semid_print(struct semid_ds *temp)
{
printf("pid, IPC_KEY, Semid, semop, change: %d, %d, %d, %d, %d\n", temp->sem_perm.uid, temp->sem_perm.key, temp->semid, temp->sem_otime, temp->sem_ctime);
for (int i = 0; i < (temp->sem_nsems); i++) {
printf("%d semaphore:\n", i + 1);
printf("value: %d, pid %d, process waiting %d\n", temp->sems[i].sem_val, temp->sems[i].sem_pid, temp->sems[i].sem_zcnt);
}
}
int main()
int main(int argc, char *argv[])
{
struct sembuf op[2];
union semun arg;
+8 -18
View File
@@ -1,4 +1,10 @@
//test
/// @file t_semget.c
/// @brief This program creates a son and then performs a blocking operation on
/// a semaphore. The son sleeps for five seconds and then it wakes up his
/// father and then it deletes the semaphore.
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/unistd.h"
#include "sys/errno.h"
#include "sys/sem.h"
@@ -7,23 +13,7 @@
#include "fcntl.h"
#include "stdio.h"
/*
Testing Semaphores.
This program creates a son and then performs a blocking operation on a semaphore. The son sleeps for
five seconds and then it wakes up his father and then it deletes the semaphore.
*/
void semid_print(struct semid_ds *temp)
{
printf("pid, IPC_KEY, Semid, semop, change: %d, %d, %d, %d, %d\n", temp->sem_perm.uid, temp->sem_perm.key, temp->semid, temp->sem_otime, temp->sem_ctime);
for (int i = 0; i < (temp->sem_nsems); i++) {
printf("%d semaphore:\n", i + 1);
printf("value: %d, pid %d, process waiting %d\n", temp->sems[i].sem_val, temp->sems[i].sem_pid, temp->sems[i].sem_zcnt);
}
}
int main()
int main(int argc, char *argv[])
{
struct sembuf op_child;
struct sembuf op_father[3];
@@ -1,4 +1,8 @@
//test
/// @file t_semop.c
/// @brief Tests semop between processes.
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "sys/sem.h"
#include "stdio.h"
#include "sys/ipc.h"
@@ -8,21 +12,7 @@
#include "sys/unistd.h"
#include "fcntl.h"
/*
First test of System V Semaphores.
Correct output should be: Corso di Sistemi Operativi.
*/
void semid_print(struct semid_ds *temp)
{
printf("pid, IPC_KEY, Semid, semop, change: %d, %d, %d, %d, %d\n", temp->sem_perm.uid, temp->sem_perm.key, temp->semid, temp->sem_otime, temp->sem_ctime);
for (int i = 0; i < (temp->sem_nsems); i++) {
printf("%d semaphore:\n", i + 1);
printf("value: %d, pid %d, process waiting %d\n", temp->sems[i].sem_val, temp->sems[i].sem_pid, temp->sems[i].sem_zcnt);
}
}
int main()
int main(int argc, char *argv[])
{
struct sembuf sops[6];
sops[0].sem_num = 0;
@@ -52,7 +42,7 @@ int main()
int status;
//create a semaphore set
int semid = semget(IPC_PRIVATE, 4, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
int semid = semget(17, 4, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
//set the values of the semaphores
unsigned short values[] = { 0, 0, 0, 1 };