microcom: tiny shrink, adding comments

This commit is contained in:
Denis Vlasenko 2008-02-19 18:26:40 +00:00
parent 671ca33aa1
commit 624188aec0

View File

@ -51,18 +51,17 @@ int microcom_main(int argc, char **argv)
enum { enum {
OPT_X = 1 << 0, // do not respect Ctrl-X, Ctrl-@ OPT_X = 1 << 0, // do not respect Ctrl-X, Ctrl-@
OPT_s = 1 << 1, // baudrate OPT_s = 1 << 1, // baudrate
OPT_d = 1 << 2, // wait for device response, msecs OPT_d = 1 << 2, // wait for device response, ms
OPT_t = 1 << 3, // timeout, ms OPT_t = 1 << 3, // timeout, ms
}; };
speed_t speed = 9600; speed_t speed = 9600;
int delay = -1; int delay = -1;
int timeout = -1; int timeout = -1;
unsigned opts;
// fetch options // fetch options
unsigned opts; opt_complementary = "=1:s+:d+:t+"; // exactly one arg, numeric options
opt_complementary = "=1:s+:d+:t+"; // exactly one arg should be there
opts = getopt32(argv, "Xs:d:t:", &speed, &delay, &timeout); opts = getopt32(argv, "Xs:d:t:", &speed, &delay, &timeout);
// argc -= optind; // argc -= optind;
argv += optind; argv += optind;
@ -71,14 +70,16 @@ int microcom_main(int argc, char **argv)
device_lock_file = xasprintf("/var/lock/LCK..%s", device_lock_file); device_lock_file = xasprintf("/var/lock/LCK..%s", device_lock_file);
sfd = open(device_lock_file, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644); sfd = open(device_lock_file, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644);
if (sfd < 0) { if (sfd < 0) {
// device already locked -> bail out
if (errno == EEXIST) if (errno == EEXIST)
bb_perror_msg_and_die("can't create %s", device_lock_file); bb_perror_msg_and_die("can't create %s", device_lock_file);
// can't create lock -> don't care
if (ENABLE_FEATURE_CLEAN_UP) if (ENABLE_FEATURE_CLEAN_UP)
free(device_lock_file); free(device_lock_file);
device_lock_file = NULL; device_lock_file = NULL;
} } else {
if (sfd > 0) { // %4d to make concurrent mgetty (if any) happy.
// %4d to make mgetty happy. It treats 4-bytes lock files as binary, // Mgetty treats 4-bytes lock files as binary,
// not text, PID. Making 5+ char file. Brrr... // not text, PID. Making 5+ char file. Brrr...
char *s = xasprintf("%4d\n", getpid()); char *s = xasprintf("%4d\n", getpid());
write(sfd, s, strlen(s)); write(sfd, s, strlen(s));