1011
1015
#if LF_USE_ASCII_PID
1016
1020
#if LF_USE_DEV_NUMBERS
1020
/* Get our PID, and initialize the filename strings */
1024
/* Get our PID, and initialize the filename strings */
1023
1027
#if !LF_USE_DEV_NUMBERS
1024
modemname = strrchr(modem_port, '/');
1025
sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX,
1026
(modemname ? (modemname + 1) : modem_port));
1028
modemname = strrchr(modem_port, '/');
1031
if( SM_BUF > (1 + strlen(LF_PATH) + strlen(LF_PREFIX) + strlen(modemname)))
1032
sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX, (modemname + 1));
1035
SePErrorF("Buffer too small for lock filename in lock_tty(): %s", modemname, "", "");
1041
if( SM_BUF > (1 + strlen(LF_PATH) + strlen(LF_PREFIX) + strlen(modem_port)))
1042
sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX, (modem_port));
1045
SePErrorF("Buffer too small for lock filename in lock_tty(): %s", modem_port, "", "");
1028
if(stat(modem_port, &mbuf) < 0) {
1029
SePErrorF("could not stat modem port %s", modem_port, "", "");
1032
sprintf(lckf,"%s/%s%03u.%03u.%03u", LF_PATH, LF_PREFIX, major(mbuf.st_dev),
1033
major(mbuf.st_rdev), minor(mbuf.st_rdev));
1051
if(stat(modem_port, &mbuf) < 0) {
1052
SePErrorF("could not stat modem port %s", modem_port, "", "");
1055
if( SM_BUF > (10 + strlen(LF_PATH) + strlen(LF_PREFIX)))
1056
sprintf(lckf,"%s/%s%03u.%03u.%03u", LF_PATH, LF_PREFIX, major(mbuf.st_dev),
1057
major(mbuf.st_rdev), minor(mbuf.st_rdev));
1060
SePErrorF("Buffer too small for lock filename in lock_tty():", "", "", "");
1034
1063
#endif /* LF_USE_DEV_NUMBERS */
1036
sprintf(ltmp, "%s/%s%d", LF_PATH, "LTMP.", pid);
1037
/* Create the LTMP.<pid> file and scribble our PID in it */
1039
if ((lfd = creat(ltmp, 0644)) == -1) {
1040
SePErrorF("Could not create temporary lock file %s", ltmp, "", "");
1065
if( SM_BUF > (11 + strlen(LF_PATH)))
1066
sprintf(ltmp, "%s/%s%d", LF_PATH, "LTMP.", pid);
1069
SePErrorF("Buffer too small for ltmp filename in lock_tty():", "", "", "");
1072
/* Create the LTMP.<pid> file and scribble our PID in it */
1074
if ((lfd = creat(ltmp, 0644)) == -1) {
1075
SePErrorF("Could not create temporary lock file %s", ltmp, "", "");
1044
1079
#if LF_USE_ASCII_PID
1045
sprintf(pidstr, "%10d\n", pid);
1046
write(lfd, pidstr, 11);
1080
/* pidstr is easily large enough */
1081
sprintf(pidstr, "%10d\n", pid);
1082
write(lfd, pidstr, 11);
1048
write(lfd, (char*)&pid, sizeof(pid));
1084
write(lfd, (char*)&pid, sizeof(pid));
1053
1089
* Attempt to link directly - if it works, we're done.