safe to use shutdown -h now to bring down system

I'm using the BeagleBoard xM as part of a robotics project and I've
decided to program the user button to safely bring down the system
when pressed. I'm running Ubuntu Maverick from rcn-ee.net with the
additional packages installed for the xfce desktop. I've written a C++
program that monitors for user button presses from /dev/input/event4,
and then uses an execl() call to issue sudo shutdown -h now command to
bring down the system. I'm wondering, is the best command to use to
safely bring down the system? Also will I need to add any code (I was
thinking some type of signal handler) to other programs I've written
so that they will exit gracefully?

Thanks,

Graham Holland