sma_cp — Lock-safe file copy
Theme: Configure
Who Is It For? System Administrator
What is it?
sma_cp copies a file to a lock-managed destination, acquiring a write lock on the target before copying to prevent conflicts when another process is simultaneously reading the file.
Use sma_cp in place of the standard cp command when updating files that the agent reads at runtime — specifically the FAD control file and the SMA_RM configuration file — to avoid crashes caused by a read/write race condition.
- Use
sma_cpwhen updating a FAD control file that is actively monitored by a runningsma_fadprocess. - Use
sma_cpwhen updatingSMA_RM.confwhile thesma_RMprocess is running. - Use the standard
cpcommand for all other file copy operations.sma_cpis only needed for lock-managed agent configuration files.
Syntax
sma_cp <from_file> <to_file>
| Argument | Description |
|---|---|
<from_file> | Full path to the source file to copy from |
<to_file> | Full path of the destination file to copy to. The destination must be a lock-managed file. |
Behavior
sma_cpacquires an exclusive write lock on the destination file.- If the lock is not available within 5 seconds,
sma_cpexits with an error. - Once the lock is held, the source file is copied to the destination byte-by-byte.
- The destination file is truncated to the source file size after copying.
- The lock is released when the destination file is closed.
The following command replaces an active FAD control file with an updated version:
sma_cp /tmp/control_new.xml $LSAM_ROOT/fad/$SMA_LSAM_INSTANCE/control/control.xml
Exit codes
| Code | Condition |
|---|---|
0 | Success — file copied successfully |
-1 | Error — destination stat failed, file open failed, lock acquisition timed out, truncate failed, or copy failed |
Exception handling
sma_cp returns -1 with no file copied — The write lock on the destination could not be acquired within 5 seconds. Another process is holding the lock. — Wait for the lock-holding process to release the file, then retry. If the condition persists, check that sma_fad or sma_RM is running normally.