Machine Problem 3 - CSIE box

  • Final due date: 11:59 PM, 2019/01/16.
  • No late submissions.

Introduction

In MP3, we want you to practice how to use non-blocking I/O and handling signals.

CSIE box

CSIE box is a client-server service, with one client and one server (you can extend it to support multiple clients and get bouns). Server and client will both monitor a directory. The files in both side should always be same. The server and client communicate with each other through FIFO. Both should handle that FIFO may be accidently broken.

Required Features

Server

  1. Server will monitor a directory that already exist. Then, it will create FIFOs, and wait for client to connect.
  2. Server should not crash when client is disconnected.

Client

  1. Client will monitor an empty directory. If it is not empty, remove all content.
  2. Before connect to the Server, the monitored directory’s permission should set to 000 for preventing anyone to write it.
  3. Set to 700 after synced.
  4. Client will be terminate by SIGINT (ctrl+c). After the client receive this signal, client should remove the monitored directory.
  5. Client should not crash when server is disconnected.

File hierarchy and usage

Place a Makefile under our homework directory. The judge will run make to build a csie_box_server and csie_box_client executable in the same directory.

repo
├── MP0
├── MP1
└── MP2
└── MP3
    ├── Makefile
    └── other files

We will run the server by ./csie_box_server [CONFIG_FILE]. Your program should loads the specified config file with this example content.

fifo_path = /home/fifo_dir
directory = /home/resol/dir

According the the config, it creates two fifos, /home/fifo_dir/server_to_client.fifo and /home/fifo_dir/client_to_server.fifo on startup, and monitory the files in /home/resol/dir directory.

We will run the client by ./csie_box_client [CONFIG_FILE]. The config file’s format is same as the server.

  • If the config file is not readable, fifo cannot be created, exit with code EXIT_FAILURE.

Special notes

Judge and grading (15pt)

  1. Run csie_box_server. Check FIFOs exist. (2pt)
  2. Stop csie_box_server and run csie_box_client. Check the permission of monitored directory. (2pt)
  3. Run csie_box_server. Check the monitored directory has been synced. (2pt)
  4. edit the files in both side. Check the contents are always synced. (2pt)
  5. Stop csie_box_server. Check csie_box_client still alive. (1pt)
  6. Run csie_box_server and edit the files in both side. Check the contents are always synced. (2pt)
  7. Stop csie_box_client. Check the monitored directory has been removed and server still alive. (2pt)
  8. Run csie_box_client. Check the monitored directory has been synced with csie_box_server. (1pt)
  9. Stop all. Check FIFOs are closed. (1pt)

Bonus (pt)

  • Also sync the file infos (permission, atime, ctime, mtime) (1pt)
  • Support 3 clients. (2pt)
  • Support directory removal. (1pt)

Write a readme file if you have implemented any of them.

Guarantees

  • fifo_path is an empty directory.
  • The number of subdirectory in the monitored directory will be less than 10.
  • The directory will not be removed during monitoring.
  • Each file will be less than 10MB.
  • Interval between any operation or query is greater than one second.

Functions you may need

  • inotify
  • select
  • fifo
  • signal

Tips for Workstation Usage

https://wslab.csie.ntu.edu.tw/tips_for_workstation_usage.html

Simple Judge

judge.py This is a simple judge program. You can use it to test your code. It cover all judge steps with a small test case without bonus.

Usage

  • Put the judge.py into your MP3 directory
  • Run python3 judge.py

FAQ

  1. Create directory with permission 000.
    mkdir("xddir", 0);
    
    d---------  2 newslab newslab 4096 Dec 19 04:18 xddir
    
  2. The subdirectory can be create in a subdirectory.