This previous post describes how TCT Tool was written, It is using POSIX Message Queue to exchange data. Basic on work, TCT Tool's message queue implementation almost work, only the main problem is the sender could read it's sent data, this sound weird because the TCT Tool would read it's data that intended to be read by the TCT. On the Toll, this problem hung up the TCT.
I change the IPC implementation using UNIX Domain Socket, first with datagram socket, the problem was just like the message queue, the TCT Tool receive it's sent data. The TCT Tool was not work until I use reliable stream socket, here the source code.
Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts
Thursday, September 02, 2010
Wednesday, June 16, 2010
TCT Tool
TCT Tool is a application that do some privileged tasks in the TCT machine. By default, TCT run in non-privileged mode so it can't do for example sending ioctl to the ethernet driver, update the system time, and many more. They use POSIX message queue for communication. Thanks for Glynn Clements at linux-c-programming who helped me out with message queue descriptor permission.
http://pastebin.com/raw.php?i=x4X6G4uf
http://pastebin.com/raw.php?i=x4X6G4uf
Wednesday, April 28, 2010
FreeBSD
My FreeBSD Notes
- Setting FreeBSD mirror for pkg_add
#setenv PACKAGEROOT ftp://ftp.itb.ac.id
- Enable non root (UID 0) group to su
Add desired user's group at pam_group.so in /etc/pam.d/su
- Installing GNOME2
Set your favourite mirror by setting PACKAGEROOT variable
#pkg_add -r gnome2
#pkg_add -r xorg
Add gdm_enable="YES", hald_enable="YES" and gnome_enable="YES" to /etc/rc.conf
Add proc /proc procfs rw 0 0 to /etc/fstab
- Setting FreeBSD mirror for pkg_add
#setenv PACKAGEROOT ftp://ftp.itb.ac.id
- Enable non root (UID 0) group to su
Add desired user's group at pam_group.so in /etc/pam.d/su
- Installing GNOME2
Set your favourite mirror by setting PACKAGEROOT variable
#pkg_add -r gnome2
#pkg_add -r xorg
Add gdm_enable="YES", hald_enable="YES" and gnome_enable="YES" to /etc/rc.conf
Add proc /proc procfs rw 0 0 to /etc/fstab
Tuesday, March 23, 2010
Using Rsync
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.
Let's begin with by creating Rsync backup server, here an /etc/rsync.conf example configuration file
# rsync daemon configuration
uid = nobody
gid = nobody
use chroot = yes
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
[thinkpad]
uid = thinkpad
gid = thinkpad
path = /home/thinkpad/backup
comment = Thinkpad's backup directory
auth users = ajhwb
secrets file = /etc/rsyncd.secrets
read only = no
auth user is a comma separated list for user who will be accepted, you also need to provide secrets file when using this option. This a sample /etc/rsyncd.secrets file
# rsync secrets file
# format username:password for each line
ajhwb:my_password
In order to restricting another user to access this file, set it's file permission to
#chmod 600 /etc/rsyncd.secrets
If everything in set, we are ready to start rsync as daemon, for starting automatically use your system init startup script.
#rsync --daemon
This is a simple command used to backup (exactly is synchronizing) a directory into the server (in this case we use localhost)
rsync --azuv --delete --delete-after /hacking/rtpatch-2.4 ajhwb@localhost::ajhwb/rtpatch-2.4
To retrieve directory and it's contents
rsync --azuv --delete --delete-after ajhwb@localhost::ajhwb/rtpatch-2.4 /hacking/rtpatch-2.4
In this example, another host alternative format is rsync://ajhwb@localhost/ajhwb/rtpatch-2.4
Rsync is very flexible tool, comes with many options and interesting configurations, explore this by yourself. Happy syncing!
Rsync website http://rsync.samba.org/
Let's begin with by creating Rsync backup server, here an /etc/rsync.conf example configuration file
# rsync daemon configuration
uid = nobody
gid = nobody
use chroot = yes
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
[thinkpad]
uid = thinkpad
gid = thinkpad
path = /home/thinkpad/backup
comment = Thinkpad's backup directory
auth users = ajhwb
secrets file = /etc/rsyncd.secrets
read only = no
auth user is a comma separated list for user who will be accepted, you also need to provide secrets file when using this option. This a sample /etc/rsyncd.secrets file
# rsync secrets file
# format username:password for each line
ajhwb:my_password
In order to restricting another user to access this file, set it's file permission to
#chmod 600 /etc/rsyncd.secrets
If everything in set, we are ready to start rsync as daemon, for starting automatically use your system init startup script.
#rsync --daemon
This is a simple command used to backup (exactly is synchronizing) a directory into the server (in this case we use localhost)
rsync --azuv --delete --delete-after /hacking/rtpatch-2.4 ajhwb@localhost::ajhwb/rtpatch-2.4
To retrieve directory and it's contents
rsync --azuv --delete --delete-after ajhwb@localhost::ajhwb/rtpatch-2.4 /hacking/rtpatch-2.4
In this example, another host alternative format is rsync://ajhwb@localhost/ajhwb/rtpatch-2.4
Rsync is very flexible tool, comes with many options and interesting configurations, explore this by yourself. Happy syncing!
Rsync website http://rsync.samba.org/
Monday, March 22, 2010
UNIX exec family system call
This codes creating pipe for IPC, fork another process (child) and executing fortune with some cookies arguments. It also redirect child's stdout to it's writer pipe to be read by parent's pipe. exec() family calls never return except for errors, if this happen it is very bad ;p. exec() will replace it's calling process with a new image, since the kernel is not know where to continue after invoking exec() then the child just exit. Just to make sure you don't write codes after that exec() except for error checking, don't care how cool your codes, it just not work. Trust me heh?.
http://pastebin.com/raw.php?i=pceQuWjc
http://pastebin.com/raw.php?i=pceQuWjc
Tuesday, December 22, 2009
PThread RWLock
For thread synchronization, use of mutex (mutual exclusion) is a very common. Mutex doesn't provide more advanced synchronization, when one thread is locking a mutex, another thread can't acquire it until it has been released. It's very expensive syncronization for some case.
POSIX threading library provide another high level synchronization, a RWLock (read and write lock), when locking in read mode, another thread can acquire the read lock (shared lock) but not with the write lock, with write lock, another thread can't acquire the lock until it has been unlocked (exclusive lock). This clear, with a RWLock mechanism, we can't avoid expense of mutex when we try only to read. No inconsistency effect when some thread try to read the same protected data.
The POSIX functions for RWLock operation:
Lock initialization
pthread_rwlock_init()
Lock in read mode
pthread_rwlock_rdlock()
pthread_rwlock_tryrdlock()
Lock in write mode
pthread_rwlock_wrlock()
pthread_rwlock_trywrlock()
Release lock
pthread_rwlock_unlcok()
POSIX threading library provide another high level synchronization, a RWLock (read and write lock), when locking in read mode, another thread can acquire the read lock (shared lock) but not with the write lock, with write lock, another thread can't acquire the lock until it has been unlocked (exclusive lock). This clear, with a RWLock mechanism, we can't avoid expense of mutex when we try only to read. No inconsistency effect when some thread try to read the same protected data.
The POSIX functions for RWLock operation:
Lock initialization
pthread_rwlock_init()
Lock in read mode
pthread_rwlock_rdlock()
pthread_rwlock_tryrdlock()
Lock in write mode
pthread_rwlock_wrlock()
pthread_rwlock_trywrlock()
Release lock
pthread_rwlock_unlcok()
Thursday, July 02, 2009
Crontab
Ok, it's time to refreshing my memory about the Crontab, here is what should remember when adding or editing a crontab.
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
Example command are:
0 0 1 * * /usr/bin/rsync -avrt rsync://archive.fedoraproject.org/pub/archive/fedora/linux/updates/8/i386/ --exclude=debug/ /data/repo/fedora/updates/8/i386
This will run rsync for every month: first minute, hour and date in that month.
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
Example command are:
0 0 1 * * /usr/bin/rsync -avrt rsync://archive.fedoraproject.org/pub/archive/fedora/linux/updates/8/i386/ --exclude=debug/ /data/repo/fedora/updates/8/i386
This will run rsync for every month: first minute, hour and date in that month.
Friday, April 17, 2009
FreeBSD

Yeah, today i installed new FreeBSD 7.1 release. Have some difficulties but resolved them by reading FreeBSD's handbook. So, here my notes regarding FreeBSD:
- Put it's rc.files in /etc/rc.d
- Put system wide configuration in /etc/rc.conf (networking, service, etc.)
- Use pkg_add to install package from it's repository.
and... what you should know about FreeBSD:
- It's a preemptive multitasking operating system
- Can run in 32 or 64 bit platforms (x86, AMD64, Alpha, Itanium, UltraSPARC)
- SMP (Symmetric Multi Processor) support
- Can run X Server: thus we are able to use GNOME or KDE for desktop
- Offer memory protection for user-space application (don't touch me)
- Great TCP/IP support
- Binary compability: you may run a program which compiled in Linux, SVR4, SCO, BSDI, or NetBSD
- C codes ;p and many more
Did someone said: "...it's about like we see in Linux kernel?" indeed.
I'm now installing GNOME 2 using pkg_add, i will update this note when i was finished.
FreeBSD Project
Subscribe to:
Posts (Atom)